Commit f6e8c3ba authored by Lars Kruse's avatar Lars Kruse

use a common base class for ParameterSection and other GTK controls

* additionally: hide a ParameterSection if all children are hidden
parent cb827740
...@@ -49,7 +49,19 @@ def _output_conversion(func): ...@@ -49,7 +49,19 @@ def _output_conversion(func):
return _output_conversion_wrapper return _output_conversion_wrapper
class InputBaseClass(object): class WidgetBaseClass(object):
def get_widget(self):
return self.control
def set_visible(self, state):
if state:
self.get_widget().show()
else:
self.get_widget().hide()
class InputBaseClass(WidgetBaseClass):
def connect(self, signal, handler, control=None): def connect(self, signal, handler, control=None):
if not handler: if not handler:
...@@ -66,15 +78,6 @@ class InputBaseClass(object): ...@@ -66,15 +78,6 @@ class InputBaseClass(object):
control.disconnect(handler_id) control.disconnect(handler_id)
self.get_widget().destroy() self.get_widget().destroy()
def get_widget(self):
return self.control
def set_visible(self, state):
if state:
self.control.show()
else:
self.control.hide()
def set_conversion(self, set_conv=None, get_conv=None): def set_conversion(self, set_conv=None, get_conv=None):
self._input_converter = set_conv self._input_converter = set_conv
self._output_converter = get_conv self._output_converter = get_conv
...@@ -235,7 +238,7 @@ class InputCheckBox(InputBaseClass): ...@@ -235,7 +238,7 @@ class InputCheckBox(InputBaseClass):
self.control.set_active(value) self.control.set_active(value)
class ParameterSection(object): class ParameterSection(WidgetBaseClass):
def __init__(self): def __init__(self):
self._widgets = [] self._widgets = []
...@@ -301,9 +304,13 @@ class ParameterSection(object): ...@@ -301,9 +304,13 @@ class ParameterSection(object):
"top-attach") "top-attach")
def _update_widgets_visibility(self, widget=None): def _update_widgets_visibility(self, widget=None):
# Hide and show labels (or other items) that share a row with a
# configured item (according to its visibility).
visibility_collector = []
for widget in self._widgets: for widget in self._widgets:
table_row = self._get_table_row_of_widget(widget[0]) table_row = self._get_table_row_of_widget(widget[0])
is_visible = widget[0].props.visible is_visible = widget[0].props.visible
visibility_collector.append(is_visible)
for child in self._table.get_children(): for child in self._table.get_children():
if widget == child: if widget == child:
continue continue
...@@ -312,4 +319,9 @@ class ParameterSection(object): ...@@ -312,4 +319,9 @@ class ParameterSection(object):
child.show() child.show()
else: else:
child.hide() child.hide()
# hide the complete section if all items are hidden
if any(visibility_collector):
self._table.show()
else:
self._table.hide()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment