Simplify interface implementing mutable buttons for on/off actions
authorjaviplx <javiplx@gmail.com>
Fri, 8 Oct 2010 18:10:43 +0000 (18:10 +0000)
committerjaviplx <javiplx@gmail.com>
Fri, 8 Oct 2010 18:10:43 +0000 (18:10 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@25 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscanner/wifiscanner

index ee9b20b..3f11db7 100755 (executable)
@@ -9,9 +9,17 @@ import gobject
 
 def hello(widget, data):
     data.do_start()
+    if widget.handler_id :
+        widget.disconnect( widget.handler_id )
+        widget.handler_id = widget.connect("clicked", bye, data)
+        widget.set_label("Switch Off!")
 
 def bye(widget, data):
     data.do_stop()
+    if widget.handler_id :
+        widget.disconnect( widget.handler_id )
+        widget.handler_id = widget.connect("clicked", hello, data)
+        widget.set_label("Switch On!")
 
 def enable_agps(widget):
     if widget.get_active() :
@@ -22,6 +30,10 @@ def scana(widget, data):
         data._timer = gobject.timeout_add( 5000 , data.scan )
     else :
         hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning was already active" )
+    if widget.handler_id :
+        widget.disconnect( widget.handler_id )
+        widget.handler_id = widget.connect("clicked", scano, data)
+        widget.set_label("Stop scanning now !!")
 
 def scano(widget, data):
     if data._timer :
@@ -31,6 +43,10 @@ def scano(widget, data):
         data.stop()
     else :
         hildon.hildon_banner_show_information( widget , "icon_path" , "Scanning is not active" )
+    if widget.handler_id :
+        widget.disconnect( widget.handler_id )
+        widget.handler_id = widget.connect("clicked", scana, data)
+        widget.set_label("Start scanning now !!")
 
 def main():
 
@@ -47,28 +63,20 @@ def main():
     bottom_frame = gtk.Frame(label="bottom")
 
     # FIXME : Temporary holder !!!
-    table = gtk.Table (2, 2, False)
+    table = gtk.Table (2, 1, False)
 
     # set the spacing to 10 on x and 10 on y 
     table.set_row_spacings(10)
     table.set_col_spacings(10)
 
     button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch On!")
-    button.connect("clicked", hello, gpsdev)
+    button.handler_id = button.connect("clicked", hello, gpsdev)
     table.attach(button, 0, 1, 0, 1)
 
-    button_off = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Switch Off!")
-    button_off.connect("clicked", bye, gpsdev)
-    table.attach(button_off, 1, 2, 0, 1)
-
     button_scan = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Start scanning now !!")
-    button_scan.connect("clicked", scana, gpsdev)
+    button_scan.handler_id = button_scan.connect("clicked", scana, gpsdev)
     table.attach(button_scan, 0, 1, 1, 2)
 
-    button_stop = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL, "Stop scanning now !!")
-    button_stop.connect("clicked", scano, gpsdev)
-    table.attach(button_stop, 1, 2, 1, 2)
-
     bottom_frame.add(table)
 
     toggle_button = gtk.CheckButton(label="Use Assisted GPS")