Infer object name from 'name' property
authorEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 09:44:08 +0000 (17:44 +0800)
committerEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 09:44:08 +0000 (17:44 +0800)
plugins/50_sat_monitor.py
plugins/99_debug.py
src/zavai
zavai/app.py
zavai/registry.py

index 8f82d1f49ea3bafd2d5d53595e374354ac1178dd..41be4b0bf4a0b5787664f51344211b25d59c8965 100644 (file)
@@ -33,8 +33,10 @@ SAT_QI_NAMES = {
 }
 
 class SatelliteMonitor(zavai.Applet):
-    def __init__(self, registry, name, **kw):
-        super(SatelliteMonitor, self).__init__(registry, name, _("Satellite monitor"))
+    def __init__(self, registry, **kw):
+        super(SatelliteMonitor, self).__init__(registry,
+                "menu.main.gps.satellite_monitor",
+                _("Satellite monitor"))
 
         self.gps = None
 
@@ -100,5 +102,4 @@ class SatelliteMonitor(zavai.Applet):
                 qi])
 
 def init(conf = None, registry = None, **kw):
-    name = "menu.main.gps.satellite_monitor"
-    registry.register(name, SatelliteMonitor(registry, name))
+    registry.register(SatelliteMonitor(registry))
index 7d2f959ca667328c576ba8c383c3ce78658e99d0..f5015cd38bbeee7534096efd7fd6b1bf2c94acf4 100644 (file)
@@ -22,20 +22,16 @@ from gettext import gettext as _
 import zavai
 
 class Useless(zavai.Applet):
-    def __init__(self, registry, name, **kw):
-        zavai.Applet.__init__(self, registry, name, _("Useless"))
+    def __init__(self, registry, **kw):
+        zavai.Applet.__init__(self, registry, "menu.main.debug.useless", _("Useless"))
         self.add(gtk.Label(_("This has no use")))
 
-class Quitter(zavai.Applet):
-    def __init__(self, registry, name, **kw):
-        zavai.Applet.__init__(self, registry, name, _("Quit"))
-        self.add(gtk.Label(_("Shutting down...")))
+class Quitter(gtk.Action):
+    def __init__(self, **kw):
+        super(Quitter, self).__init__("menu.main.debug.quit", _("Quit"), None, None)
 
-    def start(self, *args):
-        gtk.main_quit()
+        self.connect("activate", gtk.main_quit)
 
 def init(conf = None, registry = None, **kw):
-    name = "menu.main.debug.useless"
-    registry.register(name, Useless(registry, name))
-    name = "menu.main.debug.quit"
-    registry.register(name, Quitter(registry, name))
+    registry.register(Useless(registry))
+    registry.register(Quitter())
index 897dd7f15f2707dd43a9f85bf02ac9e6d6e2993e..d425b328cacc128b5d67d8753d8aff700cae0db1 100755 (executable)
--- a/src/zavai
+++ b/src/zavai
@@ -61,10 +61,10 @@ dbus_system_bus = dbus.SystemBus()
 registry = zavai.Registry()
 
 # Register main factories
-registry.register("dbus.system_bus", dbus_system_bus)
-registry.register("conf", conf)
-registry.register_factory("app", zavai.Zavai)
-registry.register_factory("gps", zavai.GPS)
+registry.register(dbus_system_bus, "dbus.system_bus")
+registry.register(conf, "conf")
+registry.register_factory(zavai.Zavai, "app")
+registry.register_factory(zavai.GPS, "gps")
 
 # Load plugins
 zavai.info("Loading plugins")
index dfa86cc4eaac613fb45deedf86a913e3d6d2e788..22be04e3cfafc85d002e75d0f660c6bde20d995e 100644 (file)
@@ -60,16 +60,20 @@ class Zavai(gtk.Window, zavai.Resource):
         gtk.main()
 
 class Applet(gtk.VBox):
+    name = gobject.property(type=str)
     label = gobject.property(type=str)
 
     def __init__(self, registry, name, label = None):
         super(Applet, self).__init__()
+
         self.zavai_registry = registry
-        self.zavai_name = name
+
+        self.props.name = name
         if label is None:
             self.props.label = zavai.default_label(name)
         else:
             self.props.label = label
+
         self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
         self.pack_end(self.back_link, False, False)
 
index 86198fd1ecccbcd8a7514122045bdeec735b1752..4af413c83e9e02c9dd4a313ece374d507c70de67 100644 (file)
@@ -47,11 +47,14 @@ class Registry(object):
         self.objects = dict()
         self.labels = dict()
 
-    def register(self, name, obj):
+    def register(self, obj, name=None):
         """Register an object at the given path.
 
         Name the path to this object, like "menu.gps.monitor".
         """
+        if name is None:
+            name = obj.props.name
+
         if name in self.objects:
             return KeyError("%s is already registered", name)
         zavai.info("Registering", name)
@@ -60,7 +63,7 @@ class Registry(object):
         if name.startswith("menu."):
             self.add_to_menu(name)
 
-    def register_factory(self, name, fac, label = None):
+    def register_factory(self, fac, name, label = None):
         """Register an object factory at the given path.
 
         Name the path to this object, like "menu.gps.monitor".
@@ -129,7 +132,7 @@ class Registry(object):
                 parent = get_parent(name)
 
             res = zavai.Menu(self, name, parent)
-            self.register(name, res)
+            self.register(res, name)
         return res
 
     def shutdown(self):