2005-08-19 19:56:03 +05:30
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-05-23 05:26:57 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2005-08-19 19:56:03 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
# $Id:ToolTips.py 9912 2008-01-22 09:17:46Z acraphae $
|
2005-08-19 19:56:03 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ToolTips
|
|
|
|
#
|
|
|
|
# The model provides a framework for generating tooltips for different
|
|
|
|
# gramps objects. The idea is to hide the task of generating these tips
|
|
|
|
# from the other parts of gramps and to provide a single place were
|
|
|
|
# a tooltip is generated so that it is consistent everywhere it is used.
|
|
|
|
#
|
|
|
|
# The tooltips generated by this module are meant to be passed to the
|
|
|
|
# TreeTips module for rendering.
|
|
|
|
#
|
|
|
|
# To add tooltips for a new object:
|
|
|
|
#
|
|
|
|
# 1. copy one of the existing <object>Tip classes and change the tooltip()
|
|
|
|
# method to suit the new object.
|
|
|
|
# 2. add a new entry to the CLASS_MAP at the bottom of the file.
|
|
|
|
# 3. thats it.
|
|
|
|
#
|
|
|
|
# To use the tips, use one of the factory classes to generate the tips.
|
|
|
|
# The factory classes generate methods that TreeTips will execute only
|
|
|
|
# if the tip is needed. So the processing is deferred until required.
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
from xml.sax.saxutils import escape
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2005-08-19 19:56:03 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2005-08-19 19:56:03 +05:30
|
|
|
import DateHandler
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Utility functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def short(val,size=60):
|
|
|
|
if len(val) > size:
|
|
|
|
return "%s..." % val[0:size]
|
|
|
|
else:
|
|
|
|
return val
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Factory classes
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class TipFromFunction(object):
|
2005-08-19 19:56:03 +05:30
|
|
|
"""
|
|
|
|
TipFromFunction generates a tooltip callable.
|
|
|
|
"""
|
|
|
|
def __init__(self,db,fetch_function):
|
|
|
|
"""
|
|
|
|
fetch_function: a callable that will return a Rellib object
|
|
|
|
when it is run. The function will not be run until the tooltip
|
|
|
|
is required. Use a lambda function to currie any required
|
|
|
|
arguments.
|
|
|
|
"""
|
|
|
|
self._db = db
|
|
|
|
self._fetch_function = fetch_function
|
|
|
|
|
|
|
|
def get_tip(self):
|
|
|
|
o = self._fetch_function()
|
|
|
|
|
|
|
|
# check if we have a handler for the object type returned
|
2009-05-27 02:18:09 +05:30
|
|
|
for cls, handler in CLASS_MAP.iteritems():
|
2005-08-19 19:56:03 +05:30
|
|
|
if isinstance(o,cls):
|
2009-05-27 02:18:09 +05:30
|
|
|
return handler(self._db, o)()
|
2005-08-19 19:56:03 +05:30
|
|
|
return "no tip"
|
|
|
|
|
|
|
|
__call__ = get_tip
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Tip generator classes.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class RepositoryTip(object):
|
2005-08-19 19:56:03 +05:30
|
|
|
def __init__(self,db,repos):
|
|
|
|
self._db = db
|
|
|
|
self._obj = repos
|
|
|
|
|
|
|
|
def get_tip(self):
|
|
|
|
global escape
|
2010-07-04 22:29:05 +05:30
|
|
|
s = "<big><b>%s:</b>\t%s</big>\n\n" % (
|
|
|
|
_("Repository"),escape(self._obj.get_name()))
|
|
|
|
|
|
|
|
addresses = self._obj.get_address_list()
|
|
|
|
if addresses:
|
|
|
|
address = addresses[0]
|
|
|
|
s += "\t<b>%s:</b>\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t\t%s\n"\
|
|
|
|
"\t<b>%s:</b>\t%s\n"\
|
|
|
|
% (
|
|
|
|
_("Location"),
|
|
|
|
escape(address.get_street()),
|
|
|
|
escape(address.get_city()),
|
|
|
|
escape(address.get_county()),
|
|
|
|
escape(address.get_state()),
|
|
|
|
escape(address.get_postal_code()),
|
|
|
|
escape(address.get_country()),
|
|
|
|
_("Telephone"), escape(address.get_phone()))
|
|
|
|
|
|
|
|
# Get the Urls
|
|
|
|
for url in self._obj.get_url_list():
|
|
|
|
s += "\t<b>%s:</b>\t%s\n" % (url.get_type(), escape(url.get_path()))
|
2007-07-20 17:33:35 +05:30
|
|
|
|
|
|
|
# Get the notes
|
|
|
|
notelist = self._obj.get_note_list()
|
|
|
|
for notehandle in notelist:
|
|
|
|
note = self._db.get_note_from_handle(notehandle)
|
|
|
|
s += "\t<b>%s:</b>\t%s\n" % (
|
2008-09-07 16:38:18 +05:30
|
|
|
_("Note"), escape(note.get()))
|
2005-08-19 19:56:03 +05:30
|
|
|
|
|
|
|
# Get the list of sources that reference this repository
|
|
|
|
repos_handle = self._obj.get_handle()
|
|
|
|
source_list = [ src_handle for src_handle \
|
|
|
|
in self._db.get_source_handles() \
|
|
|
|
if self._db.get_source_from_handle(src_handle).has_repo_reference(repos_handle)]
|
|
|
|
|
|
|
|
if len(source_list) > 0:
|
|
|
|
s += "\n<big><b>%s</b></big>\n\n" % (_("Sources in repository"),)
|
|
|
|
|
|
|
|
for src_handle in source_list:
|
|
|
|
src = self._db.get_source_from_handle(src_handle)
|
|
|
|
s += "\t<b>%s:</b>\t%s\n" % (
|
|
|
|
_("Name"),escape(short(src.get_title())))
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
__call__ = get_tip
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class PersonTip(object):
|
2005-08-19 19:56:03 +05:30
|
|
|
def __init__(self,db,repos):
|
|
|
|
self._db = db
|
|
|
|
self._obj = repos
|
|
|
|
|
|
|
|
def get_tip(self):
|
|
|
|
global escape
|
|
|
|
|
|
|
|
birth_str = ""
|
2005-12-23 07:34:54 +05:30
|
|
|
birth_ref = self._obj.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth = self._db.get_event_from_handle(birth_ref.ref)
|
2005-08-19 19:56:03 +05:30
|
|
|
date_str = DateHandler.get_date(birth)
|
|
|
|
if date_str != "":
|
|
|
|
birth_str = escape(date_str)
|
|
|
|
|
2006-01-08 08:36:58 +05:30
|
|
|
s = "<span size=\"larger\" weight=\"bold\">%s</span>\n"\
|
|
|
|
" <span weight=\"bold\">%s:</span> %s\n"\
|
|
|
|
" <span weight=\"bold\">%s:</span> %s\n" % (
|
2005-08-19 19:56:03 +05:30
|
|
|
_("Person"),
|
|
|
|
_("Name"),escape(self._obj.get_primary_name().get_name()),
|
|
|
|
_("Birth"),birth_str)
|
|
|
|
|
|
|
|
if len(self._obj.get_source_references()) > 0:
|
2005-08-19 20:57:25 +05:30
|
|
|
psrc_ref = self._obj.get_source_references()[0]
|
2006-05-23 05:26:57 +05:30
|
|
|
psrc_id = psrc_ref.get_reference_handle()
|
2005-08-19 19:56:03 +05:30
|
|
|
psrc = self._db.get_source_from_handle(psrc_id)
|
|
|
|
|
2006-01-08 08:36:58 +05:30
|
|
|
s += "\n<span size=\"larger\" weight=\"bold\">%s</span>\n"\
|
|
|
|
" <span weight=\"bold\">%s:</span> %s\n" % (
|
2005-08-19 19:56:03 +05:30
|
|
|
_("Primary source"),
|
|
|
|
_("Name"),
|
|
|
|
escape(short(psrc.get_title())))
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
__call__ = get_tip
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class FamilyTip(object):
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self,db, obj):
|
2006-01-15 06:56:47 +05:30
|
|
|
self._db = db
|
|
|
|
self._obj = obj
|
|
|
|
|
|
|
|
def get_tip(self):
|
|
|
|
global escape
|
|
|
|
|
|
|
|
fhandle = self._obj.get_father_handle()
|
|
|
|
mhandle = self._obj.get_mother_handle()
|
|
|
|
|
|
|
|
s = "<span size=\"larger\" weight=\"bold\">%s</span>" % _("Family")
|
|
|
|
|
|
|
|
if fhandle:
|
|
|
|
father = self._db.get_person_from_handle(fhandle)
|
|
|
|
s +="\n <span weight=\"bold\">%s:</span> %s" % (
|
|
|
|
_("Father"),escape(father.get_primary_name().get_name()))
|
|
|
|
|
|
|
|
if mhandle:
|
|
|
|
mother = self._db.get_person_from_handle(mhandle)
|
|
|
|
s +="\n <span weight=\"bold\">%s:</span> %s" % (
|
|
|
|
_("Mother"),escape(mother.get_primary_name().get_name()))
|
|
|
|
|
2006-04-14 01:14:35 +05:30
|
|
|
for cref in self._obj.get_child_ref_list():
|
|
|
|
child = self._db.get_person_from_handle(cref.ref)
|
2006-01-15 06:56:47 +05:30
|
|
|
s +="\n <span weight=\"bold\">%s:</span> %s" % (
|
|
|
|
_("Child"),escape(child.get_primary_name().get_name()))
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
__call__ = get_tip
|
|
|
|
|
2005-08-19 19:56:03 +05:30
|
|
|
|
|
|
|
CLASS_MAP = {
|
2007-10-08 22:11:39 +05:30
|
|
|
gen.lib.Repository : RepositoryTip,
|
|
|
|
gen.lib.Person : PersonTip,
|
|
|
|
gen.lib.Family : FamilyTip
|
2005-08-19 19:56:03 +05:30
|
|
|
}
|