REFACTORING : abstract a single method to plot points
authorjaviplx <javiplx@gmail.com>
Sun, 1 May 2011 20:47:11 +0000 (20:47 +0000)
committerjaviplx <javiplx@gmail.com>
Sun, 1 May 2011 20:47:11 +0000 (20:47 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@106 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscanner/wifimap/view.py

index bcb4c51..57bc1ee 100755 (executable)
@@ -206,7 +206,7 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) :
         self.draw_paths()
         self.plot_APs()
 
-    def draw_paths( self ) :
+    def plot( self , pixmap , coords , colorname , radius=3 ) :
 
         center_x , center_y = self.win_x / 2 , self.win_y / 2
 
@@ -214,36 +214,29 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) :
         center_x -= self.refpix_x
         center_y -= self.refpix_y
 
+        gc = pixmap.new_gc()
+        gc.foreground = pixmap.get_colormap().alloc_color( colorname )
+
+        dest_x , dest_y = self.gps2pix( coords , ( center_x , center_y ) )
+        pixmap.draw_rectangle(gc, True , dest_x , dest_y , radius , radius )
+
+    def draw_paths( self ) :
+
         pixmap,mask = self.get_pixbuf().render_pixmap_and_mask()
-        red = pixmap.new_gc()
-        red.foreground = pixmap.get_colormap().alloc_color("red")
-        green = pixmap.new_gc()
-        green.foreground = pixmap.get_colormap().alloc_color("green")
-        blue = pixmap.new_gc()
-        blue.foreground = pixmap.get_colormap().alloc_color("blue")
 
         filename = "data/wiscan_gui.info.old"
         fd = open( filename )
         for line in fd.readlines() :
             values = line.split()
             if values[1] == "FIX" :
-                dest_x , dest_y = self.gps2pix( ( float(values[5]) , float(values[6]) ) , ( center_x , center_y ) )
-                pixmap.draw_rectangle(blue, True , dest_x , dest_y , 3 , 3 )
+                self.plot( pixmap , ( float(values[5]) , float(values[6]) ) , "red" )
         fd.close()
 
         self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y )
 
     def plot_APs( 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
-
         pixmap,mask = self.get_pixbuf().render_pixmap_and_mask()
-        blue = pixmap.new_gc()
-        blue.foreground = pixmap.get_colormap().alloc_color("blue")
 
         db = wifimap.db.database( os.path.join( self.conf.homedir , self.conf.dbname ) )
         db.open()
@@ -251,8 +244,7 @@ class simpleMapWidget ( AbstractmapWidget , gtk.Image ) :
         lat , lon = self.conf.lat , self.conf.lon
         for ap in db.db.execute( "SELECT * FROM ap where lat/n>%f and lat/n<%f and lon/n>%f and lon/n<%f" % ( lat - 0.003 , lat + 0.003 , lon - 0.007 , lon + 0.007 ) ) :
             if ap[3] > 1 :
-                dest_x , dest_y = self.gps2pix( ( ap[4]/ap[3] , ap[5]/ap[3] ) , ( center_x , center_y ) )
-                pixmap.draw_rectangle(blue, True , dest_x , dest_y , 3 , 3 )
+                self.plot( pixmap , ( ap[4]/ap[3] , ap[5]/ap[3] ) , "blue" )
         db.close()
 
         self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y )