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$'
|
|
|
|
|
2017-02-10 17:59:53 +02:00
|
|
|
from qgis.PyQt.QtWidgets import (QWidget,
|
|
|
|
QVBoxLayout,
|
|
|
|
QPushButton,
|
|
|
|
QLabel,
|
|
|
|
QPlainTextEdit,
|
|
|
|
QLineEdit,
|
|
|
|
QComboBox,
|
|
|
|
QCheckBox,
|
|
|
|
QSizePolicy)
|
|
|
|
|
|
|
|
from qgis.gui import QgsMessageBar
|
|
|
|
|
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):
|
2017-02-10 17:59:53 +02:00
|
|
|
AlgorithmDialogBase.__init__(self, alg)
|
2015-05-07 13:14:01 +02:00
|
|
|
|
|
|
|
self.alg = alg
|
2016-09-19 11:52:31 +03:00
|
|
|
|
2017-02-10 17:59:53 +02:00
|
|
|
self.bar = QgsMessageBar()
|
|
|
|
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
|
|
|
|
self.layout().insertWidget(0, self.bar)
|
|
|
|
|
2016-09-14 09:51:17 +02:00
|
|
|
self.setMainWidget(GdalParametersPanel(self, alg))
|
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-09-19 11:52:31 +03: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):
|
2016-11-17 12:06:24 +01:00
|
|
|
for wrapper in list(self.wrappers.values()):
|
|
|
|
w = wrapper.widget
|
2015-05-07 13:14:01 +02:00
|
|
|
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:
|
2017-05-15 16:16:32 +10:00
|
|
|
parameters = self.parent.getParamValues()
|
|
|
|
for output in self.alg.destinationParameterDefinitions():
|
|
|
|
if parameters[output.name()] is None:
|
|
|
|
parameters[output.name()] = self.tr("[temporary file]")
|
2017-05-15 16:19:46 +10:00
|
|
|
commands = self.alg.getConsoleCommands(parameters)
|
2015-05-07 13:14:01 +02:00
|
|
|
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:
|
2017-05-16 15:21:41 +10:00
|
|
|
self.text.setPlainText(self.tr("Invalid value for parameter '{0}'").format(e.parameter.description()))
|
2015-05-07 13:14:01 +02:00
|
|
|
except:
|
2015-08-22 14:29:41 +02:00
|
|
|
self.text.setPlainText("")
|