Consolidated register_action into register
authorEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 09:31:25 +0000 (17:31 +0800)
committerEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 09:31:25 +0000 (17:31 +0800)
zavai/registry.py

index cece6c738a5d27e6f15bd73b0c8b3cbcc755c9ff..86198fd1ecccbcd8a7514122045bdeec735b1752 100644 (file)
@@ -71,33 +71,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"