New style request
[gregoa/zavai.git] / plugins / 55_gpx_trace.py
1 # gpx_trace - zavai GPX trace functions
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 from gettext import gettext as _
20 import gtk
21 import zavai
22
23 class GPXTracer(gtk.ToggleAction):
24     states = [_("Start GPX trace"), _("Stop GPX trace")]
25
26     def __init__(self, registry, **kw):
27         self.state = 0
28         super(GPXTracer, self).__init__("menu.main.gps.toggle", self.states[self.state], None, None)
29
30         self.registry = registry
31         self.set_active(False)
32
33         self.connect("toggled", self.on_toggle)
34
35     def on_toggle(self, *args):
36         self.state = (self.state + 1) % len(self.states)
37         self.set_property("label", self.states[self.state])
38         if self.get_active():
39             self.start()
40         else:
41             self.stop()
42
43     def start(self):
44         zavai.info("GPX trace started")
45         self.registry.resource("gpx").connect("gpx", self)
46
47     def stop(self):
48         zavai.info("GPX trace ended")
49         self.registry.resource("gpx").disconnect("gpx", self)
50
51 class GPXWaypoint(gtk.Action):
52     def __init__(self, registry, **kw):
53         super(GPXWaypoint, self).__init__("menu.main.gps.waypoint", _("Take waypoint"), None, None)
54         self.gpx = registry.resource("gpx")
55         self.gpx.add_activity_monitor(self.on_gpx_activity_changed)
56         self.connect("activate", self.on_activate)
57
58     def on_gpx_activity_changed(self, gpx, state):
59         self.set_sensitive(state)
60
61     def on_activate(self, *args):
62         self.gpx.waypoint()
63
64
65 def init(conf = None, registry = None, **kw):
66     registry.register(GPXTracer(registry))
67     registry.register(GPXWaypoint(registry))