2006-06-24 Alex Roitman <shura@gramps-project.org>

* src/NameDisplay.py (_format_base): Add format string display;
	(_format_raw, _format): Add format string methods.
	* src/GrampsCfg.py (name_changed): Switch back to int key.
	* data/gramps.schemas.in: Add name-format-str key for custom name
	display format string.
	* src/Config/_GrampsConfigKeys.py: Re-generate the file.
	* src/Config/gen_schema_keys.py (copy): Add Id string; 
	Write header into the generated file.



svn: r6967
This commit is contained in:
Alex Roitman 2006-06-25 05:39:32 +00:00
parent 210a66996d
commit cfd5ae93fb
6 changed files with 110 additions and 14 deletions

View File

@ -1,3 +1,13 @@
2006-06-24 Alex Roitman <shura@gramps-project.org>
* src/NameDisplay.py (_format_base): Add format string display;
(_format_raw, _format): Add format string methods.
* src/GrampsCfg.py (name_changed): Switch back to int key.
* data/gramps.schemas.in: Add name-format-str key for custom name
display format string.
* src/Config/_GrampsConfigKeys.py: Re-generate the file.
* src/Config/gen_schema_keys.py (copy): Add Id string;
Write header into the generated file.
2006-06-24 Brian Matherly <brian@gramps-project.org>
* src/plugins/BookReport.py: fix book loading

View File

@ -404,19 +404,34 @@
<key>/schemas/apps/gramps/preferences/name-format</key>
<applyto>/apps/gramps/preferences/name-format</applyto>
<owner>gramps</owner>
<type>string</type>
<type>int</type>
<default>0</default>
<locale name="C">
<short>Name display format</short>
<long>This key determines the name display format.
Use "0" for "Surname, Firstname",
"1" for "Firstname Surname",
"2" for "Patronymic Firstname",
and "3" for "Firstname" style.
For custom styles, use a string where every character denotes
the name component as follows: "f" for firstname, "s" for surname,
"t" for title, "p" for prefix", "u" for suffix", "a" for patronymic,
"c" for callname". </long>
<long>This key determines the name display format. Use
0 for "Surname, Firstname",
1 for "Firstname Surname",
2 for "Patronymic Firstname", and
3 for "Firstname" style.
For custom styles, use -1 and set the name-format-str key.</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gramps/preferences/name-format-str</key>
<applyto>/apps/gramps/preferences/name-format-str</applyto>
<owner>gramps</owner>
<type>string</type>
<default></default>
<locale name="C">
<short>Name display format string</short>
<long>This key determines the custom name display format.
Its value is unimportant unless the name-format keyis set to -1.
When used, the following substitutions are made:
%t -> title, %f -> given name, %p -> prefix, %s -> suffix,
%l -> family name, %y -> patronymic, %c -> call name.
The capital letters are substituted for capitalized name components.
The %% is substituted with the single % character.</long>
</locale>
</schema>

View File

@ -1,3 +1,25 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2006 Donald N. Allingham
#
# 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$
RELATION_SHADE = ('preferences','relation-shade', 0)
ONLINE_MAPS = ('preferences','online-maps', 0)
FAMILY_DETAILS = ('preferences','family-details', 0)
@ -30,7 +52,8 @@ PAPER_PREFERENCE = ('preferences','paper-preference', 2)
RECENT_FILE = ('paths','recent-file', 2)
RECENT_IMPORT_DIR = ('paths','recent-import-dir', 2)
RECENT_EXPORT_DIR = ('paths','recent-export-dir', 2)
NAME_FORMAT = ('preferences','name-format', 2)
NAME_FORMAT = ('preferences','name-format', 1)
NAME_FORMAT_STR = ('preferences','name-format-str', 2)
REPORT_DIRECTORY = ('paths','report-directory', 2)
RESEARCHER_ADDR = ('researcher','researcher-addr', 2)
RESEARCHER_CITY = ('researcher','researcher-city', 2)
@ -86,7 +109,8 @@ default_value = {
RECENT_FILE : '',
RECENT_IMPORT_DIR : '',
RECENT_EXPORT_DIR : '',
NAME_FORMAT : '0',
NAME_FORMAT : 0,
NAME_FORMAT_STR : '',
REPORT_DIRECTORY : './',
RESEARCHER_ADDR : '',
RESEARCHER_CITY : '',

View File

@ -17,6 +17,9 @@ copy = """#
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
"""
from xml.parsers.expat import ExpatError, ParserCreate
@ -84,6 +87,7 @@ if __name__ == "__main__":
parser.parse(sys.argv[1])
f = open("_GrampsConfigKeys.py","w")
f.write(copy)
for (key, key_type, default, long, short, include) in parser.list:
data = key.split('/')

View File

@ -280,7 +280,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
self.name_exp.set_sensitive(True)
self.name_exp.set_expanded(True)
else:
Config.set(Config.NAME_FORMAT,str(obj.get_active()))
Config.set(Config.NAME_FORMAT,obj.get_active())
self.name_exp.set_expanded(False)
self.name_exp.set_sensitive(False)

View File

@ -47,6 +47,7 @@ _SNAME = 11
_GROUP = 12
_SORT = 13
_DISPLAY = 14
_CALL = 15
formats = {
Name.LNFN: _("Family name, Given name Patronymic"),
@ -227,7 +228,7 @@ class NameDisplay:
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
"""
return self._lnfn_base(name.first_name,name.surname,name.prefix,
name.suffix,name.patronymic)
name.suffix,name.patronymic)
def _lnfn_raw(self,raw_data):
"""
@ -256,6 +257,48 @@ 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_raw(self,raw_data,format):
surname = raw_data[_SURNAME]
prefix = raw_data[_PREFIX]
first = raw_data[_FIRSTNAME]
patronymic = raw_data[_PATRONYM]
suffix = raw_data[_SUFFIX]
title = raw_data[_TITLE]
call = raw_data[_CALL]
return self._format_base(first,surname,prefix,suffix,patronymic,
title,call,format)
def _format_base(self,first,surname,prefix,suffix,patronymic,title,call,
format):
"""
Generates name from a format string, e.g. '%T. %p %F %L (%p)' .
"""
output = format
output = output.replace("%t",title)
output = output.replace("%f",first)
output = output.replace("%p",prefix)
output = output.replace("%l",surname)
output = output.replace("%s",suffix)
output = output.replace("%y",patronymic)
output = output.replace("%c",call)
output = output.replace("%T",title.upper())
output = output.replace("%F",first.upper())
output = output.replace("%P",prefix.upper())
output = output.replace("%L",surname.upper())
output = output.replace("%S",suffix.upper())
output = output.replace("%Y",patronymic.upper())
output = output.replace("%C",call.upper())
output = output.replace("%%",'%')
return output
def sorted_name(self,name):
"""
Returns a text string representing the L{Name} instance