# gpx_trace - zavai GPX trace functions # # Copyright (C) 2009 Enrico Zini # # 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 from gettext import gettext as _ import gtk import zavai class GPXTracer(gtk.ToggleAction): states = [_("Start GPX trace"), _("Stop GPX trace")] def __init__(self, registry, **kw): self.state = 0 super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None) self.registry = registry self.set_active(False) self.connect("toggled", self.on_toggle) def on_toggle(self, *args): self.state = (self.state + 1) % len(self.states) self.set_property("label", self.states[self.state]) if self.get_active(): self.start() else: self.stop() def start(self): zavai.info("GPX trace started") self.registry.resource("gpx").connect("gpx", self) def stop(self): zavai.info("GPX trace ended") self.registry.resource("gpx").disconnect("gpx", self) class GPXWaypoint(gtk.Action): def __init__(self, registry, **kw): super(GPXWaypoint, self).__init__("menu.main.gps.waypoint", _("Take waypoint"), None, None) self.gpx = registry.resource("gpx") self.gpx.add_activity_monitor(self.on_gpx_activity_changed) self.connect("activate", self.on_activate) def on_gpx_activity_changed(self, gpx, state): self.set_sensitive(state) def on_activate(self, *args): self.gpx.waypoint() class GPXAudioTracer(gtk.ToggleAction): states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")] def __init__(self, registry, **kw): self.state = 0 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None) self.registry = registry self.recorder = zavai.Recorder(registry) self.set_active(False) self.connect("toggled", self.on_toggle) def shutdown(self): self.recorder.stop() super(GPXAudioTracer, self).shutdown() def on_toggle(self, *args): self.state = (self.state + 1) % len(self.states) self.set_property("label", self.states[self.state]) if self.get_active(): self.start() else: self.stop() def start(self): zavai.info("GPX trace started") gpx = self.registry.resource("gpx") gpx.connect("gpx", self) gpx.add_activity_monitor(self.on_gpx_activity_changed) def stop(self): zavai.info("GPX trace ended") gpx = self.registry.resource("gpx") gpx.disconnect("gpx", self) self.recorder.stop() gpx.del_activity_monitor(self.on_gpx_activity_changed) def on_gpx_activity_changed(self, gpx, state): if state: self.recorder.start(gpx.basename + ".wav") else: self.recorder.stop() def init(conf = None, registry = None, **kw): registry.register(GPXTracer(registry)) registry.register(GPXAudioTracer(registry)) registry.register(GPXWaypoint(registry))