Implement status bar and fix layout issues
[wifihood] / wifimap / wifiscan.py
1
2 import osso
3
4 import time
5
6 import gps
7
8 import gobject
9
10 class Scanner ( gps.GPSObject ) :
11
12     def __init__ ( self , widget=None , ifname="wlan0" ) :
13         gps.GPSObject.__init__( self , widget )
14         self.osso_context = osso.Context("wifi_scanner", "2.0", False)
15         osso_rpc = osso.Rpc(self.osso_context)
16         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
17         self._timer = None
18         self.nscan = 0
19         self.nfp = 0
20         self.aplist = {}
21
22     def start ( self ) :
23         osso_rpc = osso.Rpc(self.osso_context)
24         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
25
26     def stop ( self ) :
27         osso_rpc = osso.Rpc(self.osso_context)
28         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
29
30     def scan ( self ) :
31         osso_rpc = osso.Rpc(self.osso_context)
32         try :
33             scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
34             self.nscan +=1
35         except Exception , ex :
36             osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
37             return True
38         out_str = ""
39         for net in scan_out.split() :
40             self.nfp += 1
41             items = net.rsplit(":", 1)
42             out_str += " %s %s" % ( items[0] , items[1] )
43             self.aplist[ items[0] ] = 1
44         self.refresh_infowin()
45         if self._debug :
46         # Use osso or hildon for notes ???
47             osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
48         #    hildon.hildon_banner_show_information( self._parent , "icon_path" , "Found %d APs" % len(scan_out) )
49         else :
50             fd = open( "/home/user/MyDocs/wiscan_gui.info" , 'a' )
51             fd.write( "%s %s%s\n" % ( time.time() , self.gps_info , out_str ) )
52             fd.close()
53             if self.satellites :
54                 loclist = open( "/home/user/MyDocs/location.info" , 'a' )
55                 loclist.write ( "%s\n" % ( self.satellites ,) )
56                 loclist.close()
57             if self.cell_info :
58                 celllist = open( "/home/user/MyDocs/cell.info" , 'a' )
59                 celllist.write ( "%s\n" % ( self.cell_info ,) )
60                 celllist.close()
61
62         return True
63
64     def refresh_infowin ( self ) :
65         self.status.set_label( "%d gps\t%d scan\t%d fp\t%d ap" % ( self.ngps , self.nscan , self.nfp , len(self.aplist.keys()) ) )
66
67
68 gobject.type_register(Scanner)
69