Skip to content
Permalink
Browse files

GdalTools: new style signals

  • Loading branch information
jef-n committed Mar 21, 2016
1 parent c55f8b7 commit 9db908ccbc2257d466c0593738944a08cea8a8bc
Showing with 608 additions and 610 deletions.
  1. +50 −49 python/plugins/GdalTools/GdalTools.py
  2. +1 −1 python/plugins/GdalTools/__init__.py
  3. +11 −10 python/plugins/GdalTools/tools/GdalTools_utils.py
  4. +33 −30 python/plugins/GdalTools/tools/dialogBase.py
  5. +1 −1 python/plugins/GdalTools/tools/dialogExtractProjection.ui
  6. +3 −4 python/plugins/GdalTools/tools/dialogSRS.py
  7. +28 −28 python/plugins/GdalTools/tools/doBuildVRT.py
  8. +21 −22 python/plugins/GdalTools/tools/doClipper.py
  9. +12 −12 python/plugins/GdalTools/tools/doContour.py
  10. +23 −24 python/plugins/GdalTools/tools/doDEM.py
  11. +21 −20 python/plugins/GdalTools/tools/doExtractProj.py
  12. +24 −24 python/plugins/GdalTools/tools/doFillNodata.py
  13. +23 −23 python/plugins/GdalTools/tools/doGrid.py
  14. +11 −11 python/plugins/GdalTools/tools/doInfo.py
  15. +24 −24 python/plugins/GdalTools/tools/doMerge.py
  16. +10 −11 python/plugins/GdalTools/tools/doNearBlack.py
  17. +16 −16 python/plugins/GdalTools/tools/doOverview.py
  18. +20 −20 python/plugins/GdalTools/tools/doPctRgb.py
  19. +12 −12 python/plugins/GdalTools/tools/doPolygonize.py
  20. +16 −16 python/plugins/GdalTools/tools/doProjection.py
  21. +13 −14 python/plugins/GdalTools/tools/doProximity.py
  22. +15 −15 python/plugins/GdalTools/tools/doRasterize.py
  23. +20 −20 python/plugins/GdalTools/tools/doRgbPct.py
  24. +14 −13 python/plugins/GdalTools/tools/doSettings.py
  25. +10 −11 python/plugins/GdalTools/tools/doSieve.py
  26. +11 −12 python/plugins/GdalTools/tools/doTileIndex.py
  27. +32 −32 python/plugins/GdalTools/tools/doTranslate.py
  28. +32 −32 python/plugins/GdalTools/tools/doWarp.py
  29. +24 −20 python/plugins/GdalTools/tools/extentSelector.py
  30. +21 −28 python/plugins/GdalTools/tools/inOutSelector.py
  31. +11 −9 python/plugins/GdalTools/tools/optionsTable.py
  32. +5 −5 python/plugins/GdalTools/tools/widgetBatchBase.py
  33. +1 −1 python/plugins/GdalTools/tools/widgetBuildVRT.ui
  34. +2 −2 python/plugins/GdalTools/tools/widgetClipper.ui
  35. +1 −1 python/plugins/GdalTools/tools/widgetContour.ui
  36. +1 −1 python/plugins/GdalTools/tools/widgetConvert.ui
  37. +1 −1 python/plugins/GdalTools/tools/widgetDEM.ui
  38. +1 −1 python/plugins/GdalTools/tools/widgetFillNodata.ui
  39. +2 −2 python/plugins/GdalTools/tools/widgetGrid.ui
  40. +1 −1 python/plugins/GdalTools/tools/widgetInfo.ui
  41. +1 −1 python/plugins/GdalTools/tools/widgetMerge.ui
  42. +1 −1 python/plugins/GdalTools/tools/widgetNearBlack.ui
  43. +1 −1 python/plugins/GdalTools/tools/widgetOverview.ui
  44. +19 −20 python/plugins/GdalTools/tools/widgetPluginBase.py
  45. +1 −1 python/plugins/GdalTools/tools/widgetPolygonize.ui
  46. +1 −1 python/plugins/GdalTools/tools/widgetProjection.ui
  47. +1 −1 python/plugins/GdalTools/tools/widgetProximity.ui
  48. +1 −1 python/plugins/GdalTools/tools/widgetRasterize.ui
  49. +1 −1 python/plugins/GdalTools/tools/widgetSieve.ui
  50. +1 −1 python/plugins/GdalTools/tools/widgetTileIndex.ui
  51. +1 −1 python/plugins/GdalTools/tools/widgetTranslate.ui
  52. +1 −1 python/plugins/GdalTools/tools/widgetWarp.ui

