import wifimap
-import gtk
-import hildon
+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")
-import gobject
+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")
-def hello(widget, data):
- data.do_start()
-def bye(widget, data):
- data.do_stop()
+class scanner ( wifimap.Scanner ) :
-def enable_agps(widget):
- if widget.get_active() :
- print "%s state is active" % widget
+ def scan ( self ) :
+ wifimap.Scanner.scan( self )
+ self.report()
-def scana(widget, data):
- if not data._timer :
- data._timer = gobject.timeout_add( 5000 , data.scan )
- else :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
+ 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 ) )
+ 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 )
+ 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()
-def scano(widget, data):
- if data._timer :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Timer was running, stopping it" )
- gobject.source_remove( data._timer )
- data._timer = None
- data.stop()
- else :
- hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
-def main():
+class AbstractWifiscanner :
- window = hildon.Window()
- program = hildon.Program.get_instance()
- program.add_window(window)
+ def __init__ ( self ) :
- gpsdev = wifimap.Scanner( window )
+ _scanner = scanner( "wlan0" )
+
+ self.connect("delete_event", gtk.main_quit, None)
- window.connect("delete_event", gtk.main_quit, None)
+ self.vbox = gtk.VBox(homogeneous=False, spacing=0)
+
+ # Top frame creation
+ top_frame = gtk.Frame()
- vbox = gtk.VBox(homogeneous=False, spacing=0)
- top_frame = gtk.Frame(label="top")
- bottom_frame = gtk.Frame(label="bottom")
+ hbox = gtk.HBox(homogeneous=False, spacing=0)
+ top_frame.add(hbox)
- # FIXME : Temporary holder !!!
- table = gtk.Table (2, 2, False)
+ # Bottom frame creation
+ bottom_frame = gtk.Frame()
+ self.vbox.pack_end(bottom_frame, expand=False)
- # set the spacing to 10 on x and 10 on y
- table.set_row_spacings(10)
- table.set_col_spacings(10)
+ self.vbox.pack_end(top_frame)
+
+ bottom_box = gtk.HBox(homogeneous=False, spacing=0)
+ bottom_frame.add( bottom_box )
- button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch On!")
- button.connect("clicked", hello, gpsdev)
- table.attach(button, 0, 1, 0, 1)
+ # Top frame population
+ notebook = gtk.Notebook()
+ hbox.pack_start( notebook )
- button_off = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch Off!")
- button_off.connect("clicked", bye, gpsdev)
- table.attach(button_off, 1, 2, 0, 1)
+ scrollview = gtk.ScrolledWindow()
+ notebook.append_page( scrollview , gtk.Label("Scanning") )
+ self.map = MapWindow()
+ notebook.append_page( self.map , gtk.Label("Map") )
- button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning now !!")
- button_scan.connect("clicked", scana, gpsdev)
- table.attach(button_scan, 0, 1, 1, 2)
+ buttons = gtk.VBox(homogeneous=False, spacing=0)
+ hbox.pack_end(buttons, expand=False)
- button_stop = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Stop scanning now !!")
- button_stop.connect("clicked", scano, gpsdev)
- table.attach(button_stop, 1, 2, 1, 2)
+ textview = self.TextView( "Scan results ..." )
+ scrollview.add( textview )
+ scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
- bottom_frame.add(table)
+ # Buttons creation
+ button = self.Button( "Switch GPS On")
+ button._id = button.connect("clicked", global_start, _scanner)
+ buttons.pack_start(button, expand=False)
- toggle_button = gtk.CheckButton(label="Use Assisted GPS")
- toggle_button.connect("toggled", enable_agps)
- top_frame.add(toggle_button)
+ button_scan = self.Button( "Start scanning")
+ button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
+ buttons.pack_start(button_scan, expand=False)
- vbox.pack_start(top_frame)
- vbox.pack_end(bottom_frame)
- window.add(vbox)
+ toggle_button = self.CheckButton( "Use Assisted GPS" )
+ toggle_button.connect("toggled", enable_agps)
+ buttons.pack_start(toggle_button, expand=False)
- window.show_all()
+ # Bottom frame population
+ status = gtk.Label( "status bar ..." )
+ _scanner.status = status
+ _scanner.buffer = textview.get_buffer()
+ _scanner.map = self.map.child
+ bottom_box.pack_start( status , expand=False , padding=20 )
- gpsdev.start()
+ def run ( self ) :
+ gtk.main()
- gtk.main()
+def settings_cb ( widget , map ) :
+ window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
-if __name__ == "__main__":
- main()
+
+if hildon :
+
+ 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 ) )
+
+ class Wifiscanner ( AbstractWifiscanner , hildon.StackableWindow ) :
+
+ def __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 ) :
+ 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
+
+ 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 ) :
+
+ 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)
+
+ self.create_menu()
+
+ self.show_all()
+
+ 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
+
+ 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()