Commit 153dcb72 authored by John Stowers's avatar John Stowers

Factor out a GSettingsComboTweak

parent 648adeb0
......@@ -3,40 +3,24 @@ import os.path
from gi.repository import Gtk
import gtweak
from gtweak.tweakmodel import Tweak, TweakGroup
from gtweak.widgets import GSettingsSwitchTweak, build_label_beside_widget, build_combo_box_text
from gtweak.gsettings import GSettingsSetting
from gtweak.tweakmodel import TweakGroup
from gtweak.widgets import GSettingsSwitchTweak, GSettingsComboTweak
class ThemeSwitcher(Tweak):
class ThemeSwitcher(GSettingsComboTweak):
""" Only shows themes that have variations for gtk+-3 and gtk+-2 """
def __init__(self, **options):
self.key_name = "gtk-theme"
self.settings = GSettingsSetting("org.gnome.desktop.interface")
Tweak.__init__(self,
self.settings.schema_get_summary(self.key_name),
self.settings.schema_get_description(self.key_name),
**options)
valid_themes = []
themedir = os.path.join(gtweak.DATA_DIR, "themes")
for t in os.listdir(themedir):
if os.path.exists(os.path.join(themedir, t, "gtk-2.0")) and \
os.path.exists(os.path.join(themedir, t, "gtk-3.0")):
valid_themes.append(t)
combo = build_combo_box_text(
self.settings.get_value(self.key_name),
*[(t, t) for t in valid_themes])
combo.connect('changed', self._on_combo_changed)
self.widget = build_label_beside_widget(self.name, combo)
def _on_combo_changed(self, combo):
_iter = combo.get_active_iter()
if _iter:
value = combo.get_model().get_value(_iter, 0)
self.settings.set_value(self.key_name, value)
GSettingsComboTweak.__init__(self,
"org.gnome.desktop.interface",
"gtk-theme",
[(t, t) for t in valid_themes],
**options)
TWEAK_GROUPS = (
TweakGroup(
......
......@@ -112,6 +112,26 @@ class GSettingsComboEnumTweak(_GSettingsTweak):
if self._values_are_different():
self.settings.set_value(self.key_name, val)
class GSettingsComboTweak(_GSettingsTweak):
def __init__(self, schema_name, key_name, key_options, **options):
_GSettingsTweak.__init__(self, schema_name, key_name, **options)
assert len(key_options) > 0
assert len(key_options[0]) == 2
combo = build_combo_box_text(
self.settings.get_value(self.key_name),
*key_options)
combo.connect('changed', self._on_combo_changed)
self.widget = build_label_beside_widget(self.name, combo)
self.widget_for_size_group = combo
def _on_combo_changed(self, combo):
_iter = combo.get_active_iter()
if _iter:
value = combo.get_model().get_value(_iter, 0)
self.settings.set_value(self.key_name, value)
class _GConfTweak(Tweak):
def __init__(self, key_name, key_type, **options):
self.gconf = GConfSetting(key_name, key_type)
......
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