Finish first implementation of settings in GTK
authorjaviplx <javiplx@gmail.com>
Fri, 6 May 2011 08:31:58 +0000 (08:31 +0000)
committerjaviplx <javiplx@gmail.com>
Fri, 6 May 2011 08:31:58 +0000 (08:31 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@118 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscanner/wifimap/config.py
wifiscanner/wifimap/view.py
wifiscanner/wifiscanner
wifiscanner/wifiview

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()
index 368df9c..a3719cc 100755 (executable)
@@ -38,6 +38,27 @@ class AbstractmapWidget :
 
             self.composeMap()
 
+  def tilex2lon ( self , ( tilex , pixx ) , zoom ) :
+        tilex = float(tilex)
+        pixx = float(pixx)
+        return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
+
+  def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
+        tiley = float(tiley)
+        pixy = float(pixy)
+        tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
+        return math.degrees( math.atan( math.sinh( tiley ) ) )
+
+  def SetZoom( self , zoom ) :
+        self.hide()
+        lat = self.tiley2lat( ( self.reftile_y , self.refpix_y ) , self.conf.zoom )
+        lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.conf.zoom )
+        self.reftile_x , self.refpix_x = self.lon2tilex( lon , zoom )
+        self.reftile_y , self.refpix_y = self.lat2tiley( lat , zoom )
+        self.conf.zoom = zoom
+        self.composeMap()
+        self.show()
+
   def lon2tilex ( self , lon , zoom ) :
     number = math.modf( ( lon + 180 ) / 360 * 2 ** zoom )
     return int( number[1] ) , int( self.tile_size * number[0] )
@@ -89,17 +110,6 @@ class AbstractmapWidget :
 
 class interactiveMapWidget :
 
-  def tilex2lon ( self , ( tilex , pixx ) , zoom ) :
-    tilex = float(tilex)
-    pixx = float(pixx)
-    return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
-
-  def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
-    tiley = float(tiley)
-    pixy = float(pixy)
-    tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
-    return math.degrees( math.atan( math.sinh( tiley ) ) )
-
   def Shift( self , dx , dy ) :
     self.hide()
 
@@ -113,22 +123,6 @@ class interactiveMapWidget :
     self.composeMap()
     self.show()
 
-  def ZoomChange ( self , selector ) :
-    model = selector.get_model(0)
-    active = selector.get_active(0)
-    value = model.get( model.get_iter(active) , 0 )
-    self.SetZoom( int(value[0]) )
-
-  def SetZoom( self , zoom ) :
-    self.hide()
-    lat = self.tiley2lat( ( self.reftile_y , self.refpix_y ) , self.conf.zoom )
-    lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.conf.zoom )
-    self.reftile_x , self.refpix_x = self.lon2tilex( lon , zoom )
-    self.reftile_y , self.refpix_y = self.lat2tiley( lat , zoom )
-    self.conf.zoom = zoom
-    self.composeMap()
-    self.show()
-
   def Up( self ) :
     self.hide()
     self.reftile_y -= 1
index f6e9253..341ad90 100755 (executable)
@@ -122,14 +122,14 @@ class AbstractWifiscanner :
         status = gtk.Label( "status bar ..." )
         _scanner.status = status
         _scanner.buffer = textview.get_buffer() 
-        _scanner.map = self.map
+        _scanner.map = self.map.child
         bottom_box.pack_start( status , expand=False , padding=20 )
 
     def run ( self ) :
         gtk.main()
 
-def settings_cb ( widget , config ) :
-    wifimap.config.SettingsWindow( config )
+def settings_cb ( widget , map ) :
+    window = wifimap.config.SettingsWindow( map.config , map.child.SetZoom )
 
 
 if hildon :
@@ -186,7 +186,7 @@ if hildon :
                                      hildon.BUTTON_ARRANGEMENT_VERTICAL,
                                      "Settings",
                                      None)
-            settings.connect( "clicked", settings_cb , self.map.config )
+            settings.connect( "clicked", settings_cb , self.map )
             menubar.append( settings )
 
             menubar.show_all()
@@ -240,7 +240,7 @@ else :
             self.vbox.pack_start( menubar )
 
             settings = gtk.MenuItem( "Settings" )
-            settings.connect( "activate", settings_cb , self.map.config )
+            settings.connect( "activate", settings_cb , self.map )
             menubar.append( settings )
 
             menubar.show_all()
index 11a02d6..407f7e5 100755 (executable)
@@ -85,10 +85,6 @@ if hildon :
 
             self.menubar = menubar = hildon.AppMenu()
 
-            #zoomlevel = hildon.Button(gtk.HILDON_SIZE_AUTO,
-            #                          hildon.BUTTON_ARRANGEMENT_VERTICAL,
-            #                          "Zoom level", None)
-            #zoomlevel.connect_object( "clicked", self.zoomstack, self.map )
             selector = wifmap.config.ZoomDialog( self.map.conf )
             zoomlevel = hildon.PickerButton(gtk.HILDON_SIZE_AUTO,
                                           hildon.BUTTON_ARRANGEMENT_VERTICAL)
@@ -124,7 +120,7 @@ else :
             vbox.pack_start(menubar,True,True,5)
 
         def zoomdialog ( self , config ) :
-            dialog = wifimap.config.ZoomDialog( config )
+            dialog = wifimap.config.ZoomDialog( config , self.map.SetZoom )
             dialog.show_all()
 
 window = MapWindow()