|
10 | 10 |
|
11 | 11 | from ui_dialogBase import Ui_GdalToolsDialog as Ui_Dialog
|
12 | 12 | import GdalTools_utils as Utils
|
| 13 | +from .. import resources_rc |
13 | 14 |
|
14 | 15 | import os, platform
|
15 | 16 |
|
@@ -39,6 +40,12 @@ def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):
|
39 | 40 | self.setupUi(self)
|
40 | 41 | self.arguments = QStringList()
|
41 | 42 |
|
| 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 | + |
42 | 49 | self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
|
43 | 50 | self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept)
|
44 | 51 | self.connect(self.buttonBox, SIGNAL("helpRequested()"), self.help)
|
@@ -66,6 +73,32 @@ def setPluginCommand(self, cmd):
|
66 | 73 | else:
|
67 | 74 | self.helpFileName = cmd + ".html"
|
68 | 75 |
|
| 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 | + |
69 | 102 | def reject(self):
|
70 | 103 | if self.process.state() != QProcess.NotRunning:
|
71 | 104 | 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):
|
98 | 131 | url = QUrl.fromLocalFile(helpPath + '/' + self.helpFileName)
|
99 | 132 | QDesktopServices.openUrl(url)
|
100 | 133 |
|
101 |
| - def setCommandViewerEnabled(self, enable): |
102 |
| - self.textEditCommand.setEnabled( enable ) |
103 |
| - |
104 | 134 | # called when a value in the plugin widget interface changed
|
105 | 135 | def refreshArgs(self, args):
|
106 | 136 | self.arguments = args
|
107 | 137 |
|
108 |
| - if not self.textEditCommand.isEnabled(): |
109 |
| - self.textEditCommand.setText(self.command) |
| 138 | + if not self.commandIsEnabled(): |
| 139 | + self.textEditCommand.setPlainText(self.command) |
110 | 140 | else:
|
111 |
| - self.textEditCommand.setText(self.command + " " + Utils.escapeAndJoin(self.arguments)) |
| 141 | + self.textEditCommand.setPlainText(self.command + " " + Utils.escapeAndJoin(self.arguments)) |
112 | 142 |
|
113 | 143 | # enables the OK button
|
114 | 144 | def enableRun(self, enable = True):
|
115 | 145 | self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
|
116 | 146 |
|
117 | 147 | # start the command execution
|
118 | 148 | def onRun(self):
|
119 |
| - self.process.start(self.command, self.arguments, QIODevice.ReadOnly) |
120 | 149 | self.enableRun(False)
|
121 | 150 | 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) |
132 | 155 |
|
133 | 156 | # stop the command execution
|
134 | 157 | def stop(self):
|
|
0 commit comments