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 self.map.recenter( self.info[4:6] )
61 pixmap,mask = self.map.get_pixbuf().render_pixmap_and_mask()
62 self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , 2 )
63 self.map.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.map.win_x, self.map.win_y )
67 class AbstractWifiscanner :
69 def __init__ ( self ) :
71 _scanner = scanner( "wlan0" )
73 self.connect("delete_event", gtk.main_quit, None)
75 self.vbox = gtk.VBox(homogeneous=False, spacing=0)
78 top_frame = gtk.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 self.vbox.pack_end(top_frame)
89 bottom_box = gtk.HBox(homogeneous=False, spacing=0)
90 bottom_frame.add( bottom_box )
92 # Top frame population
93 notebook = gtk.Notebook()
94 hbox.pack_start( notebook )
96 scrollview = gtk.ScrolledWindow()
97 notebook.append_page( scrollview , gtk.Label("Scanning") )
98 self.map = MapWindow()
99 notebook.append_page( self.map , gtk.Label("Map") )
101 buttons = gtk.VBox(homogeneous=False, spacing=0)
102 hbox.pack_end(buttons, expand=False)
104 textview = self.TextView( "Scan results ..." )
105 scrollview.add( textview )
106 scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
109 button = self.Button( "Switch GPS On")
110 button._id = button.connect("clicked", global_start, _scanner)
111 buttons.pack_start(button, expand=False)
113 button_scan = self.Button( "Start scanning")
114 button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
115 buttons.pack_start(button_scan, expand=False)
117 toggle_button = self.CheckButton( "Use Assisted GPS" )
118 toggle_button.connect("toggled", enable_agps)
119 buttons.pack_start(toggle_button, expand=False)
121 # Bottom frame population
122 status = gtk.Label( "status bar ..." )
123 _scanner.status = status
124 _scanner.buffer = textview.get_buffer()
125 _scanner.map = self.map.child
126 bottom_box.pack_start( status , expand=False , padding=20 )
131 def settings_cb ( widget , map ) :
132 window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
137 class MapWindow ( gtk.Frame ) :
140 gtk.Frame.__init__( self )
142 self.config = wifimap.config.Configuration()
143 self.config.zoom = 16
144 self.add( wifimap.simpleMapWidget( self.config ) )
146 class Wifiscanner ( AbstractWifiscanner , hildon.StackableWindow ) :
148 def __init__ ( self ) :
149 hildon.StackableWindow.__init__( self )
150 self.set_title( "Wifihood Scanner" )
151 program = hildon.Program.get_instance()
152 program.add_window(self)
154 AbstractWifiscanner.__init__( self )
161 def TextView ( self , placeholder=None ) :
162 textview = hildon.TextView()
164 textview.set_placeholder( placeholder )
165 textview.set_editable( False )
166 textview.set_cursor_visible( False )
167 textview.modify_font( pango.FontDescription("Courier 12") )
170 def Button ( self , label="" ) :
171 button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
174 def CheckButton ( self , label=None ) :
175 toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
177 toggle_button.set_label( label )
180 def create_menu ( self ) :
182 menubar = hildon.AppMenu()
183 self.set_app_menu( menubar )
185 settings = hildon.Button(gtk.HILDON_SIZE_AUTO,
186 hildon.BUTTON_ARRANGEMENT_VERTICAL,
189 settings.connect( "clicked", settings_cb , self.map )
190 menubar.append( settings )
196 class MapWindow ( gtk.Frame ) :
199 gtk.Frame.__init__( self )
201 self.config = wifimap.config.Configuration()
202 self.config.zoom = 16
203 self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
205 class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
207 def __init__ ( self ) :
208 gtk.Window.__init__( self )
211 AbstractWifiscanner.__init__( self )
218 def TextView ( self , placeholder=None ) :
219 textview = gtk.TextView()
221 textview.get_buffer().set_text( placeholder )
222 textview.set_editable( False )
223 textview.set_cursor_visible( False )
224 textview.modify_font( pango.FontDescription("Courier 12") )
227 def Button ( self , label="" ) :
228 button = gtk.Button( label )
231 def CheckButton ( self , label=None ) :
232 toggle_button = gtk.CheckButton()
234 toggle_button.set_label( label )
237 def create_menu ( self ) :
239 menubar = gtk.MenuBar()
240 self.vbox.pack_start( menubar )
242 settings = gtk.MenuItem( "Settings" )
243 settings.connect( "activate", settings_cb , self.map )
244 menubar.append( settings )
248 window = Wifiscanner()