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. """ files = [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 = photos.get(filename) if photo is not None: photo.manual = True photo.set_location( map_view.y_to_latitude(y), map_view.x_to_longitude(x)) modified.add(photo) self.selection.emit('changed') map_view.emit('animation-completed')
def drag_finish(label, event, selection): """Update photos with new locations after photos have been dragged.""" photo = photos[label.get_name()] photo.set_location(label.get_latitude(), label.get_longitude()) photo.manual = True selection.emit('changed') map_view.emit('animation-completed')
def load_gpx_from_file(self, uri): """Parse GPX data, drawing each GPS track segment on the map.""" start_time = clock() open_file = KMLFile if uri[-3:].lower() == 'kml' else GPXFile gpx = open_file(uri, self.progressbar) # Emitting this signal ensures the new tracks get the correct color. get_obj('colorselection').emit('color-changed') self.status_message(_('%d points loaded in %.2fs.') % (len(gpx.tracks), clock() - start_time), True) if len(gpx.tracks) < 2: return points.update(gpx.tracks) metadata.alpha = min(metadata.alpha, gpx.alpha) metadata.omega = max(metadata.omega, gpx.omega) map_view.emit('realize') map_view.set_zoom_level(map_view.get_max_zoom_level()) bounds = Champlain.BoundingBox.new() for poly in polygons: bounds.compose(poly.get_bounding_box()) gpx.latitude, gpx.longitude = bounds.get_center() map_view.ensure_visible(bounds, False) self.prefs.gpx_timezone = gpx.lookup_geoname() self.prefs.set_timezone() gpx_sensitivity()
def __init__(self): """Start the map at the previous location, and connect signals.""" perform_zoom = lambda button, zoom: zoom() back_button = get_obj('back_button') zoom_in_button = get_obj('zoom_in_button') zoom_out_button = get_obj('zoom_out_button') zoom_out_button.connect('clicked', perform_zoom, map_view.zoom_out) zoom_in_button.connect('clicked', perform_zoom, map_view.zoom_in) back_button.connect('clicked', go_back, map_view) for key in ['latitude', 'longitude', 'zoom-level']: gst.bind(key, map_view, key) accel = Gtk.AccelGroup() window = get_obj('main') window.add_accel_group(accel) for key in ['Left', 'Right', 'Up', 'Down']: accel.connect(Gdk.keyval_from_name(key), Gdk.ModifierType.MOD1_MASK, 0, move_by_arrow_keys) map_view.connect('notify::zoom-level', zoom_button_sensitivity, zoom_in_button.set_sensitive, zoom_out_button.set_sensitive) map_view.connect('realize', remember_location) map_view.connect('animation-completed', set_window_title, window.set_title, Coordinates()) map_view.emit('animation-completed')
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. """ files = [ 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 = photos.get(filename) if photo is not None: photo.manual = True photo.set_location(map_view.y_to_latitude(y), map_view.x_to_longitude(x)) modified.add(photo) self.selection.emit('changed') map_view.emit('animation-completed')
def load_gpx_from_file(self, uri): """Parse GPX data, drawing each GPS track segment on the map.""" start_time = clock() gpx = get_trackfile(uri) self.status_message(_('%d points loaded in %.2fs.') % (len(gpx.tracks), clock() - start_time), True) if len(gpx.tracks) < 2: return metadata.alpha = min(metadata.alpha, gpx.alpha) metadata.omega = max(metadata.omega, gpx.omega) map_view.emit('realize') map_view.set_zoom_level(map_view.get_max_zoom_level()) bounds = Champlain.BoundingBox.new() for trackfile in known_trackfiles.values(): for polygon in trackfile.polygons: bounds.compose(polygon.get_bounding_box()) map_view.ensure_visible(bounds, False) for camera in known_cameras.values(): camera.set_found_timezone(gpx.timezone)
def test_search(self): """Make sure the search box functions.""" entry = get_obj('search_box') self.assertEqual(len(gui.search.results), 0) entry.set_text('jo') self.assertEqual(len(gui.search.results), 0) entry.set_text('edm') self.assertEqual(len(gui.search.results), 23) get_title = get_obj("main").get_title for result in gui.search.results: gui.search.search_completed(entry, gui.search.results, result.iter, map_view) loc, lat, lon = result self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) map_view.emit("animation-completed") self.assertEqual(get_title(), "GottenGeography - " + loc) entry.set_text('calg') self.assertEqual(len(gui.search.results), 652) entry.set_text('st.') self.assertEqual(len(gui.search.results), 671)
def load_gpx_from_file(self, uri): """Parse GPX data, drawing each GPS track segment on the map.""" start_time = clock() open_file = KMLFile if uri[-3:].lower() == 'kml' else GPXFile gpx = open_file(uri, self.progressbar) # Emitting this signal ensures the new tracks get the correct color. get_obj('colorselection').emit('color-changed') self.status_message( _('%d points loaded in %.2fs.') % (len(gpx.tracks), clock() - start_time), True) if len(gpx.tracks) < 2: return points.update(gpx.tracks) metadata.alpha = min(metadata.alpha, gpx.alpha) metadata.omega = max(metadata.omega, gpx.omega) map_view.emit('realize') map_view.set_zoom_level(map_view.get_max_zoom_level()) bounds = Champlain.BoundingBox.new() for poly in polygons: bounds.compose(poly.get_bounding_box()) gpx.latitude, gpx.longitude = bounds.get_center() map_view.ensure_visible(bounds, False) self.prefs.gpx_timezone = gpx.lookup_geoname() self.prefs.set_timezone() gpx_sensitivity()
def __init__(self): """Start the map at the previous location, and connect signals.""" perform_zoom = lambda button, zoom: zoom() back_button = get_obj('back_button') zoom_in_button = get_obj('zoom_in_button') zoom_out_button = get_obj('zoom_out_button') zoom_out_button.connect('clicked', perform_zoom, map_view.zoom_out) zoom_in_button.connect('clicked', perform_zoom, map_view.zoom_in) back_button.connect('clicked', go_back, map_view) for key in ['latitude', 'longitude', 'zoom-level']: gst.bind(key, map_view, key) accel = Gtk.AccelGroup() window = get_obj('main') window.add_accel_group(accel) for key in [ 'Left', 'Right', 'Up', 'Down' ]: accel.connect(Gdk.keyval_from_name(key), Gdk.ModifierType.MOD1_MASK, 0, move_by_arrow_keys) map_view.connect('notify::zoom-level', zoom_button_sensitivity, zoom_in_button.set_sensitive, zoom_out_button.set_sensitive) map_view.connect('realize', remember_location) map_view.connect('animation-completed', set_window_title, window.set_title, Coordinates()) map_view.emit('animation-completed')
def go_back(button, view): """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): view.set_zoom_level(zoom) view.center_on(lat, lon) if len(history) > 1: gst.set_history(history) else: gst.reset('history') map_view.emit('animation-completed')
def test_gsettings(self): """Make sure that GSettings is storing data correctly.""" app.gst.reset('history') self.assertEqual(gst_get('history')[0], (34.5, 15.8, 2)) map_view.center_on(12.3, 45.6) self.assertEqual(app.gst.get_double('latitude'), 12.3) self.assertEqual(app.gst.get_double('longitude'), 45.6) map_view.zoom_in() map_view.emit('realize') self.assertEqual(list(gst_get('history')), [(34.5, 15.8, 2), (12.3, 45.6, 3)]) map_view.set_map_source(MAP_SOURCES['osm-cyclemap']) self.assertEqual(app.gst.get_string('map-source-id'), 'osm-cyclemap')
def open_files(self, files): """Attempt to load all of the specified files.""" self.progressbar.show() invalid, total = [], len(files) for i, name in enumerate(files, 1): self.redraw_interface(i / total, basename(name)) try: try: self.load_img_from_file(name) except IOError: self.load_gpx_from_file(name) except IOError: invalid.append(basename(name)) if len(invalid) > 0: self.status_message(_('Could not open: ') + ', '.join(invalid)) self.progressbar.hide() self.labels.selection.emit('changed') map_view.emit('animation-completed')
def open_files(self, files): """Attempt to load all of the specified files.""" self.progressbar.show() invalid, total = [], len(files) for i, name in enumerate(files, 1): self.redraw_interface(i / total, basename(name)) try: try: self.load_img_from_file(name) except IOError: self.load_gpx_from_file(name) except IOError: invalid.append(basename(name)) if invalid: self.status_message(_('Could not open: ') + ', '.join(invalid)) self.progressbar.hide() self.labels.selection.emit('changed') map_view.emit('animation-completed')
def open_files(self, files): """Attempt to load all of the specified files.""" self.progressbar.show() invalid, total = [], len(files) for i, name in enumerate(files, 1): self.redraw_interface(i / total, basename(name)) try: try: self.load_img_from_file(name) except IOError: self.load_gpx_from_file(name) except IOError: invalid.append(basename(name)) if len(invalid) > 0: self.status_message(_('Could not open: ') + ', '.join(invalid)) # Ensure camera has found correct timezone regardless of the order # that the GPX/KML files were loaded in. for camera in known_cameras.values(): camera.set_timezone() self.progressbar.hide() self.labels.selection.emit('changed') map_view.emit('animation-completed')
def test_search(self): """Make sure the search box functions.""" entry = get_obj('search_box') self.assertEqual(len(gui.search.results), 0) entry.set_text('jo') self.assertEqual(len(gui.search.results), 0) entry.set_text('edm') self.assertEqual(len(gui.search.results), 8) get_title = get_obj("main").get_title for result in gui.search.results: gui.search.search_completed(entry, gui.search.results, result.iter, map_view) loc, lat, lon = result self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) map_view.emit("animation-completed") self.assertEqual(get_title(), "GottenGeography - " + loc) entry.set_text('calg') self.assertEqual(len(gui.search.results), 411)
def search_completed(self, entry, model, itr, view): """Go to the selected location.""" self.last_search = itr.copy() map_view.emit('realize') view.set_zoom_level(11) self.slide_to(*model.get(itr, LATITUDE, LONGITUDE))
def test_navigation_controller(self): """Ensure that it's possible to navigate the map.""" coords = [[ map_view.get_property('latitude'), map_view.get_property('longitude') ]] map_view.emit('realize') map_view.emit('animation-completed') self.assertGreater(len(get_obj('main').get_title()[18:]), 5) lat = round(random_coord(90), 6) lon = round(random_coord(180), 6) map_view.center_on(lat, lon) coords.append([lat, lon]) self.assertAlmostEqual(coords[0][0], gst_get('history')[-1][0], 5) self.assertAlmostEqual(coords[0][1], gst_get('history')[-1][1], 5) lat = round(random_coord(80), 6) lon = round(random_coord(170), 6) map_view.center_on(lat, lon) zoom_in = get_obj('zoom_in_button') zoom_out = get_obj('zoom_out_button') map_view.set_zoom_level(0) self.assertFalse(zoom_out.get_sensitive()) self.assertTrue(zoom_in.get_sensitive()) zoom_in.emit('clicked') self.assertTrue(zoom_out.get_sensitive()) self.assertTrue(zoom_in.get_sensitive()) self.assertEqual(1, map_view.get_zoom_level()) zoom_in.emit('clicked') self.assertEqual(2, map_view.get_zoom_level()) zoom_in.emit('clicked') self.assertEqual(3, map_view.get_zoom_level()) zoom_out.emit('clicked') self.assertEqual(2, map_view.get_zoom_level()) map_view.set_zoom_level(map_view.get_max_zoom_level()-1) self.assertTrue(zoom_out.get_sensitive()) self.assertTrue(zoom_in.get_sensitive()) zoom = map_view.get_zoom_level() zoom_in.emit('clicked') self.assertTrue(zoom_out.get_sensitive()) self.assertFalse(zoom_in.get_sensitive()) self.assertEqual(map_view.get_max_zoom_level(), map_view.get_zoom_level()) get_obj("back_button").emit('clicked') map_view.set_zoom_level(5) lat = map_view.get_property('latitude') lon = map_view.get_property('longitude') move_by_arrow_keys(None, None, Gdk.keyval_from_name("Left"), None) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) self.assertGreater( lon, map_view.get_property('longitude')) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Right"), None) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 0) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Right"), None) self.assertLess( lon, map_view.get_property('longitude')) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Left"), None) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 0) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 4) lon = map_view.get_property('longitude') move_by_arrow_keys(None, None, Gdk.keyval_from_name("Up"), None) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) self.assertLess( lat, map_view.get_property('latitude')) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Down"), None) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 0) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Down"), None) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) self.assertGreater( lat, map_view.get_property('latitude')) move_by_arrow_keys(None, None, Gdk.keyval_from_name("Up"), None) self.assertAlmostEqual(lon, map_view.get_property('longitude'), 4) self.assertAlmostEqual(lat, map_view.get_property('latitude'), 0)
def jump_to_photo(self, button): """Center on the first selected photo.""" photo = selected.copy().pop() if photo.valid_coords(): map_view.emit('realize') map_view.center_on(photo.latitude, photo.longitude)