Moved powerbutton UI in the right place
[gregoa/zavai.git] / zavai / menu.py
index b1ff0e1221c762d1ea7c423126682f9b0ac2181e..629495afda2c6551230517e45191ffe292032332 100644 (file)
@@ -17,6 +17,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import sys
+from gettext import gettext as _
 import zavai
 import gtk
 
@@ -27,32 +28,41 @@ class MenuButton(gtk.Button):
         self.set_size_request(0, 80)
 
 class Menu(gtk.VBox, zavai.Resource):
-    def __init__(self, registry, name, *args, **kw):
+    def __init__(self, registry, name, parent = None, *args, **kw):
         super(Menu, self).__init__()
         self.vbox = self
 
-        parent = None
-        pos = name.rfind(".")
-        if pos != -1:
-            parent = name[:pos]
-            if parent == "menu":
-                parent = None
-
         if parent is not None:
             self.vbox = gtk.VBox()
             self.pack_start(self.vbox, False, False)
             self.pack_start(gtk.Label(""), True, True)
-            self.pack_start(registry.menu_link(parent, "Back"), False, False)
+            self.pack_start(LinkButton(registry, parent, _("Back")), False, False)
 
     def add_child(self, widget):
         self.vbox.pack_start(widget, False, False)
 
-class MenuLink(MenuButton, zavai.Resource):
-    def __init__(self, registry, targetName, label):
-        super(MenuLink, self).__init__(label)
-        self.target = "menu." + targetName
-        self.registry = registry
-        self.connect("clicked", self.on_click)
+class LinkButton(MenuButton, zavai.Resource):
+    def __init__(self, registry, targetName, label=None, action=None):
+        if action is not None:
+            super(LinkButton, self).__init__()
+            self.target = targetName
+            self.registry = registry
+            self.action = action
+            action.connect_proxy(self)
+            self.connect("clicked", self.on_click)
+        else:
+            super(LinkButton, self).__init__(label)
+            self.target = targetName
+            self.registry = registry
+            self.action = None
+            self.connect("clicked", self.on_click)
 
     def on_click(self, *args):
-        self.registry.resource("app").show_widget(self.target)
+        self.registry.resource("app").activate_resource(self.target)
+
+class ToggleButton(gtk.ToggleButton):
+    def __init__(self, registry, targetName, action, *args, **kw):
+        super(ToggleButton, self).__init__()
+        # TODO: take this from the configuration
+        self.set_size_request(0, 80)
+        action.connect_proxy(self)