UI Elements do not go through register_factory
[gregoa/zavai.git] / plugins / 50_sat_monitor.py
index 47458dcf92fa862d3bdc0c8cf42918b7d0a55d49..243697dea4f9b02092889bae8405a604033777cd 100644 (file)
@@ -18,8 +18,7 @@
 
 import gtk
 import sys
 
 import gtk
 import sys
-import gettext
-_ = gettext.gettext
+from gettext import gettext as _
 import zavai
 
 SAT_QI_NAMES = {
 import zavai
 
 SAT_QI_NAMES = {
@@ -33,15 +32,16 @@ SAT_QI_NAMES = {
     7: _("receiving data")
 }
 
     7: _("receiving data")
 }
 
-class SatelliteMonitor(gtk.VBox, zavai.Resource):
+class SatelliteMonitor(gtk.VBox, zavai.Applet):
     def __init__(self, registry, name, **kw):
     def __init__(self, registry, name, **kw):
-        super(SatelliteMonitor, self).__init__()
+        zavai.Applet.__init__(self, registry, name)
+        gtk.VBox.__init__(self)
 
 
-        self.gps = registry.resource("gps")
+        self.registry = registry
+        self.gps = None
 
         self.store = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str)
         self.view = gtk.TreeView(self.store)
 
         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"),
         renderer = gtk.CellRendererText()
         for idx, name in enumerate((_("CH"), _("ID"), _("SN"), _("ELE"), _("AZI"),
                      _("Used"), _("Diff"), _("Alm"), _("Eph"),
@@ -51,16 +51,16 @@ class SatelliteMonitor(gtk.VBox, zavai.Resource):
             col.add_attribute(renderer, "text", idx)
             self.view.append_column(col)
 
             col.add_attribute(renderer, "text", idx)
             self.view.append_column(col)
 
-        self.back = registry.menu_link("gps", _("Back"))
-        self.back.connect("clicked", self.stop)
-
         self.pack_start(self.view, True, True)
         self.pack_start(self.view, True, True)
-        self.pack_start(self.back, False, False)
+        self.pack_start(self.make_parent_link(), False, False)
 
 
-    def shutdown(self):
-        self.stop()
+
+    def init(self):
+        self.gps = self.registry.resource("gps")
 
     def start(self, *args):
 
     def start(self, *args):
+        if self.gps is None:
+            self.init()
         self.gps.monitor.connect(self.on_ubxdebug_packet)
 
     def stop(self, *args):
         self.gps.monitor.connect(self.on_ubxdebug_packet)
 
     def stop(self, *args):
@@ -104,19 +104,6 @@ class SatelliteMonitor(gtk.VBox, zavai.Resource):
                 bad and "bad" or "",
                 qi])
 
                 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):
 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")))
-
+    name = "menu.main.gps.satellite_monitor"
+    registry.register(name, SatelliteMonitor(registry, name), _("Satellite monitor"))