MERGE : incorporate changes on cleaning branch to completelly decouple wifiview and...
[wifihood] / wifiscanner / wifiview.py
index 850deee..0437d70 100755 (executable)
@@ -1,6 +1,5 @@
 
 import gtk
-import gobject
 try :
     import hildon
 except :
@@ -8,109 +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 ) :
-
-    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 )
-
 
 if hildon :
 
@@ -181,42 +81,21 @@ class AbstractMapWindow:
         gtk.main_quit()
 
     def press_event ( self, widget, event, *args ) :
-      # FIXME : Set only if far enough from borders
-      border_x = 40
-      border_y = 30
-      print "press  ",event.get_coords(),event.get_root_coords()
+      border_x , border_y = 40 , 30
       if event.x > border_x and event.y > border_y and event.x < ( self.size_x - border_x ) and event.y < ( self.size_y - border_y ) :
         self.click_x = event.x
         self.click_y = event.y
 
     def release_event ( self, widget, event, *args ) :
       min_shift = 50
-      print "unpress",event.get_coords(),event.get_root_coords()
       if self.click_x is not None and self.click_y is not None :
         delta_x = int( event.x - self.click_x )
         delta_y = int( event.y - self.click_y )
         shift = math.sqrt( delta_x * delta_x + delta_y * delta_y )
         if shift > min_shift :
           self.map.Shift(delta_x, delta_y)
-        #  if delta_x > 100 :
-        #    self.map.Left()
-        #  elif delta_x < -100 :
-        #    self.map.Right()
-        #  elif delta_y > 100 :
-        #    self.map.Up()
-        #  elif delta_y < -100 :
-        #    self.map.Down()
       self.click_x , self.click_y = None , None
 
-    def screen_event ( self, widget, event, *args ) :
-      print "REDIOS",event
-      print "      ",widget
-      print "      ",args
-
-
-    def on_button_press ( self, widget, event, *args ) :
-      print "HOLA",event
-
     def on_key_press ( self, widget, event, *args ) :
       if event.keyval == gtk.keysyms.Up :
           self.map.Up()
@@ -239,16 +118,12 @@ class AbstractMapWindow:
 
         self.vbox = gtk.VBox(False, 0)
 
-        # To get explicit GDK_BUTTON_PRESS instead of paired GDK_LEAVE_NOTIFY & GDK_ENTER_NOTIFY
-#        self.add_events(gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK)
         self.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK )
-        #
-#        self.connect('motion_notify_event', self.screen_event)
         self.connect('button_press_event', self.press_event)
         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