From ebe5229822a527abe7075830cc20f2108819bbed Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 4 Feb 2011 10:51:28 +0000 Subject: [PATCH] 4599: regression from 3.2.5 - name format preference doesn't persist across reloads svn: r16565 --- src/cli/grampscli.py | 3 +-- src/gen/display/name.py | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/cli/grampscli.py b/src/cli/grampscli.py index 4046e522e..ac0803d19 100644 --- a/src/cli/grampscli.py +++ b/src/cli/grampscli.py @@ -266,8 +266,7 @@ class CLIManager(object): name_displayer.set_name_format(self.dbstate.db.name_formats) fmt_default = config.get('preferences.name-format') - if fmt_default < 0: - name_displayer.set_default_format(fmt_default) + name_displayer.set_default_format(fmt_default) self.dbstate.db.enable_signals() self.dbstate.signal_change() diff --git a/src/gen/display/name.py b/src/gen/display/name.py index 4b718a10f..d4a65b8c3 100644 --- a/src/gen/display/name.py +++ b/src/gen/display/name.py @@ -222,17 +222,22 @@ class NameDisplay(object): def __init__(self): global WITH_GRAMP_CONFIG self.name_formats = {} + #preinit the name formats, this should be updated with the data + #in the database once a database is loaded self.set_name_format(self.STANDARD_FORMATS) if WITH_GRAMPS_CONFIG: self.default_format = config.get('preferences.name-format') - if self.default_format == 0 \ - or self.default_format not in Name.NAMEFORMATS : + if self.default_format == 0: self.default_format = Name.LNFN config.set('preferences.name-format', self.default_format) else: self.default_format = Name.LNFN - + + #following has little sense as the database name formats are not + #loaded yet, but we do it to set up everything + #when loading a database, name formats must be loaded and + #default format set again! self.set_default_format(self.default_format) def _format_fn(self, fmt_str): @@ -258,18 +263,22 @@ class NameDisplay(object): return ' '.join(result.split()) def set_name_format(self, formats): + raw_func_dict = { Name.LNFN : self._raw_lnfn, Name.FNLN : self._raw_fnln, Name.FN : self._raw_fn, } - for (num, name, fmt_str, act) in formats: - func = self._format_fn(fmt_str) - func_raw = raw_func_dict.get(num) - if func_raw is None: - func_raw = self._format_raw_fn(fmt_str) - self.name_formats[num] = (name, fmt_str, act, func, func_raw) + #remove data from previous database + self.name_formats = {} + for tformats in [self.STANDARD_FORMATS, formats]: + for (num, name, fmt_str, act) in tformats: + func = self._format_fn(fmt_str) + func_raw = raw_func_dict.get(num) + if func_raw is None: + func_raw = self._format_raw_fn(fmt_str) + self.name_formats[num] = (name, fmt_str, act, func, func_raw) def add_name_format(self, name, fmt_str): num = -1 @@ -292,6 +301,10 @@ class NameDisplay(object): def set_default_format(self, num): if num not in self.name_formats: num = Name.LNFN + # if user sets default format to the Gramps default format, + # then we select LNFN as format. + if num == Name.DEF: + num = Name.LNFN self.default_format = num