From: javiplx Date: Wed, 4 May 2011 14:22:19 +0000 (+0000) Subject: Move scanning area as the position changes (fixes #6887) X-Git-Tag: hildon-wrapped~39 X-Git-Url: http://vcs.maemo.org/git/?p=wifihood;a=commitdiff_plain;h=4d078c612c958f7ea563c37700d3c4c1379bbe53 Move scanning area as the position changes (fixes #6887) git-svn-id: file:///svnroot/wifihood/trunk@113 c51dfc6a-5949-4919-9c8e-f207a149c383 --- diff --git a/wifiscanner/wifimap/view.py b/wifiscanner/wifimap/view.py index 57bc1ee..368df9c 100755 --- a/wifiscanner/wifimap/view.py +++ b/wifiscanner/wifimap/view.py @@ -22,6 +22,22 @@ class AbstractmapWidget : 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 ) + def recenter ( self , latlon ) : + + center = self.gps2pix( latlon , self.center() ) + pixel = self.gps2pix( (self.conf.lat,self.conf.lon) , self.center() ) + + distance = math.sqrt( (pixel[0]-center[0])**2 + (pixel[1]-center[1])**2 ) + + # FIXME : instead of hardcoded, should depend on the actual display size + if distance > 150 : + self.conf.lat , self.conf.lon = 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 ) + + self.composeMap() + def lon2tilex ( self , lon , zoom ) : number = math.modf( ( lon + 180 ) / 360 * 2 ** zoom ) return int( number[1] ) , int( self.tile_size * number[0] ) @@ -150,11 +166,7 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) : self.composeMap() 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 - center_x -= self.refpix_x - center_y -= self.refpix_y + center_x , center_y = self.center() # Ranges should be long enough as to fill the screen # Maybe they should be decided based on self.win_x, self.win_y @@ -203,10 +215,10 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) : pixbuf.copy_area( init_x, init_y, size_x, size_y, self.get_pixbuf(), dest_x , dest_y ) del(pixbuf) - self.draw_paths() +# self.draw_paths() self.plot_APs() - def plot( self , pixmap , coords , colorname , radius=3 ) : + def center( self ) : center_x , center_y = self.win_x / 2 , self.win_y / 2 @@ -214,6 +226,12 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) : center_x -= self.refpix_x center_y -= self.refpix_y + return center_x , center_y + + def plot( self , pixmap , coords , colorname , radius=3 ) : + + center_x , center_y = self.center() + gc = pixmap.new_gc() gc.foreground = pixmap.get_colormap().alloc_color( colorname ) diff --git a/wifiscanner/wifiscanner b/wifiscanner/wifiscanner index cb2a452..88a9e4c 100755 --- a/wifiscanner/wifiscanner +++ b/wifiscanner/wifiscanner @@ -57,6 +57,7 @@ class scanner ( wifimap.Scanner ) : self.buffer.insert_at_cursor( "%s %5d\n" % ( mac , rss ) ) if self.info[0] == "FIX" : self.map.hide() + self.map.recenter( self.info[4:6] ) pixmap,mask = self.map.get_pixbuf().render_pixmap_and_mask() self.map.plot( pixmap , ( float(self.info[4]) , float(self.info[5]) ) , "red" , 2 ) self.map.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.map.win_x, self.map.win_y ) @@ -134,9 +135,7 @@ if hildon : self.config = wifimap.config.Configuration() self.config.zoom = 16 - self.map = wifimap.simpleMapWidget( self.config ) - self.map.plot_APs() - self.add( self.map ) + self.add( wifimap.simpleMapWidget( self.config ) ) class Wifiscanner ( AbstractWifiscanner , hildon.Window ) :