Large diffs are not rendered by default.

@@ -21,5 +21,5 @@

def classFactory(iface):
# load GdalTools class from file GdalTools
from GdalTools import GdalTools
from .GdalTools import GdalTools
return GdalTools(iface)
@@ -29,8 +29,8 @@
# setLastUsedDir( QString *file_or_dir path )
# -------------------------------------------------

from PyQt4.QtCore import QObject, QSettings, QFileInfo, SIGNAL, QDir, QCoreApplication
from PyQt4.QtGui import QFileDialog
from PyQt.QtCore import QObject, QSettings, QFileInfo, QDir, QCoreApplication, pyqtSignal
from PyQt.QtWidgets import QFileDialog

from qgis.core import QgsApplication, QgsMapLayerRegistry, QgsRectangle, QgsProviderRegistry, QgsLogger
from qgis.gui import QgsEncodingFileDialog
@@ -153,6 +153,7 @@ def getVectorExtensions():


class LayerRegistry(QObject):
layersChanged = pyqtSignal()

_instance = None
_iface = None
@@ -176,9 +177,9 @@ def __init__(self):

LayerRegistry.layers = self.getAllLayers()
LayerRegistry._instance = self
self.connect(QgsMapLayerRegistry.instance(), SIGNAL("removeAll()"), self.removeAllLayers)
self.connect(QgsMapLayerRegistry.instance(), SIGNAL("layerWasAdded(QgsMapLayer *)"), self.layerAdded)
self.connect(QgsMapLayerRegistry.instance(), SIGNAL("layerWillBeRemoved(QString)"), self.removeLayer)
QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.layerAdded)
QgsMapLayerRegistry.instance().layerWillBeRemoved.connect(self.removeLayer)

def getAllLayers(self):
if LayerRegistry._iface and hasattr(LayerRegistry._iface, 'legendInterface'):
@@ -187,15 +188,15 @@ def getAllLayers(self):

def layerAdded(self, layer):
LayerRegistry.layers.append(layer)
self.emit(SIGNAL("layersChanged"))
self.layersChanged.emit()

def removeLayer(self, layerId):
LayerRegistry.layers = filter(lambda x: x.id() != layerId, LayerRegistry.layers)
self.emit(SIGNAL("layersChanged"))
LayerRegistry.layers = [x for x in LayerRegistry.layers if x.id() != layerId]
self.layersChanged.emit()

def removeAllLayers(self):
LayerRegistry.layers = []
self.emit(SIGNAL("layersChanged"))
self.layersChanged.emit()

@classmethod
def isRaster(self, layer):
@@ -904,7 +905,7 @@ def setProcessEnvironment(process):
envval = os.getenv(name)
if envval is None or envval == "":
envval = unicode(val)
elif (platform.system() == "Windows" and val.lower() not in envval.lower().split( sep )) or \
elif (platform.system() == "Windows" and val.lower() not in envval.lower().split(sep)) or \
(platform.system() != "Windows" and val not in envval.split(sep)):
envval += "%s%s" % (sep, unicode(val))
else:
@@ -23,20 +23,29 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import Qt, SIGNAL, QProcess, QUrl, QIODevice, QCoreApplication
from PyQt4.QtGui import QDialog, QIcon, QDialogButtonBox, QMessageBox, QDesktopServices, QErrorMessage, QApplication
from PyQt.QtCore import Qt, QProcess, QUrl, QIODevice, QCoreApplication, pyqtSignal
from PyQt.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QErrorMessage, QApplication
from PyQt.QtGui import QIcon, QDesktopServices

# to know the os
import platform

from ui_dialogBase import Ui_GdalToolsDialog as Ui_Dialog
import GdalTools_utils as Utils
#from .. import resources_rc
from .ui_dialogBase import Ui_GdalToolsDialog as Ui_Dialog
from . import GdalTools_utils as Utils
from .. import resources_rc # NOQA

import string


class GdalToolsBaseDialog(QDialog, Ui_Dialog):
refreshArgs = pyqtSignal()
okClicked = pyqtSignal()
closeClicked = pyqtSignal()
helpClicked = pyqtSignal()
processError = pyqtSignal(QProcess.ProcessError)
processFinished = pyqtSignal(int, QProcess.ExitStatus)
finished = pyqtSignal(bool)
valuesChanged = pyqtSignal(list)

def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):
QDialog.__init__(self, parent)
@@ -45,26 +54,26 @@ def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):

