+# menu - zavai menus
+#
+# Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
import sys
+from gettext import gettext as _
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):
- def __init__(self, registry, name, *args, **kw):
+ def __init__(self, registry, name, parent = None, *args, **kw):
super(Menu, self).__init__()
self.vbox = self
- print >>sys.stderr, "PARENT?", name
- parent = None
- pos = name.rfind(".")
- if pos != -1:
- parent = name[:pos]
- print >>sys.stderr, "PARENT IS", parent
- if parent == "menu":
- parent = None
- print >>sys.stderr, "PARENT MAIN?"
-
if parent is not None:
- print >>sys.stderr, "MAKE PARENT"
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):
- 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):
- 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)