From bbe6df03997e64c10378d5ee0dc26baa637401f4 Mon Sep 17 00:00:00 2001 From: javiplx Date: Sun, 1 May 2011 11:43:03 +0000 Subject: [PATCH] REFACTORING : move mapWidget into the wifimap module git-svn-id: file:///svnroot/wifihood/branches/cleaning@98 c51dfc6a-5949-4919-9c8e-f207a149c383 --- wifimap/view.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++ wifiscanner.py | 4 +- wifiview.py | 132 +------------------------------------------------------ 3 files changed, 131 insertions(+), 133 deletions(-) diff --git a/wifimap/view.py b/wifimap/view.py index f98f582..8ec989a 100755 --- a/wifimap/view.py +++ b/wifimap/view.py @@ -1,4 +1,5 @@ +import gtk import gobject import urllib2 @@ -134,3 +135,130 @@ class AbstractmapWidget : self.composeMap() self.show() +class mapWidget ( AbstractmapWidget , gtk.Image ) : + + def __init__ ( self , config , map_size=(800,480) ) : + AbstractmapWidget.__init__( self , config , map_size ) + + gtk.Image.__init__(self) + + p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y) + self.set_from_pixbuf(p) + + 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 + + # Ranges should be long enough as to fill the screen + # 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.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 ) + else : + try : + pixbuf = gtk.gdk.pixbuf_new_from_file( file ) + except gobject.GError , ex : + print "Corrupted file %s" % ( file ) + os.unlink( file ) + #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 : + print "Total failure for tile for %s,%s" % ( self.reftile_x + i , self.reftile_y + j ) + pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.tile_size, self.tile_size ) + + dest_x = self.tile_size * i + center_x + dest_y = self.tile_size * j + center_y + + init_x = 0 + size_x = self.tile_size + if dest_x < 0 : + init_x = abs(dest_x) + size_x = self.tile_size + dest_x + dest_x = 0 + if dest_x + self.tile_size > self.win_x : + size_x = self.win_x - dest_x + + init_y = 0 + size_y = self.tile_size + if dest_y < 0 : + init_y = abs(dest_y) + size_y = self.tile_size + dest_y + dest_y = 0 + if dest_y + self.tile_size > self.win_y : + size_y = self.win_y - dest_y + + if ( size_x > 0 and size_y > 0 ) and ( init_x < self.tile_size and init_y < self.tile_size ) : + pixbuf.copy_area( init_x, init_y, size_x, size_y, self.get_pixbuf(), dest_x , dest_y ) + del(pixbuf) + + self.draw_paths() + + def draw_paths( 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() + 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 ) + fd.close() + + db = wifimap.db.database( os.path.join( self.conf.homedir , self.conf.dbname ) ) + db.open() + for ap in db.db.execute( "SELECT * FROM ap" ) : + 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(red, True , dest_x , dest_y , 3 , 3 ) + db.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() + # NOTE : Intervals for query are just educated guesses to fit in window + 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 ) + db.close() + + self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y ) + diff --git a/wifiscanner.py b/wifiscanner.py index eb51435..dfa108a 100755 --- a/wifiscanner.py +++ b/wifiscanner.py @@ -123,7 +123,7 @@ if hildon : self.config = wifimap.config.Configuration() self.config.zoom = 16 - self.map = wifiview.mapWidget( self.config ) + self.map = wifimap.mapWidget( self.config ) self.map.plot_APs() self.add( self.map ) @@ -165,7 +165,7 @@ else : self.config = wifimap.config.Configuration() self.config.zoom = 16 - self.add( wifiview.mapWidget( self.config , (640,400) ) ) + self.add( wifimap.mapWidget( self.config , (640,400) ) ) class Wifiscanner ( AbstractWifiscanner , gtk.Window ) : diff --git a/wifiview.py b/wifiview.py index b2d942c..41fed02 100755 --- a/wifiview.py +++ b/wifiview.py @@ -1,6 +1,5 @@ import gtk -import gobject try : import hildon except : @@ -8,139 +7,10 @@ except : import math -import os - import wifimap.config import wifimap.view -class mapWidget ( wifimap.view.AbstractmapWidget , gtk.Image ) : - - def __init__ ( self , config , map_size=(800,480) ) : - wifimap.view.AbstractmapWidget.__init__( self , config , map_size ) - - gtk.Image.__init__(self) - - p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y) - self.set_from_pixbuf(p) - - 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 - - # Ranges should be long enough as to fill the screen - # 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.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 ) - else : - try : - pixbuf = gtk.gdk.pixbuf_new_from_file( file ) - except gobject.GError , ex : - print "Corrupted file %s" % ( file ) - os.unlink( file ) - #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 : - print "Total failure for tile for %s,%s" % ( self.reftile_x + i , self.reftile_y + j ) - pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.tile_size, self.tile_size ) - - dest_x = self.tile_size * i + center_x - dest_y = self.tile_size * j + center_y - - init_x = 0 - size_x = self.tile_size - if dest_x < 0 : - init_x = abs(dest_x) - size_x = self.tile_size + dest_x - dest_x = 0 - if dest_x + self.tile_size > self.win_x : - size_x = self.win_x - dest_x - - init_y = 0 - size_y = self.tile_size - if dest_y < 0 : - init_y = abs(dest_y) - size_y = self.tile_size + dest_y - dest_y = 0 - if dest_y + self.tile_size > self.win_y : - size_y = self.win_y - dest_y - - if ( size_x > 0 and size_y > 0 ) and ( init_x < self.tile_size and init_y < self.tile_size ) : - pixbuf.copy_area( init_x, init_y, size_x, size_y, self.get_pixbuf(), dest_x , dest_y ) - del(pixbuf) - - self.draw_paths - - def draw_paths( 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() - 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 ) - fd.close() - - db = wifimap.db.database( os.path.join( self.conf.homedir , self.conf.dbname ) ) - db.open() - for ap in db.db.execute( "SELECT * FROM ap" ) : - 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(red, True , dest_x , dest_y , 3 , 3 ) - db.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() - # NOTE : Intervals for query are just educated guesses to fit in window - 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 ) - db.close() - - self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y ) - if hildon : @@ -278,7 +148,7 @@ class AbstractMapWindow: self.connect('button_release_event', self.release_event) # self.config = wifimap.config.Configuration() - self.map = mapWidget( self.config , map_size ) + self.map = wifimap.view.mapWidget( self.config , map_size ) self.vbox.pack_end( self.map , True , True , 5) self.size_x , self.size_y = map_size -- 1.7.9.5