No need to fullscreen: matchbox does it for us
[gregoa/zavai.git] / zavai / registry.py
index cece6c738a5d27e6f15bd73b0c8b3cbcc755c9ff..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".
@@ -71,33 +74,20 @@ class Registry(object):
         self.factories[name] = fac
         if label is not None: self.labels[name] = label
 
-    def register_action(self, name, obj):
-        """Register an object at the given path.
-
-        Name the path to this object, like "menu.gps.monitor".
-        """
-        if name in self.objects:
-            return KeyError("%s is already registered", name)
-        zavai.info("Registering action", name)
-        self.objects[name] = obj
-
-        if name.startswith("menu."):
-            parent = get_parent(name)
-            if parent is not None:
-                zavai.info("Add action to menu", name, parent)
-                menu = self.menu(parent)
-                if isinstance(obj, gtk.ToggleAction):
-                    menu.add_child(zavai.ToggleButton(self, name, action=obj))
-                else:
-                    menu.add_child(zavai.LinkButton(self, name, action=obj))
-
     def add_to_menu(self, name):
         "Add the applet with the given name to the menu structure"
         parent = get_parent(name)
         if parent is not None:
             zavai.info("Add to menu", name, parent)
             menu = self.menu(parent)
-            menu.add_child(zavai.LinkButton(self, name, self.label(name)))
+
+            obj = self.resource(name)
+            if isinstance(obj, gtk.ToggleAction):
+                menu.add_child(zavai.ToggleButton(self, name, action=obj))
+            elif isinstance(obj, gtk.Action):
+                menu.add_child(zavai.LinkButton(self, name, action=obj))
+            else:
+                menu.add_child(zavai.LinkButton(self, name, self.label(name)))
 
     def label(self, name):
         "Return the label for the object with the given name"
@@ -142,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):