Example #1
0
    def photo_drag_end(self, widget, drag_context, x, y, data, info, time, on_map):
        """Respond to drops and position photos accordingly.
        
        This method allows photos to be dropped in from the photo
        pane or any other drag source, such as the file browser.
        """
        if not data.get_text():
            return

        lat, lon = MapView.y_to_latitude(y), MapView.x_to_longitude(x)

        files = [unquote(urlparse(s).path.strip()) for s in data.get_text().split("\n") if s]

        if self.external_drag:
            self.open_files(files)
        self.external_drag = True

        if on_map:
            for filename in files:
                photo = Photograph.cache.get(filename)
                if photo is not None:
                    photo.manual = True
                    photo.set_location(lat, lon)

        self.selection.emit("changed")
Example #2
0
 def __init__(self):
     Clutter.Box.__init__(self)
     self.set_layout_manager(Clutter.BinLayout())
     self.set_color(Clutter.Color.new(0, 0, 0, 96))
     Gst.bind('show-map-coords', self, 'visible')
     MapView.bin_layout_add(self, START, START)
     self.get_layout_manager().add(CoordLabel, CENTER, CENTER)
     MapView.connect('notify::width',
         lambda *ignore: self.set_size(MapView.get_width(), 30))
def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')
 def search_completed(self, entry, model, itr):
     """Go to the selected location."""
     self.last_search = itr.copy()
     MapView.emit('realize')
     MapView.set_zoom_level(MapView.get_max_zoom_level())
     Widgets.redraw_interface()
     MapView.center_on(*model.get(itr, LATITUDE, LONGITUDE))
     MapView.set_zoom_level(11)
 def destroy(self, button=None):
     """Die a horrible death."""
     for polygon in self.polygons:
         MapView.remove_layer(polygon)
     self.polygons.clear()
     self.widgets.trackfile_settings.destroy()
     del self.cache[self.filename]
     TrackFile.instances.discard(self)
     points.clear()
     for trackfile in TrackFile.instances:
         points.update(trackfile.tracks)
     TrackFile.update_range()
 def load_from_file(uri):
     """Determine the correct subclass to instantiate.
     
     Also time everything and report how long it took. Raises IOError if
     the file extension is unknown, or no track points were found.
     """
     start_time = clock()
     
     try:
         gpx = globals()[uri[-3:].upper() + 'File'](uri)
     except KeyError:
         raise IOError
     
     Widgets.status_message(_('%d points loaded in %.2fs.') %
         (len(gpx.tracks), clock() - start_time), True)
     
     if len(gpx.tracks) < 2:
         return
     
     TrackFile.instances.add(gpx)
     MapView.emit('realize')
     MapView.set_zoom_level(MapView.get_max_zoom_level())
     MapView.ensure_visible(TrackFile.get_bounding_box(), False)
     
     TrackFile.update_range()
     Camera.set_all_found_timezone(gpx.start.geotimezone)
def move_by_arrow_keys(accel_group, acceleratable, keyval, modifier):
    """Move the map view by 5% of its length in the given direction."""
    key = Gdk.keyval_name(keyval)
    factor = 0.45 if key in ('Up', 'Left') else 0.55
    if key in ('Up', 'Down'):
        lat = MapView.y_to_latitude(MapView.get_height() * factor)
        lon = MapView.get_center_longitude()
    else:
        lat = MapView.get_center_latitude()
        lon = MapView.x_to_longitude(MapView.get_width() * factor)
    if valid_coords(lat, lon):
        MapView.center_on(lat, lon)
        ('latitude', 'longitude', 'zoom-level')])
    if history[-1] != location:
        history.append(location)
    Gst.set_history(history[-30:])

def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')

def zoom_button_sensitivity(view, signal, in_sensitive, out_sensitive):
    """Ensure zoom buttons are only sensitive when they need to be."""
    zoom = view.get_zoom_level()
    out_sensitive(view.get_min_zoom_level() != zoom)
    in_sensitive( view.get_max_zoom_level() != zoom)

for prop in ('latitude', 'longitude', 'zoom-level'):
    Gst.bind(prop, MapView, prop)

MapView.connect('notify::zoom-level', zoom_button_sensitivity,
    Widgets.zoom_in_button.set_sensitive, Widgets.zoom_out_button.set_sensitive)
MapView.connect('realize', remember_location)

 def __init__(self):
     Champlain.PathLayer.__init__(self)
     self.set_stroke_width(4)
     MapView.add_layer(self)
Example #10
0
 def menu_item_clicked(self, item, map_id):
     """Switch to the clicked map source."""
     if self.get_active():
         MapView.set_map_source(MAP_SOURCES[map_id])
Example #11
0
 def __init__(self):
     Champlain.Scale.__init__(self)
     self.connect_view(MapView)
     Gst.bind('show-map-scale', self, 'visible')
     MapView.bin_layout_add(self, START, END)
Example #12
0
 def __init__(self):
     Champlain.Point.__init__(self)
     self.set_size(4)
     self.set_color(Clutter.Color.new(0, 0, 0, 64))
     Gst.bind('show-map-center', self, 'visible')
     MapView.bin_layout_add(self, CENTER, CENTER)