Skip to content
Permalink
Browse files

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

  • Loading branch information
brushtyler committed Oct 6, 2011
1 parent 47f82ab commit dd6a594178d6d480ff9585fde12fb7987c81e2d1
@@ -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.
Binary file not shown.
@@ -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>
@@ -10,6 +10,7 @@

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 @@ def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):
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 @@ def setPluginCommand(self, cmd):
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,37 +131,27 @@ def onHelp(self):
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):
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)

# 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):
@@ -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/>
@@ -22,6 +22,7 @@ def __init__(self, iface, commandName, parent = None):
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())

0 comments on commit dd6a594

Please sign in to comment.
You can’t perform that action at this time.