def test_drags_from_liststore(): """Drag from the GtkListStore to the map""" gui.open_files(DEMOFILES) assert Photograph.instances assert Label.instances for photo in Photograph.instances: old = [photo.latitude, photo.longitude] selected.add(photo) data = Struct({'get_text': lambda: photo.filename}) gui.drag.photo_drag_end(None, None, 20, 20, data, None, None, True) assert Label(photo).get_latitude() == photo.latitude assert Label(photo).get_longitude() == photo.longitude photo.lookup_geodata() assert len(photo.geoname) > 5 assert photo.latitude != old[0] assert photo.longitude != old[1]
def load_from_file(uri): """Coordinates instantiation of various classes. Ensures that related Photograph, Camera, CameraView, and Label are all instantiated together. """ photo = Photograph(uri) Label(photo) photo.read() Widgets.empty_camera_list.hide() camera_id, camera_name = Camera.generate_id(photo.camera_info) camera = Camera(camera_id) camera.add_photo(photo) CameraView(camera, camera_name) # If the user has selected the lookup method, then the timestamp # was probably calculated incorrectly the first time (before the # timezone was discovered). So call it again to get the correct value. if camera.timezone_method == 'lookup': photo.calculate_timestamp(camera.offset) Widgets.button_sensitivity() return photo
def destroy(self): """Agony!""" self.update_derived_properties() # To clear any callback... # TODO: Disconnect this from here if self in Label.cache: Label(self).destroy() if self.camera is not None: self.camera.remove_photo(self) modified.discard(self) if self.iter: Widgets.loaded_photos.remove(self.iter) del Photograph.cache[self.filename]
def test_creatability(): """ChamplainLabels should exist""" lat = random_coord(90) lon = random_coord(180) label = Label(Photograph('demo/IMG_2411.JPG')) label.set_location(lat, lon) assert isinstance(label, Champlain.Label) assert label.get_name() == 'demo/IMG_2411.JPG' assert label.get_text() == 'IMG_2411.JPG' assert label.get_latitude() == lat assert label.get_longitude() == lon label.photo.destroy()
def test_demo_data(): """Load the demo data and ensure that we're reading it in properly""" teardown() assert not points assert not TrackFile.instances assert not TrackFile.range Widgets.photos_selection.emit('changed') # No buttons should be sensitive yet because nothing's loaded. buttons = {} for button in ('jump', 'save', 'revert', 'close'): buttons[button] = Widgets[button + '_button'] assert not buttons[button].get_sensitive() # Load only the photos first. with ignored(OSError): TrackFile.load_from_file(IMGFILES[0]) assert False # Because it should have raised the exception gui.open_files(IMGFILES) # Nothing is yet selected or modified, so buttons still insensitive. for button in buttons.values(): assert not button.get_sensitive() # Something loaded in the liststore? assert len(Widgets.loaded_photos) == 6 assert Widgets.loaded_photos.get_iter_first() assert Photograph.instances for photo in Photograph.instances: assert not photo in modified assert not photo in selected # Pristine demo data shouldn't have any tags. assert not photo.altitude assert not photo.latitude assert not photo.longitude assert not photo.positioned # Add some crap photo.latitude = 10.0 photo.altitude = 650 photo.longitude = 45.0 assert photo.positioned # photo.read() should discard all the crap we added above. # This is in response to a bug where I was using pyexiv2 wrongly # and it would load data from disk without discarding old data. photo.read() photo.lookup_geodata() assert not photo.geoname assert not photo.altitude assert not photo.latitude assert not photo.longitude assert not photo.positioned assert photo.filename == Label(photo).get_name() assert Label(photo).photo.filename == Label(photo).get_name() # Load the GPX with ignored(OSError): Photograph.load_from_file(GPXFILES[0]) assert False # Because it should have raised the exception gui.open_files(GPXFILES) # Check that the GPX is loaded assert len(points) == 374 assert len(TrackFile.instances) == 1 assert TrackFile.range[0] == 1287259751 assert TrackFile.range[1] == 1287260756 for photo in Photograph.instances: photo.update_derived_properties() Widgets.photos_selection.emit('changed') # The save button should be sensitive because loading GPX modifies # photos, but nothing is selected so the others are insensitive. assert buttons['save'].get_sensitive() for button in ('jump', 'revert', 'close'): assert not buttons[button].get_sensitive() assert Photograph.instances for photo in Photograph.instances: assert photo in modified assert photo.latitude assert photo.longitude assert photo.positioned assert Label(photo).get_property('visible') # Unload the GPX data. TrackFile.clear_all() assert not points assert not TrackFile.instances assert not TrackFile.range # Save all photos buttons['save'].emit('clicked') assert not modified for button in ('save', 'revert'): assert not buttons[button].get_sensitive() Widgets.photos_selection.select_all() assert len(selected) == 6 for button in ('save', 'revert'): assert not buttons[button].get_sensitive() for button in ('jump', 'close'): assert buttons[button].get_sensitive() # Close all the photos. files = [photo.filename for photo in selected] buttons['close'].emit('clicked') for button in ('save', 'revert', 'close'): assert not buttons[button].get_sensitive() assert not Photograph.instances assert not modified assert not selected # Re-read the photos back from disk to make sure that the saving # was successful. assert len(files) == 6 for filename in files: photo = Photograph(filename) photo.read() photo.update_derived_properties() print(photo.latitude, photo.longitude, photo.altitude) assert photo not in modified assert photo.positioned assert photo.latitude assert photo.longitude assert photo.altitude > 600 assert photo.geoname == 'Edmonton, Alberta, Canada' assert not modified assert len(Photograph.instances) == 6