537ff8516aae54a65fdf1c524dc41241f7fe7f16
[gregoa/zavai.git] / zavai / app.py
1 # app - zavai main window
2 #
3 # Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19 import sys
20 from gettext import gettext as _
21 import gtk
22 import zavai
23
24 class Zavai(gtk.Window, zavai.Resource):
25     def __init__(self, registry, name):
26         super(Zavai, self).__init__()
27         self.registry = registry
28         self.current = None
29         self.show_widget("menu.main")
30
31     def show_widget(self, name):
32         # Remove the current widget.
33         # If it is an Applet, stop it
34         if self.current is not None:
35             cur = self.registry.resource(self.current)
36             if isinstance(cur, zavai.Applet):
37                 cur.stop()
38             self.remove(self.get_child())
39             self.current = None
40
41         # Add the new widget. If it is an applet, start it
42         widget = self.registry.resource(name)
43         if widget is None:
44             widget = self.registry.resource("menu.main")
45         self.add(widget)
46         self.current = name
47         if isinstance(widget, zavai.Applet):
48             widget.start()
49         widget.show_all()
50
51     def run(self):
52         self.fullscreen()
53         self.show_all()
54         gtk.main()
55
56 class Applet(zavai.Resource):
57     def __init__(self, registry, name):
58         super(Applet, self).__init__()
59         self.zavai_registry = registry
60         self.zavai_name = name
61
62     def make_parent_link(self):
63         return zavai.LinkButton(self.zavai_registry, zavai.get_parent(self.zavai_name), _("Back"))
64
65     def shutdown(self):
66         self.stop()
67
68     def start(self, *args):
69         pass
70
71     def stop(self, *args):
72         pass