2006-01-20 22:01:25 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2006-01-20 16:00:35 +05:30
|
|
|
import os.path
|
2006-01-15 03:51:56 +05:30
|
|
|
import gtk
|
|
|
|
import gobject
|
2006-01-17 19:13:29 +05:30
|
|
|
from logging import getLogger
|
|
|
|
log = getLogger(".ObjectSelector")
|
|
|
|
|
|
|
|
import ImgManip
|
2006-01-20 16:00:35 +05:30
|
|
|
import const
|
2006-01-15 03:51:56 +05:30
|
|
|
|
2006-02-08 22:02:47 +05:30
|
|
|
from _PreviewFrameBase import PreviewFrameBase
|
|
|
|
|
|
|
|
class FamilyPreviewFrame(PreviewFrameBase):
|
2006-01-15 03:51:56 +05:30
|
|
|
|
|
|
|
__gproperties__ = {}
|
|
|
|
|
|
|
|
__gsignals__ = {
|
|
|
|
}
|
|
|
|
|
|
|
|
__default_border_width = 5
|
|
|
|
|
|
|
|
def __init__(self,dbstate,label="Preview"):
|
2006-02-08 22:02:47 +05:30
|
|
|
PreviewFrameBase.__init__(self,label)
|
2006-01-15 03:51:56 +05:30
|
|
|
|
2006-01-17 19:13:29 +05:30
|
|
|
self._dbstate = dbstate
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
align = gtk.Alignment()
|
|
|
|
|
|
|
|
# Image
|
2006-01-17 19:13:29 +05:30
|
|
|
self._image_l = gtk.Image()
|
|
|
|
self._image_r = gtk.Image()
|
2006-01-15 03:51:56 +05:30
|
|
|
|
2006-01-17 19:13:29 +05:30
|
|
|
image_box = gtk.HBox()
|
|
|
|
image_box.pack_start(self._image_l)
|
|
|
|
image_box.pack_start(self._image_r)
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
# Text
|
|
|
|
label = gtk.Label()
|
|
|
|
label.set_use_markup(True)
|
|
|
|
label.set_line_wrap(True)
|
|
|
|
label.set_justify(gtk.JUSTIFY_LEFT)
|
|
|
|
label.set_alignment(xalign=0.1,yalign=0.1)
|
|
|
|
label.set_markup("<b>Father:</b> Joe Blogs\n"
|
|
|
|
"<b>Mother:</b> Joe Blogs\n"
|
|
|
|
"<b>m:</b> 1906\n")
|
|
|
|
|
|
|
|
# box
|
|
|
|
box = gtk.VBox()
|
2006-01-17 20:24:46 +05:30
|
|
|
box.pack_start(image_box,False,False)
|
2006-01-15 03:51:56 +05:30
|
|
|
box.pack_start(label)
|
|
|
|
|
|
|
|
|
|
|
|
# align
|
|
|
|
|
|
|
|
align.add(box)
|
|
|
|
align.set_padding(self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width)
|
|
|
|
align.set(0.5,0.5,
|
|
|
|
1.0,1.0)
|
|
|
|
|
|
|
|
|
|
|
|
self.add(align)
|
|
|
|
|
2006-01-17 19:13:29 +05:30
|
|
|
self.clear_object()
|
|
|
|
|
|
|
|
def set_object_from_id(self,id):
|
|
|
|
try:
|
|
|
|
family = self._dbstate.db.get_family_from_gramps_id(id)
|
|
|
|
|
|
|
|
image = [self._image_l, self._image_r]
|
|
|
|
image_no = 0
|
|
|
|
for person_handle in (family.get_father_handle(),family.get_mother_handle()):
|
|
|
|
person = self._dbstate.db.get_person_from_handle(person_handle)
|
|
|
|
if not person:
|
|
|
|
return
|
|
|
|
|
|
|
|
image_list = person.get_media_list()
|
|
|
|
if image_list:
|
|
|
|
mobj = self._dbstate.db.get_object_from_handle(image_list[0].ref)
|
|
|
|
if mobj.get_mime_type()[0:5] == "image":
|
|
|
|
pixbuf = ImgManip.get_thumbnail_image(mobj.get_path())
|
|
|
|
image[image_no].set_from_pixbuf(pixbuf)
|
|
|
|
image_no += 1
|
|
|
|
else:
|
2006-03-03 05:47:58 +05:30
|
|
|
self._image_l.set_from_file(os.path.join(const.image_dir,"person.svg"))
|
|
|
|
self._image_r.set_from_file(os.path.join(const.image_dir,"person.svg"))
|
2006-01-17 19:13:29 +05:30
|
|
|
|
|
|
|
except:
|
|
|
|
log.warn("Failed to generate preview for family", exc_info=True)
|
|
|
|
self.clear_object()
|
|
|
|
|
|
|
|
def clear_object(self):
|
2006-03-03 05:47:58 +05:30
|
|
|
self._image_l.set_from_file(os.path.join(const.image_dir,"person.svg"))
|
|
|
|
self._image_r.set_from_file(os.path.join(const.image_dir,"person.svg"))
|
2006-01-17 19:13:29 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
|
|
|
|
if gtk.pygtk_version < (2,8,0):
|
|
|
|
gobject.type_register(FamilyPreviewFrame)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
w = gtk.Window()
|
|
|
|
f = PersonPreviewFrame()
|
|
|
|
w.add(f)
|
|
|
|
w.show_all()
|
|
|
|
|
|
|
|
gtk.main()
|