Skip to content
Browse files
Create the boolean widget wrapper
  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent ecb7b3a commit 728be70c0b562490ed0fe10fa7e017cb373c9617
Showing with 123 additions and 2 deletions.
  1. +6 −2 python/plugins/processing/core/
  2. +117 −0 python/plugins/processing/gui/
@@ -132,8 +132,12 @@ def tr(self, string, context=''):

class ParameterBoolean(Parameter):

def __init__(self, name='', description='', default=None, optional=False):
Parameter.__init__(self, name, description, parseBool(default), optional)
default_metadata = {
'widget_wrapper': 'processing.gui.wrappers.BooleanWidgetWrapper'

def __init__(self, name='', description='', default=None, optional=False, metadata={}):
Parameter.__init__(self, name, description, parseBool(default), optional, metadata)

def setValue(self, value):
if value is None:
@@ -0,0 +1,117 @@
# -*- coding: utf-8 -*-

Date : May 2016
Copyright : (C) 2016 by Arnaud Morvan
Email : arnaud dot morvan at camptocamp dot com
* *
* 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. *
* *

__author__ = 'Arnaud Morvan'
__date__ = 'May 2016'
__copyright__ = '(C) 2016, Arnaud Morvan'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from inspect import isclass

from qgis.PyQt.QtWidgets import (

DIALOG_STANDARD = 'standard'
DIALOG_BATCH = 'batch'
DIALOG_MODELER = 'modeler'

def wrapper_from_param(param, dialog=DIALOG_STANDARD, extra_values=[]):
wrapper = param.metadata.get('widget_wrapper', None)
# wrapper metadata should be a class path
if isinstance(wrapper, basestring):
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(param=param, dialog=dialog, extra_values=extra_values)
# or a wrapper instance
return wrapper

class NotYetImplementedWidgetWrapper():

"""Temporary substitute class for not yet implemented wrappers"""

implemented = False

def __init__(self, param, widget):
self.param = param
self.widget = widget

class WidgetWrapper():

implemented = True # TODO: Should be removed at the end

def __init__(self, param, dialog=DIALOG_STANDARD, extra_values=[]):
self.param = param
self.dialog = dialog
self.widget = self.createWidget(extra_values)

def createWidget(self, extra_values=[]):

def setValue(self, value):

def value(self):

class BooleanWidgetWrapper(WidgetWrapper):

def createWidget(self, extra_values=[]):
if self.dialog == DIALOG_STANDARD:
return QCheckBox()

if self.dialog in (DIALOG_BATCH, DIALOG_MODELER):
widget = QComboBox()
widget.addItem('Yes'), True)
widget.addItem('No'), False)
for text, value in extra_values:
widget.addItem(text, value)
return widget

def setValue(self, value):
if self.dialog == DIALOG_STANDARD:

if self.dialog in (DIALOG_BATCH, DIALOG_MODELER):
values = [self.widget.itemData(i) for i in range(self.widget.count())]
idx = values.index(value)
except ValueError:

def value(self):
if self.dialog == DIALOG_STANDARD:
return self.widget.isChecked()

if self.dialog in (DIALOG_BATCH, DIALOG_MODELER):
return self.widget.itemData(self.widget.currentIndex())

0 comments on commit 728be70

Please sign in to comment.