X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=wifiscanner%2Fwifiscanner;h=5aff5304fcb37d60f2ce42e50f5834fdf44b0026;hb=5a6481baa084244a7f777d440eff21eb129809ec;hp=aaf97a2952579f6d254ed3e7f170ce85caf6f24e;hpb=8da4db8977df27965d5d9c974d4e5737f9e77d4f;p=wifihood diff --git a/wifiscanner/wifiscanner b/wifiscanner/wifiscanner index aaf97a2..5aff530 100755 --- a/wifiscanner/wifiscanner +++ b/wifiscanner/wifiscanner @@ -2,107 +2,184 @@ import wifimap -import gtk -import hildon - -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 : - 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 : - 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" ) - if widget.handler_id : - widget.disconnect( widget.handler_id ) - widget.handler_id = widget.connect("clicked", scana, data) - widget.set_label("Start scanning now !!") - -def main(): - - window = hildon.Window() - program = hildon.Program.get_instance() - program.add_window(window) - - gpsdev = wifimap.Scanner( window ) - - window.connect("delete_event", gtk.main_quit, None) - - vbox = gtk.VBox(homogeneous=False, spacing=0) - top_frame = gtk.Frame(label="top") - bottom_frame = gtk.Frame(label="bottom") - bottom_box = gtk.HBox(homogeneous=False, spacing=0) - - hbox = gtk.HBox(homogeneous=False, spacing=0) - top_frame.add(hbox) - - textview = gtk.TextView() - - scrollview = gtk.ScrolledWindow() - scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC ) - scrollview.add( textview ) - hbox.pack_start( scrollview ) - - buttons = gtk.VBox(homogeneous=False, spacing=0) - hbox.pack_end( buttons ) - - button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch On!") - button.handler_id = button.connect("clicked", hello, gpsdev) - buttons.pack_start(button, expand=False) - - button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning now !!") - button_scan.handler_id = button_scan.connect("clicked", scana, gpsdev) - buttons.pack_start(button_scan, expand=False) - - toggle_button = gtk.CheckButton(label="Use Assisted GPS") - toggle_button.connect("toggled", enable_agps) - buttons.pack_start(toggle_button, expand=False) - - status = gtk.Label( "status bar ..." ) - bottom_box.pack_start( status , expand=False , padding=20 ) - - bottom_frame.add( bottom_box ) - - vbox.pack_start(top_frame) - vbox.pack_end(bottom_frame) - window.add(vbox) - - window.show_all() - - gpsdev.start() - - gtk.main() - -if __name__ == "__main__": - main() +import gtk , pango +try : + import hildon +except : + from hildongtk import hildon + +def global_start(button, scanner, config): + scanner.start( int( 1000 * config.scan_period ) , config.store_log ) + if button._id : + button.disconnect( button._id ) + button._id = button.connect("clicked", global_stop, scanner, config) + button.set_label("Switch GPS Off") + +def global_stop(button, scanner, config): + scanner.stop() + if button._id : + button.disconnect( button._id ) + button._id = button.connect("clicked", global_start, scanner, config) + 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 ) ) + 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() + pointsize = 2 + if self.newaps : + pointsize += 2 + self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , pointsize ) + for mac,ap in self.aps.iteritems() : + if self.oldpos.get( mac ) : + self.map.line( pixmap , self.oldpos[mac] , ( ap[1]/ap[0] , ap[2]/ap[0] ) , "green" ) + self.map.plot( pixmap , ( ap[1]/ap[0] , ap[2]/ap[0] ) , "green" , 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() + + +class Wifiscanner ( hildon.StackableWindow ) : + + def __init__ ( self ) : + + hildon.StackableWindow.__init__( self ) + self.set_title( "Wifihood Scanner" ) + program = hildon.Program.get_instance() + program.add_window(self) + + config = wifimap.config.Configuration( 'scanner' ) + _scanner = scanner( config , "wlan0" ) + + self.connect("delete_event", gtk.main_quit, None) + + self.vbox = gtk.VBox(homogeneous=False, spacing=0) + + # Top frame creation + top_frame = gtk.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) + + self.vbox.pack_end(top_frame) + + 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") ) + self.map = MapWindow( config ) + notebook.append_page( self.map , gtk.Label("Map") ) + + buttons = gtk.VBox(homogeneous=False, spacing=0) + hbox.pack_end(buttons, expand=False) + + textview = hildon.TextView() + textview.set_placeholder( "Scan results ..." ) + textview.set_editable( False ) + textview.set_cursor_visible( False ) + textview.modify_font( pango.FontDescription("Courier 12") ) + scrollview.add( textview ) + scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC ) + + # Buttons creation + button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch GPS On" ) + button._id = button.connect("clicked", global_start, _scanner, config) + buttons.pack_start(button, expand=False) + + button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning" ) + button_scan._id = button_scan.connect("clicked", start_scan, _scanner) + buttons.pack_start(button_scan, expand=False) + + toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT ) + toggle_button.set_label( "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() + _scanner.map = self.map.child + bottom_box.pack_start( status , expand=False , padding=20 ) + + self.add(self.vbox) + + self.create_menu( ) + + self.show_all() + + 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() + + def run ( self ) : + gtk.main() + + +def settings_cb ( widget , map ) : + window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom ) + + +class MapWindow ( gtk.Frame ) : + + def __init__( self , config ): + gtk.Frame.__init__( self ) + + self.config = config + self.add( wifimap.simpleMapWidget( self.config ) ) + + +window = Wifiscanner() +window.run()