2006-07-06 Alex Roitman <shura@gramps-project.org>
* src/ViewManager.py (ViewManager.post_load_newdb): Register custom formats after loading the db. * src/GrampsCfg.py: Switch to use new formats (still in progress). * src/GrampsDb/_GrampsDbBase.py (GrampsDbBase.__init__): Set up custom name formats list. * src/GrampsDb/_DbUtils.py (db_copy): Copy custom name formats. * src/GrampsDb/_ReadXML.py (start_format): Parse custom formats. * src/GrampsDb/_WriteXML.py (write_name_formats): Add method. * src/GrampsDb/_GrampsBSDDB.py (GrampsBSDDB._load_metadata) (GrampsBSDDB._close_metadata): load and save name_formats. * src/Editors/_EditName.py (EditName._setup_fields): Use proper format lists. * src/NameDisplay.py: Support new name formats scheme. * src/RelLib/_Name.py (Name.DEFAULT_FORMATS): Add list of formats. svn: r6999
This commit is contained in:
parent
c72b2cbda5
commit
89189e2d35
@ -1,3 +1,19 @@
|
|||||||
|
2006-07-06 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/ViewManager.py (ViewManager.post_load_newdb): Register
|
||||||
|
custom formats after loading the db.
|
||||||
|
* src/GrampsCfg.py: Switch to use new formats (still in progress).
|
||||||
|
* src/GrampsDb/_GrampsDbBase.py (GrampsDbBase.__init__): Set up
|
||||||
|
custom name formats list.
|
||||||
|
* src/GrampsDb/_DbUtils.py (db_copy): Copy custom name formats.
|
||||||
|
* src/GrampsDb/_ReadXML.py (start_format): Parse custom formats.
|
||||||
|
* src/GrampsDb/_WriteXML.py (write_name_formats): Add method.
|
||||||
|
* src/GrampsDb/_GrampsBSDDB.py (GrampsBSDDB._load_metadata)
|
||||||
|
(GrampsBSDDB._close_metadata): load and save name_formats.
|
||||||
|
* src/Editors/_EditName.py (EditName._setup_fields): Use proper
|
||||||
|
format lists.
|
||||||
|
* src/NameDisplay.py: Support new name formats scheme.
|
||||||
|
* src/RelLib/_Name.py (Name.DEFAULT_FORMATS): Add list of formats.
|
||||||
|
|
||||||
2006-07-05 Don Allingham <don@gramps-project.org>
|
2006-07-05 Don Allingham <don@gramps-project.org>
|
||||||
* src/Editors/_EditChildRef.py: fix title
|
* src/Editors/_EditChildRef.py: fix title
|
||||||
* src/Editors/_EditFamily.py: call sequence for EditChildRef
|
* src/Editors/_EditFamily.py: call sequence for EditChildRef
|
||||||
|
@ -96,24 +96,24 @@ class EditName(EditSecondary):
|
|||||||
if not self.original_group_as:
|
if not self.original_group_as:
|
||||||
self.group_as.force_value(self.obj.get_surname())
|
self.group_as.force_value(self.obj.get_surname())
|
||||||
|
|
||||||
|
|
||||||
|
format_list = [(name,number) for (number,name,fmt_str)
|
||||||
|
in RelLib.Name.DEFAULT_FORMATS]
|
||||||
|
format_list += [(name,number) for (number,name,fmt_str)
|
||||||
|
in NameDisplay.CUSTOM_FORMATS]
|
||||||
|
|
||||||
self.sort_as = MonitoredMenu(
|
self.sort_as = MonitoredMenu(
|
||||||
self.top.get_widget('sort_as'),
|
self.top.get_widget('sort_as'),
|
||||||
self.obj.set_sort_as,
|
self.obj.set_sort_as,
|
||||||
self.obj.get_sort_as,
|
self.obj.get_sort_as,
|
||||||
[(_('Given name Family name'), RelLib.Name.FNLN),
|
format_list,
|
||||||
(_('Family name Given Name Patronymic'), RelLib.Name.LNFN),
|
|
||||||
(_('Custom'), RelLib.Name.CUSTOM),
|
|
||||||
],
|
|
||||||
self.db.readonly)
|
self.db.readonly)
|
||||||
|
|
||||||
self.display_as = MonitoredMenu(
|
self.display_as = MonitoredMenu(
|
||||||
self.top.get_widget('display_as'),
|
self.top.get_widget('display_as'),
|
||||||
self.obj.set_display_as,
|
self.obj.set_display_as,
|
||||||
self.obj.get_display_as,
|
self.obj.get_display_as,
|
||||||
[(_('Given name Family name'), RelLib.Name.FNLN),
|
format_list,
|
||||||
(_('Family name Given Name Patronymic'), RelLib.Name.LNFN),
|
|
||||||
(_('Custom'), RelLib.Name.CUSTOM),
|
|
||||||
],
|
|
||||||
self.db.readonly)
|
self.db.readonly)
|
||||||
|
|
||||||
self.given_field = MonitoredEntry(
|
self.given_field = MonitoredEntry(
|
||||||
|
@ -213,76 +213,84 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
_('C_ustom format details'))
|
_('C_ustom format details'))
|
||||||
self.name_exp.set_sensitive(False)
|
self.name_exp.set_sensitive(False)
|
||||||
|
|
||||||
obox = gtk.combo_box_new_text()
|
|
||||||
for key,value in NameDisplay.formats.items():
|
|
||||||
obox.append_text(value)
|
|
||||||
|
|
||||||
try:
|
format_list = [(name,number) for (number,name,fmt_str)
|
||||||
active = int(Config.get(Config.NAME_FORMAT))
|
in Name.DEFAULT_FORMATS]
|
||||||
if active >= len(NameDisplay.formats):
|
format_list += [(name,number) for (number,name,fmt_str)
|
||||||
active = 0
|
in NameDisplay.CUSTOM_FORMATS]
|
||||||
except ValueError: # not an integer-convertible string => custom
|
|
||||||
active = len(NameDisplay.formats)
|
obox = gtk.ComboBox()
|
||||||
self.name_exp.set_sensitive(True)
|
obox_data = {}
|
||||||
|
obox_model = gtk.ListStore(str, int)
|
||||||
|
index = 0
|
||||||
|
for t, v in format_list:
|
||||||
|
obox_model.append(row=[t, v])
|
||||||
|
print [t, v]
|
||||||
|
obox_data[v] = index
|
||||||
|
index += 1
|
||||||
|
|
||||||
obox.set_active(active)
|
obox.set_model(obox_model)
|
||||||
obox.connect('changed', self.name_changed)
|
|
||||||
|
#active = int(Config.get(Config.NAME_FORMAT))
|
||||||
|
#obox.set_active(active)
|
||||||
|
# obox.connect('changed', self.name_changed)
|
||||||
lwidget = BasicLabel("%s: " % _('Preset format'))
|
lwidget = BasicLabel("%s: " % _('Preset format'))
|
||||||
|
|
||||||
custom_ui = self.build_custom_name_ui()
|
# custom_ui = self.build_custom_name_ui()
|
||||||
self.name_exp.add(custom_ui)
|
# self.name_exp.add(custom_ui)
|
||||||
|
|
||||||
table.attach(lwidget, 0, 1, 0, 1, yoptions=0)
|
table.attach(lwidget, 0, 1, 0, 1, yoptions=0)
|
||||||
table.attach(obox, 1,3,0, 1, yoptions=0)
|
table.attach(obox, 1,3,0, 1, yoptions=0)
|
||||||
table.attach(self.name_exp, 0,3,1, 2, yoptions=0)
|
# table.attach(self.name_exp, 0,3,1, 2, yoptions=0)
|
||||||
return table
|
return table
|
||||||
|
|
||||||
def build_custom_name_ui(self):
|
## def build_custom_name_ui(self):
|
||||||
table = gtk.Table(2,3)
|
## table = gtk.Table(2,3)
|
||||||
table.set_border_width(6)
|
## table.set_border_width(6)
|
||||||
table.set_col_spacings(6)
|
## table.set_col_spacings(6)
|
||||||
table.set_row_spacings(6)
|
## table.set_row_spacings(6)
|
||||||
|
|
||||||
avail_sw = gtk.ScrolledWindow()
|
## avail_sw = gtk.ScrolledWindow()
|
||||||
avail_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
|
## avail_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
|
||||||
avail_tree = gtk.TreeView()
|
## avail_tree = gtk.TreeView()
|
||||||
avail_sw.add(avail_tree)
|
## avail_sw.add(avail_tree)
|
||||||
|
|
||||||
use_sw = gtk.ScrolledWindow()
|
## use_sw = gtk.ScrolledWindow()
|
||||||
use_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
|
## use_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
|
||||||
use_tree = gtk.TreeView()
|
## use_tree = gtk.TreeView()
|
||||||
use_sw.add(use_tree)
|
## use_sw.add(use_tree)
|
||||||
|
|
||||||
button_table = gtk.Table(3,3)
|
## button_table = gtk.Table(3,3)
|
||||||
|
|
||||||
up_button = _set_button(gtk.STOCK_GO_UP)
|
## up_button = _set_button(gtk.STOCK_GO_UP)
|
||||||
down_button = _set_button(gtk.STOCK_GO_DOWN)
|
## down_button = _set_button(gtk.STOCK_GO_DOWN)
|
||||||
add_button = _set_button(gtk.STOCK_ADD)
|
## add_button = _set_button(gtk.STOCK_ADD)
|
||||||
remove_button = _set_button(gtk.STOCK_REMOVE)
|
## remove_button = _set_button(gtk.STOCK_REMOVE)
|
||||||
button_table.attach(up_button, 1, 2, 0, 1, xoptions = 0, yoptions=0)
|
## button_table.attach(up_button, 1, 2, 0, 1, xoptions = 0, yoptions=0)
|
||||||
button_table.attach(remove_button, 2, 3, 1, 2, xoptions = 0,yoptions=0)
|
## button_table.attach(remove_button, 2, 3, 1, 2, xoptions = 0,yoptions=0)
|
||||||
button_table.attach(down_button, 1, 2, 2, 3, xoptions = 0, yoptions=0)
|
## button_table.attach(down_button, 1, 2, 2, 3, xoptions = 0, yoptions=0)
|
||||||
button_table.attach(add_button, 0, 1, 1, 2, xoptions = 0,yoptions=0)
|
## button_table.attach(add_button, 0, 1, 1, 2, xoptions = 0,yoptions=0)
|
||||||
|
|
||||||
example_label = gtk.Label('<b>%s</b>' % _('Example'))
|
## example_label = gtk.Label('<b>%s</b>' % _('Example'))
|
||||||
example_label.set_use_markup(True)
|
## example_label.set_use_markup(True)
|
||||||
|
|
||||||
table.attach(example_label,0,3,0,1,xoptions = 0,yoptions=0)
|
## table.attach(example_label,0,3,0,1,xoptions = 0,yoptions=0)
|
||||||
table.attach(avail_sw, 0,1,1,2, yoptions=gtk.FILL)
|
## table.attach(avail_sw, 0,1,1,2, yoptions=gtk.FILL)
|
||||||
table.attach(button_table, 1, 2, 1, 2, xoptions = 0, yoptions=0)
|
## table.attach(button_table, 1, 2, 1, 2, xoptions = 0, yoptions=0)
|
||||||
table.attach(use_sw, 2,3,1,2, yoptions=gtk.FILL)
|
## table.attach(use_sw, 2,3,1,2, yoptions=gtk.FILL)
|
||||||
|
|
||||||
return table
|
## return table
|
||||||
|
|
||||||
def name_changed(self,obj):
|
## def name_changed(self,obj):
|
||||||
custom_text = NameDisplay.formats[Name.CUSTOM]
|
## return
|
||||||
if obj.get_active_text() == custom_text:
|
## custom_text = NameDisplay.formats[Name.CUSTOM]
|
||||||
self.name_exp.set_sensitive(True)
|
## if obj.get_active_text() == custom_text:
|
||||||
self.name_exp.set_expanded(True)
|
## self.name_exp.set_sensitive(True)
|
||||||
else:
|
## self.name_exp.set_expanded(True)
|
||||||
Config.set(Config.NAME_FORMAT,obj.get_active())
|
## else:
|
||||||
self.name_exp.set_expanded(False)
|
## Config.set(Config.NAME_FORMAT,obj.get_active())
|
||||||
self.name_exp.set_sensitive(False)
|
## self.name_exp.set_expanded(False)
|
||||||
|
## self.name_exp.set_sensitive(False)
|
||||||
|
|
||||||
def add_formats_panel(self):
|
def add_formats_panel(self):
|
||||||
table = gtk.Table(3,8)
|
table = gtk.Table(3,8)
|
||||||
|
@ -238,6 +238,9 @@ def db_copy(from_db,to_db,callback):
|
|||||||
to_db.media_bookmarks = from_db.media_bookmarks
|
to_db.media_bookmarks = from_db.media_bookmarks
|
||||||
to_db.repo_bookmarks = from_db.repo_bookmarks
|
to_db.repo_bookmarks = from_db.repo_bookmarks
|
||||||
|
|
||||||
|
# Copy name formats
|
||||||
|
to_db.name_formats = from_db.name_formats
|
||||||
|
|
||||||
# Copy gender stats
|
# Copy gender stats
|
||||||
to_db.genderStats = from_db.genderStats
|
to_db.genderStats = from_db.genderStats
|
||||||
|
|
||||||
|
@ -383,6 +383,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
def _load_metadata(self):
|
def _load_metadata(self):
|
||||||
|
# name display formats
|
||||||
|
self.name_formats = self.metadata.get('name_formats',[])
|
||||||
# bookmarks
|
# bookmarks
|
||||||
self.bookmarks = self.metadata.get('bookmarks',[])
|
self.bookmarks = self.metadata.get('bookmarks',[])
|
||||||
self.family_bookmarks = self.metadata.get('family_bookmarks',[])
|
self.family_bookmarks = self.metadata.get('family_bookmarks',[])
|
||||||
@ -805,6 +807,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
|
|
||||||
def _close_metadata(self):
|
def _close_metadata(self):
|
||||||
if not self.readonly:
|
if not self.readonly:
|
||||||
|
# name display formats
|
||||||
|
self.metadata['name_formats'] = self.name_formats
|
||||||
# bookmarks
|
# bookmarks
|
||||||
self.metadata['bookmarks'] = self.bookmarks
|
self.metadata['bookmarks'] = self.bookmarks
|
||||||
self.metadata['family_bookmarks'] = self.family_bookmarks
|
self.metadata['family_bookmarks'] = self.family_bookmarks
|
||||||
|
@ -273,6 +273,7 @@ class GrampsDbBase(GrampsDBCallback):
|
|||||||
self.undo_history_timestamp = 0
|
self.undo_history_timestamp = 0
|
||||||
self.default = None
|
self.default = None
|
||||||
self.owner = Researcher()
|
self.owner = Researcher()
|
||||||
|
self.name_formats = []
|
||||||
self.bookmarks = []
|
self.bookmarks = []
|
||||||
self.family_bookmarks = []
|
self.family_bookmarks = []
|
||||||
self.event_bookmarks = []
|
self.event_bookmarks = []
|
||||||
|
@ -361,6 +361,8 @@ class GrampsParser(UpdateCallback):
|
|||||||
"attr_value" : (None,self.stop_attr_value),
|
"attr_value" : (None,self.stop_attr_value),
|
||||||
"bookmark" : (self.start_bmark, None),
|
"bookmark" : (self.start_bmark, None),
|
||||||
"bookmarks" : (None, None),
|
"bookmarks" : (None, None),
|
||||||
|
"format" : (self.start_format, None),
|
||||||
|
"name-formats" : (None, None),
|
||||||
"child" : (self.start_child,None),
|
"child" : (self.start_child,None),
|
||||||
"childof" : (self.start_childof,None),
|
"childof" : (self.start_childof,None),
|
||||||
"childref" : (self.start_childref,self.stop_childref),
|
"childref" : (self.start_childref,self.stop_childref),
|
||||||
@ -838,6 +840,12 @@ class GrampsParser(UpdateCallback):
|
|||||||
self.db.check_repository_from_handle(handle,self.trans)
|
self.db.check_repository_from_handle(handle,self.trans)
|
||||||
self.db.repo_bookmarks.append(handle)
|
self.db.repo_bookmarks.append(handle)
|
||||||
|
|
||||||
|
def start_format(self,attrs):
|
||||||
|
number = int(attrs['number'])
|
||||||
|
name = attrs['name']
|
||||||
|
fmt_str = attrs['fmt_str']
|
||||||
|
self.db.name_formats.append((number,name,fmt_str))
|
||||||
|
|
||||||
def start_person(self,attrs):
|
def start_person(self,attrs):
|
||||||
self.update(self.p.CurrentLineNumber)
|
self.update(self.p.CurrentLineNumber)
|
||||||
new_id = self.map_gid(attrs['id'])
|
new_id = self.map_gid(attrs['id'])
|
||||||
|
@ -310,6 +310,9 @@ class XmlWriter(UpdateCallback):
|
|||||||
# Data is written, now write bookmarks.
|
# Data is written, now write bookmarks.
|
||||||
self.write_bookmarks()
|
self.write_bookmarks()
|
||||||
|
|
||||||
|
# Also write name formats
|
||||||
|
self.write_name_formats()
|
||||||
|
|
||||||
self.g.write("</database>\n")
|
self.g.write("</database>\n")
|
||||||
|
|
||||||
def write_bookmarks(self):
|
def write_bookmarks(self):
|
||||||
@ -350,6 +353,14 @@ class XmlWriter(UpdateCallback):
|
|||||||
% handle )
|
% handle )
|
||||||
self.g.write(" </bookmarks>\n")
|
self.g.write(" </bookmarks>\n")
|
||||||
|
|
||||||
|
def write_name_formats(self):
|
||||||
|
if len(self.db.name_formats) > 0:
|
||||||
|
self.g.write(" <name-formats>\n")
|
||||||
|
for number,name,fmt_str in self.db.name_formats:
|
||||||
|
self.g.write('%s<format number="%d" name="%s" fmt_str="%s"/>\n'
|
||||||
|
% (' ',number,name,fmt_str) )
|
||||||
|
self.g.write(" </name-formats>\n")
|
||||||
|
|
||||||
def fix(self,line):
|
def fix(self,line):
|
||||||
l = line.strip()
|
l = line.strip()
|
||||||
l = l.replace('&','&')
|
l = l.replace('&','&')
|
||||||
|
@ -24,14 +24,13 @@
|
|||||||
Class handling language-specific displaying of names.
|
Class handling language-specific displaying of names.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from gettext import gettext as _
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from RelLib import Name
|
from RelLib import Name
|
||||||
|
import Config
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -51,13 +50,15 @@ _SORT = 13
|
|||||||
_DISPLAY = 14
|
_DISPLAY = 14
|
||||||
_CALL = 15
|
_CALL = 15
|
||||||
|
|
||||||
formats = {
|
#-------------------------------------------------------------------------
|
||||||
Name.LNFN: _("Family name, Given name Patronymic"),
|
#
|
||||||
Name.FNLN: _("Given name Family name"),
|
# formats registration
|
||||||
Name.PTFN: _("Patronymic Given name"),
|
#
|
||||||
Name.FN: _("Given name"),
|
#-------------------------------------------------------------------------
|
||||||
Name.CUSTOM: _("Custom"),
|
CUSTOM_FORMATS = []
|
||||||
}
|
|
||||||
|
def register_custom_formats(formats):
|
||||||
|
CUSTOM_FORMATS = formats[:]
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -82,15 +83,38 @@ class NameDisplay:
|
|||||||
displayed in upper case.
|
displayed in upper case.
|
||||||
@type use_upper: bool
|
@type use_upper: bool
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.gramps_format = Config.get(Config.NAME_FORMAT)
|
||||||
|
if self.gramps_format == 0:
|
||||||
|
self.gramps_format = Name.LNFN
|
||||||
|
|
||||||
self.force_upper = use_upper
|
self.force_upper = use_upper
|
||||||
|
|
||||||
self.fn_array = [
|
self.fn_array = {
|
||||||
self._lnfn, self._lnfn, self._fnln,
|
Name.LNFN: self._lnfn,
|
||||||
self._ptfn, self._empty ]
|
Name.FNLN: self._fnln,
|
||||||
|
Name.PTFN: self._ptfn,
|
||||||
|
Name.FN: self._fn,
|
||||||
|
}
|
||||||
|
|
||||||
self.raw_fn_array = (
|
self.raw_fn_array = {
|
||||||
self._lnfn_raw, self._lnfn_raw, self._fnln_raw,
|
Name.LNFN: self._lnfn_raw,
|
||||||
self._ptfn_raw, self._empty_raw )
|
Name.FNLN: self._fnln_raw,
|
||||||
|
Name.PTFN: self._ptfn_raw,
|
||||||
|
Name.FN: self._fn_raw,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.extend_formats()
|
||||||
|
|
||||||
|
def extend_formats(self):
|
||||||
|
# Add custom formats to the mappings
|
||||||
|
for number,name,fmt_str in CUSTOM_FORMATS:
|
||||||
|
self.fn_array[number] = lambda x: self._format_str(x,fmt_str)
|
||||||
|
self.raw_fn_array[number] = lambda x: \
|
||||||
|
self._format_str_raw(x,fmt_str)
|
||||||
|
# Add mappings for the gramps-prefs format
|
||||||
|
self.fn_array[0] = self.fn_array[self.gramps_format]
|
||||||
|
self.raw_fn_array[0] = self.raw_fn_array[self.gramps_format]
|
||||||
|
|
||||||
def use_upper(self,upper):
|
def use_upper(self,upper):
|
||||||
"""
|
"""
|
||||||
@ -106,34 +130,15 @@ class NameDisplay:
|
|||||||
def sort_string(self,name):
|
def sort_string(self,name):
|
||||||
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
|
||||||
|
|
||||||
def sorted(self,person):
|
def _fn(self,name):
|
||||||
"""
|
return self._fn_base(name.first_name)
|
||||||
Returns a text string representing the L{RelLib.Person} instance's
|
|
||||||
L{Name} in a manner that should be used for displaying a sorted
|
|
||||||
name.
|
|
||||||
|
|
||||||
@param person: L{RelLib.Person} instance that contains the
|
def _fn_raw(self,raw_data):
|
||||||
L{Name} that is to be displayed. The primary name is used for
|
first = raw_data[_FIRSTNAME]
|
||||||
the display.
|
return self._fn_base(first)
|
||||||
@type person: L{RelLib.Person}
|
|
||||||
@returns: Returns the L{RelLib.Person} instance's name
|
|
||||||
@rtype: str
|
|
||||||
"""
|
|
||||||
name = person.get_primary_name()
|
|
||||||
if name.sort_as == Name.FNLN:
|
|
||||||
return self._fnln(name)
|
|
||||||
elif name.sort_as == Name.PTFN:
|
|
||||||
return self._ptfn(name)
|
|
||||||
elif name.sort_as == Name.FN:
|
|
||||||
return name.first_name
|
|
||||||
else:
|
|
||||||
return self._lnfn(name)
|
|
||||||
|
|
||||||
def _empty(self,name):
|
def _fn_base(self,first):
|
||||||
return name.first_name
|
return first
|
||||||
|
|
||||||
def _empty_raw(self,raw_data):
|
|
||||||
return raw_data[_FIRSTNAME]
|
|
||||||
|
|
||||||
def _ptfn(self,name):
|
def _ptfn(self,name):
|
||||||
"""
|
"""
|
||||||
@ -259,12 +264,12 @@ class NameDisplay:
|
|||||||
|
|
||||||
return " ".join([prefix, last, first, patronymic, suffix])
|
return " ".join([prefix, last, first, patronymic, suffix])
|
||||||
|
|
||||||
def _format(self,name,format):
|
def _format_str(self,name,format_str):
|
||||||
return self._format_base(name.first_name,name.surname,name.prefix,
|
return self._format_str_base(name.first_name,name.surname,name.prefix,
|
||||||
name.suffix,name.patronymic,name.title,
|
name.suffix,name.patronymic,name.title,
|
||||||
name.call,format)
|
name.call,format_str)
|
||||||
|
|
||||||
def _format_raw(self,raw_data,format):
|
def _format_str_raw(self,raw_data,format_str):
|
||||||
surname = raw_data[_SURNAME]
|
surname = raw_data[_SURNAME]
|
||||||
prefix = raw_data[_PREFIX]
|
prefix = raw_data[_PREFIX]
|
||||||
first = raw_data[_FIRSTNAME]
|
first = raw_data[_FIRSTNAME]
|
||||||
@ -272,16 +277,16 @@ class NameDisplay:
|
|||||||
suffix = raw_data[_SUFFIX]
|
suffix = raw_data[_SUFFIX]
|
||||||
title = raw_data[_TITLE]
|
title = raw_data[_TITLE]
|
||||||
call = raw_data[_CALL]
|
call = raw_data[_CALL]
|
||||||
return self._format_base(first,surname,prefix,suffix,patronymic,
|
return self._format_str_base(first,surname,prefix,suffix,patronymic,
|
||||||
title,call,format)
|
title,call,format_str)
|
||||||
|
|
||||||
def _format_base(self,first,surname,prefix,suffix,patronymic,title,call,
|
def _format_str_base(self,first,surname,prefix,suffix,patronymic,
|
||||||
format):
|
title,call,format_str):
|
||||||
"""
|
"""
|
||||||
Generates name from a format string, e.g. '%T. %p %F %L (%p)' .
|
Generates name from a format string, e.g. '%T. %p %F %L (%p)' .
|
||||||
"""
|
"""
|
||||||
|
|
||||||
output = format
|
output = format_str
|
||||||
|
|
||||||
output = output.replace("%t",title)
|
output = output.replace("%t",title)
|
||||||
output = output.replace("%f",first)
|
output = output.replace("%f",first)
|
||||||
@ -301,6 +306,22 @@ class NameDisplay:
|
|||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def sorted(self,person):
|
||||||
|
"""
|
||||||
|
Returns a text string representing the L{RelLib.Person} instance's
|
||||||
|
L{Name} in a manner that should be used for displaying a sorted
|
||||||
|
name.
|
||||||
|
|
||||||
|
@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()
|
||||||
|
return self.sorted_name(name)
|
||||||
|
|
||||||
def sorted_name(self,name):
|
def sorted_name(self,name):
|
||||||
"""
|
"""
|
||||||
Returns a text string representing the L{Name} instance
|
Returns a text string representing the L{Name} instance
|
||||||
@ -313,7 +334,6 @@ class NameDisplay:
|
|||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
return self.fn_array[name.sort_as](name)
|
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):
|
def raw_sorted_name(self,raw_data):
|
||||||
"""
|
"""
|
||||||
@ -328,13 +348,6 @@ class NameDisplay:
|
|||||||
"""
|
"""
|
||||||
return self.raw_fn_array[raw_data[_SORT]](raw_data)
|
return self.raw_fn_array[raw_data[_SORT]](raw_data)
|
||||||
|
|
||||||
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):
|
def display(self,person):
|
||||||
"""
|
"""
|
||||||
Returns a text string representing the L{RelLib.Person} instance's
|
Returns a text string representing the L{RelLib.Person} instance's
|
||||||
@ -348,10 +361,7 @@ class NameDisplay:
|
|||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
name = person.get_primary_name()
|
name = person.get_primary_name()
|
||||||
if name.display_as == Name.LNFN:
|
return self.display_name(name)
|
||||||
return self._lnfn(name)
|
|
||||||
else:
|
|
||||||
return self._fnln(name)
|
|
||||||
|
|
||||||
def display_formal(self,person):
|
def display_formal(self,person):
|
||||||
"""
|
"""
|
||||||
@ -365,11 +375,9 @@ class NameDisplay:
|
|||||||
@returns: Returns the L{RelLib.Person} instance's name
|
@returns: Returns the L{RelLib.Person} instance's name
|
||||||
@rtype: str
|
@rtype: str
|
||||||
"""
|
"""
|
||||||
|
# FIXME: At this time, this is just duplicating display() method
|
||||||
name = person.get_primary_name()
|
name = person.get_primary_name()
|
||||||
if name.display_as == Name.LNFN:
|
return self.display_name(name)
|
||||||
return self._lnfn(name)
|
|
||||||
else:
|
|
||||||
return self._fnln(name)
|
|
||||||
|
|
||||||
def display_name(self,name):
|
def display_name(self,name):
|
||||||
"""
|
"""
|
||||||
@ -383,22 +391,23 @@ class NameDisplay:
|
|||||||
"""
|
"""
|
||||||
if name == None:
|
if name == None:
|
||||||
return ""
|
return ""
|
||||||
elif name.display_as == Name.LNFN:
|
return self.fn_array[name.display_as](name)
|
||||||
return self._lnfn(name)
|
|
||||||
elif name.display_as == Name.PTFN:
|
def display_given(self,person):
|
||||||
return self._ptfn(name)
|
name = person.get_primary_name()
|
||||||
|
if name.patronymic:
|
||||||
|
return "%s %s" % (name.first_name, name.patronymic)
|
||||||
else:
|
else:
|
||||||
return self._fnln(name)
|
return name.first_name
|
||||||
|
|
||||||
def name_grouping(self,db,person):
|
def name_grouping(self,db,person):
|
||||||
return self.name_grouping_name(db,person.primary_name)
|
return self.name_grouping_name(db,person.primary_name)
|
||||||
|
|
||||||
|
|
||||||
def name_grouping_name(self,db,pn):
|
def name_grouping_name(self,db,pn):
|
||||||
if pn.group_as:
|
if pn.group_as:
|
||||||
return pn.group_as
|
return pn.group_as
|
||||||
sv = pn.sort_as
|
sv = pn.sort_as
|
||||||
if sv <= Name.LNFN:
|
if sv == Name.LNFN:
|
||||||
return db.get_name_group_mapping(pn.surname)
|
return db.get_name_group_mapping(pn.surname)
|
||||||
elif sv == Name.PTFN:
|
elif sv == Name.PTFN:
|
||||||
return db.get_name_group_mapping(pn.patronymic)
|
return db.get_name_group_mapping(pn.patronymic)
|
||||||
|
@ -24,6 +24,13 @@
|
|||||||
Name class for GRAMPS
|
Name class for GRAMPS
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Python modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
@ -48,11 +55,19 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase):
|
|||||||
A person may have more that one name throughout his or her life.
|
A person may have more that one name throughout his or her life.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CUSTOM = -1 # user-built ordering
|
DEF = 0 # Default format (determined by gramps-wide prefs)
|
||||||
LNFN = 0 # last name first name [patronymic]
|
LNFN = 1 # last name first name [patronymic]
|
||||||
FNLN = 1 # first name last name
|
FNLN = 2 # first name last name
|
||||||
PTFN = 2 # patronymic first name
|
PTFN = 3 # patronymic first name
|
||||||
FN = 3 # first name
|
FN = 4 # first name
|
||||||
|
|
||||||
|
DEFAULT_FORMATS = [
|
||||||
|
(DEF, _("Default format (defined by GRAMPS preferences)"),''),
|
||||||
|
(LNFN, _("Family name, Given name Patronymic"),''),
|
||||||
|
(FNLN, _("Given name Family name"),''),
|
||||||
|
(PTFN, _("Patronymic, Given name"),''),
|
||||||
|
(FN, _("Given name"),'')
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self,source=None,data=None):
|
def __init__(self,source=None,data=None):
|
||||||
"""creates a new Name instance, copying from the source if provided"""
|
"""creates a new Name instance, copying from the source if provided"""
|
||||||
@ -98,8 +113,8 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase):
|
|||||||
self.patronymic = ""
|
self.patronymic = ""
|
||||||
self.sname = '@'
|
self.sname = '@'
|
||||||
self.group_as = ""
|
self.group_as = ""
|
||||||
self.sort_as = self.LNFN
|
self.sort_as = self.DEF
|
||||||
self.display_as = self.LNFN
|
self.display_as = self.DEF
|
||||||
self.call = ''
|
self.call = ''
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
|
@ -761,6 +761,7 @@ class ViewManager:
|
|||||||
self.state.db.set_researcher(owner)
|
self.state.db.set_researcher(owner)
|
||||||
|
|
||||||
self.setup_bookmarks()
|
self.setup_bookmarks()
|
||||||
|
NameDisplay.register_custom_formats(self.state.db.name_formats)
|
||||||
|
|
||||||
self.state.db.enable_signals()
|
self.state.db.enable_signals()
|
||||||
self.state.signal_change()
|
self.state.signal_change()
|
||||||
|
Loading…
Reference in New Issue
Block a user