2004-03-22 10:11:35 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2004-03-22 10:11:35 +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
|
2006-04-08 11:26:31 +05:30
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
2004-03-22 10:11:35 +05:30
|
|
|
# (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,
|
2004-03-22 10:11:35 +05:30
|
|
|
# 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
|
2004-03-22 10:11:35 +05:30
|
|
|
#
|
|
|
|
|
* src/RelLib.py (Transaction.__len__): Redefine length.
* src/ChooseParents.py, src/EditPerson.py, src/EditSource.py,
src/EventEdit.py, src/FamilyView.py, src/gramps_main.py,
src/ImageSelect.py, src/Marriage.py, src/MediaView.py,
src/PedView.py, src/PeopleModel.py, src/PlaceView.py,
src/SelectChild.py, src/SelectObject.py, src/Sources.py,
src/SourceView.py, src/Utils.py, src/Witness.py,
src/WriteXML.py: Switch from find_* to try_to_find_* methods.
svn: r3193
2004-05-26 08:56:18 +05:30
|
|
|
# $Id$
|
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
"""
|
|
|
|
TreeModel for the GRAMPS Person tree.
|
|
|
|
"""
|
|
|
|
|
2004-04-28 09:36:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2004-08-24 09:18:15 +05:30
|
|
|
import time
|
2005-04-05 20:32:59 +05:30
|
|
|
import cgi
|
2005-12-30 09:27:31 +05:30
|
|
|
import locale
|
2004-04-28 09:36:25 +05:30
|
|
|
|
2006-03-05 10:15:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".")
|
|
|
|
|
2004-04-28 09:36:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-03-08 03:20:41 +05:30
|
|
|
import gtk
|
|
|
|
|
2004-04-28 09:36:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-10 21:38:56 +05:30
|
|
|
import const
|
2008-02-19 01:37:09 +05:30
|
|
|
from gen.lib import Name, EventRef, EventType, EventRoleType, MarkerType
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2005-08-19 19:56:03 +05:30
|
|
|
import ToolTips
|
2005-12-30 09:27:31 +05:30
|
|
|
import GrampsLocale
|
2006-05-17 06:18:46 +05:30
|
|
|
import Config
|
2007-10-09 02:49:32 +05:30
|
|
|
from gen.utils.longop import LongOpStatus
|
2006-12-19 10:17:07 +05:30
|
|
|
from Filters import SearchFilter, ExactSearchFilter
|
2006-10-30 09:39:43 +05:30
|
|
|
from Lru import LRU
|
2004-04-28 09:36:25 +05:30
|
|
|
|
2006-11-29 10:59:25 +05:30
|
|
|
_CACHE_SIZE = 250
|
2008-04-22 07:06:03 +05:30
|
|
|
invalid_date_format = Config.get(Config.INVALID_DATE_FORMAT)
|
2006-11-29 10:59:25 +05:30
|
|
|
|
2007-01-30 10:05:13 +05:30
|
|
|
def locale_sort(mylist):
|
|
|
|
"""
|
|
|
|
Normal sort routine
|
|
|
|
"""
|
|
|
|
l = [ (locale.strxfrm(x),x) for x in mylist ]
|
|
|
|
l.sort()
|
|
|
|
return [ x[1] for x in l ]
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2007-01-30 10:05:13 +05:30
|
|
|
class NodeTreeMap:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.sortnames = {}
|
|
|
|
self.temp_top_path2iter = []
|
|
|
|
|
|
|
|
self.iter2path = {}
|
|
|
|
self.path2iter = {}
|
|
|
|
self.sname_sub = {}
|
|
|
|
|
|
|
|
self.temp_iter2path = {}
|
|
|
|
self.temp_path2iter = {}
|
|
|
|
self.temp_sname_sub = {}
|
|
|
|
|
|
|
|
def clear_sort_names(self):
|
|
|
|
self.sortnames = {}
|
|
|
|
|
|
|
|
def clear_temp_data(self):
|
|
|
|
self.temp_iter2path = {}
|
|
|
|
self.temp_path2iter = {}
|
|
|
|
self.temp_sname_sub = {}
|
|
|
|
|
|
|
|
def build_toplevel(self):
|
|
|
|
self.temp_top_path2iter = locale_sort(self.temp_sname_sub.keys())
|
|
|
|
for name in self.temp_top_path2iter:
|
|
|
|
self.build_sub_entry(name)
|
|
|
|
|
|
|
|
def get_group_names(self):
|
|
|
|
return self.temp_top_path2iter
|
|
|
|
|
|
|
|
def assign_sort_name(self, handle, sorted_name, group_name):
|
|
|
|
self.sortnames[handle] = sorted_name
|
|
|
|
try:
|
|
|
|
self.temp_sname_sub[group_name].append(handle)
|
|
|
|
except:
|
|
|
|
self.temp_sname_sub[group_name] = [handle]
|
|
|
|
|
|
|
|
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
|
|
|
|
self.top_iter2path = {}
|
|
|
|
i = 0
|
|
|
|
for item in self.top_path2iter:
|
|
|
|
self.top_iter2path[item] = i
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
def get_path(self, node):
|
|
|
|
try:
|
|
|
|
return (self.top_iter2path[node], )
|
|
|
|
except:
|
|
|
|
(surname, index) = self.iter2path[node]
|
|
|
|
return (self.top_iter2path[surname], index)
|
|
|
|
|
|
|
|
def has_entry(self, handle):
|
|
|
|
return self.iter2path.has_key(handle)
|
|
|
|
|
|
|
|
def 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]]
|
|
|
|
return self.path2iter[(surname, path[1])]
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def has_top_node(self, node):
|
|
|
|
return self.sname_sub.has_key(node)
|
|
|
|
|
|
|
|
def find_next_node(self, node):
|
|
|
|
try:
|
|
|
|
path = self.top_iter2path[node]
|
|
|
|
if path+1 == len(self.top_path2iter):
|
|
|
|
return None
|
|
|
|
return self.top_path2iter[path+1]
|
|
|
|
except:
|
|
|
|
(surname, val) = self.iter2path[node]
|
|
|
|
return self.path2iter.get((surname, val+1))
|
|
|
|
|
|
|
|
def first_child(self, node):
|
2008-06-16 20:31:46 +05:30
|
|
|
if node is None:
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.top_path2iter[0]
|
|
|
|
else:
|
|
|
|
return self.path2iter.get((node, 0))
|
|
|
|
|
|
|
|
def has_child(self, node):
|
2008-06-16 20:31:46 +05:30
|
|
|
if node is None:
|
2007-01-30 10:05:13 +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
|
|
|
|
|
|
|
|
def number_of_children(self, node):
|
2008-06-16 20:31:46 +05:30
|
|
|
if node is None:
|
2007-01-30 10:05:13 +05:30
|
|
|
return len(self.sname_sub)
|
|
|
|
try:
|
|
|
|
return len(self.sname_sub[node])
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_nth_child(self, node, n):
|
|
|
|
try:
|
2008-06-16 20:31:46 +05:30
|
|
|
if node is None:
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.top_path2iter[n]
|
|
|
|
try:
|
|
|
|
return self.path2iter[(node, n)]
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
except IndexError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_parent_of(self, node):
|
|
|
|
path = self.iter2path.get(node)
|
|
|
|
if path:
|
|
|
|
return path[0]
|
|
|
|
return None
|
|
|
|
|
|
|
|
def build_sub_entry(self, name):
|
|
|
|
slist = [ (locale.strxfrm(self.sortnames[x]), x) \
|
|
|
|
for x in self.temp_sname_sub[name] ]
|
|
|
|
slist.sort()
|
|
|
|
|
|
|
|
val = 0
|
|
|
|
for (junk, person_handle) in slist:
|
|
|
|
tpl = (name, val)
|
|
|
|
self.temp_iter2path[person_handle] = tpl
|
|
|
|
self.temp_path2iter[tpl] = person_handle
|
|
|
|
val += 1
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2004-04-28 09:36:25 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PeopleModel
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-03-08 03:20:41 +05:30
|
|
|
class PeopleModel(gtk.GenericTreeModel):
|
2006-04-08 11:26:31 +05:30
|
|
|
"""
|
|
|
|
Basic GenericTreeModel interface to handle the Tree interface for
|
|
|
|
the PersonView
|
|
|
|
"""
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
# Model types
|
|
|
|
GENERIC = 0
|
|
|
|
SEARCH = 1
|
|
|
|
FAST = 2
|
|
|
|
|
|
|
|
# Column numbers
|
|
|
|
_ID_COL = 1
|
|
|
|
_GENDER_COL = 2
|
|
|
|
_NAME_COL = 3
|
|
|
|
_DEATH_COL = 5
|
|
|
|
_BIRTH_COL = 6
|
|
|
|
_EVENT_COL = 7
|
|
|
|
_FAMILY_COL = 8
|
|
|
|
_CHANGE_COL = 17
|
|
|
|
_MARKER_COL = 18
|
|
|
|
|
|
|
|
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
|
|
|
|
|
|
|
|
# dynamic calculation of column indices, for use by various Views
|
2006-08-22 08:49:37 +05:30
|
|
|
COLUMN_INT_ID = 12
|
2006-05-17 06:18:46 +05:30
|
|
|
|
|
|
|
# indices into main column definition table
|
|
|
|
COLUMN_DEF_LIST = 0
|
|
|
|
COLUMN_DEF_HEADER = 1
|
|
|
|
COLUMN_DEF_TYPE = 2
|
|
|
|
|
2006-05-16 00:19:35 +05:30
|
|
|
def __init__(self, db, filter_info=None, skip=[]):
|
2006-04-08 11:26:31 +05:30
|
|
|
"""
|
|
|
|
Initialize the model building the initial data
|
|
|
|
"""
|
2004-03-08 03:20:41 +05:30
|
|
|
gtk.GenericTreeModel.__init__(self)
|
2004-03-22 10:11:35 +05:30
|
|
|
|
2004-03-08 03:20:41 +05:30
|
|
|
self.db = db
|
2007-10-28 15:54:15 +05:30
|
|
|
self.in_build = False
|
2006-02-04 04:01:46 +05:30
|
|
|
|
2006-05-12 23:50:18 +05:30
|
|
|
Config.client.notify_add("/apps/gramps/preferences/todo-color",
|
|
|
|
self.update_todo)
|
|
|
|
Config.client.notify_add("/apps/gramps/preferences/custom-marker-color",
|
|
|
|
self.update_custom)
|
|
|
|
Config.client.notify_add("/apps/gramps/preferences/complete-color",
|
|
|
|
self.update_complete)
|
|
|
|
|
|
|
|
self.complete_color = Config.get(Config.COMPLETE_COLOR)
|
|
|
|
self.todo_color = Config.get(Config.TODO_COLOR)
|
|
|
|
self.custom_color = Config.get(Config.CUSTOM_MARKER_COLOR)
|
|
|
|
|
2006-08-21 12:02:31 +05:30
|
|
|
self.marker_color_column = 10
|
|
|
|
self.tooltip_column = 11
|
2007-01-30 10:05:13 +05:30
|
|
|
|
|
|
|
self.mapper = NodeTreeMap()
|
2007-01-21 10:47:06 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
self.total = 0
|
|
|
|
self.displayed = 0
|
|
|
|
|
2007-01-17 06:01:06 +05:30
|
|
|
if filter_info and filter_info != (1, (0, u'', False)):
|
2006-05-17 06:18:46 +05:30
|
|
|
if filter_info[0] == PeopleModel.GENERIC:
|
2006-05-16 00:19:35 +05:30
|
|
|
data_filter = filter_info[1]
|
|
|
|
self._build_data = self._build_filter_sub
|
2006-05-17 06:18:46 +05:30
|
|
|
elif filter_info[0] == PeopleModel.SEARCH:
|
2006-05-16 00:19:35 +05:30
|
|
|
col = filter_info[1][0]
|
|
|
|
text = filter_info[1][1]
|
|
|
|
inv = filter_info[1][2]
|
|
|
|
func = lambda x: self.on_get_value(x, col) or u""
|
2006-12-19 10:17:07 +05:30
|
|
|
|
|
|
|
if col == self._GENDER_COL:
|
|
|
|
data_filter = ExactSearchFilter(func, text, inv)
|
|
|
|
else:
|
|
|
|
data_filter = SearchFilter(func, text, inv)
|
|
|
|
|
2006-05-16 00:19:35 +05:30
|
|
|
self._build_data = self._build_search_sub
|
|
|
|
else:
|
|
|
|
data_filter = filter_info[1]
|
|
|
|
self._build_data = self._build_search_sub
|
2006-05-12 10:21:44 +05:30
|
|
|
else:
|
2006-05-16 00:19:35 +05:30
|
|
|
self._build_data = self._build_search_sub
|
|
|
|
data_filter = None
|
2007-01-21 10:47:06 +05:30
|
|
|
self.current_filter = data_filter
|
2006-04-08 06:23:44 +05:30
|
|
|
self.rebuild_data(data_filter, skip)
|
2006-01-20 11:03:38 +05:30
|
|
|
|
2006-05-12 23:50:18 +05:30
|
|
|
def update_todo(self,client,cnxn_id,entry,data):
|
|
|
|
self.todo_color = Config.get(Config.TODO_COLOR)
|
|
|
|
|
|
|
|
def update_custom(self,client,cnxn_id,entry,data):
|
|
|
|
self.custom_color = Config.get(Config.CUSTOM_MARKER_COLOR)
|
|
|
|
|
|
|
|
def update_complete(self,client,cnxn_id,entry,data):
|
|
|
|
self.complete_color = Config.get(Config.COMPLETE_COLOR)
|
|
|
|
|
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)
|
2005-03-31 10:00:44 +05:30
|
|
|
self.assign_data()
|
2007-01-21 10:47:06 +05:30
|
|
|
self.current_filter = data_filter
|
2005-03-31 10:00:44 +05:30
|
|
|
|
2006-05-12 10:21:44 +05:30
|
|
|
def _build_search_sub(self,dfilter, skip):
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2007-06-28 11:11:40 +05:30
|
|
|
ngn = name_displayer.name_grouping_data
|
|
|
|
nsn = name_displayer.raw_sorted_name
|
2006-01-21 03:13:40 +05:30
|
|
|
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.clear_sort_names()
|
|
|
|
|
2007-03-27 03:46:10 +05:30
|
|
|
cursor = self.db.get_person_cursor()
|
|
|
|
node = cursor.first()
|
2006-05-10 09:32:45 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
self.total = 0
|
|
|
|
self.displayed = 0
|
|
|
|
|
2007-03-27 03:46:10 +05:30
|
|
|
while node:
|
2007-04-02 04:07:10 +05:30
|
|
|
self.total += 1
|
2006-04-08 06:23:44 +05:30
|
|
|
handle, d = node
|
2008-01-01 03:52:12 +05:30
|
|
|
if not (handle in skip or (dfilter and not dfilter.match(handle,self.db))):
|
2006-05-17 06:18:46 +05:30
|
|
|
name_data = d[PeopleModel._NAME_COL]
|
2007-01-30 10:05:13 +05:30
|
|
|
|
|
|
|
group_name = ngn(self.db, name_data)
|
|
|
|
sorted_name = nsn(name_data)
|
2007-04-02 04:07:10 +05:30
|
|
|
self.displayed += 1
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.assign_sort_name(handle, sorted_name, group_name)
|
2007-03-27 03:46:10 +05:30
|
|
|
node = cursor.next()
|
|
|
|
cursor.close()
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-05-12 10:21:44 +05:30
|
|
|
def _build_filter_sub(self,dfilter, skip):
|
|
|
|
|
2007-06-28 11:11:40 +05:30
|
|
|
ngn = name_displayer.name_grouping_data
|
|
|
|
nsn = name_displayer.raw_sorted_name
|
2006-05-12 10:21:44 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
plist = self.db.get_person_handles()
|
|
|
|
|
|
|
|
self.total = len(plist)
|
|
|
|
|
2006-05-16 00:19:35 +05:30
|
|
|
if dfilter:
|
|
|
|
handle_list = dfilter.apply(self.db, self.db.get_person_handles())
|
|
|
|
else:
|
|
|
|
handle_list = self.db.get_person_handles()
|
2006-05-12 10:21:44 +05:30
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
self.displayed = len(handle_list)
|
|
|
|
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.clear_sort_names()
|
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
status = LongOpStatus(msg="Loading People",
|
|
|
|
total_steps=len(handle_list),
|
|
|
|
interval=len(handle_list)/10)
|
|
|
|
self.db.emit('long-op-start', (status,))
|
|
|
|
|
2006-05-12 10:21:44 +05:30
|
|
|
for handle in handle_list:
|
2007-02-18 01:29:21 +05:30
|
|
|
status.heartbeat()
|
2006-05-12 10:21:44 +05:30
|
|
|
d = self.db.get_raw_person_data(handle)
|
2008-01-03 10:04:18 +05:30
|
|
|
if not handle in skip:
|
2006-05-17 06:18:46 +05:30
|
|
|
name_data = d[PeopleModel._NAME_COL]
|
2007-01-30 10:05:13 +05:30
|
|
|
|
|
|
|
group_name = ngn(self.db, name_data)
|
|
|
|
sorted_name = nsn(name_data)
|
|
|
|
|
|
|
|
self.mapper.assign_sort_name(handle, sorted_name, group_name)
|
2006-05-12 10:21:44 +05:30
|
|
|
|
2007-02-18 01:29:21 +05:30
|
|
|
status.end()
|
|
|
|
|
2006-05-12 10:21:44 +05:30
|
|
|
def calculate_data(self, dfilter=None, skip=[]):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Calculate the new path to node values for the model.
|
2006-05-12 10:21:44 +05:30
|
|
|
"""
|
2007-10-28 15:54:15 +05:30
|
|
|
self.in_build = True
|
2006-11-29 10:59:25 +05:30
|
|
|
self.lru_data = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_name = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_bdate = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_ddate = LRU(_CACHE_SIZE)
|
|
|
|
|
2007-04-02 04:07:10 +05:30
|
|
|
self.total = 0
|
|
|
|
self.displayed = 0
|
|
|
|
|
2006-05-12 10:21:44 +05:30
|
|
|
if dfilter:
|
|
|
|
self.dfilter = dfilter
|
2007-01-30 10:05:13 +05:30
|
|
|
|
|
|
|
self.mapper.clear_temp_data()
|
2006-05-12 10:21:44 +05:30
|
|
|
|
|
|
|
if not self.db.is_open():
|
|
|
|
return
|
|
|
|
|
|
|
|
self._build_data(dfilter, skip)
|
|
|
|
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.build_toplevel()
|
|
|
|
|
2007-10-28 15:54:15 +05:30
|
|
|
self.in_build = False
|
2006-02-09 10:40:20 +05:30
|
|
|
|
|
|
|
def clear_cache(self):
|
2006-11-29 10:59:25 +05:30
|
|
|
self.lru_data = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_name = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_bdate = LRU(_CACHE_SIZE)
|
|
|
|
self.lru_ddate = LRU(_CACHE_SIZE)
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def build_sub_entry(self, name):
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.build_sub_entry(name)
|
2004-12-10 05:08:43 +05:30
|
|
|
|
2005-03-31 10:00:44 +05:30
|
|
|
def assign_data(self):
|
2007-01-30 10:05:13 +05:30
|
|
|
self.mapper.assign_data()
|
2004-12-10 05:08:43 +05:30
|
|
|
|
2004-03-08 03:20:41 +05:30
|
|
|
def on_get_flags(self):
|
2008-02-18 21:22:40 +05:30
|
|
|
"""returns the GtkTreeModelFlags for this particular type of model"""
|
2005-04-05 20:32:59 +05:30
|
|
|
return gtk.TREE_MODEL_ITERS_PERSIST
|
2004-03-08 03:20:41 +05:30
|
|
|
|
|
|
|
def on_get_n_columns(self):
|
2006-05-17 06:18:46 +05:30
|
|
|
return len(PeopleModel.COLUMN_DEFS)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
def on_get_path(self, node):
|
2008-02-18 21:22:40 +05:30
|
|
|
"""returns the tree path (a tuple of indices at the various
|
|
|
|
levels) for a particular node."""
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.get_path(node)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def is_visable(self, handle):
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.has_entry(handle)
|
2005-03-31 10:00:44 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def on_get_column_type(self, index):
|
2006-05-17 06:18:46 +05:30
|
|
|
return PeopleModel.COLUMN_DEFS[index][PeopleModel.COLUMN_DEF_TYPE]
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
def on_get_iter(self, path):
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.get_iter(path)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def on_get_value(self, node, col):
|
2004-08-26 09:33:11 +05:30
|
|
|
# test for header or data row-type
|
2007-01-30 10:05:13 +05:30
|
|
|
if self.mapper.has_top_node(node):
|
2006-05-13 10:15:46 +05:30
|
|
|
# Header rows dont get the foreground color set
|
2006-04-08 11:26:31 +05:30
|
|
|
if col == self.marker_color_column:
|
2005-09-16 20:55:27 +05:30
|
|
|
return None
|
2004-08-26 09:33:11 +05:30
|
|
|
# test for 'header' column being empty (most are)
|
2006-05-17 06:18:46 +05:30
|
|
|
if not PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_HEADER]:
|
2004-08-26 09:33:11 +05:30
|
|
|
return u''
|
2006-04-08 11:26:31 +05:30
|
|
|
# return values for 'header' row, calling a function
|
2004-08-26 09:33:11 +05:30
|
|
|
# according to column_defs table
|
2006-05-17 06:18:46 +05:30
|
|
|
val = PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_HEADER](self, node)
|
2004-08-26 09:33:11 +05:30
|
|
|
return val
|
2004-03-08 03:20:41 +05:30
|
|
|
else:
|
2006-04-08 11:26:31 +05:30
|
|
|
# return values for 'data' row, calling a function
|
2004-08-26 09:33:11 +05:30
|
|
|
# according to column_defs table
|
2004-08-25 09:07:48 +05:30
|
|
|
try:
|
2006-11-29 10:59:25 +05:30
|
|
|
try:
|
|
|
|
data = self.lru_data[node]
|
|
|
|
except:
|
|
|
|
data = self.db.get_raw_person_data(str(node))
|
2007-10-28 15:54:15 +05:30
|
|
|
if not self.in_build:
|
|
|
|
self.lru_data[node] = data
|
|
|
|
return PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_LIST](self, data, node)
|
2004-08-25 09:07:48 +05:30
|
|
|
except:
|
2006-04-20 08:40:23 +05:30
|
|
|
return None
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
def on_iter_next(self, node):
|
2008-02-18 21:22:40 +05:30
|
|
|
"""returns the next node at this level of the tree"""
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.find_next_node(node)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def on_iter_children(self, node):
|
2004-03-22 10:11:35 +05:30
|
|
|
"""Return the first child of the node"""
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.first_child(node)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
def on_iter_has_child(self, node):
|
2008-02-18 21:22:40 +05:30
|
|
|
"""returns true if this node has children"""
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.has_child(node)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def on_iter_n_children(self, node):
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.number_of_children(node)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def on_iter_nth_child(self, node, n):
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.get_nth_child(node, n)
|
2004-03-08 03:20:41 +05:30
|
|
|
|
2006-04-08 11:26:31 +05:30
|
|
|
def on_iter_parent(self, node):
|
2008-02-18 21:22:40 +05:30
|
|
|
"""returns the parent of this node"""
|
2007-01-30 10:05:13 +05:30
|
|
|
return self.mapper.get_parent_of(node)
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_sort_name(self, data, node):
|
2006-02-04 03:33:53 +05:30
|
|
|
n = Name()
|
2006-05-17 06:18:46 +05:30
|
|
|
n.unserialize(data[PeopleModel._NAME_COL])
|
2007-06-28 11:11:40 +05:30
|
|
|
return name_displayer.sort_string(n)
|
2004-03-23 10:31:19 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_spouse(self, data, node):
|
2005-04-05 20:32:59 +05:30
|
|
|
spouses_names = u""
|
2004-08-24 09:44:08 +05:30
|
|
|
handle = data[0]
|
2006-05-17 06:18:46 +05:30
|
|
|
for family_handle in data[PeopleModel._FAMILY_COL]:
|
2004-08-24 09:44:08 +05:30
|
|
|
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()]:
|
2004-08-24 09:44:08 +05:30
|
|
|
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 += ", "
|
2007-06-28 11:11:40 +05:30
|
|
|
spouses_names += name_displayer.display(spouse)
|
2005-04-05 20:32:59 +05:30
|
|
|
return spouses_names
|
2004-06-03 08:58:46 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_name(self, data, node):
|
2007-10-28 15:54:15 +05:30
|
|
|
try:
|
|
|
|
name = self.lru_name[node]
|
|
|
|
except:
|
|
|
|
name = name_displayer.raw_sorted_name(data[PeopleModel._NAME_COL])
|
|
|
|
if not self.in_build:
|
|
|
|
self.lru_name[node] = name
|
2006-10-30 07:07:43 +05:30
|
|
|
return name
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_id(self, data, node):
|
2006-05-17 06:18:46 +05:30
|
|
|
return data[PeopleModel._ID_COL]
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_change(self, data, node):
|
2006-04-08 11:26:31 +05:30
|
|
|
return unicode(
|
2006-05-17 06:18:46 +05:30
|
|
|
time.strftime('%x %X',
|
|
|
|
time.localtime(data[PeopleModel._CHANGE_COL])),
|
|
|
|
GrampsLocale.codeset)
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_gender(self, data, node):
|
2006-05-17 06:18:46 +05:30
|
|
|
return PeopleModel._GENDER[data[PeopleModel._GENDER_COL]]
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_birth_day(self, data, node):
|
2007-10-28 15:54:15 +05:30
|
|
|
try:
|
|
|
|
value = self.lru_bdate[node]
|
|
|
|
except:
|
2008-02-24 19:25:55 +05:30
|
|
|
value = self._get_birth_data(data, node)
|
2007-10-28 15:54:15 +05:30
|
|
|
if not self.in_build:
|
|
|
|
self.lru_bdate[node] = value
|
2006-11-29 10:59:25 +05:30
|
|
|
return value
|
|
|
|
|
|
|
|
def _get_birth_data(self, data, node):
|
2006-05-24 02:37:26 +05:30
|
|
|
index = data[PeopleModel._BIRTH_COL]
|
|
|
|
if index != -1:
|
|
|
|
try:
|
|
|
|
local = data[PeopleModel._EVENT_COL][index]
|
|
|
|
b = EventRef()
|
|
|
|
b.unserialize(local)
|
|
|
|
birth = self.db.get_event_from_handle(b.ref)
|
|
|
|
date_str = DateHandler.get_date(birth)
|
|
|
|
if date_str != "":
|
2008-04-20 04:11:48 +05:30
|
|
|
retval = cgi.escape(date_str)
|
|
|
|
if not DateHandler.get_date_valid(birth):
|
2008-04-22 07:06:03 +05:30
|
|
|
return invalid_date_format % retval
|
2008-04-20 04:11:48 +05:30
|
|
|
else:
|
|
|
|
return retval
|
2006-05-24 02:37:26 +05:30
|
|
|
except:
|
|
|
|
return u''
|
2005-04-05 20:32:59 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
for event_ref in data[PeopleModel._EVENT_COL]:
|
2006-02-04 03:33:53 +05:30
|
|
|
er = EventRef()
|
|
|
|
er.unserialize(event_ref)
|
|
|
|
event = self.db.get_event_from_handle(er.ref)
|
2006-12-11 00:18:29 +05:30
|
|
|
etype = event.get_type()
|
2005-08-06 08:27:37 +05:30
|
|
|
date_str = DateHandler.get_date(event)
|
2006-04-20 08:40:23 +05:30
|
|
|
if (etype in [EventType.BAPTISM, EventType.CHRISTEN]
|
2006-12-11 00:18:29 +05:30
|
|
|
and er.get_role() == EventRoleType.PRIMARY
|
2005-08-06 08:27:37 +05:30
|
|
|
and date_str != ""):
|
2008-04-20 04:11:48 +05:30
|
|
|
retval = u"<i>%s</i>" % cgi.escape(date_str)
|
|
|
|
if not DateHandler.get_date_valid(event):
|
2008-04-22 07:06:03 +05:30
|
|
|
return invalid_date_format % retval
|
2008-04-20 04:11:48 +05:30
|
|
|
else:
|
|
|
|
return retval
|
2005-04-05 20:32:59 +05:30
|
|
|
|
|
|
|
return u""
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_death_day(self, data, node):
|
2007-10-28 15:54:15 +05:30
|
|
|
try:
|
|
|
|
value = self.lru_ddate[node]
|
|
|
|
except:
|
2008-02-24 19:25:55 +05:30
|
|
|
value = self._get_death_data(data, node)
|
2007-10-28 15:54:15 +05:30
|
|
|
if not self.in_build:
|
|
|
|
self.lru_ddate[node] = value
|
2006-11-29 10:59:25 +05:30
|
|
|
return value
|
|
|
|
|
|
|
|
def _get_death_data(self, data, node):
|
2006-05-24 02:37:26 +05:30
|
|
|
index = data[PeopleModel._DEATH_COL]
|
|
|
|
if index != -1:
|
|
|
|
try:
|
|
|
|
local = data[PeopleModel._EVENT_COL][index]
|
|
|
|
ref = EventRef()
|
|
|
|
ref.unserialize(local)
|
|
|
|
event = self.db.get_event_from_handle(ref.ref)
|
|
|
|
date_str = DateHandler.get_date(event)
|
|
|
|
if date_str != "":
|
2008-04-20 04:11:48 +05:30
|
|
|
retval = cgi.escape(date_str)
|
|
|
|
if not DateHandler.get_date_valid(event):
|
2008-04-22 07:06:03 +05:30
|
|
|
return invalid_date_format % retval
|
2008-04-20 04:11:48 +05:30
|
|
|
else:
|
|
|
|
return retval
|
2006-05-24 02:37:26 +05:30
|
|
|
except:
|
|
|
|
return u''
|
2005-04-05 20:32:59 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
for event_ref in data[PeopleModel._EVENT_COL]:
|
2006-02-04 03:33:53 +05:30
|
|
|
er = EventRef()
|
|
|
|
er.unserialize(event_ref)
|
|
|
|
event = self.db.get_event_from_handle(er.ref)
|
2006-11-07 17:35:40 +05:30
|
|
|
etype = event.get_type()
|
2005-08-06 08:27:37 +05:30
|
|
|
date_str = DateHandler.get_date(event)
|
2006-04-20 08:40:23 +05:30
|
|
|
if (etype in [EventType.BURIAL, EventType.CREMATION]
|
2006-11-23 04:00:47 +05:30
|
|
|
and er.get_role() == EventRoleType.PRIMARY
|
2007-01-30 10:05:13 +05:30
|
|
|
and date_str):
|
2008-04-20 04:11:48 +05:30
|
|
|
retval = "<i>%s</i>" % cgi.escape(date_str)
|
|
|
|
if not DateHandler.get_date_valid(event):
|
2008-04-22 07:06:03 +05:30
|
|
|
return invalid_date_format % retval
|
2008-04-20 04:11:48 +05:30
|
|
|
else:
|
|
|
|
return retval
|
2005-04-05 20:32:59 +05:30
|
|
|
return u""
|
2005-03-20 05:14:01 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_birth_place(self, data, node):
|
2006-05-24 02:37:26 +05:30
|
|
|
index = data[PeopleModel._BIRTH_COL]
|
|
|
|
if index != -1:
|
|
|
|
try:
|
|
|
|
local = data[PeopleModel._EVENT_COL][index]
|
|
|
|
br = EventRef()
|
|
|
|
br.unserialize(local)
|
|
|
|
event = self.db.get_event_from_handle(br.ref)
|
|
|
|
if event:
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
place_title = place.get_title()
|
2007-01-30 10:05:13 +05:30
|
|
|
if place_title:
|
2006-05-24 02:37:26 +05:30
|
|
|
return cgi.escape(place_title)
|
|
|
|
except:
|
|
|
|
return u''
|
2005-04-05 20:32:59 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
for event_ref in data[PeopleModel._EVENT_COL]:
|
2006-02-04 03:33:53 +05:30
|
|
|
er = EventRef()
|
|
|
|
er.unserialize(event_ref)
|
|
|
|
event = self.db.get_event_from_handle(er.ref)
|
2006-11-07 17:35:40 +05:30
|
|
|
etype = event.get_type()
|
2006-11-10 21:53:11 +05:30
|
|
|
if etype in [EventType.BAPTISM, EventType.CHRISTEN]\
|
2006-11-23 04:00:47 +05:30
|
|
|
and er.get_role() == EventRoleType.PRIMARY:
|
2004-07-28 07:59:07 +05:30
|
|
|
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()
|
2007-01-30 10:05:13 +05:30
|
|
|
if place_title:
|
|
|
|
return "<i>%s</i>" % cgi.escape(place_title)
|
2005-04-05 20:32:59 +05:30
|
|
|
|
2004-03-10 10:45:06 +05:30
|
|
|
return u""
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_death_place(self, data, node):
|
2006-05-24 02:37:26 +05:30
|
|
|
index = data[PeopleModel._DEATH_COL]
|
|
|
|
if index != -1:
|
|
|
|
try:
|
|
|
|
local = data[PeopleModel._EVENT_COL][index]
|
|
|
|
dr = EventRef()
|
|
|
|
dr.unserialize(local)
|
|
|
|
event = self.db.get_event_from_handle(dr.ref)
|
|
|
|
if event:
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
place_title = place.get_title()
|
2007-01-30 10:05:13 +05:30
|
|
|
if place_title:
|
2006-05-24 02:37:26 +05:30
|
|
|
return cgi.escape(place_title)
|
|
|
|
except:
|
|
|
|
return u''
|
2005-04-05 20:32:59 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
for event_ref in data[PeopleModel._EVENT_COL]:
|
2006-02-04 03:33:53 +05:30
|
|
|
er = EventRef()
|
|
|
|
er.unserialize(event_ref)
|
|
|
|
event = self.db.get_event_from_handle(er.ref)
|
2006-11-07 17:35:40 +05:30
|
|
|
etype = event.get_type()
|
2006-11-10 21:53:11 +05:30
|
|
|
if etype in [EventType.BURIAL, EventType.CREMATION]\
|
2006-11-23 04:00:47 +05:30
|
|
|
and er.get_role() == EventRoleType.PRIMARY:
|
2004-07-28 07:59:07 +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()
|
2005-04-05 20:32:59 +05:30
|
|
|
if place_title != "":
|
|
|
|
return "<i>" + cgi.escape(place_title) + "</i>"
|
|
|
|
|
2004-03-10 10:45:06 +05:30
|
|
|
return u""
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_marker_text(self, data, node):
|
2005-09-16 20:55:27 +05:30
|
|
|
try:
|
2006-05-17 06:18:46 +05:30
|
|
|
if data[PeopleModel._MARKER_COL]:
|
|
|
|
return str(data[PeopleModel._MARKER_COL])
|
2005-09-16 20:55:27 +05:30
|
|
|
except IndexError:
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_marker_color(self, data, node):
|
2005-09-16 20:55:27 +05:30
|
|
|
try:
|
2006-05-17 06:18:46 +05:30
|
|
|
if data[PeopleModel._MARKER_COL]:
|
|
|
|
if data[PeopleModel._MARKER_COL][0] == MarkerType.COMPLETE:
|
2006-05-12 23:50:18 +05:30
|
|
|
return self.complete_color
|
2007-01-17 16:27:37 +05:30
|
|
|
if data[PeopleModel._MARKER_COL][0] == MarkerType.TODO_TYPE:
|
2006-05-12 23:50:18 +05:30
|
|
|
return self.todo_color
|
2006-05-17 06:18:46 +05:30
|
|
|
if data[PeopleModel._MARKER_COL][0] == MarkerType.CUSTOM:
|
2006-05-12 23:50:18 +05:30
|
|
|
return self.custom_color
|
2005-09-16 20:55:27 +05:30
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
return None
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_tooltip(self, data, node):
|
2007-09-08 11:24:02 +05:30
|
|
|
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])
|
|
|
|
)
|
2006-03-10 00:37:13 +05:30
|
|
|
else:
|
|
|
|
return u''
|
2005-08-19 19:56:03 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_int_id(self, data, node):
|
2004-08-26 09:33:11 +05:30
|
|
|
return node
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_header(self, node):
|
2004-08-26 09:33:11 +05:30
|
|
|
return node
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def column_header_view(self, node):
|
2004-12-10 05:08:43 +05:30
|
|
|
return True
|
2004-08-26 09:33:11 +05:30
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
# table of column definitions
|
|
|
|
# (unless this is declared after the PeopleModel class, an error is thrown)
|
|
|
|
|
|
|
|
COLUMN_DEFS = [
|
|
|
|
(column_name, column_header, str),
|
|
|
|
(column_id, None, str),
|
|
|
|
(column_gender, None, str),
|
|
|
|
(column_birth_day, None, str),
|
|
|
|
(column_birth_place, None, str),
|
|
|
|
(column_death_day, None, str),
|
|
|
|
(column_death_place, None, str),
|
|
|
|
(column_spouse, None, str),
|
|
|
|
(column_change, None, str),
|
|
|
|
(column_marker_text, None, str),
|
|
|
|
(column_marker_color, None, str),
|
|
|
|
# the order of the above columns must match PeopleView.column_names
|
|
|
|
|
|
|
|
# these columns are hidden, and must always be last in the list
|
|
|
|
(column_tooltip, None, object),
|
|
|
|
(column_int_id, None, str),
|
|
|
|
]
|