[gnome-tweak-tool] Support multiple schema per .gschema.xml file



commit e16e6525149c9a187398f33908567a06c41f7f77
Author: John Stowers <john stowers gmail com>
Date:   Mon Mar 21 16:22:06 2011 +1300

    Support multiple schema per .gschema.xml file

 gtweak/gsettings.py |   33 ++++++++++++++++++++-------------
 gtweak/widgets.py   |    2 +-
 2 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/gtweak/gsettings.py b/gtweak/gsettings.py
index 1f0c5d5..2010678 100644
--- a/gtweak/gsettings.py
+++ b/gtweak/gsettings.py
@@ -6,35 +6,42 @@ import gtweak
 from gi.repository import Gio, GLib
 
 class _GSettingsSchema:
-    def __init__(self, schema_name, schema_dir=None, schema_file=None):
+    def __init__(self, schema_name, schema_dir=None, schema_filename=None, **options):
         if not schema_dir:
             schema_dir = gtweak.GSETTINGS_SCHEMA_DIR
-        if not schema_file:
-            schema_file = os.path.join(schema_dir,schema_name) + ".gschema.xml"
-        
-        print "creating schema cache: ", schema_file
+        if not schema_filename:
+            schema_filename = schema_name + ".gschema.xml"
+
+        schema_path = os.path.join(schema_dir, schema_filename)
+        assert(os.path.exists(schema_path))
 
-        assert(os.path.exists(schema_file))
+        self._schema_name = schema_name
         self._schema = {}
 
         try:
-            dom = xml.dom.minidom.parse(schema_file)
+            dom = xml.dom.minidom.parse(schema_path)
             for schema in dom.getElementsByTagName("schema"):
-                for key in schema.getElementsByTagName("key"):
-                    self._schema[key.getAttribute("name")] = {
-                            "summary"       :   key.getElementsByTagName("summary")[0].childNodes[0].data,
-                            "description"   :   key.getElementsByTagName("description")[0].childNodes[0].data}
+                if schema_name == schema.getAttribute("id"):
+                    for key in schema.getElementsByTagName("key"):
+                        self._schema[key.getAttribute("name")] = {
+                                "summary"       :   key.getElementsByTagName("summary")[0].childNodes[0].data,
+                                "description"   :   key.getElementsByTagName("description")[0].childNodes[0].data}
         except:
             import traceback
             traceback.print_exc()
 
+    def __repr__(self):
+        return "<gtweak.gsettings._GSettingsSchema: %s>" % self._schema_name
+
 _SCHEMA_CACHE = {}
 
 class GSettingsSetting(Gio.Settings):
-    def __init__(self, schema_name):
+    def __init__(self, schema_name, **options):
         Gio.Settings.__init__(self, schema_name)
         if schema_name not in _SCHEMA_CACHE:
-            _SCHEMA_CACHE[schema_name] = _GSettingsSchema(schema_name)
+            _SCHEMA_CACHE[schema_name] = _GSettingsSchema(schema_name, **options)
+            print "Caching schema: ", _SCHEMA_CACHE[schema_name]
+
         self._schema = _SCHEMA_CACHE[schema_name]
 
     def schema_get_summary(self, key):
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index 29646f5..9ab4401 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -40,7 +40,7 @@ class _GSettingsTweak(Tweak):
     def __init__(self, schema_name, key_name, **options):
         self.schema_name = schema_name
         self.key_name = key_name
-        self.settings = GSettingsSetting(schema_name)
+        self.settings = GSettingsSetting(schema_name, **options)
         Tweak.__init__(self,
             self.settings.schema_get_summary(key_name),
             self.settings.schema_get_description(key_name),



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