Access linux/input.h via a vapi file
[gregoa/zavai.git] / plugins / 55_gpx_trace.py
index d85f41de52708c79a5fbf54531231f6039cf4c9c..6cc08ace44edaa9bc0f6237d3a1cf4989e570ad8 100644 (file)
@@ -20,6 +20,32 @@ from gettext import gettext as _
 import gtk
 import zavai
 
+class GPSOn(gtk.ToggleAction):
+    states = [_("GPS always on"), _("GPS on when needed")]
+
+    def __init__(self, registry, **kw):
+        self.state = 0
+        super(GPSOn, self).__init__("menu.main.gps.alwayson", 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):
+        self.registry.resource("gps").connect("gps", self)
+
+    def stop(self):
+        self.registry.resource("gps").disconnect("gps", self)
+
 class GPXTracer(gtk.ToggleAction):
     states = [_("Start GPX trace"), _("Stop GPX trace")]
 
@@ -88,14 +114,16 @@ class GPXAudioTracer(gtk.ToggleAction):
 
     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)
+        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")
-        self.registry.resource("gpx").disconnect("gpx", self)
+        gpx = self.registry.resource("gpx")
+        gpx.disconnect("gpx", self)
         self.recorder.stop()
-        self.gpx.del_activity_monitor(self.on_gpx_activity_changed)
+        gpx.del_activity_monitor(self.on_gpx_activity_changed)
 
     def on_gpx_activity_changed(self, gpx, state):
         if state:
@@ -107,3 +135,4 @@ def init(conf = None, registry = None, **kw):
     registry.register(GPXTracer(registry))
     registry.register(GPXAudioTracer(registry))
     registry.register(GPXWaypoint(registry))
+    registry.register(GPSOn(registry))