From 82ea4d1b8604192f5dfdc96dbbcd4965fbf7b3d4 Mon Sep 17 00:00:00 2001 From: javiplx Date: Sat, 30 Apr 2011 09:27:34 +0000 Subject: [PATCH] Achieve full decoupling of Scanner object and graphical environment git-svn-id: file:///svnroot/wifihood/branches/cleaning@89 c51dfc6a-5949-4919-9c8e-f207a149c383 --- wifimap/wifiscan.py | 38 ++++++++++++++------------------------ wifiscanner.py | 3 +-- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/wifimap/wifiscan.py b/wifimap/wifiscan.py index 013fb9c..c5495ce 100644 --- a/wifimap/wifiscan.py +++ b/wifimap/wifiscan.py @@ -16,29 +16,27 @@ conf = config.Configuration() class Scanner ( gps.GPSObject ) : - def __init__ ( self , widget=None , ifname="wlan0" ) : + def __init__ ( self , ifname="wlan0" ) : gps.GPSObject.__init__( self ) - self.osso_context = None - if widget : - self.osso_context = osso.Context("wifi_scanner", "2.0", False) - osso_rpc = osso.Rpc(self.osso_context) - osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True) - self._timer = None + self.osso_context = osso.Context("wifi_scanner", "2.0", False) + osso_rpc = osso.Rpc(self.osso_context) + osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True) + self.db = db.database( os.path.join( conf.homedir , conf.dbname ) ) + + # Values to be set by wireless scans self.nscan = 0 self.nfp = 0 - self.scanlist = None self.newap = 0 - self.db = db.database( os.path.join( conf.homedir , conf.dbname ) ) + self.scanlist = [] def start ( self ) : - if self.osso_context : - osso_rpc = osso.Rpc(self.osso_context) - scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start") + osso_rpc = osso.Rpc(self.osso_context) + osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start") self.db.open() def stop ( self ) : osso_rpc = osso.Rpc(self.osso_context) - scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop") + osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop") self.db.close() def scan ( self ) : @@ -49,15 +47,12 @@ class Scanner ( gps.GPSObject ) : except Exception , ex : osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex ) return True - if self.scanlist : - start, end = self.scanlist.get_bounds() - self.scanlist.delete( start , end ) + del self.scanlist[:] tstamp = time.time() latlon = None if self.gps_state == "FIX" : latlon = ( self.device.fix[4] , self.device.fix[5] , self.device.fix[7] ) self.store_scan( tstamp , scan_out , latlon ) - self.refresh_infowin() if self._debug : osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) ) else : @@ -69,8 +64,7 @@ class Scanner ( gps.GPSObject ) : for net in scan_out.split() : self.nfp += 1 items = net.rsplit(":", 1) - if self.scanlist : - self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) ) + self.scanlist.append( "%s %5d\n" % ( items[0] , int(items[1]) ) ) stored = self.db.get( items[0] ) if stored : max_rss = int(items[1]) @@ -86,8 +80,7 @@ class Scanner ( gps.GPSObject ) : while nets : self.nfp += 1 items = ( nets.pop(0) , nets.pop(0) ) - if self.scanlist : - self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) ) + self.scanlist.append( "%s %5d\n" % ( items[0] , int(items[1]) ) ) stored = self.db.get( items[0] ) if stored : max_rss = int(items[1]) @@ -111,9 +104,6 @@ class Scanner ( gps.GPSObject ) : celllist.write ( "%s\n" % ( self.cell_info ,) ) celllist.close() - def set_infowin ( self , listwin ) : - self.scanlist = listwin - def report ( self ) : return "%s\t%d scan\t%d fp\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , self.nscan , self.nfp , self.newap , self.db.nrows() ) diff --git a/wifiscanner.py b/wifiscanner.py index de72421..eb51435 100755 --- a/wifiscanner.py +++ b/wifiscanner.py @@ -57,7 +57,7 @@ class AbstractWifiscanner : def __init__ ( self ) : - self.gpsdev = wifimap.Scanner( self ) + self.gpsdev = wifimap.Scanner() self.connect("delete_event", gtk.main_quit, None) @@ -107,7 +107,6 @@ class AbstractWifiscanner : # Bottom frame population status = gtk.Label( "status bar ..." ) - self.gpsdev.set_infowin( textview.get_buffer() ) bottom_box.pack_start( status , expand=False , padding=20 ) def run ( self ) : -- 1.7.9.5