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 )
#!/usr/bin/env python
import gtk
-import gobject , gconf
+import gobject
try :
import hildon
except :
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
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()
# 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 )
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 :
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 )
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()
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 )