-import wifimap , wifiview
+import wifimap
import gtk , pango
try :
except :
hildon = False
-import gobject
-
-def hello(widget, data):
- data.do_start()
- if widget.handler_id :
- widget.disconnect( widget.handler_id )
- widget.handler_id = widget.connect("clicked", bye, data)
- widget.set_label("Switch Off!")
-
-def bye(widget, data):
- data.do_stop()
- if widget.handler_id :
- widget.disconnect( widget.handler_id )
- widget.handler_id = widget.connect("clicked", hello, data)
- widget.set_label("Switch On!")
-
-def enable_agps(widget):
- if widget.get_active() :
- print "%s state is active" % widget
-
-def scana(widget, data):
- if not data._timer :
- data._timer = gobject.timeout_add( 5000 , data.scan )
- else :
- if hildon :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
- if widget.handler_id :
- widget.disconnect( widget.handler_id )
- widget.handler_id = widget.connect("clicked", scano, data)
- widget.set_label("Stop scanning now !!")
-
-def scano(widget, data):
- if data._timer :
- if hildon :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Timer was running, stopping it" )
- gobject.source_remove( data._timer )
- data._timer = None
- data.stop()
- else :
- if hildon :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
- if widget.handler_id :
- widget.disconnect( widget.handler_id )
- widget.handler_id = widget.connect("clicked", scana, data)
- widget.set_label("Start scanning now !!")
+def global_start(button, scanner):
+ scanner.start()
+ if button._id :
+ button.disconnect( button._id )
+ button._id = button.connect("clicked", global_stop, scanner)
+ button.set_label("Switch GPS Off")
+
+def global_stop(button, scanner):
+ scanner.stop()
+ if button._id :
+ button.disconnect( button._id )
+ button._id = button.connect("clicked", global_start, scanner)
+ button.set_label("Switch GPS On")
+
+def enable_agps(button):
+ if button.get_active() :
+ print "%s state is active" % button
+
+def start_scan(button, scanner):
+ # BUG : If gps is not started in advance, database is not opened and an exception happens
+ scanner.scan()
+ if button._id :
+ button.disconnect( button._id )
+ button._id = button.connect("clicked", stop_scan, scanner)
+ button.set_label("Stop scanning")
+
+def stop_scan(button, scanner):
+ # FIXME : This method do not clear the scheduled scan
+ scanner.scan_timeout = 0
+ if button._id :
+ button.disconnect( button._id )
+ button._id = button.connect("clicked", start_scan, scanner)
+ button.set_label("Start scanning")
+
+
+class scanner ( wifimap.Scanner ) :
+
+ def scan ( self ) :
+ wifimap.Scanner.scan( self )
+ self.report()
+
+ def report ( self ) :
+ self.status.set_label( wifimap.Scanner.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 ) )
+
class AbstractWifiscanner :
def __init__ ( self ) :
- self.gpsdev = wifimap.Scanner( self )
+ _scanner = scanner()
self.connect("delete_event", gtk.main_quit, None)
scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
# Buttons creation
- button = self.Button( "Switch On!")
- button.handler_id = button.connect("clicked", hello, self.gpsdev)
+ button = self.Button( "Switch GPS On")
+ button._id = button.connect("clicked", global_start, _scanner)
buttons.pack_start(button, expand=False)
- button_scan = self.Button( "Start scanning now !!")
- button_scan.handler_id = button_scan.connect("clicked", scana, self.gpsdev)
+ button_scan = self.Button( "Start scanning")
+ button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
buttons.pack_start(button_scan, expand=False)
toggle_button = self.CheckButton( "Use Assisted GPS" )
# Bottom frame population
status = gtk.Label( "status bar ..." )
- self.gpsdev.set_infowin( status , textview.get_buffer() )
+ _scanner.status = status
+ _scanner.buffer = textview.get_buffer()
bottom_box.pack_start( status , expand=False , padding=20 )
def run ( self ) :
self.show_all()
- self.gpsdev.start()
gtk.main()
if hildon :
self.config = wifimap.config.Configuration()
self.config.zoom = 16
- self.map = wifiview.mapWidget( self.config )
+ self.map = wifimap.simpleMapWidget( self.config )
self.map.plot_APs()
self.add( self.map )
self.config = wifimap.config.Configuration()
self.config.zoom = 16
- self.add( wifiview.mapWidget( self.config , (640,400) ) )
+ self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :