Commit c7e40dae authored by Diego Gangl's avatar Diego Gangl Committed by Alexandru Băluț

Preferences: Use a switch for boolean settings

parent 9e80acc9
Pipeline #92705 passed with stages
in 121 minutes and 48 seconds
......@@ -255,21 +255,17 @@ class PreferencesDialog(Loggable):
prop_size_group.add_widget(widget)
if isinstance(widget, widgets.ToggleWidget):
widget.check_button.set_label(label)
label_widget = None
else:
label_widget = Gtk.Label(label=label)
label_widget.set_tooltip_text(description)
label_widget.set_alignment(0.0, 0.5)
label_widget.props.margin_left = PADDING * 3
label_widget.props.margin_right = PADDING * 3
label_widget.props.margin_top = PADDING * 2
label_widget.props.margin_bottom = PADDING * 2
label_widget.show()
label_size_group.add_widget(label_widget)
label_widget = Gtk.Label(label=label)
label_widget.set_tooltip_text(description)
label_widget.set_alignment(0.0, 0.5)
label_widget.props.margin_left = PADDING * 3
label_widget.props.margin_right = PADDING * 3
label_widget.props.margin_top = PADDING * 2
label_widget.props.margin_bottom = PADDING * 2
label_widget.show()
label_size_group.add_widget(label_widget)
icon = Gtk.Image()
icon.set_from_icon_name(
......
......@@ -452,25 +452,28 @@ class FractionWidget(TextWidget, DynamicWidget):
class ToggleWidget(Gtk.Box, DynamicWidget):
"""Widget for entering an on/off value."""
def __init__(self, default=None, check_button=None):
def __init__(self, default=None, switch_button=None):
Gtk.Box.__init__(self)
DynamicWidget.__init__(self, default)
if check_button is None:
self.check_button = Gtk.CheckButton()
self.pack_start(self.check_button, expand=False, fill=False, padding=0)
self.check_button.show()
if switch_button is None:
self.switch_button = Gtk.Switch()
self.pack_start(self.switch_button, expand=False, fill=False, padding=0)
self.switch_button.show()
else:
self.check_button = check_button
self.switch_button = switch_button
self.setWidgetToDefault()
def connectValueChanged(self, callback, *args):
self.check_button.connect("toggled", callback, *args)
def callback_wrapper(switch_button, unused_state):
callback(switch_button, *args)
self.switch_button.connect("state-set", callback_wrapper)
def setWidgetValue(self, value):
self.check_button.set_active(value)
self.switch_button.set_active(value)
def getWidgetValue(self):
return self.check_button.get_active()
return self.switch_button.get_active()
class ChoiceWidget(Gtk.Box, DynamicWidget):
......@@ -645,7 +648,7 @@ def make_widget_wrapper(prop, widget):
widget_lower = widget_adjustment.props.lower
widget_upper = widget_adjustment.props.upper
return NumericWidget(upper=widget_upper, lower=widget_lower, adjustment=widget_adjustment, default=prop.default_value)
elif isinstance(widget, Gtk.CheckButton):
elif isinstance(widget, Gtk.Switch):
return ToggleWidget(prop.default_value, widget)
else:
Loggable().fixme("%s has not been wrapped into a Dynamic Widget", widget)
......@@ -899,15 +902,10 @@ class GstElementSettingsWidget(Gtk.Box, Loggable):
except KeyError:
widget = prop_widget
if isinstance(prop_widget, ToggleWidget):
prop_widget.check_button.set_label(prop.nick)
grid.attach(widget, 0, y, 2, 1)
else:
text = _("%(preference_label)s:") % {"preference_label": prop.nick}
label = Gtk.Label(label=text)
label.set_alignment(0.0, 0.5)
grid.attach(label, 0, y, 1, 1)
grid.attach(widget, 1, y, 1, 1)
label = Gtk.Label(label=prop.nick)
label.set_alignment(0.0, 0.5)
grid.attach(label, 0, y, 1, 1)
grid.attach(widget, 1, y, 1, 1)
if hasattr(prop, 'blurb'):
widget.set_tooltip_text(prop.blurb)
......
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