Added basic scanner application
[wifihood] / wifiscanner / wifiscanner
1 #!/usr/bin/python
2
3 import wifimap
4
5 import gtk
6 import hildon
7
8 import gobject
9
10 def hello(widget, data):
11     data.do_start()
12
13 def bye(widget, data):
14     data.do_stop()
15
16 def enable_agps(widget):
17     if widget.get_active() :
18         print "%s state is active" % widget
19
20 def scana(widget, data):
21     if not data._timer :
22         data._timer = gobject.timeout_add( 5000 , data.scan )
23     else :
24         hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
25
26 def scano(widget, data):
27     if data._timer :
28         hildon.hildon_banner_show_information( widget , "icon_path" , "Timer was running, stopping it" )
29         gobject.source_remove( data._timer )
30         data._timer = None
31         data.stop()
32     else :
33         hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
34
35 def main():
36
37     window = hildon.Window()
38     program = hildon.Program.get_instance()
39     program.add_window(window)
40
41     gpsdev = wifimap.Scanner( window )
42
43     window.connect("delete_event", gtk.main_quit, None)
44
45     vbox = gtk.VBox(homogeneous=False, spacing=0)
46     top_frame = gtk.Frame(label="top")
47     bottom_frame = gtk.Frame(label="bottom")
48
49     # FIXME : Temporary holder !!!
50     table = gtk.Table (2, 2, False)
51
52     # set the spacing to 10 on x and 10 on y 
53     table.set_row_spacings(10)
54     table.set_col_spacings(10)
55
56     button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch On!")
57     button.connect("clicked", hello, gpsdev)
58     table.attach(button, 0, 1, 0, 1)
59
60     button_off = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch Off!")
61     button_off.connect("clicked", bye, gpsdev)
62     table.attach(button_off, 1, 2, 0, 1)
63
64     button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning now !!")
65     button_scan.connect("clicked", scana, gpsdev)
66     table.attach(button_scan, 0, 1, 1, 2)
67
68     button_stop = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Stop scanning now !!")
69     button_stop.connect("clicked", scano, gpsdev)
70     table.attach(button_stop, 1, 2, 1, 2)
71
72     bottom_frame.add(table)
73
74     toggle_button = gtk.CheckButton(label="Use Assisted GPS")
75     toggle_button.connect("toggled", enable_agps)
76     top_frame.add(toggle_button)
77
78     vbox.pack_start(top_frame)
79     vbox.pack_end(bottom_frame)
80     window.add(vbox)
81
82     window.show_all()
83
84     gpsdev.start()
85
86     gtk.main()
87
88 if __name__ == "__main__":
89     main()
90