Skip to content

Commit 9c6f1c8

Browse files
brushtylermach0
authored andcommittedNov 13, 2011
[FEATURE] Make the gdaltools command editable to fix #3041
Conflicts: python/plugins/GdalTools/__init__.py python/plugins/GdalTools/resources.qrc
1 parent caa2146 commit 9c6f1c8

File tree

7 files changed

+121
-38
lines changed

7 files changed

+121
-38
lines changed
 

‎python/plugins/GdalTools/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def name():
2222
def description():
2323
return "Integrate gdal tools into qgis"
2424
def version():
25-
return "Version 1.2.26"
25+
return "Version 1.2.28"
2626
def qgisMinimumVersion():
2727
return "1.0"
2828
def icon():
1.09 KB
Loading
1.39 KB
Loading

‎python/plugins/GdalTools/resources.qrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/" >
2+
<qresource prefix="/">
33
<file>icons/contour.png</file>
44
<file>icons/merge.png</file>
55
<file>icons/polygonize.png</file>
@@ -20,5 +20,8 @@
2020
<file>icons/tileindex.png</file>
2121
<file>icons/about.png</file>
2222
<file>icons/dem.png</file>
23+
<file>icons/projection-export.png</file>
24+
<file>icons/edit.png</file>
25+
<file>icons/reset.png</file>
2326
</qresource>
2427
</RCC>

‎python/plugins/GdalTools/tools/dialogBase.py

+40-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ui_dialogBase import Ui_GdalToolsDialog as Ui_Dialog
1212
import GdalTools_utils as Utils
13+
from .. import resources_rc
1314

1415
import os, platform
1516

@@ -39,6 +40,12 @@ def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):
3940
self.setupUi(self)
4041
self.arguments = QStringList()
4142

43+
self.editCmdBtn.setIcon( QIcon(":/icons/edit.png") )
44+
self.connect(self.editCmdBtn, SIGNAL("toggled(bool)"), self.editCommand)
45+
self.resetCmdBtn.setIcon( QIcon(":/icons/reset.png") )
46+
self.connect(self.resetCmdBtn, SIGNAL("clicked()"), self.resetCommand)
47+
self.editCommand( False )
48+
4249
self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
4350
self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept)
4451
self.connect(self.buttonBox, SIGNAL("helpRequested()"), self.help)
@@ -66,6 +73,32 @@ def setPluginCommand(self, cmd):
6673
else:
6774
self.helpFileName = cmd + ".html"
6875

76+
77+
def editCommand(self, enabled):
78+
if not self.commandIsEnabled():
79+
return
80+
self.editCmdBtn.setChecked( enabled )
81+
self.resetCmdBtn.setEnabled( enabled )
82+
self.textEditCommand.setReadOnly( not enabled )
83+
self.controlsWidget.setEnabled( not enabled )
84+
self.emit( SIGNAL("refreshArgs()") )
85+
86+
def resetCommand(self):
87+
if not self.commandIsEditable():
88+
return
89+
self.emit( SIGNAL("refreshArgs()") )
90+
91+
def commandIsEditable(self):
92+
return self.commandIsEnabled() and self.editCmdBtn.isChecked()
93+
94+
def setCommandViewerEnabled(self, enable):
95+
if not enable:
96+
self.editCommand( False )
97+
self.commandWidget.setEnabled( enable )
98+
99+
def commandIsEnabled(self):
100+
return self.commandWidget.isEnabled()
101+
69102
def reject(self):
70103
if self.process.state() != QProcess.NotRunning:
71104
ret = QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "The command is still running. \nDo you want terminate it anyway?" ), QMessageBox.Yes | QMessageBox.No)
@@ -98,37 +131,27 @@ def onHelp(self):
98131
url = QUrl.fromLocalFile(helpPath + '/' + self.helpFileName)
99132
QDesktopServices.openUrl(url)
100133

101-
def setCommandViewerEnabled(self, enable):
102-
self.textEditCommand.setEnabled( enable )
103-
104134
# called when a value in the plugin widget interface changed
105135
def refreshArgs(self, args):
106136
self.arguments = args
107137

108-
if not self.textEditCommand.isEnabled():
109-
self.textEditCommand.setText(self.command)
138+
if not self.commandIsEnabled():
139+
self.textEditCommand.setPlainText(self.command)
110140
else:
111-
self.textEditCommand.setText(self.command + " " + Utils.escapeAndJoin(self.arguments))
141+
self.textEditCommand.setPlainText(self.command + " " + Utils.escapeAndJoin(self.arguments))
112142

113143
# enables the OK button
114144
def enableRun(self, enable = True):
115145
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
116146

