Added action to keep the GPS always on
authorEnrico Zini <enrico@enricozini.org>
Tue, 16 Jun 2009 01:16:40 +0000 (09:16 +0800)
committerEnrico Zini <enrico@enricozini.org>
Tue, 16 Jun 2009 01:16:40 +0000 (09:16 +0800)
plugins/55_gpx_trace.py

index 7cffc08174fdb47b64d1f3e020ccd81c1416900e..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")]
 
@@ -109,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))