2005-01-01 20:46:44 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-06-15 01:50:39 +05:30
|
|
|
# Copyright (C) 2004-2006 Donald N. Allingham
|
2005-01-01 20:46:44 +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$
|
|
|
|
|
|
|
|
"""
|
|
|
|
Class handling language-specific displaying of names.
|
|
|
|
"""
|
|
|
|
|
2005-02-25 22:36:04 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-01-21 03:13:40 +05:30
|
|
|
from RelLib import Name
|
2005-01-01 20:46:44 +05:30
|
|
|
|
2006-04-13 10:56:19 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
_FIRSTNAME = 4
|
|
|
|
_SURNAME = 5
|
|
|
|
_SUFFIX = 6
|
|
|
|
_TITLE = 7
|
|
|
|
_TYPE = 8
|
|
|
|
_PREFIX = 9
|
|
|
|
_PATRONYM = 10
|
|
|
|
_SNAME = 11
|
|
|
|
_GROUP = 12
|
|
|
|
_SORT = 13
|
|
|
|
_DISPLAY = 14
|
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
formats = {
|
|
|
|
Name.LNFN: _("Family name, Given name Patronymic"),
|
|
|
|
Name.FNLN: _("Given name Family name"),
|
|
|
|
Name.PTFN: _("Patronymic Given name"),
|
|
|
|
Name.FN: _("Given name"),
|
|
|
|
Name.CUSTOM: _("Custom"),
|
|
|
|
}
|
|
|
|
|
2005-02-25 22:36:04 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# NameDisplay class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-01-01 20:46:44 +05:30
|
|
|
class NameDisplay:
|
|
|
|
"""
|
|
|
|
Base class for displaying of Name instances.
|
|
|
|
"""
|
2006-06-15 01:50:39 +05:30
|
|
|
|
|
|
|
# FIXME: Is this used anywhere? I cannot see that it is.
|
|
|
|
sort_field = (Name.get_surname, Name.get_surname,
|
|
|
|
Name.get_first_name, Name.get_patronymic,
|
|
|
|
Name.get_first_name)
|
|
|
|
|
2005-01-01 20:46:44 +05:30
|
|
|
def __init__(self,use_upper=False):
|
|
|
|
"""
|
|
|
|
Creates a new NameDisplay class.
|
|
|
|
|
|
|
|
@param use_upper: True indicates that the surname should be
|
|
|
|
displayed in upper case.
|
|
|
|
@type use_upper: bool
|
|
|
|
"""
|
2005-01-09 07:48:49 +05:30
|
|
|
self.force_upper = use_upper
|
2006-03-20 05:04:23 +05:30
|
|
|
|
|
|
|
self.fn_array = [
|
|
|
|
self._lnfn, self._lnfn, self._fnln,
|
|
|
|
self._ptfn, self._empty ]
|
|
|
|
|
|
|
|
self.raw_fn_array = (
|
|
|
|
self._lnfn_raw, self._lnfn_raw, self._fnln_raw,
|
|
|
|
self._ptfn_raw, self._empty_raw )
|
2005-01-01 20:46:44 +05:30
|
|
|
|
|
|
|
def use_upper(self,upper):
|
|
|
|
"""
|
|
|
|
Changes the NameDisplay class to enable or display the displaying
|
|
|
|
of surnames in upper case.
|
|
|
|
|
|
|
|
@param upper: True indicates that the surname should be
|
|
|
|
displayed in upper case.
|
|
|
|
@type upper: bool
|
|
|
|
"""
|
2005-01-09 07:48:49 +05:30
|
|
|
self.force_upper = upper
|
2005-01-01 20:46:44 +05:30
|
|
|
|
2006-03-21 11:53:45 +05:30
|
|
|
def sort_string(self,name):
|
|
|
|
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
|
|
|
|
2005-01-01 20:46:44 +05:30
|
|
|
def sorted(self,person):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{RelLib.Person} instance's
|
2006-01-21 03:13:40 +05:30
|
|
|
L{Name} in a manner that should be used for displaying a sorted
|
2005-01-01 20:46:44 +05:30
|
|
|
name.
|
|
|
|
|
|
|
|
@param person: L{RelLib.Person} instance that contains the
|
2006-01-21 03:13:40 +05:30
|
|
|
L{Name} that is to be displayed. The primary name is used for
|
2005-01-01 20:46:44 +05:30
|
|
|
the display.
|
|
|
|
@type person: L{RelLib.Person}
|
|
|
|
@returns: Returns the L{RelLib.Person} instance's name
|
|
|
|
@rtype: str
|
|
|
|
"""
|
|
|
|
name = person.get_primary_name()
|
2006-01-21 03:13:40 +05:30
|
|
|
if name.sort_as == Name.FNLN:
|
2005-01-01 20:46:44 +05:30
|
|
|
return self._fnln(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
elif name.sort_as == Name.PTFN:
|
2005-08-18 11:28:28 +05:30
|
|
|
return self._ptfn(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
elif name.sort_as == Name.FN:
|
2005-08-18 11:28:28 +05:30
|
|
|
return name.first_name
|
2005-01-27 08:48:21 +05:30
|
|
|
else:
|
|
|
|
return self._lnfn(name)
|
2005-01-01 20:46:44 +05:30
|
|
|
|
2006-01-21 03:13:40 +05:30
|
|
|
def _empty(self,name):
|
|
|
|
return name.first_name
|
2005-01-01 20:46:44 +05:30
|
|
|
|
2006-03-20 05:04:23 +05:30
|
|
|
def _empty_raw(self,raw_data):
|
2006-04-13 10:56:19 +05:30
|
|
|
return raw_data[_FIRSTNAME]
|
2006-03-20 05:04:23 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
def _ptfn(self,name):
|
|
|
|
"""
|
|
|
|
Prints the Western style first name, last name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
SurnamePrefix Patronymic SurnameSuffix, FirstName
|
|
|
|
"""
|
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
return self._ptfn_base(name.first_name,name.suffix,
|
|
|
|
name.prefix,name.patronymic)
|
2006-03-20 05:04:23 +05:30
|
|
|
|
|
|
|
def _ptfn_raw(self,raw_data):
|
|
|
|
"""
|
|
|
|
Prints the Western style first name, last name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
SurnamePrefix Patronymic SurnameSuffix, FirstName
|
|
|
|
"""
|
|
|
|
|
2006-04-13 10:56:19 +05:30
|
|
|
first = raw_data[_FIRSTNAME]
|
|
|
|
suffix = raw_data[_SUFFIX]
|
|
|
|
prefix = raw_data[_PREFIX]
|
|
|
|
patronymic = raw_data[_PATRONYM]
|
2006-03-20 05:04:23 +05:30
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
return self._ptfn_base(first,suffix,prefix,patronymic)
|
|
|
|
|
|
|
|
def _ptfn_base(self,first,suffix,prefix,patronymic):
|
2006-03-20 05:04:23 +05:30
|
|
|
if self.force_upper:
|
|
|
|
last = patronymic.upper()
|
|
|
|
else:
|
|
|
|
last = patronymic
|
|
|
|
|
|
|
|
if suffix:
|
|
|
|
if prefix:
|
|
|
|
return "%s %s %s, %s" % (prefix, last, suffix, first)
|
|
|
|
else:
|
|
|
|
return "%s %s, %s" % (last, suffix, first)
|
|
|
|
else:
|
2006-03-23 04:33:57 +05:30
|
|
|
if prefix:
|
2006-03-20 05:04:23 +05:30
|
|
|
return "%s %s, %s" % (prefix, last, first)
|
|
|
|
else:
|
|
|
|
return "%s, %s" % (last, first)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-05-18 07:09:50 +05:30
|
|
|
def _fnln(self,name):
|
2005-01-01 20:46:44 +05:30
|
|
|
"""
|
|
|
|
Prints the Western style first name, last name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
FirstName Patronymic SurnamePrefix Surname SurnameSuffix
|
|
|
|
"""
|
2006-06-15 01:50:39 +05:30
|
|
|
return self._fnln_base(name.first_name,name.surname,name.suffix,
|
|
|
|
name.prefix,name.patronymic)
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-03-20 05:04:23 +05:30
|
|
|
def _fnln_raw(self,raw_data):
|
|
|
|
"""
|
|
|
|
Prints the Western style first name, last name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
FirstName Patronymic SurnamePrefix Surname SurnameSuffix
|
|
|
|
"""
|
2006-04-13 10:56:19 +05:30
|
|
|
first = raw_data[_FIRSTNAME]
|
|
|
|
surname = raw_data[_SURNAME]
|
|
|
|
suffix = raw_data[_SUFFIX]
|
|
|
|
prefix = raw_data[_PREFIX]
|
|
|
|
patronymic = raw_data[_PATRONYM]
|
2006-06-15 01:50:39 +05:30
|
|
|
return self._fnln_base(first,surname,suffix,prefix,patronymic)
|
2006-03-20 05:04:23 +05:30
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
def _fnln_base(self,first,surname,suffix,prefix,patronymic):
|
2006-03-20 05:04:23 +05:30
|
|
|
if patronymic:
|
|
|
|
first = "%s %s" % (first, patronymic)
|
|
|
|
|
|
|
|
if self.force_upper:
|
|
|
|
last = surname.upper()
|
|
|
|
else:
|
|
|
|
last = surname
|
|
|
|
|
|
|
|
if suffix:
|
|
|
|
if prefix:
|
|
|
|
return "%s %s %s, %s" % (first, prefix, last, suffix)
|
|
|
|
else:
|
|
|
|
return "%s %s, %s" % (first, last, suffix)
|
|
|
|
else:
|
|
|
|
if prefix:
|
|
|
|
return "%s %s %s" % (first, prefix, last)
|
|
|
|
else:
|
|
|
|
return "%s %s" % (first, last)
|
|
|
|
|
2006-05-18 07:09:50 +05:30
|
|
|
def _lnfn(self,name):
|
2005-01-01 20:46:44 +05:30
|
|
|
"""
|
|
|
|
Prints the Western style last name, first name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
|
|
|
|
"""
|
2006-06-15 01:50:39 +05:30
|
|
|
return self._lnfn_base(name.first_name,name.surname,name.prefix,
|
|
|
|
name.suffix,name.patronymic)
|
2006-01-21 03:13:40 +05:30
|
|
|
|
2006-03-20 05:04:23 +05:30
|
|
|
def _lnfn_raw(self,raw_data):
|
|
|
|
"""
|
|
|
|
Prints the Western style last name, first name style.
|
|
|
|
Typically this is::
|
|
|
|
|
|
|
|
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
|
|
|
|
"""
|
2006-06-15 01:50:39 +05:30
|
|
|
|
|
|
|
surname = raw_data[_SURNAME]
|
|
|
|
prefix = raw_data[_PREFIX]
|
|
|
|
first = raw_data[_FIRSTNAME]
|
|
|
|
patronymic = raw_data[_PATRONYM]
|
|
|
|
suffix = raw_data[_SUFFIX]
|
|
|
|
|
|
|
|
return self._lnfn_base(first,surname,prefix,suffix,patronymic)
|
|
|
|
|
|
|
|
def _lnfn_base(self,first,surname,prefix,suffix,patronymic):
|
2006-03-20 05:04:23 +05:30
|
|
|
if self.force_upper:
|
2006-06-15 01:50:39 +05:30
|
|
|
last = surname.upper()
|
2006-03-20 05:04:23 +05:30
|
|
|
else:
|
2006-06-15 01:50:39 +05:30
|
|
|
last = surname
|
2006-03-20 05:04:23 +05:30
|
|
|
|
|
|
|
if last:
|
|
|
|
last += ","
|
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
return " ".join([prefix, last, first, patronymic, suffix])
|
2006-03-20 05:04:23 +05:30
|
|
|
|
2006-01-21 03:13:40 +05:30
|
|
|
def sorted_name(self,name):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{Name} instance
|
|
|
|
in a manner that should be used for displaying a sorted
|
|
|
|
name.
|
|
|
|
|
|
|
|
@param name: L{Name} instance that is to be displayed.
|
|
|
|
@type name: L{Name}
|
|
|
|
@returns: Returns the L{Name} string representation
|
|
|
|
@rtype: str
|
|
|
|
"""
|
2006-03-20 05:04:23 +05:30
|
|
|
return self.fn_array[name.sort_as](name)
|
|
|
|
#return self.fn_array.get(name.sort_as,self._lnfn)(name)
|
|
|
|
|
|
|
|
def raw_sorted_name(self,raw_data):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{Name} instance
|
|
|
|
in a manner that should be used for displaying a sorted
|
|
|
|
name.
|
|
|
|
|
|
|
|
@param name: L{Name} instance that is to be displayed.
|
|
|
|
@type name: L{Name}
|
|
|
|
@returns: Returns the L{Name} string representation
|
|
|
|
@rtype: str
|
|
|
|
"""
|
2006-04-13 10:56:19 +05:30
|
|
|
return self.raw_fn_array[raw_data[_SORT]](raw_data)
|
2006-01-21 03:13:40 +05:30
|
|
|
|
|
|
|
def display_given(self,person):
|
|
|
|
name = person.get_primary_name()
|
|
|
|
if name.patronymic:
|
|
|
|
return "%s %s" % (name.first_name, name.patronymic)
|
|
|
|
else:
|
|
|
|
return name.first_name
|
|
|
|
|
|
|
|
def display(self,person):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{RelLib.Person} instance's
|
|
|
|
L{Name} in a manner that should be used for normal displaying.
|
|
|
|
|
|
|
|
@param person: L{RelLib.Person} instance that contains the
|
|
|
|
L{Name} that is to be displayed. The primary name is used for
|
|
|
|
the display.
|
|
|
|
@type person: L{RelLib.Person}
|
|
|
|
@returns: Returns the L{RelLib.Person} instance's name
|
|
|
|
@rtype: str
|
|
|
|
"""
|
|
|
|
name = person.get_primary_name()
|
|
|
|
if name.display_as == Name.LNFN:
|
2006-05-18 07:09:50 +05:30
|
|
|
return self._lnfn(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
else:
|
2006-05-18 07:09:50 +05:30
|
|
|
return self._fnln(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
|
|
|
|
def display_formal(self,person):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{RelLib.Person} instance's
|
|
|
|
L{Name} in a manner that should be used for normal displaying.
|
|
|
|
|
|
|
|
@param person: L{RelLib.Person} instance that contains the
|
|
|
|
L{Name} that is to be displayed. The primary name is used for
|
|
|
|
the display.
|
|
|
|
@type person: L{RelLib.Person}
|
|
|
|
@returns: Returns the L{RelLib.Person} instance's name
|
|
|
|
@rtype: str
|
|
|
|
"""
|
|
|
|
name = person.get_primary_name()
|
|
|
|
if name.display_as == Name.LNFN:
|
2006-05-18 07:09:50 +05:30
|
|
|
return self._lnfn(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
else:
|
2006-05-18 07:09:50 +05:30
|
|
|
return self._fnln(name)
|
2006-01-21 03:13:40 +05:30
|
|
|
|
|
|
|
def display_name(self,name):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the L{Name} instance
|
|
|
|
in a manner that should be used for normal displaying.
|
|
|
|
|
|
|
|
@param name: L{Name} instance that is to be displayed.
|
|
|
|
@type name: L{Name}
|
|
|
|
@returns: Returns the L{Name} string representation
|
|
|
|
@rtype: str
|
|
|
|
"""
|
|
|
|
if name == None:
|
|
|
|
return ""
|
|
|
|
elif name.display_as == Name.LNFN:
|
|
|
|
return self._lnfn(name)
|
|
|
|
elif name.display_as == Name.PTFN:
|
|
|
|
return self._ptfn(name)
|
|
|
|
else:
|
|
|
|
return self._fnln(name)
|
|
|
|
|
|
|
|
def name_grouping(self,db,person):
|
|
|
|
return self.name_grouping_name(db,person.primary_name)
|
|
|
|
|
|
|
|
|
|
|
|
def name_grouping_name(self,db,pn):
|
|
|
|
if pn.group_as:
|
|
|
|
return pn.group_as
|
|
|
|
sv = pn.sort_as
|
|
|
|
if sv <= Name.LNFN:
|
|
|
|
return db.get_name_group_mapping(pn.surname)
|
|
|
|
elif sv == Name.PTFN:
|
|
|
|
return db.get_name_group_mapping(pn.patronymic)
|
|
|
|
else:
|
|
|
|
return db.get_name_group_mapping(pn.first_name)
|
|
|
|
|
2005-01-01 20:46:44 +05:30
|
|
|
displayer = NameDisplay()
|