2005-08-17 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/DisplayModels.py: call new tooltips generator * src/PeopleModel.py: call new tooltips generator * src/ToolTips.py: new tooltips generator added svn: r5110
This commit is contained in:
216
src/ToolTips.py
Normal file
216
src/ToolTips.py
Normal file
@@ -0,0 +1,216 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2003 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$
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# 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
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gtk
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
import DateHandler
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Utility functions
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
def short(val,size=60):
|
||||
if len(val) > size:
|
||||
return "%s..." % val[0:size]
|
||||
else:
|
||||
return val
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Factory classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
class TipFromFunction:
|
||||
"""
|
||||
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
|
||||
for cls in CLASS_MAP.keys():
|
||||
if isinstance(o,cls):
|
||||
return CLASS_MAP[cls](self._db,o)()
|
||||
|
||||
return "no tip"
|
||||
|
||||
__call__ = get_tip
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Tip generator classes.
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
class RepositoryTip:
|
||||
def __init__(self,db,repos):
|
||||
self._db = db
|
||||
self._obj = repos
|
||||
|
||||
def get_tip(self):
|
||||
global escape
|
||||
s = "<big><b>%s:</b>\t%s</big>\n\n"\
|
||||
"\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"\
|
||||
"\t<b>%s:</b>\t%s\n"\
|
||||
"\t<b>%s:</b>\t%s\n"\
|
||||
"\t<b>%s:</b>\t%s\n"\
|
||||
"\t<b>%s:</b>\t%s\n"\
|
||||
% (
|
||||
_("Repository"),escape(self._obj.get_name()),
|
||||
_("Location"),
|
||||
escape(self._obj.address.get_parish()),
|
||||
escape(self._obj.address.get_city()),
|
||||
escape(self._obj.address.get_county()),
|
||||
escape(self._obj.address.get_state()),
|
||||
escape(self._obj.address.get_postal_code()),
|
||||
escape(self._obj.address.get_country()),
|
||||
_("Telephone"), escape(self._obj.address.get_phone()),
|
||||
_("Email"), escape(self._obj.get_email()),
|
||||
_("Search Url"), escape(self._obj.get_search_url()),
|
||||
_("Home Url"), escape(self._obj.get_home_url()),
|
||||
_("Note"), escape(self._obj.get_note()))
|
||||
|
||||
# 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
|
||||
|
||||
class PersonTip:
|
||||
def __init__(self,db,repos):
|
||||
self._db = db
|
||||
self._obj = repos
|
||||
|
||||
def get_tip(self):
|
||||
global escape
|
||||
|
||||
birth_str = ""
|
||||
birth_handle = self._obj.get_birth_handle()
|
||||
if birth_handle:
|
||||
birth = self._db.get_event_from_handle(birth_handle)
|
||||
date_str = DateHandler.get_date(birth)
|
||||
if date_str != "":
|
||||
birth_str = escape(date_str)
|
||||
|
||||
s = "<big><b>%s</b></big>\n\n"\
|
||||
"\t<b>%s:</b>\t%s\n"\
|
||||
"\t<b>%s:</b>\t%s\n" % (
|
||||
_("Person"),
|
||||
_("Name"),escape(self._obj.get_primary_name().get_name()),
|
||||
_("Birth"),birth_str)
|
||||
|
||||
if len(self._obj.get_source_references()) > 0:
|
||||
psrc_ref = person.get_source_references()[0]
|
||||
psrc_id = psrc_ref.get_base_handle()
|
||||
psrc = self._db.get_source_from_handle(psrc_id)
|
||||
|
||||
s += "\n<big><b>%s</b></big>\n\n"\
|
||||
"\t<b>%s:</b>\t%s\n" % (
|
||||
_("Primary source"),
|
||||
_("Name"),
|
||||
escape(short(psrc.get_title())))
|
||||
|
||||
return s
|
||||
|
||||
__call__ = get_tip
|
||||
|
||||
|
||||
CLASS_MAP = {
|
||||
RelLib.Repository : RepositoryTip,
|
||||
RelLib.Person : PersonTip
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user