Advertisement
Guest User

gps_slip_map.py

a guest
Dec 31st, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.96 KB | None | 0 0
  1. import sys
  2. import os.path
  3. import gtk
  4. import gobject
  5. import osmgpsmap
  6.  
  7. gobject.threads_init()
  8. gtk.gdk.threads_init()
  9.  
  10. #Try static lib first
  11. mydir = os.path.dirname(os.path.abspath(__file__))
  12. libdir = os.path.abspath(os.path.join(mydir, "..", "python", ".libs"))
  13. sys.path.insert(0, libdir)
  14.  
  15. class UI(gtk.Window):
  16.     def __init__(self):
  17.         #initialize the window settings
  18.         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
  19.         self.set_default_size(640, 480)
  20.         self.connect('destroy', lambda x: gtk.main_quit())
  21.         self.set_title('OSURC GPS MAP VIEWER')
  22.         self.set_position(gtk.WIN_POS_CENTER)
  23.  
  24.         #creating the osmgpsmap module (changes the default sources from-1)
  25.         self.osm = osmgpsmap.GpsMap(map_source = 12)
  26.         self.osm.layer_add(osmgpsmap.GpsMapOsd(show_dpad=True, show_zoom=True, show_gps_in_dpad=True))
  27.  
  28.         #Object initialization and Connections
  29.         zoom_in_button = gtk.Button('Zoom In')
  30.         zoom_in_button.connect('clicked', self.zoom_in_clicked)
  31.        
  32.         zoom_out_button = gtk.Button('Zoom Out')
  33.         zoom_out_button.connect('clicked', self.zoom_out_clicked)
  34.        
  35.         home_button = gtk.Button('Home')
  36.         home_button.connect('clicked', self.home_clicked)
  37.         cache_button = gtk.Button('Cache')
  38.         cache_button.connect('clicked', self.cache_clicked)
  39.        
  40.         clear_track_button = gtk.Button('Clear Track')
  41.         clear_track_button.connect('clicked', self.remove_track)
  42.        
  43.         self.combobox = gtk.combo_box_new_text()
  44.         self.combobox.connect('changed', self.set_map_source)
  45.         self.combobox.insert_text(0, "test1")
  46.         self.combobox.insert_text(1, "test2")
  47.         self.combobox.insert_text(2, "test3")
  48.         self.combobox.insert_text(3, "test4")
  49.         self.combobox.insert_text(4, "test5")
  50.         self.combobox.set_active(0)
  51.        
  52.         self.latlon_entry = gtk.Entry()
  53.         self.echo_entry = gtk.Entry()
  54.  
  55.         #Program Layout
  56.         self.vbox = gtk.VBox(False, 0)
  57.         self.hbox = gtk.HBox(False, 0)
  58.         self.add(self.vbox)
  59.        
  60.         self.vbox.pack_start(self.osm, expand=True, fill=True, padding=0)
  61.         self.vbox.pack_start(self.latlon_entry, expand=False, fill=True, padding=0)
  62.         self.vbox.pack_start(self.hbox, expand=False, fill=False, padding=4)
  63.        
  64.         self.hbox.pack_start(zoom_in_button)
  65.         self.hbox.pack_start(zoom_out_button)
  66.         self.hbox.pack_start(home_button)
  67.         self.hbox.pack_start(cache_button)
  68.         self.hbox.pack_start(clear_track_button)
  69.         self.hbox.pack_start(self.combobox)
  70.  
  71.         self.vbox.pack_start(self.echo_entry, expand=False, fill=True)
  72.        
  73.         #Event Monitoring      
  74.         self.osm.connect("motion_notify_event", self.mouse_hover)
  75.         self.osm.connect("button_release_event", self.poi)
  76.  
  77.         #regullary timed callback function
  78.         gobject.timeout_add(500, self.print_tiles)
  79.  
  80.     def set_map_source(self, combobox):
  81.         active = self.combobox.get_active()
  82.         if self.osm:
  83.             #remove old map
  84.             self.vbox.remove(self.osm)
  85.         try:
  86.             self.osm = osmgpsmap.GpsMap(map_source=active)
  87.         except Exception, e:
  88.             print "ERROR:", e
  89.             self.osm = osmgpsmap.GpsMap()
  90.         self.vbox.pack_start(self.osm, True)
  91.         self.osm.show()
  92.  
  93.  
  94.     def print_tiles(self):
  95.         if self.osm.props.tiles_queued != 0:
  96.             self.echo_entry.set_text("%s Tiles Queued" % self.osm.props.tiles_queued)
  97.         else:
  98.             self.echo_entry.set_text("0 Tiles Queued")
  99.         return True
  100.  
  101.     def remove_track(self, osm):
  102.         self.osm.track_remove_all
  103.         self.osm.gps_clear
  104.  
  105.     def poi(self, osm, event):
  106.         lat,lon = self.osm.get_event_location(event).get_degrees()
  107.         if event.button == 3:
  108.             self.osm.gps_add(lat, lon, heading=osmgpsmap.INVALID);
  109.         elif event.button == 2:
  110.             pb = gtk.gdk.pixbuf_new_from_file_at_size ("poi.png", 24,24)
  111.             self.osm.image_add(lat,lon,pb)
  112.  
  113.         #Mouse Click on Map Event
  114.     def mouse_hover(self, osm, event):
  115.         lat,lon = self.osm.get_event_location(event).get_degrees()
  116.         self.latlon_entry.set_text('LAT [%s] LON [%s]' % (lat, lon))
  117.  
  118.     def zoom_in_clicked(self, button):
  119.         self.osm.set_zoom(self.osm.props.zoom + 1)
  120.  
  121.     def zoom_out_clicked(self, button):
  122.         self.osm.set_zoom(self.osm.props.zoom - 1)
  123.  
  124.     def home_clicked(self, button):
  125.         self.osm.set_center_and_zoom(44.5595092773, -123.281433105, 20)
  126.  
  127.     def cache_clicked(self, button):
  128.         bbox = self.osm.get_bbox()
  129.         self.osm.download_maps(
  130.             *bbox,
  131.             zoom_start=self.osm.props.zoom,
  132.             zoom_end=self.osm.props.max_zoom
  133.         )
  134.  
  135.  
  136.    
  137. if __name__ == "__main__":
  138.     u = UI()
  139.     u.show_all()
  140.     if os.name == "nt": gtk.gdk.threads_enter()
  141.     gtk.main()
  142.     if os.name == "nt": gtk.gdk.threads_leave()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement