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 ) )
60 class AbstractWifiscanner :
62 def __init__ ( self ) :
66 self.connect("delete_event", gtk.main_quit, None)
68 self.vbox = gtk.VBox(homogeneous=False, spacing=0)
71 top_frame = gtk.Frame()
72 self.vbox.pack_start(top_frame)
74 hbox = gtk.HBox(homogeneous=False, spacing=0)
77 # Bottom frame creation
78 bottom_frame = gtk.Frame()
79 self.vbox.pack_end(bottom_frame, expand=False)
81 bottom_box = gtk.HBox(homogeneous=False, spacing=0)
82 bottom_frame.add( bottom_box )
84 # Top frame population
85 notebook = gtk.Notebook()
86 hbox.pack_start( notebook )
88 scrollview = gtk.ScrolledWindow()
89 notebook.append_page( scrollview , gtk.Label("Scanning") )
90 notebook.append_page( MapWindow() , gtk.Label("Map") )
92 buttons = gtk.VBox(homogeneous=False, spacing=0)
93 hbox.pack_end(buttons, expand=False)
95 textview = self.TextView( "Scan results ..." )
96 scrollview.add( textview )
97 scrollview.set_policy( gtk.POLICY_NEVER , gtk.POLICY_AUTOMATIC )
100 button = self.Button( "Switch GPS On")
101 button._id = button.connect("clicked", global_start, _scanner)
102 buttons.pack_start(button, expand=False)
104 button_scan = self.Button( "Start scanning")
105 button_scan._id = button_scan.connect("clicked", start_scan, _scanner)
106 buttons.pack_start(button_scan, expand=False)
108 toggle_button = self.CheckButton( "Use Assisted GPS" )
109 toggle_button.connect("toggled", enable_agps)
110 buttons.pack_start(toggle_button, expand=False)
112 # Bottom frame population
113 status = gtk.Label( "status bar ..." )
114 _scanner.status = status
115 _scanner.buffer = textview.get_buffer()
116 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 )
146 def TextView ( self , placeholder=None ) :
147 textview = hildon.TextView()
149 textview.set_placeholder( placeholder )
150 textview.set_editable( False )
151 textview.set_cursor_visible( False )
152 textview.modify_font( pango.FontDescription("Courier 12") )
155 def Button ( self , label="" ) :
156 button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL, label)
159 def CheckButton ( self , label=None ) :
160 toggle_button = hildon.CheckButton( gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT )
162 toggle_button.set_label( label )
167 class MapWindow ( gtk.Frame ) :
170 gtk.Frame.__init__( self )
172 self.config = wifimap.config.Configuration()
173 self.config.zoom = 16
174 self.add( wifimap.simpleMapWidget( self.config , (640,400) ) )
176 class Wifiscanner ( AbstractWifiscanner , gtk.Window ) :
178 def __init__ ( self ) :
179 gtk.Window.__init__( self )
182 AbstractWifiscanner.__init__( self )
187 def TextView ( self , placeholder=None ) :
188 textview = gtk.TextView()
190 textview.get_buffer().set_text( placeholder )
191 textview.set_editable( False )
192 textview.set_cursor_visible( False )
193 textview.modify_font( pango.FontDescription("Courier 12") )
196 def Button ( self , label="" ) :
197 button = gtk.Button( label )
200 def CheckButton ( self , label=None ) :
201 toggle_button = gtk.CheckButton()
203 toggle_button.set_label( label )
206 window = Wifiscanner()