Skip to content

Commit

Permalink
Use boolean wrapper in standard algorithm dialog
Browse files Browse the repository at this point in the history
Conflicts:
	python/plugins/processing/gui/AlgorithmDialog.py
  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent 728be70 commit f3c9aaa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
24 changes: 16 additions & 8 deletions python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
32 changes: 22 additions & 10 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f3c9aaa

Please sign in to comment.