Add Place Details, Repository Details and Media Preview gramplets

svn: r16717
This commit is contained in:
Nick Hall
2011-02-25 22:03:41 +00:00
parent 1d66e9e3cf
commit b74edfca2d
12 changed files with 395 additions and 163 deletions

View File

@ -19,8 +19,8 @@
# $Id$
#
from gui.utils import open_file_with_default_application
from gen.plug import Gramplet
from gui.widgets import Photo
import Utils
import gtk
@ -37,9 +37,6 @@ class Gallery(Gramplet):
"""
Build the GUI interface.
"""
tip = _('Double-click on a picture to view it in the default image '
'viewer application.')
self.set_tooltip(tip)
self.image_list = []
self.top = gtk.HBox(False, 3)
return self.top
@ -57,59 +54,18 @@ class Gallery(Gramplet):
Load the primary image into the main form if it exists.
"""
media_list = obj.get_media_list()
for photo in media_list:
object_handle = photo.get_reference_handle()
for media_ref in media_list:
object_handle = media_ref.get_reference_handle()
obj = self.dbstate.db.get_object_from_handle(object_handle)
full_path = Utils.media_path_full(self.dbstate.db, obj.get_path())
mime_type = obj.get_mime_type()
if mime_type and mime_type.startswith("image"):
pb = self.get_pixbuf(full_path, photo.get_rectangle())
eb = gtk.EventBox()
eb.connect('button-press-event', self.display_image, full_path)
image = gtk.Image()
eb.add(image)
self.image_list.append(eb)
image.set_from_pixbuf(pb)
self.top.pack_start(eb, expand=False, fill=False)
photo = Photo(180.0)
photo.set_image(full_path, media_ref.get_rectangle())
self.image_list.append(photo)
self.top.pack_start(photo, expand=False, fill=False)
self.top.show_all()
def display_image(self, widget, event, path):
"""
Display the image with the default application.
"""
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
open_file_with_default_application(path)
def get_pixbuf(self, path, rectangle=None):
"""
Load, scale and display the person's main photo from the path.
"""
try:
i = gtk.gdk.pixbuf_new_from_file(path)
width = i.get_width()
height = i.get_height()
if rectangle is not None:
upper_x = min(rectangle[0], rectangle[2])/100.
lower_x = max(rectangle[0], rectangle[2])/100.
upper_y = min(rectangle[1], rectangle[3])/100.
lower_y = max(rectangle[1], rectangle[3])/100.
sub_x = int(upper_x * width)
sub_y = int(upper_y * height)
sub_width = int((lower_x - upper_x) * width)
sub_height = int((lower_y - upper_y) * height)
if sub_width > 0 and sub_height > 0:
i = i.subpixbuf(sub_x, sub_y, sub_width, sub_height)
ratio = float(max(i.get_height(), i.get_width()))
scale = float(180.0)/ratio
x = int(scale*(i.get_width()))
y = int(scale*(i.get_height()))
i = i.scale_simple(x, y, gtk.gdk.INTERP_BILINEAR)
return i
except:
return None
class PersonGallery(Gallery):
"""
Displays a gallery of media objects for a person.