[gnome-tweak-tool] Factor out a GConfComboTweak



commit 884869a0693d6654ce5481840ded492423658502
Author: John Stowers <john stowers gmail com>
Date:   Fri Mar 18 14:20:44 2011 +1300

    Factor out a GConfComboTweak

 gtweak/tweaks/tweak_shell.py |   28 ++++++++--------------------
 gtweak/widgets.py            |   31 ++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_shell.py b/gtweak/tweaks/tweak_shell.py
index b167b76..879218e 100644
--- a/gtweak/tweaks/tweak_shell.py
+++ b/gtweak/tweaks/tweak_shell.py
@@ -6,33 +6,21 @@ import tempfile
 from gi.repository import Gtk
 from gi.repository import GLib
 
-from gtweak.gconf import GConfSetting
 from gtweak.gsettings import GSettingsSetting
 from gtweak.gshellwrapper import GnomeShell
 from gtweak.tweakmodel import Tweak, TweakGroup
-from gtweak.widgets import GSettingsComboEnumTweak, build_label_beside_widget, build_combo_box_text, build_horizontal_sizegroup
+from gtweak.widgets import GConfComboTweak, GSettingsComboEnumTweak, build_label_beside_widget, build_horizontal_sizegroup
 
-class ShowWindowButtons(Tweak):
+class ShowWindowButtons(GConfComboTweak):
     def __init__(self, **options):
-        Tweak.__init__(self, "Window buttons", "Should the maximize and minimize buttons be shown", **options)
-
-        self._gconf = GConfSetting("/desktop/gnome/shell/windows/button_layout", str)
-
-        combo = build_combo_box_text(
-            self._gconf.get_value(),
-            (':close', 'Close Only'),
+        GConfComboTweak.__init__(self,
+            "/desktop/gnome/shell/windows/button_layout",
+            str,
+            ((':close', 'Close Only'),
             (':minimize,close', 'Minimize and Close'),
             (':maximize,close', 'Maximize and Close'),
-            (':minimize,maximize,close', 'All'))
-        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._gconf.set_value(value)
+            (':minimize,maximize,close', 'All')),
+            **options)
 
 class _ThemeZipChooser(Gtk.FileChooserButton):
     def __init__(self):
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index 39b9176..9765f3c 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -2,6 +2,7 @@ from gi.repository import Gtk, Gio
 
 from gtweak.tweakmodel import Tweak
 from gtweak.gsettings import GSettingsSetting
+from gtweak.gconf import GConfSetting
 
 def build_label_beside_widget(txt, widget, hbox=None):
     if not hbox:
@@ -103,7 +104,7 @@ class GSettingsComboEnumTweak(_GSettingsTweak):
         model = self.combo.get_model()
         for row in model:
             if val == row[0]:
-                self.combo.set_active_iter(row.iter) #iter_ = self.combo.get_model().get_iter(row)
+                self.combo.set_active_iter(row.iter)
                 break
 
     def _on_combo_changed(self, combo):
@@ -111,3 +112,31 @@ class GSettingsComboEnumTweak(_GSettingsTweak):
         if self._values_are_different():
             self.settings.set_value(self.key_name, val)
 
+class _GConfTweak(Tweak):
+    def __init__(self, key_name, key_type, **options):
+        self.gconf = GConfSetting(key_name, key_type)
+        Tweak.__init__(self,
+            self.gconf.schema_get_summary(),
+            self.gconf.schema_get_description(),
+            **options)
+
+class GConfComboTweak(_GConfTweak):
+    def __init__(self, key_name, key_type, key_options, **options):
+        _GConfTweak.__init__(self, key_name, key_type, **options)
+
+        assert len(key_options) > 0
+        assert len(key_options[0]) == 2
+
+        combo = build_combo_box_text(
+            self.gconf.get_value(),
+            *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.gconf.set_value(value)
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]