11 def global_start(button, scanner):
14 button.disconnect( button._id )
15 button._id = button.connect("clicked", global_stop, scanner)
16 button.set_label("Switch GPS Off")
18 def global_stop(button, scanner):
21 button.disconnect( button._id )
22 button._id = button.connect("clicked", global_start, scanner)
23 button.set_label("Switch GPS On")
25 def enable_agps(button):
26 if button.get_active() :
27 print "%s state is active" % button
29 def start_scan(button, scanner):
30 # BUG : If gps is not started in advance, database is not opened and an exception happens
33 button.disconnect( button._id )
34 button._id = button.connect("clicked", stop_scan, scanner)
35 button.set_label("Stop scanning")
37 def stop_scan(button, scanner):
38 # FIXME : This method do not clear the scheduled scan
39 scanner.scan_timeout = 0
41 button.disconnect( button._id )
42 button._id = button.connect("clicked", start_scan, scanner)
43 button.set_label("Start scanning")
46 class scanner ( wifimap.Scanner ) :
49 wifimap.Scanner.scan( self )
53 self.status.set_label( wifimap.Scanner.report(self) )
54 start, end = self.buffer.get_bounds()
55 self.buffer.delete( start , end )
56 for mac,rss in self.scanlist.iteritems() :
57 self.buffer.insert_at_cursor( "%s %5d\n" % ( mac , rss ) )
58 if self.info[0] == "FIX" :
60 pixmap,mask = self.map.get_pixbuf().render_pixmap_and_mask()
61 self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , 2 )
62 self.map.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.map.win_x, self.map.win_y )
66 class AbstractWifiscanner :
68 def __init__ ( self ) :
70 _scanner = scanner( "wlan0" )
72 self.connect("delete_event", gtk.main_quit, None)
74 self.vbox = gtk.VBox(homogeneous=False, spacing=0)
77 top_frame = gtk.Frame()
78 self.vbox.pack_start(top_frame)
80 hbox = gtk.HBox(homogeneous=False, spacing=0)
83 # Bottom frame creation
84 bottom_frame = gtk.Frame()
85 self.vbox.pack_end(bottom_frame, expand=False)
87 bottom_box = gtk.HBox(homogeneous=False, spacing=0)
88 bottom_frame.add( bottom_box )
90 # Top frame population
91 notebook = gtk.Notebook()
92 hbox.pack_start( notebook )
94 scrollview = gtk.ScrolledWindow()
95 notebook.append_page( scrollview , gtk.Label("Scanning") )
96 notebook.append_page( MapWindow() , gtk.Label("Map") )
98 buttons = gtk.VBox(homogeneous=False, spacing=0)
99 hbox.pack_end(buttons, expand=False)
101 textview = self.TextView( "Scan results ..." )
102 scrollview.add( textview )
103 scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
106 button = self.Button( "Switch GPS On")
107 button._id = button.connect("clicked", global_start, _scanner)
108 buttons.pack_start(button, expand=False)
110 button_scan = self.Button( "Start scanning")
111 button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
112 buttons.pack_start(button_scan, expand=False)
114 toggle_button = self.CheckButton( "Use Assisted GPS" )
115 toggle_button.connect("toggled", enable_agps)
116 buttons.pack_start(toggle_button, expand=False)
118 # Bottom frame population
119 status = gtk.Label( "status bar ..." )
120 _scanner.status = status
121 _scanner.buffer = textview.get_buffer()
122 _scanner.map = notebook.get_nth_page(1).child
123 bottom_box.pack_start( status , expand=False , padding=20 )
130 class MapWindow ( gtk.Frame ) :
133 gtk.Frame.__init__( self )
135 self.config = wifimap.config.Configuration()
136 self.config.zoom = 16
137 self.map = wifimap.simpleMapWidget( self.config )
141 class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :
143 def __init__ ( self ) :
144 hildon.Window.__init__( self )
145 program = hildon.Program.get_instance()
146 program.add_window(self)
148 AbstractWifiscanner.__init__( self )
153 def TextView ( self , placeholder=None ) :
154 textview = hildon.TextView()
156 textview.set_placeholder( placeholder )
157 textview.set_editable( False )
158 textview.set_cursor_visible( False )
159 textview.modify_font( pango.FontDescription("Courier 12") )
162 def Button ( self , label="" ) :
163 button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
166 def CheckButton ( self , label=None ) :
167 toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
169 toggle_button.set_label( label )
174 class MapWindow ( gtk.Frame ) :
177 gtk.Frame.__init__( self )
179 self.config = wifimap.config.Configuration()
180 self.config.zoom = 16
181 self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
183 class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
185 def __init__ ( self ) :
186 gtk.Window.__init__( self )
189 AbstractWifiscanner.__init__( self )
194 def TextView ( self , placeholder=None ) :
195 textview = gtk.TextView()
197 textview.get_buffer().set_text( placeholder )
198 textview.set_editable( False )
199 textview.set_cursor_visible( False )
200 textview.modify_font( pango.FontDescription("Courier 12") )
203 def Button ( self , label="" ) :
204 button = gtk.Button( label )
207 def CheckButton ( self , label=None ) :
208 toggle_button = gtk.CheckButton()
210 toggle_button.set_label( label )
213 window = Wifiscanner()