Skip to content

Commit 482aadc

Browse files
committedFeb 9, 2017
[processing] Add possibility to pass additionnal parameters to widget wrapper
1 parent 2c188b2 commit 482aadc

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
 

‎python/plugins/processing/core/parameters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,19 @@ def tr(self, string, context=''):
178178

179179
def wrapper(self, dialog, row=0, col=0):
180180
wrapper = self.metadata.get('widget_wrapper', None)
181+
params = {}
182+
# wrapper metadata should be a dict with class key
183+
if isinstance(wrapper, dict):
184+
params = deepcopy(wrapper)
185+
wrapper = params.pop('class')
181186
# wrapper metadata should be a class path
182187
if isinstance(wrapper, str):
183188
tokens = wrapper.split('.')
184189
mod = __import__('.'.join(tokens[:-1]), fromlist=[tokens[-1]])
185190
wrapper = getattr(mod, tokens[-1])
186191
# or directly a class object
187192
if isclass(wrapper):
188-
wrapper = wrapper(self, dialog, row, col)
193+
wrapper = wrapper(self, dialog, row, col, **params)
189194
# or a wrapper instance
190195
return wrapper
191196

‎python/plugins/processing/gui/wrappers.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""
44
***************************************************************************
5-
wrappers.py
5+
wrappers.py - Standard parameters widget wrappers
66
---------------------
77
Date : May 2016
88
Copyright : (C) 2016 by Arnaud Morvan, Victor Olaya
@@ -17,8 +17,6 @@
1717
* *
1818
***************************************************************************
1919
"""
20-
from builtins import str
21-
from builtins import range
2220

2321

2422
__author__ = 'Arnaud Morvan'
@@ -101,14 +99,14 @@ class WidgetWrapper(QObject):
10199

102100
widgetValueHasChanged = pyqtSignal(object)
103101

104-
def __init__(self, param, dialog, row=0, col=0):
102+
def __init__(self, param, dialog, row=0, col=0, **kwargs):
105103
QObject.__init__(self)
106104
self.param = param
107105
self.dialog = dialog
108106
self.row = row
109107
self.col = col
110108
self.dialogType = dialogTypes.get(dialog.__class__.__name__, DIALOG_STANDARD)
111-
self.widget = self.createWidget()
109+
self.widget = self.createWidget(**kwargs)
112110
if param.default is not None:
113111
self.setValue(param.default)
114112

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

126-
def createWidget(self):
124+
def createWidget(self, **kwargs):
127125
pass
128126

129127
def setValue(self, value):

0 commit comments

Comments
 (0)
Please sign in to comment.