More skip hints
[gregoa/zavai.git] / zavai / menu.py
index 21559d3877a7a9a4f1a87db17149f70ec895fd18..629495afda2c6551230517e45191ffe292032332 100644 (file)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import sys
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import sys
+from gettext import gettext as _
 import zavai
 import gtk
 
 import zavai
 import gtk
 
+class MenuButton(gtk.Button):
+    def __init__(self, *args, **kw):
+        super(MenuButton, self).__init__(*args, **kw)
+        # TODO: take this from the configuration
+        self.set_size_request(0, 80)
+
 class Menu(gtk.VBox, zavai.Resource):
 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
 
         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()
         if parent is not None:
             self.vbox = gtk.VBox()
-            self.pack_start(self.vbox)
-            self.pack_start(registry.menu_link(parent, "Back"), True, True)
+            self.pack_start(self.vbox, False, False)
+            self.pack_start(gtk.Label(""), True, True)
+            self.pack_start(LinkButton(registry, parent, _("Back")), False, False)
 
     def add_child(self, widget):
 
     def add_child(self, widget):
-        self.vbox.pack_start(widget, True, True)
+        self.vbox.pack_start(widget, False, False)
 
 
-class MenuLink(gtk.Button, 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):
 
     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)