gramps/src/PeopleModel.py

547 lines
18 KiB
Python
Raw Normal View History

#
# 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
2006-04-08 11:26:31 +05:30
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
2006-04-08 11:26:31 +05:30
# 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
2006-04-08 11:26:31 +05:30
# 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-04-08 11:26:31 +05:30
"""
TreeModel for the GRAMPS Person tree.
"""
__author__ = "Donald N. Allingham"
__revision__ = "$Revision$"
2006-04-08 11:26:31 +05:30
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
import time
import cgi
import sys
import locale
try:
set()
except:
from sets import Set as set
2006-03-05 10:15:44 +05:30
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".")
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from RelLib import *
2005-01-01 09:57:15 +05:30
import NameDisplay
import DateHandler
import ToolTips
import GrampsLocale
import Utils
import const
#-------------------------------------------------------------------------
#
# Localized constants
#
#-------------------------------------------------------------------------
_codeset = GrampsLocale.codeset
#-------------------------------------------------------------------------
#
# constants
#
#-------------------------------------------------------------------------
2006-04-08 11:26:31 +05:30
_ID_COL = 1
_GENDER_COL = 2
_NAME_COL = 3
_DEATH_COL = 6
_BIRTH_COL = 7
_EVENT_COL = 8
_FAMILY_COL = 9
_CHANGE_COL = 18
_MARKER_COL = 19
#-------------------------------------------------------------------------
#
# python 2.3 has a bug in the unicode sorting using locale.strcoll. Seems
# to have a buffer overrun. We can convince it to do the right thing by
2006-04-08 11:26:31 +05:30
# forcing the string to be nul terminated, sorting, then stripping off the
# nul.
#
#-------------------------------------------------------------------------
2006-04-08 06:23:44 +05:30
if sys.version_info[0:2] == (2, 3):
def locale_sort(mylist):
2006-04-08 11:26:31 +05:30
"""
Sort version to get around a python2.3 bug with unicode strings
"""
mylist = [ value + "\x00" for value in mylist ]
mylist.sort(locale.strcoll)
2006-04-08 11:26:31 +05:30
return [ value[:-1] for value in mylist ]
else:
def locale_sort(mylist):
2006-04-08 11:26:31 +05:30
"""
Normal sort routine
"""
mylist.sort(locale.strcoll)
return mylist
#-------------------------------------------------------------------------
#
# PeopleModel
#
#-------------------------------------------------------------------------
class PeopleModel(gtk.GenericTreeModel):
2006-04-08 11:26:31 +05:30
"""
Basic GenericTreeModel interface to handle the Tree interface for
the PersonView
"""
2006-04-08 06:23:44 +05:30
def __init__(self, db, data_filter=None, invert_result=False, skip=[]):
2006-04-08 11:26:31 +05:30
"""
Initialize the model building the initial data
"""
gtk.GenericTreeModel.__init__(self)
self.db = db
self.invert_result = invert_result
self.sortnames = {}
self.marker_color_column = 11
self.tooltip_column = 12
self.prev_handle = None
self.prev_data = None
2006-03-20 10:12:37 +05:30
self.temp_top_path2iter = []
2006-04-08 06:23:44 +05:30
self.rebuild_data(data_filter, skip)
2006-04-08 06:23:44 +05:30
def rebuild_data(self, data_filter=None, skip=[]):
2006-04-08 11:26:31 +05:30
"""
Convience function that calculates the new data and assigns it.
"""
2006-04-08 06:23:44 +05:30
self.calculate_data(data_filter, skip)
self.assign_data()
2006-04-08 06:23:44 +05:30
def calculate_data(self, dfilter=None, skip=[]):
2006-04-08 11:26:31 +05:30
"""
Calculates the new path to node values for the model.
"""
if dfilter:
self.dfilter = dfilter
self.temp_iter2path = {}
self.temp_path2iter = {}
self.temp_sname_sub = {}
if not self.db.is_open():
return
ngn = NameDisplay.displayer.name_grouping_name
2006-03-20 05:04:23 +05:30
nsn = NameDisplay.displayer.raw_sorted_name
self.sortnames = {}
cursor = self.db.get_person_cursor()
node = cursor.first()
2006-01-21 09:04:57 +05:30
while node:
2006-04-08 06:23:44 +05:30
handle, d = node
if not (handle in skip or (dfilter and not dfilter.match(handle))):
2006-03-20 10:12:37 +05:30
name_data = d[_NAME_COL]
self.sortnames[handle] = nsn(name_data)
try:
self.temp_sname_sub[name_data[5]].append(handle)
2006-03-20 10:12:37 +05:30
except:
self.temp_sname_sub[name_data[5]] = [handle]
2006-03-20 10:12:37 +05:30
node = cursor.next()
cursor.close()
self.temp_top_path2iter = locale_sort(self.temp_sname_sub.keys())
for name in self.temp_top_path2iter:
self.build_sub_entry(name)
def clear_cache(self):
self.prev_handle = None
2006-04-08 06:23:44 +05:30
def build_sub_entry(self, name):
self.prev_handle = None
2006-04-08 06:23:44 +05:30
slist = [ (locale.strxfrm(self.sortnames[x]), x) \
for x in self.temp_sname_sub[name] ]
slist.sort()
val = 0
2006-04-08 06:23:44 +05:30
for (junk, person_handle) in slist:
tpl = (name, val)
self.temp_iter2path[person_handle] = tpl
self.temp_path2iter[tpl] = person_handle
val += 1
def assign_data(self):
self.top_path2iter = self.temp_top_path2iter
self.iter2path = self.temp_iter2path
self.path2iter = self.temp_path2iter
self.sname_sub = self.temp_sname_sub
def on_get_flags(self):
'''returns the GtkTreeModelFlags for this particular type of model'''
return gtk.TREE_MODEL_ITERS_PERSIST
def on_get_n_columns(self):
return len(COLUMN_DEFS)
2006-04-08 11:26:31 +05:30
def on_get_path(self, node):
'''returns the tree path (a tuple of indices at the various
levels) for a particular node.'''
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
try:
2006-04-08 06:23:44 +05:30
return (self.top_path2iter.index(node), )
except:
2006-04-08 06:23:44 +05:30
(surname, index) = self.iter2path[node]
return (self.top_path2iter.index(surname), index)
2006-04-08 06:23:44 +05:30
def is_visable(self, handle):
return self.iter2path.has_key(handle)
2006-04-08 06:23:44 +05:30
def on_get_column_type(self, index):
return COLUMN_DEFS[index][COLUMN_DEF_TYPE]
2006-04-08 11:26:31 +05:30
def on_get_iter(self, path):
try:
if len(path)==1: # Top Level
return self.top_path2iter[path[0]]
else: # Sublevel
surname = self.top_path2iter[path[0]]
2006-04-08 06:23:44 +05:30
return self.path2iter[(surname, path[1])]
except:
return None
2006-04-08 06:23:44 +05:30
def on_get_value(self, node, col):
# test for header or data row-type
if self.sname_sub.has_key(node):
# Header rows dont get the background color set
2006-04-08 11:26:31 +05:30
if col == self.marker_color_column:
return None
# test for 'header' column being empty (most are)
if not COLUMN_DEFS[col][COLUMN_DEF_HEADER]:
return u''
2006-04-08 11:26:31 +05:30
# return values for 'header' row, calling a function
# according to column_defs table
2006-04-08 06:23:44 +05:30
val = COLUMN_DEFS[col][COLUMN_DEF_HEADER](self, node)
return val
else:
2006-04-08 11:26:31 +05:30
# return values for 'data' row, calling a function
# according to column_defs table
try:
if node != self.prev_handle:
self.prev_data = self.db.get_raw_person_data(str(node))
self.prev_handle = node
2006-04-08 11:26:31 +05:30
return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,
2006-04-08 06:23:44 +05:30
self.prev_data, node)
except:
2006-03-06 05:09:20 +05:30
if col == _MARKER_COL:
return None
else:
return u'error'
2006-04-08 11:26:31 +05:30
def on_iter_next(self, node):
'''returns the next node at this level of the tree'''
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
try:
path = self.top_path2iter.index(node)
if path+1 == len(self.top_path2iter):
return None
return self.top_path2iter[path+1]
except:
2006-04-08 06:23:44 +05:30
(surname, val) = self.iter2path[node]
return self.path2iter.get((surname, val+1))
2006-04-08 06:23:44 +05:30
def on_iter_children(self, node):
"""Return the first child of the node"""
if node == None:
return self.top_path2iter[0]
else:
2006-04-08 06:23:44 +05:30
return self.path2iter.get((node, 0))
2006-04-08 11:26:31 +05:30
def on_iter_has_child(self, node):
'''returns true if this node has children'''
if node == None:
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
return len(self.sname_sub)
if self.sname_sub.has_key(node) and len(self.sname_sub[node]) > 0:
return True
return False
2006-04-08 06:23:44 +05:30
def on_iter_n_children(self, node):
if node == None:
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
return len(self.sname_sub)
try:
return len(self.sname_sub[node])
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
except:
return 0
2006-04-08 06:23:44 +05:30
def on_iter_nth_child(self, node, n):
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
try:
if node == None:
return self.top_path2iter[n]
try:
2006-04-08 06:23:44 +05:30
return self.path2iter[(node, n)]
except:
return None
except IndexError:
return None
2006-04-08 11:26:31 +05:30
def on_iter_parent(self, node):
'''returns the parent of this node'''
path = self.iter2path.get(node)
if path:
return path[0]
return None
2006-04-08 06:23:44 +05:30
def column_sort_name(self, data, node):
n = Name()
n.unserialize(data[_NAME_COL])
2006-03-21 11:53:45 +05:30
return NameDisplay.displayer.sort_string(n)
2006-04-08 06:23:44 +05:30
def column_spouse(self, data, node):
spouses_names = u""
handle = data[0]
for family_handle in data[_FAMILY_COL]:
family = self.db.get_family_from_handle(family_handle)
2006-04-08 11:26:31 +05:30
for spouse_id in [family.get_father_handle(),
2006-04-08 06:23:44 +05:30
family.get_mother_handle()]:
if not spouse_id:
continue
if spouse_id == handle:
continue
spouse = self.db.get_person_from_handle(spouse_id)
if len(spouses_names) > 0:
2006-04-08 11:26:31 +05:30
spouses_names += ", "
2005-01-01 09:57:15 +05:30
spouses_names += NameDisplay.displayer.display(spouse)
return spouses_names
2006-04-08 06:23:44 +05:30
def column_name(self, data, node):
n = Name()
n.unserialize(data[_NAME_COL])
return NameDisplay.displayer.sorted_name(n)
2006-04-08 06:23:44 +05:30
def column_id(self, data, node):
return data[_ID_COL]
2006-04-08 06:23:44 +05:30
def column_change(self, data, node):
2006-04-08 11:26:31 +05:30
return unicode(
time.strftime('%x %X', time.localtime(data[_CHANGE_COL])),
_codeset)
2006-04-08 06:23:44 +05:30
def column_gender(self, data, node):
return _GENDER[data[_GENDER_COL]]
2006-04-08 06:23:44 +05:30
def column_birth_day(self, data, node):
if data[_BIRTH_COL]:
2006-04-08 11:26:31 +05:30
b = EventRef()
b.unserialize(data[_BIRTH_COL])
birth = self.db.get_event_from_handle(b.ref)
date_str = DateHandler.get_date(birth)
if date_str != "":
return cgi.escape(date_str)
for event_ref in data[_EVENT_COL]:
er = EventRef()
er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref)
2005-06-02 10:14:51 +05:30
etype = event.get_type()[0]
date_str = DateHandler.get_date(event)
2006-04-08 11:26:31 +05:30
if (etype in [Event.BAPTISM, Event.CHRISTEN]
and date_str != ""):
return "<i>" + cgi.escape(date_str) + "</i>"
return u""
2006-04-08 06:23:44 +05:30
def column_death_day(self, data, node):
if data[_DEATH_COL]:
dr = EventRef()
dr.unserialize(data[_DEATH_COL])
death = self.db.get_event_from_handle(dr.ref)
date_str = DateHandler.get_date(death)
if date_str != "":
return cgi.escape(date_str)
2005-06-02 10:14:51 +05:30
for event_ref in data[_EVENT_COL]:
er = EventRef()
er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref)
2005-06-02 10:14:51 +05:30
etype = event.get_type()[0]
date_str = DateHandler.get_date(event)
2006-04-08 11:26:31 +05:30
if (etype in [Event.BURIAL, Event.CREMATION]
and date_str != ""):
return "<i>" + cgi.escape(date_str) + "</i>"
return u""
2006-04-08 06:23:44 +05:30
def column_cause_of_death(self, data, node):
if data[_DEATH_COL]:
dr = EventRef()
dr.unserialize(data[_DEATH_COL])
return self.db.get_event_from_handle(dr.ref).get_cause()
else:
return u""
2006-04-08 06:23:44 +05:30
def column_birth_place(self, data, node):
if data[_BIRTH_COL]:
br = EventRef()
br.unserialize(data[_BIRTH_COL])
event = self.db.get_event_from_handle(br.ref)
if event:
2006-04-08 06:23:44 +05:30
place_handle = event.get_place_handle()
if place_handle:
place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "":
return cgi.escape(place_title)
2005-06-02 10:14:51 +05:30
for event_ref in data[_EVENT_COL]:
er = EventRef()
er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref)
2005-06-02 10:14:51 +05:30
etype = event.get_type()[0]
2006-04-08 11:26:31 +05:30
if etype in [Event.BAPTISM, Event.CHRISTEN]:
place_handle = event.get_place_handle()
if place_handle:
2006-04-08 06:23:44 +05:30
place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "":
return "<i>" + cgi.escape(place_title) + "</i>"
return u""
2006-04-08 06:23:44 +05:30
def column_death_place(self, data, node):
if data[_DEATH_COL]:
dr = EventRef()
dr.unserialize(data[_DEATH_COL])
event = self.db.get_event_from_handle(dr.ref)
if event:
2006-04-08 06:23:44 +05:30
place_handle = event.get_place_handle()
if place_handle:
2006-04-08 11:26:31 +05:30
place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "":
return cgi.escape(place_title)
2005-06-02 10:14:51 +05:30
for event_ref in data[_EVENT_COL]:
er = EventRef()
er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref)
2005-06-02 10:14:51 +05:30
etype = event.get_type()[0]
2006-04-08 11:26:31 +05:30
if etype in [Event.BURIAL, Event.CREMATION]:
place_handle = event.get_place_handle()
if place_handle:
2006-04-08 11:26:31 +05:30
place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "":
return "<i>" + cgi.escape(place_title) + "</i>"
return u""
2006-04-08 06:23:44 +05:30
def column_marker_text(self, data, node):
try:
if data[_MARKER_COL]:
if data[_MARKER_COL][0] == PrimaryObject.MARKER_CUSTOM:
return data[_MARKER_COL][1]
elif data[_MARKER_COL][0] in Utils.marker_types.keys():
return Utils.marker_types[data[_MARKER_COL][0]]
except IndexError:
return ""
return ""
2006-04-08 06:23:44 +05:30
def column_marker_color(self, data, node):
try:
if data[_MARKER_COL]:
if data[_MARKER_COL][0] == PrimaryObject.MARKER_COMPLETE:
return u"#46a046" # green
if data[_MARKER_COL][0] == PrimaryObject.MARKER_TODO:
return u"#df421e" # red
if data[_MARKER_COL][0] == PrimaryObject.MARKER_CUSTOM:
return u"#eed680" # blue
except IndexError:
pass
return None
2006-04-08 06:23:44 +05:30
def column_tooltip(self, data, node):
if const.use_tips:
2006-04-08 11:26:31 +05:30
return ToolTips.TipFromFunction(
self.db,
lambda: self.db.get_person_from_handle(data[0])
)
else:
return u''
2006-04-08 06:23:44 +05:30
def column_int_id(self, data, node):
return node
2006-04-08 06:23:44 +05:30
def column_header(self, node):
return node
2006-04-08 06:23:44 +05:30
def column_header_view(self, node):
return True
2006-04-08 11:26:31 +05:30
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
# table of column definitions
2006-04-08 11:26:31 +05:30
# (unless this is declared after the PeopleModel class, an error is thrown)
COLUMN_DEFS = [
2006-04-08 11:26:31 +05:30
(PeopleModel.column_name, PeopleModel.column_header, str),
(PeopleModel.column_id, None, str),
(PeopleModel.column_gender, None, str),
(PeopleModel.column_birth_day, None, str),
(PeopleModel.column_birth_place, None, str),
(PeopleModel.column_death_day, None, str),
(PeopleModel.column_death_place, None, str),
(PeopleModel.column_spouse, None, str),
(PeopleModel.column_change, None, str),
(PeopleModel.column_cause_of_death, None, str),
(PeopleModel.column_marker_text, None, str),
(PeopleModel.column_marker_color, None, str),
# the order of the above columns must match PeopleView.column_names
2006-04-08 11:26:31 +05:30
# these columns are hidden, and must always be last in the list
(PeopleModel.column_tooltip, None, object),
(PeopleModel.column_int_id, None, str),
]
2006-04-08 11:26:31 +05:30
# dynamic calculation of column indices, for use by various Views
COLUMN_INT_ID = 13
# indices into main column definition table
COLUMN_DEF_LIST = 0
COLUMN_DEF_HEADER = 1
COLUMN_DEF_TYPE = 2