From cfd5ae93fbcecfe537ba04a2210c8d79126dd185 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sun, 25 Jun 2006 05:39:32 +0000 Subject: [PATCH] 2006-06-24 Alex Roitman * 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 --- gramps2/ChangeLog | 10 ++++++ gramps2/data/gramps.schemas.in | 35 +++++++++++++------ gramps2/src/Config/_GrampsConfigKeys.py | 28 +++++++++++++-- gramps2/src/Config/gen_schema_keys.py | 4 +++ gramps2/src/GrampsCfg.py | 2 +- gramps2/src/NameDisplay.py | 45 ++++++++++++++++++++++++- 6 files changed, 110 insertions(+), 14 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 6779fd9e1..3f943d81c 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,13 @@ +2006-06-24 Alex Roitman + * 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 * src/plugins/BookReport.py: fix book loading diff --git a/gramps2/data/gramps.schemas.in b/gramps2/data/gramps.schemas.in index c1dc9c166..c76a0b580 100644 --- a/gramps2/data/gramps.schemas.in +++ b/gramps2/data/gramps.schemas.in @@ -404,19 +404,34 @@ /schemas/apps/gramps/preferences/name-format /apps/gramps/preferences/name-format gramps - string + int 0 Name display format - 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". + 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. + + + + + /schemas/apps/gramps/preferences/name-format-str + /apps/gramps/preferences/name-format-str + gramps + string + + + Name display format string + 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. diff --git a/gramps2/src/Config/_GrampsConfigKeys.py b/gramps2/src/Config/_GrampsConfigKeys.py index 27589148b..e159badbf 100644 --- a/gramps2/src/Config/_GrampsConfigKeys.py +++ b/gramps2/src/Config/_GrampsConfigKeys.py @@ -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 : '', diff --git a/gramps2/src/Config/gen_schema_keys.py b/gramps2/src/Config/gen_schema_keys.py index 497ba997d..b9b98f872 100644 --- a/gramps2/src/Config/gen_schema_keys.py +++ b/gramps2/src/Config/gen_schema_keys.py @@ -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('/') diff --git a/gramps2/src/GrampsCfg.py b/gramps2/src/GrampsCfg.py index 371d85c0d..504c48ab0 100644 --- a/gramps2/src/GrampsCfg.py +++ b/gramps2/src/GrampsCfg.py @@ -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) diff --git a/gramps2/src/NameDisplay.py b/gramps2/src/NameDisplay.py index b0637bd0d..d737e90c3 100644 --- a/gramps2/src/NameDisplay.py +++ b/gramps2/src/NameDisplay.py @@ -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