Skip to content

Commit

Permalink
[processing] Add possibility to pass additionnal parameters to widget…
Browse files Browse the repository at this point in the history
… wrapper
  • Loading branch information
arnaud-morvan committed Feb 9, 2017
1 parent 2c188b2 commit 482aadc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 6 additions & 1 deletion python/plugins/processing/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,19 @@ def tr(self, string, context=''):

def wrapper(self, dialog, row=0, col=0):
wrapper = self.metadata.get('widget_wrapper', None)
params = {}
# wrapper metadata should be a dict with class key
if isinstance(wrapper, dict):
params = deepcopy(wrapper)
wrapper = params.pop('class')
# wrapper metadata should be a class path
if isinstance(wrapper, str):
tokens = wrapper.split('.')
mod = __import__('.'.join(tokens[:-1]), fromlist=[tokens[-1]])
wrapper = getattr(mod, tokens[-1])
# or directly a class object
if isclass(wrapper):
wrapper = wrapper(self, dialog, row, col)
wrapper = wrapper(self, dialog, row, col, **params)
# or a wrapper instance
return wrapper

Expand Down
10 changes: 4 additions & 6 deletions python/plugins/processing/gui/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
***************************************************************************
wrappers.py
wrappers.py - Standard parameters widget wrappers
---------------------
Date : May 2016
Copyright : (C) 2016 by Arnaud Morvan, Victor Olaya
Expand All @@ -17,8 +17,6 @@
* *
***************************************************************************
"""
from builtins import str
from builtins import range


__author__ = 'Arnaud Morvan'
Expand Down Expand Up @@ -101,14 +99,14 @@ class WidgetWrapper(QObject):

widgetValueHasChanged = pyqtSignal(object)

def __init__(self, param, dialog, row=0, col=0):
def __init__(self, param, dialog, row=0, col=0, **kwargs):
QObject.__init__(self)
self.param = param
self.dialog = dialog
self.row = row
self.col = col
self.dialogType = dialogTypes.get(dialog.__class__.__name__, DIALOG_STANDARD)
self.widget = self.createWidget()
self.widget = self.createWidget(**kwargs)
if param.default is not None:
self.setValue(param.default)

Expand All @@ -123,7 +121,7 @@ def comboValue(self, validator=None, combobox=None):
return v
return combobox.currentData()

def createWidget(self):
def createWidget(self, **kwargs):
pass

def setValue(self, value):
Expand Down

0 comments on commit 482aadc

Please sign in to comment.