10 def global_start(button, scanner):
13 button.disconnect( button._id )
14 button._id = button.connect("clicked", global_stop, scanner)
15 button.set_label("Switch GPS Off")
17 def global_stop(button, scanner):
20 button.disconnect( button._id )
21 button._id = button.connect("clicked", global_start, scanner)
22 button.set_label("Switch GPS On")
24 def enable_agps(button):
25 if button.get_active() :
26 print "%s state is active" % button
28 def start_scan(button, scanner):
29 # BUG : If gps is not started in advance, database is not opened and an exception happens
32 button.disconnect( button._id )
33 button._id = button.connect("clicked", stop_scan, scanner)
34 button.set_label("Stop scanning")
36 def stop_scan(button, scanner):
37 # FIXME : This method do not clear the scheduled scan
38 scanner.scan_timeout = 0
40 button.disconnect( button._id )
41 button._id = button.connect("clicked", start_scan, scanner)
42 button.set_label("Start scanning")
45 class scanner ( wifimap.Scanner ) :
48 wifimap.Scanner.scan( self )
52 self.status.set_label( wifimap.Scanner.report(self) )
53 start, end = self.buffer.get_bounds()
54 self.buffer.delete( start , end )
55 for mac,rss in self.scanlist.iteritems() :
56 self.buffer.insert_at_cursor( "%s %5d\n" % ( mac , rss ) )
59 class AbstractWifiscanner :
61 def __init__ ( self ) :
65 self.connect("delete_event", gtk.main_quit, None)
67 self.vbox = gtk.VBox(homogeneous=False, spacing=0)
70 top_frame = gtk.Frame()
71 self.vbox.pack_start(top_frame)
73 hbox = gtk.HBox(homogeneous=False, spacing=0)
76 # Bottom frame creation
77 bottom_frame = gtk.Frame()
78 self.vbox.pack_end(bottom_frame, expand=False)
80 bottom_box = gtk.HBox(homogeneous=False, spacing=0)
81 bottom_frame.add( bottom_box )
83 # Top frame population
84 notebook = gtk.Notebook()
85 hbox.pack_start( notebook )
87 scrollview = gtk.ScrolledWindow()
88 notebook.append_page( scrollview , gtk.Label("Scanning") )
89 notebook.append_page( MapWindow() , gtk.Label("Map") )
91 buttons = gtk.VBox(homogeneous=False, spacing=0)
92 hbox.pack_end(buttons, expand=False)
94 textview = self.TextView( "Scan results ..." )
95 scrollview.add( textview )
96 scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
99 button = self.Button( "Switch GPS On")
100 button._id = button.connect("clicked", global_start, _scanner)
101 buttons.pack_start(button, expand=False)
103 button_scan = self.Button( "Start scanning")
104 button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
105 buttons.pack_start(button_scan, expand=False)
107 toggle_button = self.CheckButton( "Use Assisted GPS" )
108 toggle_button.connect("toggled", enable_agps)
109 buttons.pack_start(toggle_button, expand=False)
111 # Bottom frame population
112 status = gtk.Label( "status bar ..." )
113 _scanner.status = status
114 _scanner.buffer = textview.get_buffer()
115 bottom_box.pack_start( status , expand=False , padding=20 )
123 class MapWindow ( gtk.Frame ) :
126 gtk.Frame.__init__( self )
128 self.config = wifimap.config.Configuration()
129 self.config.zoom = 16
130 self.map = wifimap.simpleMapWidget( self.config )
134 class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :
136 def __init__ ( self ) :
137 hildon.Window.__init__( self )
138 program = hildon.Program.get_instance()
139 program.add_window(self)
141 AbstractWifiscanner.__init__( self )
144 def TextView ( self , placeholder=None ) :
145 textview = hildon.TextView()
147 textview.set_placeholder( placeholder )
148 textview.set_editable( False )
149 textview.set_cursor_visible( False )
150 textview.modify_font( pango.FontDescription("Courier 12") )
153 def Button ( self , label="" ) :
154 button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
157 def CheckButton ( self , label=None ) :
158 toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
160 toggle_button.set_label( label )
165 class MapWindow ( gtk.Frame ) :
168 gtk.Frame.__init__( self )
170 self.config = wifimap.config.Configuration()
171 self.config.zoom = 16
172 self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
174 class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
176 def __init__ ( self ) :
177 gtk.Window.__init__( self )
180 AbstractWifiscanner.__init__( self )
183 def TextView ( self , placeholder=None ) :
184 textview = gtk.TextView()
186 textview.get_buffer().set_text( placeholder )
187 textview.set_editable( False )
188 textview.set_cursor_visible( False )
189 textview.modify_font( pango.FontDescription("Courier 12") )
192 def Button ( self , label="" ) :
193 button = gtk.Button( label )
196 def CheckButton ( self , label=None ) :
197 toggle_button = gtk.CheckButton()
199 toggle_button.set_label( label )