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:
Alex Roitman 2006-07-06 17:46:46 +00:00
parent 1d03a4efb1
commit 154787c06c
11 changed files with 218 additions and 142 deletions

View File

@ -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>
* src/Editors/_EditChildRef.py: fix title
* src/Editors/_EditFamily.py: call sequence for EditChildRef

View File

@ -96,24 +96,24 @@ class EditName(EditSecondary):
if not self.original_group_as:
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.top.get_widget('sort_as'),
self.obj.set_sort_as,
self.obj.get_sort_as,
[(_('Given name Family name'), RelLib.Name.FNLN),
(_('Family name Given Name Patronymic'), RelLib.Name.LNFN),
(_('Custom'), RelLib.Name.CUSTOM),
],
format_list,
self.db.readonly)
self.display_as = MonitoredMenu(
self.top.get_widget('display_as'),
self.obj.set_display_as,
self.obj.get_display_as,
[(_('Given name Family name'), RelLib.Name.FNLN),
(_('Family name Given Name Patronymic'), RelLib.Name.LNFN),
(_('Custom'), RelLib.Name.CUSTOM),
],
format_list,
self.db.readonly)
self.given_field = MonitoredEntry(

View File

@ -213,76 +213,84 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
_('C_ustom format details'))
self.name_exp.set_sensitive(False)
obox = gtk.combo_box_new_text()
for key,value in NameDisplay.formats.items():
obox.append_text(value)
try:
active = int(Config.get(Config.NAME_FORMAT))
if active >= len(NameDisplay.formats):
active = 0
except ValueError: # not an integer-convertible string => custom
active = len(NameDisplay.formats)
self.name_exp.set_sensitive(True)
format_list = [(name,number) for (number,name,fmt_str)
in Name.DEFAULT_FORMATS]
format_list += [(name,number) for (number,name,fmt_str)
in NameDisplay.CUSTOM_FORMATS]
obox.set_active(active)
obox.connect('changed', self.name_changed)
obox = gtk.ComboBox()
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_model(obox_model)
#active = int(Config.get(Config.NAME_FORMAT))
#obox.set_active(active)
# obox.connect('changed', self.name_changed)
lwidget = BasicLabel("%s: " % _('Preset format'))
custom_ui = self.build_custom_name_ui()
self.name_exp.add(custom_ui)
# custom_ui = self.build_custom_name_ui()
# self.name_exp.add(custom_ui)
table.attach(lwidget, 0, 1, 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
def build_custom_name_ui(self):
table = gtk.Table(2,3)
table.set_border_width(6)
table.set_col_spacings(6)
table.set_row_spacings(6)
## def build_custom_name_ui(self):
## table = gtk.Table(2,3)
## table.set_border_width(6)
## table.set_col_spacings(6)
## table.set_row_spacings(6)
avail_sw = gtk.ScrolledWindow()
avail_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
avail_tree = gtk.TreeView()
avail_sw.add(avail_tree)
## avail_sw = gtk.ScrolledWindow()
## avail_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
## avail_tree = gtk.TreeView()
## avail_sw.add(avail_tree)
use_sw = gtk.ScrolledWindow()
use_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
use_tree = gtk.TreeView()
use_sw.add(use_tree)
## use_sw = gtk.ScrolledWindow()
## use_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
## use_tree = gtk.TreeView()
## 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)
down_button = _set_button(gtk.STOCK_GO_DOWN)
add_button = _set_button(gtk.STOCK_ADD)
remove_button = _set_button(gtk.STOCK_REMOVE)
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(down_button, 1, 2, 2, 3, xoptions = 0, yoptions=0)
button_table.attach(add_button, 0, 1, 1, 2, xoptions = 0,yoptions=0)
## up_button = _set_button(gtk.STOCK_GO_UP)
## down_button = _set_button(gtk.STOCK_GO_DOWN)
## add_button = _set_button(gtk.STOCK_ADD)
## remove_button = _set_button(gtk.STOCK_REMOVE)
## 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(down_button, 1, 2, 2, 3, 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.set_use_markup(True)
## example_label = gtk.Label('<b>%s</b>' % _('Example'))
## example_label.set_use_markup(True)
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(button_table, 1, 2, 1, 2, xoptions = 0, yoptions=0)
table.attach(use_sw, 2,3,1,2, yoptions=gtk.FILL)
## 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(button_table, 1, 2, 1, 2, xoptions = 0, yoptions=0)
## table.attach(use_sw, 2,3,1,2, yoptions=gtk.FILL)
return table
## return table
def name_changed(self,obj):
custom_text = NameDisplay.formats[Name.CUSTOM]
if obj.get_active_text() == custom_text:
self.name_exp.set_sensitive(True)
self.name_exp.set_expanded(True)
else:
Config.set(Config.NAME_FORMAT,obj.get_active())
self.name_exp.set_expanded(False)
self.name_exp.set_sensitive(False)
## def name_changed(self,obj):
## return
## custom_text = NameDisplay.formats[Name.CUSTOM]
## if obj.get_active_text() == custom_text:
## self.name_exp.set_sensitive(True)
## self.name_exp.set_expanded(True)
## else:
## Config.set(Config.NAME_FORMAT,obj.get_active())
## self.name_exp.set_expanded(False)
## self.name_exp.set_sensitive(False)
def add_formats_panel(self):
table = gtk.Table(3,8)

View File

@ -238,6 +238,9 @@ def db_copy(from_db,to_db,callback):
to_db.media_bookmarks = from_db.media_bookmarks
to_db.repo_bookmarks = from_db.repo_bookmarks
# Copy name formats
to_db.name_formats = from_db.name_formats
# Copy gender stats
to_db.genderStats = from_db.genderStats

View File

@ -383,6 +383,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
return 1
def _load_metadata(self):
# name display formats
self.name_formats = self.metadata.get('name_formats',[])
# bookmarks
self.bookmarks = self.metadata.get('bookmarks',[])
self.family_bookmarks = self.metadata.get('family_bookmarks',[])
@ -805,6 +807,8 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
def _close_metadata(self):
if not self.readonly:
# name display formats
self.metadata['name_formats'] = self.name_formats
# bookmarks
self.metadata['bookmarks'] = self.bookmarks
self.metadata['family_bookmarks'] = self.family_bookmarks

View File

@ -273,6 +273,7 @@ class GrampsDbBase(GrampsDBCallback):
self.undo_history_timestamp = 0
self.default = None
self.owner = Researcher()
self.name_formats = []
self.bookmarks = []
self.family_bookmarks = []
self.event_bookmarks = []

View File

@ -361,6 +361,8 @@ class GrampsParser(UpdateCallback):
"attr_value" : (None,self.stop_attr_value),
"bookmark" : (self.start_bmark, None),
"bookmarks" : (None, None),
"format" : (self.start_format, None),
"name-formats" : (None, None),
"child" : (self.start_child,None),
"childof" : (self.start_childof,None),
"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.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):
self.update(self.p.CurrentLineNumber)
new_id = self.map_gid(attrs['id'])

View File

@ -310,6 +310,9 @@ class XmlWriter(UpdateCallback):
# Data is written, now write bookmarks.
self.write_bookmarks()
# Also write name formats
self.write_name_formats()
self.g.write("</database>\n")
def write_bookmarks(self):
@ -350,6 +353,14 @@ class XmlWriter(UpdateCallback):
% handle )
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):
l = line.strip()
l = l.replace('&','&amp;')