117147
# start the command execution
118148
def onRun(self):
119-
self.process.start(self.command, self.arguments, QIODevice.ReadOnly)
120149
self.enableRun(False)
121150
self.setCursor(Qt.WaitCursor)
122-
123-
"""
124-
try:
125-
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments))
126-
except UnicodeEncodeError:
127-
try:
128-
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments)).encode('cp866', 'replace')
129-
except:
130-
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments)).encode('ascii', 'replace')
131-
"""
151+
if not self.commandIsEditable():
152+
self.process.start(self.command, self.arguments, QIODevice.ReadOnly)
153+
else:
154+
self.process.start(self.textEditCommand.toPlainText(), QIODevice.ReadOnly)
132155

133156
# stop the command execution
134157
def stop(self):

‎python/plugins/GdalTools/tools/dialogBase.ui

+75-19
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
<property name="windowTitle">
1414
<string>Dialog</string>
1515
</property>
16-
<layout class="QVBoxLayout" name="verticalLayout">
16+
<layout class="QVBoxLayout" name="verticalLayout_2">
1717
<item>
18-
<layout class="QVBoxLayout" name="pluginLayout">
19-
<property name="margin">
20-
<number>0</number>
21-
</property>
22-
</layout>
18+
<widget class="QWidget" name="controlsWidget" native="true">
19+
<layout class="QVBoxLayout" name="pluginLayout">
20+
<property name="margin">
21+
<number>0</number>
22+
</property>
23+
</layout>
24+
</widget>
2325
</item>
2426
<item>
2527
<widget class="QCheckBox" name="loadCheckBox">
@@ -29,19 +31,74 @@
2931
</widget>
3032
</item>
3133
<item>
32-
<widget class="QTextEdit" name="textEditCommand">
33-
<property name="minimumSize">
34-
<size>
35-
<width>0</width>
36-
<height>0</height>
37-
</size>
38-
</property>
39-
<property name="readOnly">
40-
<bool>true</bool>
41-
</property>
42-
<property name="textInteractionFlags">
43-
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
34+
<widget class="QWidget" name="commandWidget" native="true">
35+
<property name="locale">
36+
<locale language="English" country="UnitedStates"/>
4437
</property>
38+
<layout class="QGridLayout" name="gridLayout">
39+
<property name="margin">
40+
<number>0</number>
41+
</property>
42+
<property name="horizontalSpacing">
43+
<number>6</number>
44+
</property>
45+
<item row="0" column="0">
46+
<widget class="QPlainTextEdit" name="textEditCommand">
47+
<property name="minimumSize">
48+
<size>
49+
<width>0</width>
50+
<height>0</height>
51+
</size>
52+
</property>
53+
<property name="readOnly">
54+
<bool>true</bool>
55+
</property>
56+
</widget>
57+
</item>
58+
<item row="0" column="1">
59+
<layout class="QVBoxLayout" name="verticalLayout">
60+
<item>
61+
<widget class="QToolButton" name="editCmdBtn">
62+
<property name="toolTip">
63+
<string>Edit</string>
64+
</property>
65+
<property name="text">
66+
<string>Edit</string>
67+
</property>
68+
<property name="checkable">
69+
<bool>true</bool>
70+
</property>
71+
</widget>
72+
</item>
73+
<item>
74+
<widget class="QToolButton" name="resetCmdBtn">
75+
<property name="enabled">
76+
<bool>false</bool>
77+
</property>
78+
<property name="toolTip">
79+
<string>Reset</string>
80+
</property>
81+
<property name="text">
82+
<string>Reset</string>
83+
</property>
84+
</widget>
85+
</item>
86+
<item>
87+
<spacer name="verticalSpacer">
88+
<property name="orientation">
89+
<enum>Qt::Vertical</enum>
90+
</property>
91+
<property name="sizeHint" stdset="0">
92+
<size>
93+
<width>20</width>
94+
<height>40</height>
95+
</size>
96+
</property>
97+
</spacer>
98+
</item>
99+
</layout>
100+
</item>
101+
</layout>
45102
</widget>
46103
</item>
47104
<item>
@@ -57,7 +114,6 @@
57114
</layout>
58115
</widget>
59116
<tabstops>
60-
<tabstop>textEditCommand</tabstop>
61117
<tabstop>buttonBox</tabstop>
62118
</tabstops>
63119
<resources/>

‎python/plugins/GdalTools/tools/widgetPluginBase.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self, iface, commandName, parent = None):
2222
self.connect(self.base, SIGNAL("helpClicked()"), self.onHelp)
2323

2424
self.connect(self.base, SIGNAL("finished(bool)"), self.finished)
25+
self.connect(self.base, SIGNAL("refreshArgs()"), self.someValueChanged)
2526

2627
def someValueChanged(self):
2728
self.emit(SIGNAL("valuesChanged(const QStringList &)"), self.getArguments())

0 commit comments

Comments
 (0)
Please sign in to comment.