2009-11-17 05:43:03 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Nick Hall
|
2010-01-09 16:40:32 +05:30
|
|
|
# Copyright (C) 2009 Benny Malengier
|
2009-11-17 05:43: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
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
Place tree model.
|
|
|
|
"""
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-11 01:41:18 +05:30
|
|
|
import cgi
|
2009-11-17 05:43:03 +05:30
|
|
|
import logging
|
|
|
|
_LOG = logging.getLogger(".gui.views.treemodels.placetreemodel")
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gui.views.treemodels.placebasemodel import PlaceBaseModel
|
|
|
|
from gui.views.treemodels.treebasemodel import TreeBaseModel
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Internationalization
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
2010-01-11 01:41:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-13 03:20:37 +05:30
|
|
|
|
2010-01-11 01:41:18 +05:30
|
|
|
COUNTRYLEVELS = {
|
|
|
|
'default': [_('<Countries>'), _('<States>'), _('<Counties>'),
|
|
|
|
_('<Places>')]
|
|
|
|
}
|
|
|
|
|
2009-11-17 05:43:03 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PlaceTreeModel
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PlaceTreeModel(PlaceBaseModel, TreeBaseModel):
|
|
|
|
"""
|
|
|
|
Hierarchical place model.
|
|
|
|
"""
|
|
|
|
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None,
|
|
|
|
skip=set(), sort_map=None):
|
|
|
|
|
|
|
|
PlaceBaseModel.__init__(self, db)
|
|
|
|
TreeBaseModel.__init__(self, db, scol=scol, order=order,
|
|
|
|
tooltip_column=13,
|
|
|
|
search=search, skip=skip, sort_map=sort_map,
|
|
|
|
nrgroups = 3,
|
|
|
|
group_can_have_handle = True)
|
|
|
|
|
2010-01-09 16:40:32 +05:30
|
|
|
def _set_base_data(self):
|
|
|
|
"""See TreeBaseModel, for place, most have been set in init of
|
|
|
|
PlaceBaseModel
|
|
|
|
"""
|
|
|
|
self.number_items = self.db.get_number_of_places
|
|
|
|
self.hmap = [self.column_header] + [None]*12
|
|
|
|
|
2009-12-17 04:26:55 +05:30
|
|
|
def get_tree_levels(self):
|
|
|
|
"""
|
|
|
|
Return the headings of the levels in the hierarchy.
|
|
|
|
"""
|
|
|
|
return ['Country', 'State', 'County', 'Place Name']
|
|
|
|
|
2009-11-17 05:43:03 +05:30
|
|
|
def add_row(self, handle, data):
|
|
|
|
"""
|
|
|
|
Add nodes to the node map for a single place.
|
|
|
|
|
|
|
|
handle The handle of the gramps object.
|
|
|
|
data The object data.
|
|
|
|
"""
|
2009-12-27 01:12:22 +05:30
|
|
|
if data[5] is None:
|
|
|
|
# No primary location
|
|
|
|
level = [''] * 5
|
|
|
|
else:
|
2010-01-11 01:41:18 +05:30
|
|
|
#country, state, county, city, street
|
2009-12-27 01:12:22 +05:30
|
|
|
level = [data[5][0][i] for i in range(4,-1,-1)]
|
2009-11-17 15:58:13 +05:30
|
|
|
|
2009-12-27 01:12:22 +05:30
|
|
|
node1 = (level[0], )
|
|
|
|
node2 = (level[1], level[0])
|
|
|
|
node3 = (level[2], level[1], level[0])
|
2009-11-17 05:43:03 +05:30
|
|
|
sort_key = self.sort_func(data)
|
|
|
|
|
2009-12-27 01:12:22 +05:30
|
|
|
if not (level[3] or level[4]):
|
|
|
|
if level[2]:
|
|
|
|
self.add_node(None, node1, level[0], None, add_parent=False)
|
|
|
|
self.add_node(node1, node2, level[1], None, add_parent=False)
|
2010-01-11 01:41:18 +05:30
|
|
|
self.add_node(node2, node3, level[2], None, add_parent=False)
|
2010-01-12 14:07:17 +05:30
|
|
|
self.add_node(node3, handle, sort_key, handle, add_parent=False)
|
2009-12-27 01:12:22 +05:30
|
|
|
elif level[1]:
|
|
|
|
self.add_node(None, node1, level[0], None, add_parent=False)
|
2010-01-11 01:41:18 +05:30
|
|
|
self.add_node(node1, node2, level[1], None, add_parent=False)
|
|
|
|
self.add_node(node2, handle, level[1], handle, add_parent=False)
|
2009-12-27 01:12:22 +05:30
|
|
|
elif level[0]:
|
2010-01-11 01:41:18 +05:30
|
|
|
self.add_node(None, node1, level[0], None, add_parent=False)
|
|
|
|
self.add_node(node1, handle, level[0], handle, add_parent=False)
|
2009-12-27 01:12:22 +05:30
|
|
|
else:
|
2010-01-12 14:07:17 +05:30
|
|
|
self.add_node(None, node1, level[0], None, add_parent=False)
|
|
|
|
self.add_node(node1, node2, level[1], None, add_parent=False)
|
|
|
|
self.add_node(node2, node3, level[2], None, add_parent=False)
|
|
|
|
self.add_node(node3, handle, sort_key, handle, add_parent=False)
|
2009-12-27 01:12:22 +05:30
|
|
|
|
|
|
|
else:
|
|
|
|
self.add_node(None, node1, level[0], None, add_parent=False)
|
|
|
|
self.add_node(node1, node2, level[1], None, add_parent=False)
|
|
|
|
self.add_node(node2, node3, level[2], None, add_parent=False)
|
|
|
|
self.add_node(node3, handle, sort_key, handle, add_parent=False)
|
|
|
|
|
|
|
|
def column_name(self, data):
|
2010-01-11 01:41:18 +05:30
|
|
|
if data[2]:
|
|
|
|
return unicode(data[2])
|
|
|
|
elif data[5] is not None:
|
2009-12-27 01:12:22 +05:30
|
|
|
level = [data[5][0][i] for i in range(4,-1,-1)]
|
|
|
|
if not (level[3] or level[4]):
|
|
|
|
return unicode(level[2] or level[1] or level[0])
|
|
|
|
elif level[3] and level[4]:
|
|
|
|
return unicode(level[3] + ', ' + level[4])
|
|
|
|
elif level[3] or level[4]:
|
|
|
|
return unicode(level[3] or level[4])
|
|
|
|
else:
|
2010-01-11 01:41:18 +05:30
|
|
|
return u"<i>%s<i>" % cgi.escape(_("<no name>"))
|
2009-12-27 01:12:22 +05:30
|
|
|
return unicode(data[2])
|
|
|
|
|
2009-11-17 05:43:03 +05:30
|
|
|
def column_header(self, node):
|
|
|
|
"""
|
|
|
|
Return a column heading. This is called for nodes with no associated
|
|
|
|
Gramps handle.
|
|
|
|
"""
|
2010-01-11 01:41:18 +05:30
|
|
|
if node.name:
|
|
|
|
return '<i>%s</i>' % cgi.escape(node.name)
|
|
|
|
else:
|
|
|
|
level = len(self.on_get_path(node))
|
|
|
|
return '<i>%s</i>' % cgi.escape(COUNTRYLEVELS['default'][level])
|
|
|
|
|