View File

@ -24,14 +24,13 @@
Class handling language-specific displaying of names.
"""
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from RelLib import Name
import Config
#-------------------------------------------------------------------------
#
@ -51,13 +50,15 @@ _SORT = 13
_DISPLAY = 14
_CALL = 15
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"),
}
#-------------------------------------------------------------------------
#
# formats registration
#
#-------------------------------------------------------------------------
CUSTOM_FORMATS = []
def register_custom_formats(formats):
CUSTOM_FORMATS = formats[:]
#-------------------------------------------------------------------------
#
@ -82,15 +83,38 @@ class NameDisplay:
displayed in upper case.
@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.fn_array = [
self._lnfn, self._lnfn, self._fnln,
self._ptfn, self._empty ]
self.fn_array = {
Name.LNFN: self._lnfn,
Name.FNLN: self._fnln,
Name.PTFN: self._ptfn,
Name.FN: self._fn,
}
self.raw_fn_array = (
self._lnfn_raw, self._lnfn_raw, self._fnln_raw,
self._ptfn_raw, self._empty_raw )
self.raw_fn_array = {
Name.LNFN: self._lnfn_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):
"""
@ -106,34 +130,15 @@ class NameDisplay:
def sort_string(self,name):
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
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.
def _fn(self,name):
return self._fn_base(name.first_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()
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 _fn_raw(self,raw_data):
first = raw_data[_FIRSTNAME]
return self._fn_base(first)
def _empty(self,name):
return name.first_name
def _empty_raw(self,raw_data):
return raw_data[_FIRSTNAME]
def _fn_base(self,first):
return first
def _ptfn(self,name):
"""
@ -259,12 +264,12 @@ class NameDisplay:
return " ".join([prefix, last, first, patronymic, suffix])
def _format(self,name,format):
return self._format_base(name.first_name,name.surname,name.prefix,
name.suffix,name.patronymic,name.title,
name.call,format)
def _format_str(self,name,format_str):
return self._format_str_base(name.first_name,name.surname,name.prefix,
name.suffix,name.patronymic,name.title,
name.call,format_str)
def _format_raw(self,raw_data,format):
def _format_str_raw(self,raw_data,format_str):
surname = raw_data[_SURNAME]
prefix = raw_data[_PREFIX]
first = raw_data[_FIRSTNAME]
@ -272,16 +277,16 @@ class NameDisplay:
suffix = raw_data[_SUFFIX]
title = raw_data[_TITLE]
call = raw_data[_CALL]
return self._format_base(first,surname,prefix,suffix,patronymic,
title,call,format)
return self._format_str_base(first,surname,prefix,suffix,patronymic,
title,call,format_str)
def _format_base(self,first,surname,prefix,suffix,patronymic,title,call,
format):
def _format_str_base(self,first,surname,prefix,suffix,patronymic,
title,call,format_str):
"""
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("%f",first)
@ -301,6 +306,22 @@ class NameDisplay:
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):
"""
Returns a text string representing the L{Name} instance
@ -313,7 +334,6 @@ class NameDisplay:
@rtype: str
"""
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):
"""
@ -328,13 +348,6 @@ class NameDisplay:
"""
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):
"""
Returns a text string representing the L{RelLib.Person} instance's
@ -348,10 +361,7 @@ class NameDisplay:
@rtype: str
"""
name = person.get_primary_name()
if name.display_as == Name.LNFN:
return self._lnfn(name)
else:
return self._fnln(name)
return self.display_name(name)
def display_formal(self,person):
"""
@ -365,11 +375,9 @@ class NameDisplay:
@returns: Returns the L{RelLib.Person} instance's name
@rtype: str
"""
# FIXME: At this time, this is just duplicating display() method
name = person.get_primary_name()
if name.display_as == Name.LNFN:
return self._lnfn(name)
else:
return self._fnln(name)
return self.display_name(name)
def display_name(self,name):
"""
@ -383,22 +391,23 @@ class NameDisplay:
"""
if name == None:
return ""
elif name.display_as == Name.LNFN:
return self._lnfn(name)
elif name.display_as == Name.PTFN:
return self._ptfn(name)
return self.fn_array[name.display_as](name)
def display_given(self,person):
name = person.get_primary_name()
if name.patronymic:
return "%s %s" % (name.first_name, name.patronymic)
else:
return self._fnln(name)
return name.first_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:
if sv == Name.LNFN:
return db.get_name_group_mapping(pn.surname)
elif sv == Name.PTFN:
return db.get_name_group_mapping(pn.patronymic)

View File

@ -24,6 +24,13 @@
Name class for GRAMPS
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# 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.
"""
CUSTOM = -1 # user-built ordering
LNFN = 0 # last name first name [patronymic]
FNLN = 1 # first name last name
PTFN = 2 # patronymic first name
FN = 3 # first name
DEF = 0 # Default format (determined by gramps-wide prefs)
LNFN = 1 # last name first name [patronymic]
FNLN = 2 # first name last name
PTFN = 3 # patronymic 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):
"""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.sname = '@'
self.group_as = ""
self.sort_as = self.LNFN
self.display_as = self.LNFN
self.sort_as = self.DEF
self.display_as = self.DEF
self.call = ''
def serialize(self):

View File

@ -761,6 +761,7 @@ class ViewManager:
self.state.db.set_researcher(owner)
self.setup_bookmarks()
NameDisplay.register_custom_formats(self.state.db.name_formats)
self.state.db.enable_signals()
self.state.signal_change()