From c6585a8fac352d23626c2c80dccd51ef4d7d1885 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Tue, 8 Oct 2013 11:32:33 +0000 Subject: [PATCH] Add right-click 'Make Active Media' to Photo class svn: r23276 --- gramps/gui/widgets/photo.py | 27 ++++++++++++++++++++++++--- gramps/plugins/gramplet/gallery.py | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gramps/gui/widgets/photo.py b/gramps/gui/widgets/photo.py index e61bf3b52..eab8e5eb7 100644 --- a/gramps/gui/widgets/photo.py +++ b/gramps/gui/widgets/photo.py @@ -34,7 +34,8 @@ from gi.repository import Gtk # #------------------------------------------------------------------------- from ..thumbnails import get_thumbnail_image, SIZE_NORMAL, SIZE_LARGE -from ..utils import open_file_with_default_application +from ..utils import is_right_click, open_file_with_default_application +from ..widgets.menuitem import add_menuitem from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext @@ -50,9 +51,11 @@ class Photo(Gtk.EventBox): def __init__(self, use_small_size=False): GObject.GObject.__init__(self) self.full_path = None + self.uistate = None + self.handle = None self.photo = Gtk.Image() self.add(self.photo) - self.connect('button-press-event', self.display_image) + self.connect('button-press-event', self.handle_button_press) tip = _('Double-click on the picture to view it in the default image ' 'viewer application.') self.set_tooltip_text(tip) @@ -73,9 +76,27 @@ class Photo(Gtk.EventBox): else: self.photo.hide() - def display_image(self, widget, event): + def handle_button_press(self, widget, event): """ Display the image with the default external viewer. """ if event.type == Gdk.EventType._2BUTTON_PRESS and event.button == 1: open_file_with_default_application(self.full_path) + return True + elif is_right_click(event): + if self.handle and self.uistate: + self.menu = Gtk.Menu() + self.menu.set_title(_("Media Object")) + add_menuitem(self.menu, _("Make Active Media"), widget, + lambda obj: self.uistate.set_active(self.handle, "Media")) + self.menu.popup(None, None, None, None, event.button, event.time) + return True + return False + + def set_uistate(self, uistate, handle): + """ + Set uistate and media handle so that Photo can be handled by + UI. + """ + self.uistate = uistate + self.handle = handle diff --git a/gramps/plugins/gramplet/gallery.py b/gramps/plugins/gramplet/gallery.py index 270df9a87..9d825edd8 100644 --- a/gramps/plugins/gramplet/gallery.py +++ b/gramps/plugins/gramplet/gallery.py @@ -64,6 +64,7 @@ class Gallery(Gramplet): if mime_type and mime_type.startswith("image"): photo = Photo(self.uistate.screen_height() < 1000) photo.set_image(full_path, mime_type, media_ref.get_rectangle()) + photo.set_uistate(self.uistate, media_handle) self.image_list.append(photo) self.top.pack_start(photo, False, False, 0) self.top.show_all()