1 # gpx_trace - zavai GPX trace functions
3 # Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
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.
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.
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
19 from gettext import gettext as _
23 class GPXTracer(gtk.ToggleAction):
24 states = [_("Start GPX trace"), _("Stop GPX trace")]
26 def __init__(self, registry, **kw):
28 super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
30 self.registry = registry
31 self.set_active(False)
33 self.connect("toggled", self.on_toggle)
35 def on_toggle(self, *args):
36 self.state = (self.state + 1) % len(self.states)
37 self.set_property("label", self.states[self.state])
44 zavai.info("GPX trace started")
45 self.registry.resource("gpx").connect("gpx", self)
48 zavai.info("GPX trace ended")
49 self.registry.resource("gpx").disconnect("gpx", self)
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)
58 def on_gpx_activity_changed(self, gpx, state):
59 self.set_sensitive(state)
61 def on_activate(self, *args):
64 class GPXAudioTracer(gtk.ToggleAction):
65 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
67 def __init__(self, registry, **kw):
69 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
71 self.registry = registry
72 self.recorder = zavai.Recorder(registry)
73 self.set_active(False)
75 self.connect("toggled", self.on_toggle)
79 super(GPXAudioTracer, self).shutdown()
81 def on_toggle(self, *args):
82 self.state = (self.state + 1) % len(self.states)
83 self.set_property("label", self.states[self.state])
90 zavai.info("GPX trace started")
91 gpx = self.registry.resource("gpx")
92 gpx.connect("gpx", self)
93 gpx.add_activity_monitor(self.on_gpx_activity_changed)
96 zavai.info("GPX trace ended")
97 gpx = self.registry.resource("gpx")
98 gpx.disconnect("gpx", self)
100 gpx.del_activity_monitor(self.on_gpx_activity_changed)
102 def on_gpx_activity_changed(self, gpx, state):
104 self.recorder.start(gpx.basename + ".wav")
108 def init(conf = None, registry = None, **kw):
109 registry.register(GPXTracer(registry))
110 registry.register(GPXAudioTracer(registry))
111 registry.register(GPXWaypoint(registry))