Added option to take waypoints
authorEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 11:21:39 +0000 (19:21 +0800)
committerEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 11:21:39 +0000 (19:21 +0800)
plugins/55_gpx_trace.py
zavai/gps.py

index 1c84c694fa15ac9807bade00101a4ccab1e569a7..b4c1106134b48d6fd31ac1ff5a5d411e06356ee5 100644 (file)
@@ -48,5 +48,20 @@ class GPXTracer(gtk.ToggleAction):
         zavai.info("GPX trace ended")
         self.registry.resource("gpx").release(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()
+
+
 def init(conf = None, registry = None, **kw):
     registry.register(GPXTracer(registry))
+    registry.register(GPXWaypoint(registry))
index ff97253bd589c2d5f240bba2f14fbe298b09f142..47af68fb9f76e6b7970c3cba824be53e12ffa571 100755 (executable)
@@ -256,6 +256,18 @@ class GPX(zavai.Resource):
         if not os.path.isdir(self.trackdir):
             zavai.info("Creating directory", self.trackdir)
             os.makedirs(self.trackdir)
+        self.activity_monitors = set()
+
+    def add_activity_monitor(self, cb):
+        self.activity_monitors.add(cb)
+        cb(self, self.last_pos is not None)
+
+    def del_activity_monitor(self, cb):
+        self.activity_monitors.discard(cb)
+
+    def notify_activity_monitors(self):
+        for mon in self.activity_monitors:
+            mon(self, self.last_pos is not None)
 
     def request(self, tag):
         "Request the GPX trace to be taken"
@@ -307,6 +319,7 @@ class GPX(zavai.Resource):
     xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">""" % VERSION
 
         self.wpt_seq = 1;
+        self.notify_activity_monitors()
 
     def stop(self):
         if self.trk is not None:
@@ -318,6 +331,7 @@ class GPX(zavai.Resource):
             self.wpt.close()
             self.wpt = None
         self.last_pos = None
+        self.notify_activity_monitors()
 
     def shutdown(self):
         self.stop()