Some attempt to compile it with new vala, failed
[gregoa/zavai.git] / plugins / 50_sat_monitor.py
index 47458dcf92fa862d3bdc0c8cf42918b7d0a55d49..e44108463806dbf3b5c363fddecf2586d8f11318 100644 (file)
@@ -18,8 +18,7 @@
 
 import gtk
 import sys
-import gettext
-_ = gettext.gettext
+from gettext import gettext as _
 import zavai
 
 SAT_QI_NAMES = {
@@ -33,15 +32,16 @@ SAT_QI_NAMES = {
     7: _("receiving data")
 }
 
-class SatelliteMonitor(gtk.VBox, zavai.Resource):
-    def __init__(self, registry, name, **kw):
-        super(SatelliteMonitor, self).__init__()
+class SatelliteMonitor(zavai.Applet):
+    def __init__(self, registry, **kw):
+        super(SatelliteMonitor, self).__init__(registry,
+                "menu.main.gps.satellite_monitor",
+                _("Satellite monitor"))
 
-        self.gps = registry.resource("gps")
+        self.gps = None
 
         self.store = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str)
         self.view = gtk.TreeView(self.store)
-
         renderer = gtk.CellRendererText()
         for idx, name in enumerate((_("CH"), _("ID"), _("SN"), _("ELE"), _("AZI"),
                      _("Used"), _("Diff"), _("Alm"), _("Eph"),
@@ -50,21 +50,18 @@ class SatelliteMonitor(gtk.VBox, zavai.Resource):
             col.pack_start(renderer, False)
             col.add_attribute(renderer, "text", idx)
             self.view.append_column(col)
+        self.add(self.view)
 
-        self.back = registry.menu_link("gps", _("Back"))
-        self.back.connect("clicked", self.stop)
-
-        self.pack_start(self.view, True, True)
-        self.pack_start(self.back, False, False)
-
-    def shutdown(self):
-        self.stop()
+    def init(self):
+        self.gps = self.zavai_registry.resource("gps")
 
     def start(self, *args):
-        self.gps.monitor.connect(self.on_ubxdebug_packet)
+        if self.gps is None:
+            self.init()
+        self.gps.monitor.connect("satellites", self.on_ubxdebug_packet)
 
     def stop(self, *args):
-        self.gps.monitor.disconnect(self.on_ubxdebug_packet)
+        self.gps.monitor.disconnect("satellites", self.on_ubxdebug_packet)
 
     def on_ubxdebug_packet(self, clid, length, data):
         # In zhone it is cbUBXDebugPacket
@@ -104,19 +101,5 @@ class SatelliteMonitor(gtk.VBox, zavai.Resource):
                 bad and "bad" or "",
                 qi])
 
-def start_monitor(registry):
-    monitor = registry.resource("app.satellite_monitor")
-    registry.resource("app").show_widget("app.satellite_monitor")
-    monitor.start()
-
 def init(conf = None, registry = None, **kw):
-    registry.register("app.satellite_monitor", SatelliteMonitor)
-    menu_gps = registry.menu("main.gps")
-
-    monitor = zavai.MenuButton(_("Monitor"))
-    monitor.connect("clicked", lambda *args: start_monitor(registry))
-    menu_gps.add_child(monitor)
-
-    # TODO: automate this in registry
-    registry.menu("main").add_child(registry.menu_link("main.gps", _("GPS")))
-
+    registry.register(SatelliteMonitor(registry))