Added gconf defaults for mapWidget
authorjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 11:58:11 +0000 (11:58 +0000)
committerjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 11:58:11 +0000 (11:58 +0000)
git-svn-id: file:///svnroot/wifihood/trunk/wifiscanner@10 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiview

index 251f828..f1fcda2 100755 (executable)
--- a/wifiview
+++ b/wifiview
@@ -1,17 +1,43 @@
 #!/usr/bin/env python
 
 import gtk
-import gobject
+import gobject , gconf
 
 import urllib2
 import math
 
 import os
 
-class mapWidget(gtk.Image):
+class WifihoodConfig :
+
+    def __init__ ( self ) :
+        self.lat , self.lon = 40.40491 , -3.6774
+        self.zoom = 11
+       self.mapsdir = "/home/user/MyDocs/.maps"
+
+        self.client = gconf.client_get_default()
+
+    def read ( self , parentdir="/apps/wifihood"  ) :
+        lat = self.client.get_float( "%s/lattitude" % parentdir )
+        if lat : self.lat = lat
+        lon = self.client.get_float( "%s/longitude" % parentdir )
+        if lon : self.lon = lon
+        zoom = self.client.get_int( "%s/zoom" % parentdir )
+        if zoom : self.zoom = zoom
+        mapsdir = self.client.get_string( "%s/mapsdir" % parentdir )
+        if mapsdir : self.mapsdir = mapsdir
+
+    def save ( self , parentdir="/apps/wifihood" ) :
+        self.client.set_float( "%s/lattitude" % parentdir , self.lat )
+        self.client.set_float( "%s/longitude" % parentdir , self.lon )
+        self.client.set_int( "%s/zoom" % parentdir , self.zoom )
+        self.client.set_string( "%s/mapsdir" % parentdir , self.mapsdir )
+
+class mapWidget ( gtk.Image , WifihoodConfig ) :
 
   def __init__(self):
 
+    WifihoodConfig.__init__( self )
     gtk.Image.__init__(self)
 
     # Maximum width should be 800, but actually gets reduced
@@ -20,16 +46,12 @@ class mapWidget(gtk.Image):
     p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y)
     self.set_from_pixbuf(p)
 
-    zoom = 17
-    lat = 40.40491 
-    lon = -3.6774
-    self.reftile_x , self.reftile_y = self.lon2tilex( lon , zoom ) , self.lat2tiley( lat , zoom )
-    self.zoom = zoom
+    self.read()
+    self.reftile_x , self.reftile_y = self.lon2tilex( self.lon , self.zoom ) , self.lat2tiley( self.lat , self.zoom )
     # Half the size of a tile
     self.refpix_x , self.refpix_y = 128 , 128
-    self.refpix_x , self.refpix_y = 0 , 0
 
-    self.composeMap( zoom )
+    self.composeMap()
 
   def lon2tilex ( self , lon , zoom ) :
     return int( ( lon + 180 ) / 360 * 2 ** zoom )
@@ -38,7 +60,7 @@ class mapWidget(gtk.Image):
     lat = lat * math.pi / 180
     return int( ( 1 - math.log( math.tan( lat ) + 1 / math.cos( lat ) ) / math.pi ) / 2 * 2 ** zoom )
 
-  def composeMap( self , zoom ) :
+  def composeMap( self ) :
     center_x , center_y = self.win_x / 2 , self.win_y / 2
 
     # To get the central pixel in the window center, we must shift to the tile origin
@@ -49,7 +71,7 @@ class mapWidget(gtk.Image):
     # Maybe they should be decided based on self.win_x, self.win_y
     for i in range(-3,4) :
       for j in range(-3,4) :
-        file = self.tilename( i , j , zoom )
+        file = self.tilename( i , j , self.zoom )
         if file is None :
           pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 256, 256 )
           pixbuf.fill( 0x00000000 )
@@ -59,8 +81,8 @@ class mapWidget(gtk.Image):
           except gobject.GError , ex :
             print "Corrupted file %s" % ( file )
             os.unlink( file )
-            #file = self.tilename( self.reftile_x + i , self.reftile_y + j , zoom )
-            file = self.tilename( i , j , zoom )
+            #file = self.tilename( self.reftile_x + i , self.reftile_y + j , self.zoom )
+            file = self.tilename( i , j , self.zoom )
             try :
               pixbuf = gtk.gdk.pixbuf_new_from_file( file )
             except :
@@ -114,8 +136,7 @@ class mapWidget(gtk.Image):
     return file
 
   def tile2file( self , tilex , tiley , zoom ) :
-    basedir = "/home/user/MyDocs/.maps/OpenStreetMap I"
-    rootdir = "%s/%s" % ( basedir , zoom )
+    rootdir = "%s/OpenStreetMap I/%s" % ( self.mapsdir , zoom )
     if not os.path.isdir( rootdir ) :
       os.mkdir(rootdir)
     rootsubdir = "%s/%s" % ( rootdir , tilex )
@@ -133,7 +154,7 @@ class mapWidget(gtk.Image):
     self.refpix_x -= dx + 256 * tile_x
     self.refpix_y -= dy + 256 * tile_y
 
-    self.composeMap( self.zoom )
+    self.composeMap()
     self.show()
 
   def SetZoom( self , zoom ) :
@@ -143,31 +164,31 @@ class mapWidget(gtk.Image):
     self.reftile_x , self.reftile_y = self.lon2tilex( lon , zoom ) , self.lat2tiley( lat , zoom )
     self.zoom = zoom
     self.refpix_x , self.refpix_y = 128 , 128
-    self.composeMap( zoom )
+    self.composeMap()
     self.show()
 
   def Up( self ) :
     self.hide()
     self.reftile_y -= 1
-    self.composeMap( self.zoom )
+    self.composeMap()
     self.show()
 
   def Down( self ) :
     self.hide()
     self.reftile_y += 1
-    self.composeMap( self.zoom )
+    self.composeMap()
     self.show()
 
   def Right( self ) :
     self.hide()
     self.reftile_x += 1
-    self.composeMap( self.zoom )
+    self.composeMap()
     self.show()
 
   def Left( self ) :
     self.hide()
     self.reftile_x -= 1
-    self.composeMap( self.zoom )
+    self.composeMap()
     self.show()
 
 class ZoomDialog ( gtk.Dialog ) :