Commit 813c6eca authored by John Stowers's avatar John Stowers

Add sizegroup support for widgets

parent 5b3e89dc
......@@ -6,10 +6,12 @@ import gtweak
from gi.repository import Gtk
class Tweak:
def __init__(self, name, description):
def __init__(self, name, description, **options):
self.name = name
self.description = description
self.size_group = options.get('size_group')
@property
def widget(self):
raise NotImplementedError
......@@ -22,11 +24,13 @@ class Tweak:
return txt in self.name or txt in self.description
class TweakGroup:
def __init__(self, name, *tweaks, **options):
def __init__(self, name, *tweaks):
self.name = name
self.tweaks = [t for t in tweaks]
self.enable_size_group = options.get('size_group')
for t in tweaks:
if t.size_group and t.widget_for_size_group:
t.size_group.add_widget(t.widget_for_size_group)
class TweakModel(Gtk.ListStore):
(COLUMN_NAME,
......
from gi.repository import Gtk
from gtweak.tweakmodel import TweakGroup
from gtweak.widgets import GSettingsFontButtonTweak
from gtweak.widgets import GSettingsFontButtonTweak, build_horizontal_sizegroup
sg = build_horizontal_sizegroup()
TWEAK_GROUPS = (
TweakGroup(
"Fonts",
GSettingsFontButtonTweak("org.gnome.desktop.interface", "font-name"),
GSettingsFontButtonTweak("org.gnome.desktop.interface", "document-font-name"),
GSettingsFontButtonTweak("org.gnome.desktop.interface", "monospace-font-name")),
GSettingsFontButtonTweak("org.gnome.desktop.interface", "font-name", size_group=sg),
GSettingsFontButtonTweak("org.gnome.desktop.interface", "document-font-name", size_group=sg),
GSettingsFontButtonTweak("org.gnome.desktop.interface", "monospace-font-name", size_group=sg)),
)
......@@ -30,25 +30,31 @@ def build_combo_box_text(selected, *values):
return combo
def build_horizontal_sizegroup():
sg = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL)
sg.props.ignore_hidden = True
return sg
class _GSettingsTweak(Tweak):
def __init__(self, schema_name, key_name):
def __init__(self, schema_name, key_name, **options):
self.settings = GSettingsSetting(schema_name)
Tweak.__init__(self, self.settings.schema_get_summary(key_name), self.settings.schema_get_description(key_name))
Tweak.__init__(self, self.settings.schema_get_summary(key_name), self.settings.schema_get_description(key_name), **options)
class GSettingsSwitchTweak(_GSettingsTweak):
def __init__(self, schema_name, key_name):
_GSettingsTweak.__init__(self, schema_name, key_name)
def __init__(self, schema_name, key_name, **options):
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
w = Gtk.Switch()
self.settings.bind(key_name, w, "active", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(self.settings.schema_get_summary(key_name), w)
self.widget_for_size_group = w
class GSettingsFontButtonTweak(_GSettingsTweak):
def __init__(self, schema_name, key_name):
_GSettingsTweak.__init__(self, schema_name, key_name)
def __init__(self, schema_name, key_name, **options):
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
w = Gtk.FontButton()
self.settings.bind(key_name, w, "font-name", Gio.SettingsBindFlags.DEFAULT)
self.widget = build_label_beside_widget(self.settings.schema_get_summary(key_name), w)
self.widget_for_size_group = w
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