+++ /dev/null
-
-import wifimap
-
-import gtk , pango
-try :
- import hildon
-except :
- hildon = False
-
-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 ) :
-
- _scanner = scanner()
-
- self.connect("delete_event", gtk.main_quit, None)
-
- self.vbox = gtk.VBox(homogeneous=False, spacing=0)
-
- # Top frame creation
- top_frame = gtk.Frame()
- self.vbox.pack_start(top_frame)
-
- hbox = gtk.HBox(homogeneous=False, spacing=0)
- top_frame.add(hbox)
-
- # Bottom frame creation
- bottom_frame = gtk.Frame()
- self.vbox.pack_end(bottom_frame, expand=False)
-
- bottom_box = gtk.HBox(homogeneous=False, spacing=0)
- bottom_frame.add( bottom_box )
-
- # Top frame population
- notebook = gtk.Notebook()
- hbox.pack_start( notebook )
-
- scrollview = gtk.ScrolledWindow()
- notebook.append_page( scrollview , gtk.Label("Scanning") )
- notebook.append_page( MapWindow() , gtk.Label("Map") )
-
- buttons = gtk.VBox(homogeneous=False, spacing=0)
- hbox.pack_end(buttons, expand=False)
-
- textview = self.TextView( "Scan results ..." )
- scrollview.add( textview )
- scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
-
- # Buttons creation
- 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")
- button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
- buttons.pack_start(button_scan, expand=False)
-
- toggle_button = self.CheckButton( "Use Assisted GPS" )
- toggle_button.connect("toggled", enable_agps)
- buttons.pack_start(toggle_button, expand=False)
-
- # Bottom frame population
- status = gtk.Label( "status bar ..." )
- _scanner.status = status
- _scanner.buffer = textview.get_buffer()
- bottom_box.pack_start( status , expand=False , padding=20 )
-
- def run ( self ) :
- self.show_all()
- gtk.main()
-
-if hildon :
-
- class MapWindow ( gtk.Frame ) :
-
- 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 )
-
- class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :
-
- def __init__ ( self ) :
- hildon.Window.__init__( self )
- program = hildon.Program.get_instance()
- program.add_window(self)
-
- AbstractWifiscanner.__init__( self )
- self.add(self.vbox)
-
- def TextView ( self , placeholder=None ) :
- textview = hildon.TextView()
- if placeholder :
- textview.set_placeholder( placeholder )
- textview.set_editable( False )
- textview.set_cursor_visible( False )
- textview.modify_font( pango.FontDescription("Courier 12") )
- return textview
-
- def Button ( self , label="" ) :
- button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
- return button
-
- def CheckButton ( self , label=None ) :
- toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
- if label :
- toggle_button.set_label( label )
- return toggle_button
-
-else :
-
- class MapWindow ( gtk.Frame ) :
-
- def __init__(self):
- gtk.Frame.__init__( self )
-
- self.config = wifimap.config.Configuration()
- self.config.zoom = 16
- self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
-
- class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
-
- def __init__ ( self ) :
- gtk.Window.__init__( self )
- self.resize(640,400)
-
- AbstractWifiscanner.__init__( self )
- self.add(self.vbox)
-
- def TextView ( self , placeholder=None ) :
- textview = gtk.TextView()
- if placeholder :
- textview.get_buffer().set_text( placeholder )
- textview.set_editable( False )
- textview.set_cursor_visible( False )
- textview.modify_font( pango.FontDescription("Courier 12") )
- return textview
-
- def Button ( self , label="" ) :
- button = gtk.Button( label )
- return button
-
- def CheckButton ( self , label=None ) :
- toggle_button = gtk.CheckButton()
- if label :
- toggle_button.set_label( label )
- return toggle_button
-