[FEATURE] Make the gdaltools command editable to fix #3041

This commit is contained in:
Giuseppe Sucameli 2011-10-07 01:26:13 +02:00
parent 47f82ab044
commit dd6a594178
7 changed files with 120 additions and 38 deletions

View File

@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.27"
return "Version 1.2.28"
def qgisMinimumVersion():
return "1.0"
def icon():

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/" >
<qresource prefix="/">
<file>icons/contour.png</file>
<file>icons/merge.png</file>
<file>icons/polygonize.png</file>
@ -21,5 +21,7 @@
<file>icons/about.png</file>
<file>icons/dem.png</file>
<file>icons/projection-export.png</file>
<file>icons/edit.png</file>
<file>icons/reset.png</file>
</qresource>
</RCC>

View File

@ -10,6 +10,7 @@ import os
from ui_dialogBase import Ui_GdalToolsDialog as Ui_Dialog
import GdalTools_utils as Utils
from .. import resources_rc
import os, platform
@ -39,6 +40,12 @@ class GdalToolsBaseDialog(QDialog, Ui_Dialog):
self.setupUi(self)
self.arguments = QStringList()
self.editCmdBtn.setIcon( QIcon(":/icons/edit.png") )
self.connect(self.editCmdBtn, SIGNAL("toggled(bool)"), self.editCommand)
self.resetCmdBtn.setIcon( QIcon(":/icons/reset.png") )
self.connect(self.resetCmdBtn, SIGNAL("clicked()"), self.resetCommand)
self.editCommand( False )
self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject)
self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept)
self.connect(self.buttonBox, SIGNAL("helpRequested()"), self.help)
@ -66,6 +73,32 @@ class GdalToolsBaseDialog(QDialog, Ui_Dialog):
else:
self.helpFileName = cmd + ".html"
def editCommand(self, enabled):
if not self.commandIsEnabled():
return
self.editCmdBtn.setChecked( enabled )
self.resetCmdBtn.setEnabled( enabled )
self.textEditCommand.setReadOnly( not enabled )
self.controlsWidget.setEnabled( not enabled )
self.emit( SIGNAL("refreshArgs()") )
def resetCommand(self):
if not self.commandIsEditable():
return
self.emit( SIGNAL("refreshArgs()") )
def commandIsEditable(self):
return self.commandIsEnabled() and self.editCmdBtn.isChecked()
def setCommandViewerEnabled(self, enable):
if not enable:
self.editCommand( False )
self.commandWidget.setEnabled( enable )
def commandIsEnabled(self):
return self.commandWidget.isEnabled()
def reject(self):
if self.process.state() != QProcess.NotRunning:
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,17 +131,14 @@ class GdalToolsBaseDialog(QDialog, Ui_Dialog):
url = QUrl.fromLocalFile(helpPath + '/' + self.helpFileName)
QDesktopServices.openUrl(url)
def setCommandViewerEnabled(self, enable):
self.textEditCommand.setEnabled( enable )
# called when a value in the plugin widget interface changed
def refreshArgs(self, args):
self.arguments = args
if not self.textEditCommand.isEnabled():
self.textEditCommand.setText(self.command)
if not self.commandIsEnabled():
self.textEditCommand.setPlainText(self.command)
else:
self.textEditCommand.setText(self.command + " " + Utils.escapeAndJoin(self.arguments))
self.textEditCommand.setPlainText(self.command + " " + Utils.escapeAndJoin(self.arguments))
# enables the OK button
def enableRun(self, enable = True):
@ -116,19 +146,12 @@ class GdalToolsBaseDialog(QDialog, Ui_Dialog):
# start the command execution
def onRun(self):
self.process.start(self.command, self.arguments, QIODevice.ReadOnly)
self.enableRun(False)
self.setCursor(Qt.WaitCursor)
"""
try:
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments))
except UnicodeEncodeError:
try:
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments)).encode('cp866', 'replace')
except:
print "Debug: " + self.command + " " + unicode(Utils.escapeAndJoin(self.arguments)).encode('ascii', 'replace')
"""
if not self.commandIsEditable():
self.process.start(self.command, self.arguments, QIODevice.ReadOnly)
else:
self.process.start(self.textEditCommand.toPlainText(), QIODevice.ReadOnly)
# stop the command execution
def stop(self):

View File

@ -13,13 +13,15 @@
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="pluginLayout">
<property name="margin">
<number>0</number>
</property>
</layout>
<widget class="QWidget" name="controlsWidget" native="true">
<layout class="QVBoxLayout" name="pluginLayout">
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="loadCheckBox">
@ -29,19 +31,74 @@
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEditCommand">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
<widget class="QWidget" name="commandWidget" native="true">
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QPlainTextEdit" name="textEditCommand">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="editCmdBtn">
<property name="toolTip">
<string>Edit</string>
</property>
<property name="text">
<string>Edit</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="resetCmdBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Reset</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
@ -57,7 +114,6 @@
</layout>
</widget>
<tabstops>
<tabstop>textEditCommand</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>

View File

@ -22,6 +22,7 @@ class GdalToolsBasePluginWidget:
self.connect(self.base, SIGNAL("helpClicked()"), self.onHelp)
self.connect(self.base, SIGNAL("finished(bool)"), self.finished)
self.connect(self.base, SIGNAL("refreshArgs()"), self.someValueChanged)
def someValueChanged(self):
self.emit(SIGNAL("valuesChanged(const QStringList &)"), self.getArguments())