From eca23c8338ea42376b73f3c49383c311e558418d Mon Sep 17 00:00:00 2001 From: javiplx Date: Fri, 6 May 2011 22:51:33 +0000 Subject: [PATCH] REFACTORING : implement setter methods for coordinates and zoom to make easier the storage of changes git-svn-id: file:///svnroot/wifihood/trunk@124 c51dfc6a-5949-4919-9c8e-f207a149c383 --- wifiscanner/wifimap/config.py | 59 ++++++++++++++++++++-------------------- wifiscanner/wifimap/replay.py | 3 +- wifiscanner/wifimap/scanner.py | 12 ++++---- wifiscanner/wifimap/view.py | 4 +-- wifiscanner/wifiscanner | 6 ++-- wifiscanner/wifiview | 2 +- 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/wifiscanner/wifimap/config.py b/wifiscanner/wifimap/config.py index f7caad9..deeb098 100644 --- a/wifiscanner/wifimap/config.py +++ b/wifiscanner/wifimap/config.py @@ -9,33 +9,35 @@ except : class Configuration : - def __init__ ( self ) : - self.homedir = None - self.dbname = None - self.mapsdir , 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" ) or "/home/user/MyDocs" - self.dbname = client.get_string( "/apps/wifihood/dbname" ) or "wifiscanner.db" - self.mapsdir = client.get_string( "/apps/wifihood/maps" ) or "/home/user/MyDocs/.maps" - self.mapclass = client.get_string( "/apps/wifihood/maptype" ) or "OpenStreetMap I" - self.lat = client.get_float( "/apps/wifihood/lattitude" ) or client.get_float( "/apps/maemo/maemo-mapper/center_latitude" ) or 40.416 - self.lon = client.get_float( "/apps/wifihood/longitude" ) or client.get_float( "/apps/maemo/maemo-mapper/center_longitude" ) or -3.683 - self.zoom = client.get_int( "/apps/wifihood/zoom" ) or client.get_float( "/apps/maemo/maemo-mapper/zoom" ) or 15 + def __init__ ( self , type ) : + self._type = type + self._client = gconf.client_get_default() + self.homedir = self._client.get_string( "/apps/wifihood/basedir" ) or "/home/user/MyDocs" + self.homedir = "/tmp" + self.dbname = self._client.get_string( "/apps/wifihood/dbname" ) or "wifiscanner.db" + self.mapsdir = self._client.get_string( "/apps/wifihood/maps" ) or "/home/user/MyDocs/.maps" + self.mapclass = self._client.get_string( "/apps/wifihood/maptype" ) or "OpenStreetMap I" + self.lat = self._client.get_float( "/apps/wifihood/latitude" ) or self._client.get_float( "/apps/maemo/maemo-mapper/center_latitude" ) or 40.416 + self.lon = self._client.get_float( "/apps/wifihood/longitude" ) or self._client.get_float( "/apps/maemo/maemo-mapper/center_longitude" ) or -3.683 + if self._type == 'map' : + self.zoom = self._client.get_int( "/apps/wifihood/map-zoom" ) or self._client.get_float( "/apps/maemo/maemo-mapper/zoom" ) or 15 + else : + self.zoom = self._client.get_int( "/apps/wifihood/%s-zoom" % self._type ) or 16 + + def set_latlon ( self , ( lat , lon ) ) : + self._client.set_float( "/apps/wifihood/latitude" , lat ) + self._client.set_float( "/apps/wifihood/longitude" , lon ) + self.lat , self.lon = lat , lon + + def set_zoom ( self , zoom ) : + self._client.set_int( "/apps/wifihood/%s-zoom" % self._type , zoom ) + self.zoom = 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 ) + self._client.set_string( "/apps/wifihood/basedir" , self.homedir ) + self._client.set_string( "/apps/wifihood/dbname" , self.dbname ) + self._client.set_string( "/apps/wifihood/maps" , self.mapsdir ) + self._client.set_string( "/apps/wifihood/maptype" , self.mapclass ) class AbstractSettingsWindow : @@ -158,7 +160,7 @@ if hildon : def zoomdialog ( self , widget , conf ) : newzoom = int( widget.get_selector().get_current_text() ) if self.handler : self.handler( newzoom ) - conf.zoom = newzoom + conf.set_zoom( newzoom ) class SettingsWindow ( hildon.StackableWindow , AbstractSettingsWindow ) : @@ -223,7 +225,7 @@ else : newzoom = model.get(item,0)[0] if labelsetter : labelsetter( newzoom ) if handler : handler( newzoom ) - config.zoom = newzoom + config.set_zoom( newzoom ) self.destroy() class SettingsWindow ( gtk.Window , AbstractSettingsWindow ) : @@ -264,9 +266,8 @@ else : def CheckButton ( self ) : return gtk.CheckButton() -config = Configuration() - if __name__ == "__main__" : + config = Configuration( 'scanner' ) window = SettingsWindow( config ) window.connect("delete_event", gtk.main_quit, None) window.show() diff --git a/wifiscanner/wifimap/replay.py b/wifiscanner/wifimap/replay.py index 6bf7c86..6d1fdc9 100644 --- a/wifiscanner/wifimap/replay.py +++ b/wifiscanner/wifimap/replay.py @@ -6,13 +6,12 @@ import gobject import os -conf = config.Configuration() - class ReplayScanner ( gobject.GObject ) : def __init__ ( self , ifname="wlan0" ) : gobject.GObject.__init__( self ) self.scan_timeout = 0 + conf = config.Configuration( 'scanner' ) self.db = db.database( os.path.join( conf.homedir , "wifireplay.db" ) ) # Values specific to replaying diff --git a/wifiscanner/wifimap/scanner.py b/wifiscanner/wifimap/scanner.py index 41f2e5c..bddd462 100644 --- a/wifiscanner/wifimap/scanner.py +++ b/wifiscanner/wifimap/scanner.py @@ -13,14 +13,14 @@ import gobject import os -conf = config.Configuration() - class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) : def __init__ ( self , ifname="wlan0" ) : gps.GPSObject.__init__( self ) wifiscan.WifiScanner.__init__( self , ifname ) - self.db = db.database( os.path.join( conf.homedir , conf.dbname ) ) + conf = config.Configuration( 'scanner' ) + self.homedir = conf.homedir + self.db = db.database( os.path.join( self.homedir , conf.dbname ) ) # Values to be set by wireless scans self.newap = 0 @@ -49,15 +49,15 @@ class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) : self.write_logs() def write_logs ( self ) : - fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' ) + fd = open( os.path.join( self.homedir , "wiscan_gui.info" ) , 'a' ) fd.write( "%s %s %s\n" % ( self.tstamp , self.info , self.scanlist ) ) fd.close() if self.satellites : - loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' ) + loclist = open( os.path.join( self.homedir , "location.info" ) , 'a' ) loclist.write ( "%s\n" % ( self.satellites ,) ) loclist.close() if self.cells : - celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' ) + celllist = open( os.path.join( self.homedir , "cell.info" ) , 'a' ) celllist.write ( "%s\n" % ( self.cells ,) ) celllist.close() diff --git a/wifiscanner/wifimap/view.py b/wifiscanner/wifimap/view.py index a3719cc..959e871 100755 --- a/wifiscanner/wifimap/view.py +++ b/wifiscanner/wifimap/view.py @@ -31,7 +31,7 @@ class AbstractmapWidget : # FIXME : instead of hardcoded, should depend on the actual display size if distance > 150 : - self.conf.lat , self.conf.lon = latlon + self.conf.set_latlon( latlon ) 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 ) @@ -55,7 +55,7 @@ class AbstractmapWidget : 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.conf.set_zoom( zoom ) self.composeMap() self.show() diff --git a/wifiscanner/wifiscanner b/wifiscanner/wifiscanner index 341ad90..42e12e6 100755 --- a/wifiscanner/wifiscanner +++ b/wifiscanner/wifiscanner @@ -139,8 +139,7 @@ if hildon : def __init__(self): gtk.Frame.__init__( self ) - self.config = wifimap.config.Configuration() - self.config.zoom = 16 + self.config = wifimap.config.Configuration( 'scanner' ) self.add( wifimap.simpleMapWidget( self.config ) ) class Wifiscanner ( AbstractWifiscanner , hildon.StackableWindow ) : @@ -198,8 +197,7 @@ else : def __init__(self): gtk.Frame.__init__( self ) - self.config = wifimap.config.Configuration() - self.config.zoom = 16 + self.config = wifimap.config.Configuration( 'scanner' ) self.add( wifimap.simpleMapWidget( self.config , (640,400) ) ) class Wifiscanner ( AbstractWifiscanner , gtk.Window ) : diff --git a/wifiscanner/wifiview b/wifiscanner/wifiview index afbed66..b7da997 100755 --- a/wifiscanner/wifiview +++ b/wifiscanner/wifiview @@ -60,7 +60,7 @@ class AbstractMapWindow: self.connect('button_press_event', self.press_event) self.connect('button_release_event', self.release_event) - self.config = wifimap.config.Configuration() + self.config = wifimap.config.Configuration( 'map' ) self.map = wifimap.view.mapWidget( self.config , map_size ) self.vbox.pack_end( self.map , True , True , 5) -- 1.7.9.5