fixed gps track
[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, gobject
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.activate_resource("menu.main")
30
31     def activate_resource(self, name):
32         widget = self.registry.resource(name)
33         if widget is None:
34             widget = self.registry.resource("menu.main")
35         if isinstance(widget, gtk.Action):
36             widget.activate()
37         else:
38             self.show_widget(name, widget)
39
40     def show_widget(self, name, widget):
41         # Remove the current widget.
42         # If it is an Applet, stop it
43         if self.current is not None:
44             cur = self.registry.resource(self.current)
45             if isinstance(cur, zavai.Applet):
46                 cur.stop()
47             self.remove(self.get_child())
48             self.current = None
49
50         # Add the new widget. If it is an applet, start it
51         self.add(widget)
52         self.current = name
53         if isinstance(widget, zavai.Applet):
54             widget.start()
55         widget.show_all()
56
57     def run(self):
58         self.set_size_request(100, 200)
59         #self.fullscreen()
60         self.show_all()
61         gtk.main()
62
63 class Applet(gtk.VBox):
64     name = gobject.property(type=str)
65     label = gobject.property(type=str)
66
67     def __init__(self, registry, name, label = None):
68         super(Applet, self).__init__()
69
70         self.zavai_registry = registry
71
72         self.props.name = name
73         if label is None:
74             self.props.label = zavai.default_label(name)
75         else:
76             self.props.label = label
77
78         self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
79         self.pack_end(self.back_link, False, False)
80
81     def add(self, widget):
82         self.pack_start(widget, True, True)
83
84     def shutdown(self):
85         self.stop()
86
87     def start(self, *args):
88         pass
89
90     def stop(self, *args):
91         pass