self.process = QProcess(self)
Utils.setProcessEnvironment(self.process)
self.connect(self.process, SIGNAL("error(QProcess::ProcessError)"), self.processError)
self.connect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"), self.processFinished)
self.process.error.connect(self.processError)
self.process.finished.connect(self.processFinished)

self.setupUi(self)
self.arguments = []

self.editCmdBtn.setIcon(QIcon(":/icons/edit.png"))
self.connect(self.editCmdBtn, SIGNAL("toggled(bool)"), self.editCommand)
self.editCmdBtn.toggled.connect(self.editCommand)
self.resetCmdBtn.setIcon(QIcon(":/icons/reset.png"))
self.connect(self.resetCmdBtn, SIGNAL("clicked()"), self.resetCommand)
self.resetCmdBtn.clicked.connect(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)
self.buttonBox.rejected.connect(self.reject)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.helpRequested.connect(self.help)

self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)

self.plugin = pluginBase
self.connect(self.plugin, SIGNAL("valuesChanged(PyQt_PyObject)"), self.refreshArgs)
self.valuesChanged.connect(self.handleRefreshArgs)

self.pluginLayout.addWidget(self.plugin)
self.plugin.setFocus()
@@ -91,12 +100,12 @@ def editCommand(self, enabled):
self.resetCmdBtn.setEnabled(enabled)
self.textEditCommand.setReadOnly(not enabled)
self.controlsWidget.setEnabled(not enabled)
self.emit(SIGNAL("refreshArgs()"))
self.refreshArgs.emit()

def resetCommand(self):
if not self.commandIsEditable():
return
self.emit(SIGNAL("refreshArgs()"))
self.refreshArgs.emit()

def commandIsEditable(self):
return self.commandIsEnabled() and self.editCmdBtn.isChecked()
@@ -115,22 +124,16 @@ def reject(self):
if ret == QMessageBox.No:
return

self.disconnect(self.process, SIGNAL("error(QProcess::ProcessError)"), self.processError)
self.disconnect(self.process, SIGNAL("finished(int, QProcess::ExitStatus)"), self.processFinished)
self.process.error.disconnect(self.processError)
self.process.finished.disconnect(self.processFinished)

self.emit(SIGNAL("closeClicked()"))
self.closeClicked.emit()

def accept(self):
self.emit(SIGNAL("okClicked()"))
self.okClicked.emit()

def help(self):
self.emit(SIGNAL("helpClicked()"))

def processError(self, error):
self.emit(SIGNAL("processError(QProcess::ProcessError)"), error)

def processFinished(self, exitCode, status):
self.emit(SIGNAL("processFinished(int, QProcess::ExitStatus)"), exitCode, status)
self.helpClicked.emit()

# show the online tool documentation in the default browser
def onHelp(self):
@@ -142,7 +145,7 @@ def onHelp(self):
QDesktopServices.openUrl(url)

# called when a value in the plugin widget interface changed
def refreshArgs(self, args):
def handleRefreshArgs(self, args):
self.arguments = [unicode(a) for a in args]

if not self.commandIsEnabled():
@@ -185,7 +188,7 @@ def onError(self, error):
msg = QCoreApplication.translate("GdalTools", "An unknown error occurred.")

QErrorMessage(self).showMessage(msg)
QApplication.processEvents() # give the user chance to see the message
QApplication.processEvents() # give the user chance to see the message

self.stop()

@@ -197,7 +200,7 @@ def onFinished(self, exitCode, status):
return

if self.command.find("gdalinfo") != -1 and exitCode == 0:
self.emit(SIGNAL("finished(bool)"), self.loadCheckBox.isChecked())
self.finished.emit(self.loadCheckBox.isChecked())
self.stop()
return

@@ -226,6 +229,6 @@ def onFinished(self, exitCode, status):
QErrorMessage(self).showMessage(msg.replace("\n", "<br>"))

if exitCode == 0:
self.emit(SIGNAL("finished(bool)"), self.loadCheckBox.isChecked())
self.finished.emit(self.loadCheckBox.isChecked())

self.stop()
@@ -75,7 +75,7 @@
<customwidget>
<class>GdalToolsInOutSelector</class>
<extends>QWidget</extends>
<header>inOutSelector</header>
<header>.inOutSelector</header>
<container>1</container>
</customwidget>
</customwidgets>
@@ -23,8 +23,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QDialog, QVBoxLayout, QDialogButtonBox
from PyQt.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox
from qgis.gui import QgsProjectionSelector


@@ -42,8 +41,8 @@ def __init__(self, title, parent=None):
layout.addWidget(buttonBox)
self.setLayout(layout)

self.connect(buttonBox, SIGNAL("accepted()"), self.accept)
self.connect(buttonBox, SIGNAL("rejected()"), self.reject)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)

