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 tilex2lon ( self , ( tilex , pixx ) , zoom ) :
+ tilex = float(tilex)
+ pixx = float(pixx)
+ return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
+
+ def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
+ tiley = float(tiley)
+ pixy = float(pixy)
+ tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
+ return math.degrees( math.atan( math.sinh( tiley ) ) )
+
+ def SetZoom( self , zoom ) :
+ self.hide()
+ 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.conf.zoom = zoom
+ self.composeMap()
+ self.show()
+
def lon2tilex ( self , lon , zoom ) :
number = math.modf( ( lon + 180 ) / 360 * 2 ** zoom )
return int( number[1] ) , int( self.tile_size * number[0] )
class interactiveMapWidget :
- def tilex2lon ( self , ( tilex , pixx ) , zoom ) :
- tilex = float(tilex)
- pixx = float(pixx)
- return ( tilex + pixx/self.tile_size ) / 2.0 ** zoom * 360.0 - 180.0
-
- def tiley2lat ( self , ( tiley , pixy ) , zoom ) :
- tiley = float(tiley)
- pixy = float(pixy)
- tiley = math.pi * ( 1 - 2 * ( tiley + pixy/self.tile_size ) / 2.0 ** zoom )
- return math.degrees( math.atan( math.sinh( tiley ) ) )
-
def Shift( self , dx , dy ) :
self.hide()
value = model.get( model.get_iter(active) , 0 )
self.SetZoom( int(value[0]) )
- def SetZoom( self , zoom ) :
- self.hide()
- 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.conf.zoom = zoom
- self.composeMap()
- self.show()
-
def Up( self ) :
self.hide()
self.reftile_y -= 1
self.composeMap()
self.show()
-class simpleMapWidget ( AbstractmapWidget , gtk.DrawingArea ) :
+class simpleMapWidget ( AbstractmapWidget , gtk.Image ) :
def __init__ ( self , config , map_size=(800,480) ) :
AbstractmapWidget.__init__( self , config , map_size )
- gtk.DrawingArea.__init__(self)
- self.set_size_request(map_size[0] , map_size[1])
+ gtk.Image.__init__(self)
- self.mapimage = gtk.Image()
p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.win_x, self.win_y)
- self.mapimage.set_from_pixbuf(p)
-
- self.connect("expose-event", self.expose)
-
- def expose(self, area, event):
+ self.set_from_pixbuf(p)
+
self.composeMap()
- # FIXME : The two below could slow the displaying
- self.draw_paths()
- self.plot_APs()
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
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.mapimage.get_pixbuf(), dest_x , dest_y )
+ pixbuf.copy_area( init_x, init_y, size_x, size_y, self.get_pixbuf(), dest_x , dest_y )
del(pixbuf)
- gc = self.style.fg_gc[gtk.STATE_NORMAL]
- self.window.draw_pixbuf( gc, self.mapimage.get_pixbuf(), 0, 0, 0, 0, self.win_x, self.win_y )
+ self.draw_paths()
+ self.plot_APs()
- def draw_paths( self ) :
+ def center( self ) :
center_x , center_y = self.win_x / 2 , self.win_y / 2
center_x -= self.refpix_x
center_y -= self.refpix_y
- red = self.window.new_gc()
- red.foreground = self.get_colormap().alloc_color("red")
+ 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 )
+
+ 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()
- filename = "data/wiscan_gui.info.old"
+ filename = "/tmp/wiscan_gui.info"
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 ) )
- self.window.draw_rectangle(red, True , dest_x , dest_y , 3 , 3 )
+ self.plot( pixmap , ( float(values[5]) , float(values[6]) ) , "red" )
fd.close()
- def plot_APs( self ) :
-
- center_x , center_y = self.win_x / 2 , self.win_y / 2
+ self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y )
- # 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
+ def plot_APs( self ) :
- blue = self.window.new_gc()
- blue.foreground = self.get_colormap().alloc_color("blue")
+ pixmap,mask = self.get_pixbuf().render_pixmap_and_mask()
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 ) )
- self.window.draw_rectangle(blue, True , dest_x , dest_y , 3 , 3 )
+ for ap in db.db.execute( "SELECT lat,lon FROM ap" ) :
+ self.plot( pixmap , ( ap[0] , ap[1] ) , "blue" )
db.close()
+ self.get_pixbuf().get_from_drawable( pixmap , pixmap.get_colormap() , 0, 0 , 0 , 0 , self.win_x, self.win_y )
+
class mapWidget ( simpleMapWidget , interactiveMapWidget ) :
pass
-