From: javiplx Date: Sun, 10 Oct 2010 12:47:58 +0000 (+0000) Subject: Extend configuration to cover wifihood view X-Git-Url: http://git.maemo.org/git/?p=wifihood;a=commitdiff_plain;h=83465eea83ddadd068a655b4ffb19f8438b9f4ab Extend configuration to cover wifihood view git-svn-id: file:///svnroot/wifihood/trunk/wifiscanner@42 c51dfc6a-5949-4919-9c8e-f207a149c383 --- diff --git a/wifimap/config.py b/wifimap/config.py index 6279396..b014ec7 100644 --- a/wifimap/config.py +++ b/wifimap/config.py @@ -6,16 +6,29 @@ class Configuration : def __init__ ( self ) : self.homedir = None self.dbname = None + self.mapdir , self.mapclass = None , None + self.lat , self.lon = 0.0 , 0.0 + self.zoom = 0 self.read() def read ( self ) : client = gconf.client_get_default() self.homedir = client.get_string( "/apps/wifihood/basedir" ) self.dbname = client.get_string( "/apps/wifihood/dbname" ) + self.mapsdir = client.get_string( "/apps/wifihood/maps" ) + self.mapclass = client.get_string( "/apps/wifihood/maptype" ) + self.lat = client.get_float( "/apps/wifihood/lattitude" ) + self.lon = client.get_float( "/apps/wifihood/longitude" ) + self.zoom = client.get_int( "/apps/wifihood/zoom" ) def save ( self ) : client = gconf.client_get_default() client.set_string( "/apps/wifihood/basedir" , self.homedir ) client.set_string( "/apps/wifihood/dbname" , self.dbname ) + client.set_string( "/apps/wifihood/maps" , self.mapsdir ) + client.set_string( "/apps/wifihood/maptype" , self.mapclass ) + client.set_float( "/apps/wifihood/lattitude" , self.lat ) + client.set_float( "/apps/wifihood/longitude" , self.lon ) + client.set_int( "/apps/wifihood/zoom" , self.zoom ) diff --git a/wifiview b/wifiview index 14f3463..bcb67a8 100755 --- a/wifiview +++ b/wifiview @@ -1,7 +1,7 @@ #!/usr/bin/env python import gtk -import gobject , gconf +import gobject try : import hildon except : @@ -12,36 +12,13 @@ import math import os -class WifihoodConfig : +import wifimap.config - def __init__ ( self ) : - self.lat , self.lon = 40.40491 , -3.6774 - self.zoom = 11 - self.mapsdir = "/home/user/MyDocs/.maps" +class mapWidget ( gtk.Image ) : - self.client = gconf.client_get_default() + def __init__ ( self , config ) : - 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 ) + self.conf = config gtk.Image.__init__(self) # Maximum width should be 800, but actually gets reduced @@ -51,9 +28,8 @@ class mapWidget ( gtk.Image , WifihoodConfig ) : p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y) self.set_from_pixbuf(p) - self.read() - self.reftile_x , self.refpix_x = self.lon2tilex( self.lon , self.zoom ) - self.reftile_y , self.refpix_y = self.lat2tiley( self.lat , self.zoom ) + self.reftile_x , self.refpix_x = self.lon2tilex( self.conf.lon , self.conf.zoom ) + self.reftile_y , self.refpix_y = self.lat2tiley( self.conf.lat , self.conf.zoom ) self.composeMap() @@ -88,7 +64,7 @@ class mapWidget ( gtk.Image , WifihoodConfig ) : # 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 , self.zoom ) + file = self.tilename( i , j , self.conf.zoom ) if file is None : pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.tile_size, self.tile_size ) pixbuf.fill( 0x00000000 ) @@ -98,8 +74,8 @@ class mapWidget ( gtk.Image , WifihoodConfig ) : except gobject.GError , ex : print "Corrupted file %s" % ( file ) os.unlink( file ) - #file = self.tilename( self.reftile_x + i , self.reftile_y + j , self.zoom ) - file = self.tilename( i , j , self.zoom ) + #file = self.tilename( self.reftile_x + i , self.reftile_y + j , self.conf.zoom ) + file = self.tilename( i , j , self.conf.zoom ) try : pixbuf = gtk.gdk.pixbuf_new_from_file( file ) except : @@ -153,7 +129,7 @@ class mapWidget ( gtk.Image , WifihoodConfig ) : return file def tile2file( self , tilex , tiley , zoom ) : - rootdir = "%s/OpenStreetMap I/%s" % ( self.mapsdir , zoom ) + rootdir = "%s/%s/%s" % ( self.conf.mapsdir , self.conf.mapclass , zoom ) if not os.path.isdir( rootdir ) : os.mkdir(rootdir) rootsubdir = "%s/%s" % ( rootdir , tilex ) @@ -182,11 +158,11 @@ class mapWidget ( gtk.Image , WifihoodConfig ) : def SetZoom( self , zoom ) : self.hide() - lat = self.tiley2lat( ( self.reftile_y , self.refpix_y ) , self.zoom ) - lon = self.tilex2lon( ( self.reftile_x , self.refpix_x ) , self.zoom ) + 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.zoom = zoom + self.conf.zoom = zoom self.composeMap() self.show() @@ -358,7 +334,8 @@ class MapWindow: self.window.connect('button_press_event', self.press_event) self.window.connect('button_release_event', self.release_event) # - self.map = mapWidget() + self.config = wifimap.config.Configuration() + self.map = mapWidget( self.config ) vbox.pack_end( self.map , True , True , 5) self.create_menu( vbox )