From 67fcedb9d1ee41670e24c1afa231931dea7f4e76 Mon Sep 17 00:00:00 2001 From: vilim Date: Wed, 16 Jan 2019 17:51:49 +0100 Subject: [PATCH] Added push button control --- lightparam/gui/__init__.py | 2 +- lightparam/gui/controls.py | 17 +++++++++++++++-- setup.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lightparam/gui/__init__.py b/lightparam/gui/__init__.py index b514206..e4f4b1c 100644 --- a/lightparam/gui/__init__.py +++ b/lightparam/gui/__init__.py @@ -10,10 +10,10 @@ combo=ControlCombo, text=ControlText, folder=ControlFolder, + button=ControlButton, range_slider=RangeSliderWidgetWithNumbers, ) - class ParameterTreeGui(QWidget): def __init__(self, param_tree): super().__init__() diff --git a/lightparam/gui/controls.py b/lightparam/gui/controls.py index d8087e7..21be8ef 100644 --- a/lightparam/gui/controls.py +++ b/lightparam/gui/controls.py @@ -49,11 +49,11 @@ def __init__(self, parametrized, name): except TypeError: pass - self.control.setValue(self.param.value) - if self.param.limits is not None and len(self.param.limits) > 2: self.control.setDecimals(int(-round(log(self.param.limits[2])/log(10)))) + self.control.setValue(self.param.value) + self.setLayout(QHBoxLayout()) self.layout().addWidget(self.label) self.layout().addWidget(self.control) @@ -86,6 +86,19 @@ def update_param(self): setattr(self.parametrized, self.param_name, self.control.isChecked()) +class ControlButton(Control): + def __init__(self, parametrized, name): + super().__init__(parametrized, name) + self.control = QPushButton(pretty_name(name)) + self.setLayout(QHBoxLayout()) + self.layout().addWidget(self.control) + self.layout().setContentsMargins(0, 0, 0, 0) + self.control.clicked.connect(self.update_param) + + def update_param(self): + setattr(self.parametrized, self.param_name, + not getattr(self.parametrized, self.param_name)) + class ControlToggleIcon(QToolButton, Control): """A toggle button for a boolean parameter""" def __init__(self, parametrized, name, icon_on=None, icon_off=None, diff --git a/setup.py b/setup.py index 7eea54d..04dc241 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="lightparam", - version="0.3.5", + version="0.3.6", author="Vilim Stich, Luigi Petrucco", author_email="vilim@neuro.mpg.de", packages=find_packages(),