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:
Richard Taylor 2005-08-19 14:26:03 +00:00
parent fbfdbae3bd
commit f93ed35eff
4 changed files with 255 additions and 11 deletions

View File

@ -1,3 +1,8 @@
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
2005-08-17 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/DisplayModels.py: added basic tooltip support to models
* src/PageView.py: added basic tooltip support

View File

@ -45,6 +45,8 @@ import NameDisplay
import DateHandler
import RelLib
import Utils
import ToolTips
import DisplayTrace
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
@ -143,6 +145,8 @@ class BaseModel(gtk.GenericTreeModel):
return self.indexlist[node]
def on_get_column_type(self,index):
if index == self.tooltip_column:
return object
return gobject.TYPE_STRING
def on_get_iter(self, path):
@ -329,11 +333,12 @@ class SourceModel(BaseModel):
return time.localtime(data[8])
def column_tooltip(self,data):
return unicode(data[2])
#-------------------------------------------------------------------------
#
# PlaceModel
try:
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_source_from_handle(data[0]))
except:
DisplayTrace.DisplayTrace()
return t
#
#-------------------------------------------------------------------------
class PlaceModel(BaseModel):
@ -434,7 +439,11 @@ class PlaceModel(BaseModel):
_codeset)
def column_tooltip(self,data):
return unicode(data[2])
try:
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_place_from_handle(data[0]))
except:
DisplayTrace.DisplayTrace()
return t
#-------------------------------------------------------------------------
#
@ -502,7 +511,11 @@ class MediaModel(BaseModel):
_codeset)
def column_tooltip(self,data):
return unicode(data[4])
try:
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_object_from_handle(data[0]))
except:
DisplayTrace.DisplayTrace()
return t
#-------------------------------------------------------------------------
#
@ -582,7 +595,11 @@ class EventModel(BaseModel):
_codeset)
def column_tooltip(self,data):
return unicode(data[4])
try:
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_event_from_handle(data[0]))
except:
DisplayTrace.DisplayTrace()
return t
#-------------------------------------------------------------------------
@ -696,4 +713,8 @@ class RepositoryModel(BaseModel):
return unicode(data[7])
def column_tooltip(self,data):
return unicode(data[3])
try:
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_repository_from_handle(data[0]))
except:
DisplayTrace.DisplayTrace()
return t

View File

@ -49,6 +49,7 @@ import pango
from RelLib import *
import NameDisplay
import DateHandler
import ToolTips
#-------------------------------------------------------------------------
#
@ -409,7 +410,8 @@ class PeopleModel(gtk.GenericTreeModel):
return u""
def column_tooltip(self,data,node):
return NameDisplay.displayer.sorted_name(data[_NAME_COL])
return ToolTips.TipFromFunction(self.db, lambda: self.db.get_person_from_handle(data[0]))
def column_int_id(self,data,node):
return node
@ -439,7 +441,7 @@ COLUMN_DEFS = [
# the order of the above columns must match PeopleView.column_names
# these columns are hidden, and must always be last in the list
(PeopleModel.column_tooltip, None, str),
(PeopleModel.column_tooltip, None, object),
(PeopleModel.column_sort_name, None, str),
(PeopleModel.column_int_id, None, str),
]

216
src/ToolTips.py Normal file
View 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
}