mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
117 lines
4.6 KiB
Python
117 lines
4.6 KiB
Python
# -*- 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$'
|
|
|
|
from qgis.PyQt.QtCore import QCoreApplication
|
|
from qgis.PyQt.QtWidgets import (QWidget,
|
|
QVBoxLayout,
|
|
QPushButton,
|
|
QLabel,
|
|
QPlainTextEdit,
|
|
QLineEdit,
|
|
QComboBox,
|
|
QCheckBox,
|
|
QSizePolicy,
|
|
QDialogButtonBox)
|
|
|
|
from qgis.gui import QgsMessageBar
|
|
|
|
from processing.gui.AlgorithmDialog import AlgorithmDialog
|
|
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
|
|
from processing.gui.ParametersPanel import ParametersPanel
|
|
from processing.gui.MultipleInputPanel import MultipleInputPanel
|
|
from processing.gui.NumberInputPanel import NumberInputPanel
|
|
|
|
|
|
class GdalAlgorithmDialog(AlgorithmDialog):
|
|
|
|
def __init__(self, alg):
|
|
AlgorithmDialogBase.__init__(self, alg)
|
|
|
|
self.alg = alg
|
|
|
|
self.bar = QgsMessageBar()
|
|
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
|
|
self.layout().insertWidget(0, self.bar)
|
|
|
|
self.setMainWidget(GdalParametersPanel(self, alg))
|
|
|
|
self.runAsBatchButton = QPushButton(QCoreApplication.translate("AlgorithmDialog", "Run as Batch Process…"))
|
|
self.runAsBatchButton.clicked.connect(self.runAsBatch)
|
|
self.buttonBox.addButton(self.runAsBatchButton, QDialogButtonBox.ResetRole) # reset role to ensure left alignment
|
|
|
|
self.mainWidget.parametersHaveChanged()
|
|
|
|
|
|
class GdalParametersPanel(ParametersPanel):
|
|
|
|
def __init__(self, parent, alg):
|
|
ParametersPanel.__init__(self, parent, alg)
|
|
|
|
w = QWidget()
|
|
layout = QVBoxLayout()
|
|
layout.setMargin(0)
|
|
layout.setSpacing(6)
|
|
label = QLabel()
|
|
label.setText(self.tr("GDAL/OGR console call"))
|
|
layout.addWidget(label)
|
|
self.text = QPlainTextEdit()
|
|
self.text.setReadOnly(True)
|
|
layout.addWidget(self.text)
|
|
w.setLayout(layout)
|
|
self.layoutMain.addWidget(w)
|
|
|
|
self.connectParameterSignals()
|
|
self.parametersHaveChanged()
|
|
|
|
def connectParameterSignals(self):
|
|
for wrapper in list(self.wrappers.values()):
|
|
w = wrapper.widget
|
|
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)
|
|
elif isinstance(w, MultipleInputPanel):
|
|
w.selectionChanged.connect(self.parametersHaveChanged)
|
|
elif isinstance(w, NumberInputPanel):
|
|
w.hasChanged.connect(self.parametersHaveChanged)
|
|
|
|
def parametersHaveChanged(self):
|
|
try:
|
|
parameters = self.parent.getParamValues()
|
|
for output in self.alg.destinationParameterDefinitions():
|
|
if parameters[output.name()] is None:
|
|
parameters[output.name()] = self.tr("[temporary file]")
|
|
commands = self.alg.getConsoleCommands(parameters)
|
|
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
|
|
self.text.setPlainText(" ".join(commands))
|
|
except AlgorithmDialogBase.InvalidParameterValue as e:
|
|
self.text.setPlainText(self.tr("Invalid value for parameter '{0}'").format(e.parameter.description()))
|
|
except:
|
|
self.text.setPlainText("")
|