Initial implementation of AP positions update
[wifihood] / wifiscanner / wifiscanner
index 7c6d3e4..f1fe5e4 100755 (executable)
@@ -8,18 +8,18 @@ try :
 except :
     hildon = False
 
-def global_start(button, scanner):
-    scanner.start()
+def global_start(button, scanner, config):
+    scanner.start( config.scan_period )
     if button._id :
         button.disconnect( button._id )
-    button._id = button.connect("clicked", global_stop, scanner)
+    button._id = button.connect("clicked", global_stop, scanner, config)
     button.set_label("Switch GPS Off")
 
-def global_stop(button, scanner):
+def global_stop(button, scanner, config):
     scanner.stop()
     if button._id :
         button.disconnect( button._id )
-    button._id = button.connect("clicked", global_start, scanner)
+    button._id = button.connect("clicked", global_start, scanner, config)
     button.set_label("Switch GPS On")
 
 def enable_agps(button):
@@ -43,22 +43,28 @@ def stop_scan(button, scanner):
     button.set_label("Start scanning")
 
 
-class scanner ( wifimap.Scanner ) :
+class scanner ( wifimap.ReplayScanner ) :
 
     def scan ( self ) :
-        wifimap.Scanner.scan( self )
+        wifimap.ReplayScanner.scan( self )
         self.report()
 
     def report ( self ) :
-        self.status.set_label( wifimap.Scanner.report(self) )
+        self.status.set_label( wifimap.ReplayScanner.report(self) )
         start, end = self.buffer.get_bounds()
         self.buffer.delete( start , end )
         for mac,rss in self.scanlist.iteritems() :
             self.buffer.insert_at_cursor( "%s %5d\n" % ( mac , rss ) )
         if self.info[0] == "FIX" :
             self.map.hide()
+            self.map.recenter( self.info[4:6] )
             pixmap,mask = self.map.get_pixbuf().render_pixmap_and_mask()
-            self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , 2 )
+            pointsize = 2
+            if self.newaps :
+                pointsize += 2
+            self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , pointsize )
+            while self.aps :
+                self.map.plot( pixmap , self.aps.pop() , "green" , 1 )
             self.map.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.map.win_x, self.map.win_y )
             self.map.show()
 
@@ -67,7 +73,7 @@ class AbstractWifiscanner :
 
     def __init__ ( self ) :
 
-        _scanner = scanner()
+        _scanner = scanner( "wlan0" )
 
         self.connect("delete_event", gtk.main_quit, None)
 
@@ -75,7 +81,6 @@ class AbstractWifiscanner :
 
         # Top frame creation
         top_frame = gtk.Frame()
-        self.vbox.pack_start(top_frame)
 
         hbox = gtk.HBox(homogeneous=False, spacing=0)
         top_frame.add(hbox)
@@ -84,6 +89,8 @@ class AbstractWifiscanner :
         bottom_frame = gtk.Frame()
         self.vbox.pack_end(bottom_frame, expand=False)
 
+        self.vbox.pack_end(top_frame)
+
         bottom_box = gtk.HBox(homogeneous=False, spacing=0)
         bottom_frame.add( bottom_box )
 
@@ -93,7 +100,8 @@ class AbstractWifiscanner :
 
         scrollview = gtk.ScrolledWindow()
         notebook.append_page( scrollview , gtk.Label("Scanning") )
-        notebook.append_page( MapWindow() , gtk.Label("Map") )
+        self.map = MapWindow()
+        notebook.append_page( self.map , gtk.Label("Map") )
 
         buttons = gtk.VBox(homogeneous=False, spacing=0)
         hbox.pack_end(buttons, expand=False)
@@ -104,7 +112,7 @@ class AbstractWifiscanner :
 
         # Buttons creation
         button = self.Button( "Switch GPS On")
-        button._id = button.connect("clicked", global_start, _scanner)
+        button._id = button.connect("clicked", global_start, _scanner, self.map.config)
         buttons.pack_start(button, expand=False)
 
         button_scan = self.Button( "Start scanning")
@@ -119,12 +127,16 @@ class AbstractWifiscanner :
         status = gtk.Label( "status bar ..." )
         _scanner.status = status
         _scanner.buffer = textview.get_buffer() 
-        _scanner.map = notebook.get_nth_page(1).child
+        _scanner.map = self.map.child
         bottom_box.pack_start( status , expand=False , padding=20 )
 
     def run ( self ) :
         gtk.main()
 
+def settings_cb ( widget , map ) :
+    window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
+
+
 if hildon :
 
     class MapWindow ( gtk.Frame ) :
@@ -132,22 +144,22 @@ if hildon :
         def __init__(self):
             gtk.Frame.__init__( self )
 
-            self.config = wifimap.config.Configuration()
-            self.config.zoom = 16
-            self.map = wifimap.simpleMapWidget( self.config )
-            self.map.plot_APs()
-            self.add( self.map )
+            self.config = wifimap.config.Configuration( 'scanner' )
+            self.add( wifimap.simpleMapWidget( self.config ) )
 
-    class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :
+    class Wifiscanner ( AbstractWifiscanner , hildon.StackableWindow ) :
 
         def __init__ ( self ) :
-            hildon.Window.__init__( self )
+            hildon.StackableWindow.__init__( self )
+            self.set_title( "Wifihood Scanner" )
             program = hildon.Program.get_instance()
             program.add_window(self)
 
             AbstractWifiscanner.__init__( self )
             self.add(self.vbox)
 
+            self.create_menu( )
+
             self.show_all()
 
         def TextView ( self , placeholder=None ) :
@@ -169,6 +181,20 @@ if hildon :
                 toggle_button.set_label( label )
             return toggle_button
 
+        def create_menu ( self ) :
+
+            menubar = hildon.AppMenu()
+            self.set_app_menu( menubar )
+
+            settings = hildon.Button(gtk.HILDON_SIZE_AUTO,
+                                     hildon.BUTTON_ARRANGEMENT_VERTICAL,
+                                     "Settings",
+                                     None)
+            settings.connect( "clicked", settings_cb , self.map )
+            menubar.append( settings )
+
+            menubar.show_all()
+
 else :
 
     class MapWindow ( gtk.Frame ) :
@@ -176,8 +202,7 @@ else :
         def __init__(self):
             gtk.Frame.__init__( self )
 
-            self.config = wifimap.config.Configuration()
-            self.config.zoom = 16
+            self.config = wifimap.config.Configuration( 'scanner' )
             self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
 
     class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
@@ -189,6 +214,8 @@ else :
             AbstractWifiscanner.__init__( self )
             self.add(self.vbox)
 
+            self.create_menu()
+
             self.show_all()
 
         def TextView ( self , placeholder=None ) :
@@ -210,6 +237,17 @@ else :
                 toggle_button.set_label( label )
             return toggle_button
 
+        def create_menu ( self ) :
+
+            menubar = gtk.MenuBar()
+            self.vbox.pack_start( menubar )
+
+            settings = gtk.MenuItem( "Settings" )
+            settings.connect( "activate", settings_cb , self.map )
+            menubar.append( settings )
+
+            menubar.show_all()
+
 window = Wifiscanner()
 window.run()