Skip to content
Permalink
Browse files

Use boolean wrapper in standard algorithm dialog

Conflicts:
	python/plugins/processing/gui/AlgorithmDialog.py
  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent 728be70 commit f3c9aaaa2b653edeb2915966b9d1b25fa0349409
Showing with 38 additions and 18 deletions.
  1. +16 −8 python/plugins/processing/gui/AlgorithmDialog.py
  2. +22 −10 python/plugins/processing/gui/ParametersPanel.py
@@ -46,7 +46,6 @@
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTable
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterSelection
from processing.core.parameters import ParameterFixedTable
from processing.core.parameters import ParameterRange
@@ -103,10 +102,17 @@ def setParamValues(self):
for param in params:
if param.hidden:
continue
if not self.setParamValue(
param, self.mainWidget.valueItems[param.name]):
raise AlgorithmDialogBase.InvalidParameterValue(
param, self.mainWidget.valueItems[param.name])
if isinstance(param, ParameterExtent):
continue
wrapper = self.mainWidget.widget_wrappers[param.name]
if not self.setParamValue(param, wrapper):
raise AlgorithmDialogBase.InvalidParameterValue(param, wrapper)

for param in params:
if isinstance(param, ParameterExtent):
wrapper = self.mainWidget.widget_wrappers[param.name]
if not self.setParamValue(param, wrapper):
raise AlgorithmDialogBase.InvalidParameterValue(param, wrapper)

for output in outputs:
if output.hidden:
@@ -129,16 +135,18 @@ def evaluateExpression(self, text):
raise ValueError(exp.evalErrorString())
return result

def setParamValue(self, param, widget, alg=None):
def setParamValue(self, param, wrapper, alg=None):
if wrapper.implemented:
return param.setValue(wrapper.value())

widget = wrapper.widget
if isinstance(param, ParameterRaster):
return param.setValue(widget.getValue())
elif isinstance(param, (ParameterVector, ParameterTable)):
try:
return param.setValue(widget.itemData(widget.currentIndex()))
except:
return param.setValue(widget.getValue())
elif isinstance(param, ParameterBoolean):
return param.setValue(widget.isChecked())
elif isinstance(param, ParameterSelection):
return param.setValue(widget.currentIndex())
elif isinstance(param, ParameterFixedTable):
@@ -42,6 +42,11 @@

from processing.core.ProcessingConfig import ProcessingConfig

from processing.gui.wrappers import (
wrapper_from_param,
NotYetImplementedWidgetWrapper,
)

from processing.gui.OutputSelectionPanel import OutputSelectionPanel
from processing.gui.InputLayerSelectorPanel import InputLayerSelectorPanel
from processing.gui.FixedTablePanel import FixedTablePanel
@@ -59,7 +64,6 @@
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTable
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterTableMultipleField
from processing.core.parameters import ParameterSelection
@@ -101,6 +105,7 @@ def __init__(self, parent, alg):
self.parent = parent
self.alg = alg
self.valueItems = {}
self.widget_wrappers = {}
self.labels = {}
self.widgets = {}
self.checkBoxes = {}
@@ -195,8 +200,10 @@ def initWidgets(self):
except:
pass

widget = self.getWidgetFromParameter(param)
self.valueItems[param.name] = widget
wrapper = self.getWidgetWrapperFromParameter(param)
self.widget_wrappers[param.name] = wrapper
self.valueItems[param.name] = wrapper.widget
widget = wrapper.widget

if isinstance(param, ParameterVector) and \
not self.alg.allowOnlyOpenedLayers:
@@ -218,7 +225,7 @@ def initWidgets(self):
tooltips = self.alg.getParameterDescriptions()
widget.setToolTip(tooltips.get(param.name, param.description))

if isinstance(param, ParameterBoolean):
if isinstance(widget, QCheckBox):
widget.setText(desc)
if param.isAdvanced:
self.layoutAdvanced.addWidget(widget)
@@ -255,6 +262,8 @@ def initWidgets(self):
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
self.checkBoxes[output.name] = check
self.valueItems[output.name] = widget
wrapper = NotYetImplementedWidgetWrapper(output, widget)
self.widget_wrappers[output.name] = wrapper

if isinstance(output, OutputVector):
if output.base_input in self.dependentItems:
@@ -287,6 +296,15 @@ def getExtendedLayerName(self, layer):
else:
return layer.name()

def getWidgetWrapperFromParameter(self, param):
wrapper = wrapper_from_param(param)
if wrapper is not None:
return wrapper

widget = self.getWidgetFromParameter(param)
wrapper = NotYetImplementedWidgetWrapper(param, widget)
return wrapper

def getWidgetFromParameter(self, param):
# TODO Create Parameter widget class that holds the logic
# for creating a widget that belongs to the parameter.
@@ -343,12 +361,6 @@ def getWidgetFromParameter(self, param):
if layer and layer.source() == param.value:
items.insert(0, items.pop(i))
item = InputLayerSelectorPanel(items, param)
elif isinstance(param, ParameterBoolean):
item = QCheckBox()
if param.default:
item.setChecked(True)
else:
item.setChecked(False)
elif isinstance(param, ParameterTableField) or isinstance(param, ParameterTableMultipleField):
if isinstance(param, ParameterTableMultipleField):
item = ListMultiSelectWidget()

0 comments on commit f3c9aaa

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