Finish first implementation of settings in GTK
[wifihood] / wifiscanner / wifimap / config.py
index 2b243dd..2d18a74 100644 (file)
@@ -40,7 +40,7 @@ class Configuration :
 
 class AbstractSettingsWindow :
 
-    def __init__ ( self , config ) :
+    def __init__ ( self , config , handler=None ) :
         self.set_title( "Wifihood Settings" )
 
         scrollwin = self.MainArea()
@@ -96,7 +96,7 @@ class AbstractSettingsWindow :
         maps.attach(button, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5)
 
         zoomlevel = self.Button( "Zoom level" , config.zoom )
-        zoomlevel.connect_object( "clicked", self.zoomdialog, config )
+        zoomlevel.connect_object( "clicked", self.zoomdialog, zoomlevel , config , handler )
         zoomlevel.show()
         maps.attach(zoomlevel, 1, 2, 0, 1, gtk.EXPAND|gtk.FILL, 0, 0, 5)
 
@@ -133,15 +133,15 @@ class AbstractSettingsWindow :
 
         self.show()
 
-    def zoomdialog ( self , widget) :
-        dialog = ZoomDialog( widget )
+    def zoomdialog ( self , widget , config , extra=None ) :
+        dialog = ZoomDialog( config , widget.set_value , extra )
         dialog.show_all()
 
 if hildon :
 
   class ZoomDialog ( hildon.TouchSelector ) :
 
-    def __init__ ( self , config ) :
+    def __init__ ( self , config , handler=None , extra=None ) :
         hildon.TouchSelector.__init__( self )
 
         zooms = gtk.ListStore(str)
@@ -161,9 +161,9 @@ if hildon :
 
   class SettingsWindow ( hildon.StackableWindow , AbstractSettingsWindow ) :
 
-    def __init__ ( self , config ) :
+    def __init__ ( self , config , handler=None ) :
         hildon.StackableWindow.__init__( self )
-        AbstractSettingsWindow.__init__( self , config )
+        AbstractSettingsWindow.__init__( self , config , handler )
 
     def MainArea ( self ) :
         return hildon.PannableArea()
@@ -181,7 +181,7 @@ else :
 
   class ZoomDialog ( gtk.Dialog ) :
 
-    def __init__ ( self , config ) :
+    def __init__ ( self , config , handler=None , extra=None ) :
         gtk.Dialog.__init__( self , "Select zoom level",
                              None,
                              gtk.DIALOG_MODAL,
@@ -205,20 +205,22 @@ else :
 
         self.vbox.pack_start(combo , True, True, 0)
 
-        self.connect_object( "response", self.response , combo , config )
+        self.connect_object( "response", self.response , combo , config , handler , extra )
 
-    def response ( self , combo , response  , config ) :
+    def response ( self , combo , response  , config , handler , extra=None ) :
         if response == gtk.RESPONSE_ACCEPT :
             item = combo.get_active_iter()
             model = combo.get_model()
+            handler( model.get(item,0)[0])
+            if extra : extra( model.get(item,0)[0])
             config.zoom = model.get(item,0)[0]
         self.destroy()
 
   class SettingsWindow ( gtk.Window , AbstractSettingsWindow ) :
 
-    def __init__ ( self , config ) :
+    def __init__ ( self , config , handler=None ) :
         gtk.Window.__init__( self )
-        AbstractSettingsWindow.__init__( self , config )
+        AbstractSettingsWindow.__init__( self , config , handler )
 
     def MainArea ( self ) :
         scrollwin = gtk.ScrolledWindow()
@@ -230,7 +232,15 @@ else :
         return gtk.Entry()
 
     def Button ( self , text , value ) :
-        return gtk.Button( "%s %s" % ( text , value ) )
+        class _button ( gtk.Button ) :
+            def __init__ ( self , text , value ) :
+                gtk.Button.__init__( self )
+                self._text = text
+                self.set_value( value )
+            def set_value ( self , value ) :
+                self._value = value
+                self.set_label( "%s -- %s" % ( self._text , self._value ) )
+        return _button( text , value )
 
     def CheckButton ( self ) :
         return gtk.CheckButton()