Skip to content

Commit

Permalink
[FEATURE] Make the gdaltools command editable to fix #3041
Browse files Browse the repository at this point in the history
Conflicts:

	python/plugins/GdalTools/__init__.py
	python/plugins/GdalTools/resources.qrc
  • Loading branch information
brushtyler authored and mach0 committed Nov 13, 2011
1 parent caa2146 commit 9c6f1c8
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 38 deletions.
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.26"
return "Version 1.2.28"
def qgisMinimumVersion():
return "1.0"
def icon():
Expand Down
Binary file added python/plugins/GdalTools/icons/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added python/plugins/GdalTools/icons/reset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion python/plugins/GdalTools/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/" >
<qresource prefix="/">
<file>icons/contour.png</file>
<file>icons/merge.png</file>
<file>icons/polygonize.png</file>
Expand All @@ -20,5 +20,8 @@
<file>icons/tileindex.png</file>
<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>
57 changes: 40 additions & 17 deletions python/plugins/GdalTools/tools/dialogBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
94 changes: 75 additions & 19 deletions python/plugins/GdalTools/tools/dialogBase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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>
Expand All @@ -57,7 +114,6 @@
</layout>
</widget>
<tabstops>
<tabstop>textEditCommand</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
Expand Down
1 change: 1 addition & 0 deletions python/plugins/GdalTools/tools/widgetPluginBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 9c6f1c8

Please sign in to comment.