2016-01-07 17:52:07 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GdalAlgorithmDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : May 2015
|
|
|
|
Copyright : (C) 2015 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'May 2015'
|
|
|
|
__copyright__ = '(C) 2015, Victor Olaya'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-03-15 16:43:52 +01:00
|
|
|
from qgis.core import QgsMapLayerRegistry
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QPlainTextEdit, QLineEdit, QComboBox, QCheckBox
|
2015-05-07 13:14:01 +02:00
|
|
|
from processing.gui.AlgorithmDialog import AlgorithmDialog
|
|
|
|
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
|
|
|
|
from processing.gui.ParametersPanel import ParametersPanel
|
2016-01-06 10:28:52 +01:00
|
|
|
from processing.gui.MultipleInputPanel import MultipleInputPanel
|
2016-01-19 09:00:13 +01:00
|
|
|
from processing.gui.NumberInputPanel import NumberInputPanel
|
2015-05-07 13:14:01 +02:00
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
class GdalAlgorithmDialog(AlgorithmDialog):
|
|
|
|
|
|
|
|
def __init__(self, alg):
|
|
|
|
AlgorithmDialogBase.__init__(self, alg)
|
|
|
|
|
|
|
|
self.alg = alg
|
|
|
|
|
|
|
|
self.mainWidget = GdalParametersPanel(self, alg)
|
|
|
|
self.setMainWidget()
|
2015-09-24 12:07:46 +02:00
|
|
|
|
|
|
|
cornerWidget = QWidget()
|
2015-09-26 19:53:10 +02:00
|
|
|
layout = QVBoxLayout()
|
|
|
|
layout.setContentsMargins(0, 0, 0, 5)
|
|
|
|
self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }")
|
2015-12-09 08:56:15 +01:00
|
|
|
runAsBatchButton = QPushButton(self.tr("Run as batch process..."))
|
2015-09-24 12:07:46 +02:00
|
|
|
runAsBatchButton.clicked.connect(self.runAsBatch)
|
|
|
|
layout.addWidget(runAsBatchButton)
|
|
|
|
cornerWidget.setLayout(layout)
|
|
|
|
self.tabWidget.setCornerWidget(cornerWidget)
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
self.mainWidget.parametersHaveChanged()
|
|
|
|
|
2016-01-18 14:16:31 +01:00
|
|
|
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded)
|
|
|
|
QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)
|
2015-08-22 14:29:41 +02:00
|
|
|
|
2016-01-19 08:41:20 +11:00
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
class GdalParametersPanel(ParametersPanel):
|
|
|
|
|
|
|
|
def __init__(self, parent, alg):
|
|
|
|
ParametersPanel.__init__(self, parent, alg)
|
|
|
|
|
|
|
|
w = QWidget()
|
|
|
|
layout = QVBoxLayout()
|
2015-05-21 13:48:26 +02:00
|
|
|
layout.setMargin(0)
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.setSpacing(6)
|
|
|
|
label = QLabel()
|
2015-12-09 08:56:15 +01:00
|
|
|
label.setText(self.tr("GDAL/OGR console call"))
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.addWidget(label)
|
|
|
|
self.text = QPlainTextEdit()
|
2015-05-21 13:48:26 +02:00
|
|
|
self.text.setReadOnly(True)
|
2015-05-07 13:14:01 +02:00
|
|
|
layout.addWidget(self.text)
|
|
|
|
w.setLayout(layout)
|
2015-05-21 13:48:26 +02:00
|
|
|
self.layoutMain.addWidget(w)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
|
|
|
self.connectParameterSignals()
|
|
|
|
self.parametersHaveChanged()
|
|
|
|
|
|
|
|
def connectParameterSignals(self):
|
|
|
|
for w in self.widgets.values():
|
|
|
|
if isinstance(w, QLineEdit):
|
|
|
|
w.textChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, QComboBox):
|
|
|
|
w.currentIndexChanged.connect(self.parametersHaveChanged)
|
|
|
|
elif isinstance(w, QCheckBox):
|
|
|
|
w.stateChanged.connect(self.parametersHaveChanged)
|
2016-01-06 10:28:52 +01:00
|
|
|
elif isinstance(w, MultipleInputPanel):
|
|
|
|
w.selectionChanged.connect(self.parametersHaveChanged)
|
2016-01-19 09:00:13 +01:00
|
|
|
elif isinstance(w, NumberInputPanel):
|
|
|
|
w.hasChanged.connect(self.parametersHaveChanged)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
|
|
|
def parametersHaveChanged(self):
|
|
|
|
try:
|
|
|
|
self.parent.setParamValues()
|
|
|
|
for output in self.alg.outputs:
|
|
|
|
if output.value is None:
|
2016-02-15 00:16:51 +01:00
|
|
|
output.value = self.tr("[temporary file]")
|
2015-05-07 13:14:01 +02:00
|
|
|
commands = self.alg.getConsoleCommands()
|
|
|
|
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
|
|
|
|
self.text.setPlainText(" ".join(commands))
|
2016-01-08 10:32:43 +02:00
|
|
|
except AlgorithmDialogBase.InvalidParameterValue as e:
|
2016-02-15 00:16:51 +01:00
|
|
|
self.text.setPlainText(self.tr("Invalid value for parameter '%s'") % e.parameter.description)
|
2015-05-07 13:14:01 +02:00
|
|
|
except:
|
2015-08-22 14:29:41 +02:00
|
|
|
self.text.setPlainText("")
|