def authid(self):
return unicode(self.selector.selectedAuthId())
@@ -23,13 +23,13 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import SIGNAL, QCoreApplication, QObject
from PyQt4.QtGui import QWidget
from PyQt.QtCore import QCoreApplication
from PyQt.QtWidgets import QWidget

from ui_widgetBuildVRT import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
from dialogSRS import GdalToolsSRSDialog as SRSDialog
import GdalTools_utils as Utils
from .ui_widgetBuildVRT import Ui_GdalToolsWidget as Ui_Widget
from .widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
from .dialogSRS import GdalToolsSRSDialog as SRSDialog
from . import GdalTools_utils as Utils


class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
@@ -49,35 +49,35 @@ def __init__(self, iface):

self.setParamsStatus(
[
(self.inSelector, SIGNAL("filenameChanged()")),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.resolutionComboBox, SIGNAL("currentIndexChanged(int)"), self.resolutionCheck),
(self.noDataEdit, SIGNAL("textChanged( const QString & )"), self.srcNoDataCheck, 1700),
(self.inputDirCheck, SIGNAL("stateChanged(int)")),
(self.separateCheck, SIGNAL("stateChanged(int)"), None, 1700),
(self.targetSRSEdit, SIGNAL("textChanged(const QString &)"), self.targetSRSCheck),
(self.allowProjDiffCheck, SIGNAL("stateChanged(int)"), None, 1700),
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck),
(self.inputSelLayersCheck, SIGNAL("stateChanged(int)"))
(self.inSelector, "filenameChanged"),
(self.outSelector, "filenameChanged"),
(self.resolutionComboBox, "currentIndexChanged", self.resolutionCheck),
(self.noDataEdit, "textChanged", self.srcNoDataCheck, 1700),
(self.inputDirCheck, "stateChanged"),
(self.separateCheck, "stateChanged", None, 1700),
(self.targetSRSEdit, "textChanged", self.targetSRSCheck),
(self.allowProjDiffCheck, "stateChanged", None, 1700),
(self.recurseCheck, "stateChanged", self.inputDirCheck),
(self.inputSelLayersCheck, "stateChanged")
]
)

self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect(self.inputDirCheck, SIGNAL("stateChanged( int )"), self.switchToolMode)
self.connect(self.inputSelLayersCheck, SIGNAL("stateChanged( int )"), self.switchLayerMode)
self.connect(self.iface.mapCanvas(), SIGNAL("stateChanged( int )"), self.switchLayerMode)
self.connect(self.selectTargetSRSButton, SIGNAL("clicked()"), self.fillTargetSRSEdit)
self.inSelector.selectClicked.connect(self.fillInputFilesEdit)
self.outSelector.selectClicked.connect(self.fillOutputFileEdit)
self.inputDirCheck.stateChanged.connect(self.switchToolMode)
self.inputSelLayersCheck.stateChanged.connect(self.switchLayerMode)
self.iface.mapCanvas().layersChanged.connect(self.switchLayerMode)
self.selectTargetSRSButton.clicked.connect(self.fillTargetSRSEdit)

def initialize(self):
# connect to mapCanvas.layerChanged() signal
self.connect(self.iface.mapCanvas(), SIGNAL("layersChanged()"), self.onVisibleLayersChanged)
self.iface.mapCanvas().layersChanged.connect(self.onVisibleLayersChanged)
self.onVisibleLayersChanged()
BasePluginWidget.initialize(self)

def onClosing(self):
# disconnect from mapCanvas.layerChanged() signal
self.disconnect(self.iface.mapCanvas(), SIGNAL("layersChanged()"), self.onVisibleLayersChanged)
self.iface.mapCanvas().layersChanged.disconnect(self.onVisibleLayersChanged)
BasePluginWidget.onClosing(self)

def onVisibleLayersChanged(self):
@@ -98,13 +98,13 @@ def switchToolMode(self):
self.inFileLabel = self.label.text()
self.label.setText(QCoreApplication.translate("GdalTools", "&Input directory"))

QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)
self.inSelector.selectClicked.disconnect(self.fillInputFilesEdit)
self.inSelector.selectClicked.connect(self.fillInputDir)
else:
self.label.setText(self.inFileLabel)

QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)
self.inSelector.selectClicked.connect(self.fillInputFilesEdit)
self.inSelector.selectClicked.disconnect(self.fillInputDir)

def switchLayerMode(self):
enableInputFiles = not self.inputSelLayersCheck.isChecked()

0 comments on commit 9db908c

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