def close_selected_photos(self, button=None): """Discard all selected photos.""" for photo in selected.copy(): self.labels.layer.remove_marker(photo.label) del photos[photo.filename] modified.discard(photo) self.liststore.remove(photo.iter) self.labels.select_all.set_active(False)
def __init__(self): self.message_timeout_source = None self.progressbar = get_obj('progressbar') self.error = Struct({ 'message': get_obj('error_message'), 'icon': get_obj('error_icon'), 'bar': get_obj('error_bar') }) self.error.bar.connect('response', lambda widget, signal: widget.hide()) self.strings = Struct({ 'quit': get_obj('quit').get_property('secondary-text'), 'preview': get_obj('preview_label').get_text() }) self.liststore = get_obj('loaded_photos') self.liststore.set_sort_column_id(TIMESTAMP, Gtk.SortType.ASCENDING) cell_string = Gtk.CellRendererText() cell_string.set_property('wrap-mode', Pango.WrapMode.WORD) cell_string.set_property('wrap-width', 200) cell_thumb = Gtk.CellRendererPixbuf() cell_thumb.set_property('stock-id', Gtk.STOCK_MISSING_IMAGE) cell_thumb.set_property('ypad', 6) cell_thumb.set_property('xpad', 12) column = Gtk.TreeViewColumn('Photos') column.pack_start(cell_thumb, False) column.add_attribute(cell_thumb, 'pixbuf', THUMB) column.pack_start(cell_string, False) column.add_attribute(cell_string, 'markup', SUMMARY) column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) # Deal with multiple selection drag and drop. self.defer_select = False photos_view = get_obj('photos_view') photos_view.connect('button-press-event', self.photoview_pressed) photos_view.connect('button-release-event', self.photoview_released) photos_view.append_column(column) self.drag = DragController(self.open_files) self.navigator = NavigationController() self.search = SearchController() self.labels = LabelController() self.actors = ActorController() about = get_obj('about') about.set_version(REVISION) about.set_program_name(APPNAME) about.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size( join(PKG_DATA_DIR, PACKAGE + '.svg'), 192, 192)) click_handlers = { 'open_button': [self.add_files_dialog, get_obj('open')], 'save_button': [self.save_all_files], 'close_button': [lambda btn: [p.destroy() for p in selected.copy()]], 'revert_button': [lambda btn: self.open_files( [p.filename for p in modified & selected])], 'about_button': [lambda yes, you_can: you_can.run() and you_can.hide(), about], 'help_button': [lambda *ignore: Gtk.show_uri(Gdk.Screen.get_default(), 'ghelp:gottengeography', Gdk.CURRENT_TIME)], 'jump_button': [self.jump_to_photo], 'apply_button': [self.apply_selected_photos], } for button, handler in click_handlers.items(): get_obj(button).connect('clicked', *handler) # Hide the unused button that appears beside the map source menu. ugly = get_obj('map_source_menu_button').get_child().get_children()[0] ugly.set_no_show_all(True) ugly.hide() accel = Gtk.AccelGroup() window = get_obj('main') window.resize(*gst.get('window-size')) window.connect('delete_event', self.confirm_quit_dialog) window.add_accel_group(accel) window.show_all() save_size = lambda v, s, size: gst.set_window_size(size()) for prop in ['width', 'height']: map_view.connect('notify::' + prop, save_size, window.get_size) accel.connect(Gdk.keyval_from_name('q'), Gdk.ModifierType.CONTROL_MASK, 0, self.confirm_quit_dialog) self.labels.selection.emit('changed') clear_all_gpx() button = get_obj('apply_button') gst.bind('left-pane-page', get_obj('photo_camera_gps'), 'page') gst.bind('use-dark-theme', Gtk.Settings.get_default(), 'gtk-application-prefer-dark-theme') # This bit of magic will only show the apply button when there is # at least one photo loaded that is not manually positioned. # In effect, it allows you to manually drag & drop some photos, # then batch-apply all the rest btn_sense = lambda *x: button.set_sensitive( [photo for photo in photos.values() if not photo.manual]) self.liststore.connect('row-changed', btn_sense) self.liststore.connect('row-deleted', btn_sense) empty = get_obj('empty_photo_list') empty_visible = lambda l, *x: empty.set_visible(l.get_iter_first() is None) self.liststore.connect('row-changed', empty_visible) self.liststore.connect('row-deleted', empty_visible) toolbar = get_obj('photo_btn_bar') bar_visible = lambda l, *x: toolbar.set_visible(l.get_iter_first() is not None) self.liststore.connect('row-changed', bar_visible) self.liststore.connect('row-deleted', bar_visible) get_obj('open').connect('update-preview', self.update_preview, get_obj('preview_label'), get_obj('preview_image'))
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)