2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ParametersPanel.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
2014-01-17 19:01:08 +01:00
|
|
|
(C) 2013 by CS Systemes d'information (CS SI)
|
2012-10-05 23:28:47 +02:00
|
|
|
Email : volayaf at gmail dot com
|
2014-01-17 19:01:08 +01:00
|
|
|
otb at c-s dot fr (CS SI)
|
2014-04-06 12:27:51 +02:00
|
|
|
Contributors : Victor Olaya
|
2016-01-18 14:16:31 +01:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
2012-10-05 23:28:47 +02:00
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
import os
|
|
|
|
import locale
|
2013-02-01 13:09:39 +04:00
|
|
|
|
2016-03-15 16:43:52 +01:00
|
|
|
from qgis.core import QgsMapLayerRegistry, QgsMapLayer
|
2016-01-18 14:16:31 +01:00
|
|
|
|
2016-04-29 11:39:26 +02:00
|
|
|
from qgis.PyQt import uic
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication, QVariant
|
2016-09-19 09:14:08 +02:00
|
|
|
from qgis.PyQt.QtWidgets import (QWidget, QLayout, QVBoxLayout, QHBoxLayout, QToolButton,
|
2016-09-08 09:57:18 +02:00
|
|
|
QLabel, QCheckBox, QComboBox, QLineEdit, QPlainTextEdit)
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2013-02-01 13:09:39 +04:00
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.gui.OutputSelectionPanel import OutputSelectionPanel
|
2016-09-09 10:48:51 +02:00
|
|
|
from processing.core.parameters import ParameterVector, ParameterExtent, ParameterPoint
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.outputs import OutputRaster
|
|
|
|
from processing.core.outputs import OutputTable
|
|
|
|
from processing.core.outputs import OutputVector
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2015-05-18 19:51:26 +03:00
|
|
|
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
2015-05-18 21:04:20 +03:00
|
|
|
WIDGET, BASE = uic.loadUiType(
|
|
|
|
os.path.join(pluginPath, 'ui', 'widgetParametersPanel.ui'))
|
2015-05-18 19:51:26 +03:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2015-05-18 21:04:20 +03:00
|
|
|
class ParametersPanel(BASE, WIDGET):
|
2012-09-15 18:25:25 +03:00
|
|
|
|
2014-10-03 21:56:24 +03:00
|
|
|
NOT_SELECTED = QCoreApplication.translate('ParametersPanel', '[Not selected]')
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def __init__(self, parent, alg):
|
2015-05-18 21:04:20 +03:00
|
|
|
super(ParametersPanel, self).__init__(None)
|
2014-11-12 11:42:29 +02:00
|
|
|
self.setupUi(self)
|
|
|
|
|
|
|
|
self.grpAdvanced.hide()
|
|
|
|
|
|
|
|
self.layoutMain = self.scrollAreaWidgetContents.layout()
|
|
|
|
self.layoutAdvanced = self.grpAdvanced.layout()
|
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
self.parent = parent
|
2013-10-01 20:52:22 +03:00
|
|
|
self.alg = alg
|
2012-09-15 18:25:25 +03:00
|
|
|
self.valueItems = {}
|
2016-09-07 14:30:20 +02:00
|
|
|
self.wrappers = {}
|
2012-09-15 18:25:25 +03:00
|
|
|
self.labels = {}
|
|
|
|
self.widgets = {}
|
|
|
|
self.checkBoxes = {}
|
|
|
|
self.dependentItems = {}
|
|
|
|
self.iterateButtons = {}
|
2014-11-12 11:42:29 +02:00
|
|
|
|
|
|
|
self.initWidgets()
|
|
|
|
|
2016-09-07 14:30:20 +02:00
|
|
|
def layerRegistryChanged(self, layers):
|
|
|
|
for wrapper in self.wrappers.values():
|
|
|
|
wrapper.refresh()
|
2016-01-18 14:16:31 +01:00
|
|
|
|
2014-11-12 11:42:29 +02:00
|
|
|
def initWidgets(self):
|
|
|
|
# If there are advanced parameters — show corresponding groupbox
|
2013-09-15 13:52:46 +02:00
|
|
|
for param in self.alg.parameters:
|
|
|
|
if param.isAdvanced:
|
2014-11-12 11:42:29 +02:00
|
|
|
self.grpAdvanced.show()
|
2013-09-15 13:52:46 +02:00
|
|
|
break
|
2014-11-12 11:42:29 +02:00
|
|
|
# Create widgets and put them in layouts
|
2013-09-15 13:52:46 +02:00
|
|
|
for param in self.alg.parameters:
|
|
|
|
if param.hidden:
|
|
|
|
continue
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2013-09-15 13:52:46 +02:00
|
|
|
desc = param.description
|
|
|
|
if isinstance(param, ParameterExtent):
|
2014-11-12 11:42:29 +02:00
|
|
|
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
2016-02-22 17:24:21 +02:00
|
|
|
if isinstance(param, ParameterPoint):
|
|
|
|
desc += self.tr(' (x, y)')
|
2016-09-19 09:14:08 +02:00
|
|
|
if param.optional:
|
|
|
|
desc += self.tr(' [optional]')
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2016-08-23 10:49:32 +02:00
|
|
|
wrapper = self.getWidgetWrapperFromParameter(param)
|
2016-09-07 14:30:20 +02:00
|
|
|
self.wrappers[param.name] = wrapper
|
2016-08-23 10:49:32 +02:00
|
|
|
self.valueItems[param.name] = wrapper.widget
|
|
|
|
widget = wrapper.widget
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2016-09-07 14:30:20 +02:00
|
|
|
if isinstance(param, ParameterVector):
|
2014-09-12 12:33:06 +03:00
|
|
|
layout = QHBoxLayout()
|
2013-09-15 13:52:46 +02:00
|
|
|
layout.setSpacing(2)
|
|
|
|
layout.setMargin(0)
|
|
|
|
layout.addWidget(widget)
|
2014-09-12 12:33:06 +03:00
|
|
|
button = QToolButton()
|
2015-05-18 19:51:26 +03:00
|
|
|
icon = QIcon(os.path.join(pluginPath, 'images', 'iterate.png'))
|
2013-09-15 13:52:46 +02:00
|
|
|
button.setIcon(icon)
|
2014-10-03 21:56:24 +03:00
|
|
|
button.setToolTip(self.tr('Iterate over this layer'))
|
2013-09-15 13:52:46 +02:00
|
|
|
button.setCheckable(True)
|
|
|
|
layout.addWidget(button)
|
|
|
|
self.iterateButtons[param.name] = button
|
2014-09-12 12:33:06 +03:00
|
|
|
button.toggled.connect(self.buttonToggled)
|
|
|
|
widget = QWidget()
|
2013-09-15 13:52:46 +02:00
|
|
|
widget.setLayout(layout)
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2016-05-26 16:57:05 +02:00
|
|
|
tooltips = self.alg.getParameterDescriptions()
|
|
|
|
widget.setToolTip(tooltips.get(param.name, param.description))
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2016-09-07 14:30:20 +02:00
|
|
|
label = QLabel(desc)
|
|
|
|
# label.setToolTip(tooltip)
|
|
|
|
self.labels[param.name] = label
|
|
|
|
if param.isAdvanced:
|
|
|
|
self.layoutAdvanced.addWidget(label)
|
|
|
|
self.layoutAdvanced.addWidget(widget)
|
2014-09-12 12:33:06 +03:00
|
|
|
else:
|
2016-09-07 14:30:20 +02:00
|
|
|
self.layoutMain.insertWidget(
|
|
|
|
self.layoutMain.count() - 2, label)
|
|
|
|
self.layoutMain.insertWidget(
|
|
|
|
self.layoutMain.count() - 2, widget)
|
2014-09-12 12:33:06 +03:00
|
|
|
|
2014-11-12 11:42:29 +02:00
|
|
|
self.widgets[param.name] = widget
|
2013-09-15 13:52:46 +02:00
|
|
|
|
|
|
|
for output in self.alg.outputs:
|
|
|
|
if output.hidden:
|
|
|
|
continue
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2014-09-12 12:33:06 +03:00
|
|
|
label = QLabel(output.description)
|
2013-10-01 20:52:22 +03:00
|
|
|
widget = OutputSelectionPanel(output, self.alg)
|
2014-11-12 11:42:29 +02:00
|
|
|
self.layoutMain.insertWidget(self.layoutMain.count() - 1, label)
|
|
|
|
self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget)
|
2013-09-15 13:52:46 +02:00
|
|
|
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
|
2014-09-12 12:33:06 +03:00
|
|
|
check = QCheckBox()
|
2014-10-03 21:56:24 +03:00
|
|
|
check.setText(self.tr('Open output file after running algorithm'))
|
2013-09-15 13:52:46 +02:00
|
|
|
check.setChecked(True)
|
2014-11-12 11:42:29 +02:00
|
|
|
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
|
2013-09-15 13:52:46 +02:00
|
|
|
self.checkBoxes[output.name] = check
|
|
|
|
self.valueItems[output.name] = widget
|
2016-09-07 14:30:20 +02:00
|
|
|
|
|
|
|
for wrapper in self.wrappers.values():
|
|
|
|
wrapper.postInitialize(self.wrappers.values())
|
2016-04-28 14:06:59 +02:00
|
|
|
|
2012-09-15 18:25:25 +03:00
|
|
|
def buttonToggled(self, value):
|
|
|
|
if value:
|
|
|
|
sender = self.sender()
|
2016-09-21 18:24:26 +02:00
|
|
|
for button in list(self.iterateButtons.values()):
|
2012-09-15 18:25:25 +03:00
|
|
|
if button is not sender:
|
|
|
|
button.setChecked(False)
|
|
|
|
|
2016-08-23 10:49:32 +02:00
|
|
|
def getWidgetWrapperFromParameter(self, param):
|
2016-09-18 16:07:32 +02:00
|
|
|
return param.wrapper(self.parent)
|