Implemented GPX + Audio recording
[gregoa/zavai.git] / plugins / 55_gpx_trace.py
index b4c1106134b48d6fd31ac1ff5a5d411e06356ee5..d85f41de52708c79a5fbf54531231f6039cf4c9c 100644 (file)
@@ -25,7 +25,7 @@ class GPXTracer(gtk.ToggleAction):
 
     def __init__(self, registry, **kw):
         self.state = 0
-        super(GPXTracer, self).__init__("menu.main.gps.toggle", self.states[self.state], None, None)
+        super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
 
         self.registry = registry
         self.set_active(False)
@@ -42,11 +42,11 @@ class GPXTracer(gtk.ToggleAction):
 
     def start(self):
         zavai.info("GPX trace started")
-        self.registry.resource("gpx").request(self)
+        self.registry.resource("gpx").connect("gpx", self)
 
     def stop(self):
         zavai.info("GPX trace ended")
-        self.registry.resource("gpx").release(self)
+        self.registry.resource("gpx").disconnect("gpx", self)
 
 class GPXWaypoint(gtk.Action):
     def __init__(self, registry, **kw):
@@ -61,7 +61,49 @@ class GPXWaypoint(gtk.Action):
     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")
+        self.registry.resource("gpx").connect("gpx", self)
+        self.gpx.add_activity_monitor(self.on_gpx_activity_changed)
+
+    def stop(self):
+        zavai.info("GPX trace ended")
+        self.registry.resource("gpx").disconnect("gpx", self)
+        self.recorder.stop()
+        self.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))