diff --git a/ChangeLog b/ChangeLog index c3e5bb380..2b6e8ce4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-06-14 Alex Roitman + * src/NameDisplay.py: Factor out commont code. + * src/Editors/_EditName.py (_setup_fields): Remove Default item. + * src/RelLib/_Name.py (Name.DEF): Replace with CUSTOM, use LNFN in + place of previous DEF. + * src/GrampsCfg.py (add_name_panel): Add Name Display panel. + * src/GrampsDb/_ReadXML.py (stop_name): Properly set name type; + do not set conf attribute on attr, addr, and event. + 2006-06-13 Brian Matherly * src/PluginUtils/_Plugins.py: pass dbstate to report diff --git a/src/Config/__init__.py b/src/Config/__init__.py index 9535ff3d0..6bf143e04 100644 --- a/src/Config/__init__.py +++ b/src/Config/__init__.py @@ -36,6 +36,3 @@ else: from _GrampsGconfKeys import * except: from _GrampsIniKeys import * - - - diff --git a/src/Editors/_EditName.py b/src/Editors/_EditName.py index f947ebf25..b07655dfb 100644 --- a/src/Editors/_EditName.py +++ b/src/Editors/_EditName.py @@ -77,7 +77,8 @@ class EditName(EditSecondary): Utils.bold_label(self.general_label) def _post_init(self): - if self.original_group_as and self.original_group_as != self.obj.get_surname(): + if self.original_group_as and \ + (self.original_group_as != self.obj.get_surname()): self.group_over.set_active(True) def _connect_signals(self): @@ -99,18 +100,20 @@ class EditName(EditSecondary): self.top.get_widget('sort_as'), self.obj.set_sort_as, self.obj.get_sort_as, - [(_('Default (based on locale)'),RelLib.Name.DEF), - (_('Given name Family name'), RelLib.Name.FNLN), - (_('Family name Given Name'), RelLib.Name.LNFN)], + [(_('Given name Family name'), RelLib.Name.FNLN), + (_('Family name Given Name Patronymic'), RelLib.Name.LNFN), + (_('Custom'), RelLib.Name.CUSTOM), + ], self.db.readonly) self.display_as = MonitoredMenu( self.top.get_widget('display_as'), self.obj.set_display_as, self.obj.get_display_as, - [(_('Default (based on locale)'),RelLib.Name.DEF), - (_('Given name Family name'), RelLib.Name.FNLN), - (_('Family name Given Name'), RelLib.Name.LNFN)], + [(_('Given name Family name'), RelLib.Name.FNLN), + (_('Family name Given Name Patronymic'), RelLib.Name.LNFN), + (_('Custom'), RelLib.Name.CUSTOM), + ], self.db.readonly) self.given_field = MonitoredEntry( diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 2949b089b..1a8cfb219 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2005 Donald N. Allingham +# Copyright (C) 2000-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 @@ -42,6 +42,7 @@ import gtk.glade #------------------------------------------------------------------------- import Config import DateHandler +import NameDisplay import ManagedWindow from GrampsWidgets import * @@ -86,13 +87,14 @@ def get_researcher(): class GrampsPreferences(ManagedWindow.ManagedWindow): def __init__(self, uistate): - ManagedWindow.ManagedWindow.__init__(self, uistate, [], GrampsPreferences) + ManagedWindow.ManagedWindow.__init__(self,uistate,[],GrampsPreferences) tlabel = gtk.Label() - self.set_window(gtk.Dialog(_('Preferences'), - flags=gtk.DIALOG_NO_SEPARATOR, - buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)), - tlabel, _('Preferences'), None) + self.set_window( + gtk.Dialog(_('Preferences'), + flags=gtk.DIALOG_NO_SEPARATOR, + buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE)), + tlabel, _('Preferences'), None) panel = gtk.Notebook() self.window.vbox.pack_start(tlabel, padding=12) @@ -102,6 +104,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): MarkupLabel("%s" % _('General'))) panel.append_page(self.add_formats_panel(), MarkupLabel("%s" % _('Display'))) + panel.append_page(self.add_name_panel(), + MarkupLabel("%s" % _('Name Display'))) panel.append_page(self.add_prefix_panel(), MarkupLabel("%s" % _('ID Formats'))) panel.append_page(self.add_advanced_panel(), @@ -199,6 +203,30 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): for widget in [self.comp_color,self.todo_color,self.custom_color]: widget.emit('color-set') + def add_name_panel(self): + table = gtk.Table(3,3) + table.set_border_width(12) + table.set_col_spacings(6) + table.set_row_spacings(6) + + obox = gtk.combo_box_new_text() + for key,value in NameDisplay.formats.items(): + obox.append_text(value) + + active = Config.get(Config.NAME_FORMAT) + if active >= len(NameDisplay.formats): + active = 0 + obox.set_active(active) + obox.connect('changed', + lambda obj: Config.set(Config.NAME_FORMAT, + obj.get_active())) + + lwidget = BasicLabel("%s: " % _('Preset format')) + + table.attach(lwidget, 0, 1, 0, 1, yoptions=0) + table.attach(obox, 1,3,0, 1, yoptions=0) + return table + def add_formats_panel(self): table = gtk.Table(3,8) table.set_border_width(12) @@ -317,5 +345,3 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): def build_menu_names(self,obj): return (_('Preferences'),None) - - diff --git a/src/GrampsDb/_ReadXML.py b/src/GrampsDb/_ReadXML.py index f3bdc919f..a16f84e4e 100644 --- a/src/GrampsDb/_ReadXML.py +++ b/src/GrampsDb/_ReadXML.py @@ -752,7 +752,6 @@ class GrampsParser(UpdateCallback): self.event.gramps_id = gramps_id except KeyError: self.event = self.find_event_by_gramps_id(gramps_id) - self.event.conf = int(attrs.get("conf",2)) self.event.private = bool(attrs.get("priv")) def start_eventref(self,attrs): @@ -782,7 +781,6 @@ class GrampsParser(UpdateCallback): def start_attribute(self,attrs): self.attribute = RelLib.Attribute() - self.attribute.conf = int(attrs.get("conf",2)) self.attribute.private = bool(attrs.get("priv")) self.attribute.type = RelLib.AttributeType() if attrs.has_key('type'): @@ -801,7 +799,6 @@ class GrampsParser(UpdateCallback): def start_address(self,attrs): self.address = RelLib.Address() - self.address.conf = int(attrs.get("conf",2)) self.address.private = bool(attrs.get("priv")) def start_bmark(self,attrs): @@ -1013,11 +1010,13 @@ class GrampsParser(UpdateCallback): if not self.in_witness: self.name = RelLib.Name() self.name.type.set_from_xml_str(attrs['type']) - self.name.sort_as = int(attrs.get("sort",RelLib.Name.DEF)) - self.name.display_as = int(attrs.get("display",RelLib.Name.DEF)) - self.name.conf = int(attrs.get("conf",2)) self.name.set_private = bool(attrs.get("priv")) self.alt_name = bool(attrs.get("alt")) + try: + self.name.sort_as = int(attrs["sort"]) + self.name.display_as = int(attrs["display"]) + except KeyError: + pass def start_last(self,attrs): self.name.prefix = attrs.get('prefix','') @@ -1479,11 +1478,11 @@ class GrampsParser(UpdateCallback): elif self.alt_name: # former aka tag -- alternate name if self.name.get_type() == "": - self.name.set_type("Also Known As") + self.name.set_type(NameType.AKA) self.person.add_alternate_name(self.name) else: if self.name.get_type() == "": - self.name.set_type("Birth Name") + self.name.set_type(NameType.BIRTH) self.person.set_primary_name (self.name) self.name = None diff --git a/src/NameDisplay.py b/src/NameDisplay.py index ea9737a61..b0637bd0d 100644 --- a/src/NameDisplay.py +++ b/src/NameDisplay.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-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 @@ -48,6 +48,14 @@ _GROUP = 12 _SORT = 13 _DISPLAY = 14 +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"), + } + #------------------------------------------------------------------------- # # NameDisplay class @@ -57,6 +65,12 @@ class NameDisplay: """ Base class for displaying of Name instances. """ + + # FIXME: Is this used anywhere? I cannot see that it is. + sort_field = (Name.get_surname, Name.get_surname, + Name.get_first_name, Name.get_patronymic, + Name.get_first_name) + def __init__(self,use_upper=False): """ Creates a new NameDisplay class. @@ -126,23 +140,8 @@ class NameDisplay: SurnamePrefix Patronymic SurnameSuffix, FirstName """ - first = name.first_name - - if self.force_upper: - last = name.patronymic.upper() - else: - last = name.patronymic - - if name.suffix: - if name.prefix: - return "%s %s %s, %s" % (name.prefix, last, name.suffix, first) - else: - return "%s %s, %s" % (last, name.suffix, first) - else: - if name.prefix: - return "%s %s, %s" % (name.prefix, last, first) - else: - return "%s, %s" % (last, first) + return self._ptfn_base(name.first_name,name.suffix, + name.prefix,name.patronymic) def _ptfn_raw(self,raw_data): """ @@ -157,6 +156,9 @@ class NameDisplay: prefix = raw_data[_PREFIX] patronymic = raw_data[_PATRONYM] + return self._ptfn_base(first,suffix,prefix,patronymic) + + def _ptfn_base(self,first,suffix,prefix,patronymic): if self.force_upper: last = patronymic.upper() else: @@ -180,26 +182,8 @@ class NameDisplay: FirstName Patronymic SurnamePrefix Surname SurnameSuffix """ - first = name.first_name - - if name.patronymic: - first = "%s %s" % (first, name.patronymic) - - if self.force_upper: - last = name.surname.upper() - else: - last = name.surname - - if name.suffix: - if name.prefix: - return "%s %s %s, %s" % (first, name.prefix, last, name.suffix) - else: - return "%s %s, %s" % (first, last, name.suffix) - else: - if name.prefix: - return "%s %s %s" % (first, name.prefix, last) - else: - return "%s %s" % (first, last) + return self._fnln_base(name.first_name,name.surname,name.suffix, + name.prefix,name.patronymic) def _fnln_raw(self,raw_data): """ @@ -213,7 +197,9 @@ class NameDisplay: suffix = raw_data[_SUFFIX] prefix = raw_data[_PREFIX] patronymic = raw_data[_PATRONYM] + return self._fnln_base(first,surname,suffix,prefix,patronymic) + def _fnln_base(self,first,surname,suffix,prefix,patronymic): if patronymic: first = "%s %s" % (first, patronymic) @@ -240,16 +226,8 @@ class NameDisplay: SurnamePrefix Surname, FirstName Patronymic SurnameSuffix """ - if self.force_upper: - last = name.surname.upper() - else: - last = name.surname - - if last: - last += "," - - return " ".join([x for x in [name.prefix, last, name.first_name, - name.patronymic, name.suffix]]) + return self._lnfn_base(name.first_name,name.surname,name.prefix, + name.suffix,name.patronymic) def _lnfn_raw(self,raw_data): """ @@ -258,17 +236,25 @@ class NameDisplay: SurnamePrefix Surname, FirstName Patronymic SurnameSuffix """ + + surname = raw_data[_SURNAME] + prefix = raw_data[_PREFIX] + first = raw_data[_FIRSTNAME] + patronymic = raw_data[_PATRONYM] + suffix = raw_data[_SUFFIX] + + return self._lnfn_base(first,surname,prefix,suffix,patronymic) + + def _lnfn_base(self,first,surname,prefix,suffix,patronymic): if self.force_upper: - last = raw_data[_SURNAME].upper() + last = surname.upper() else: - last = raw_data[_SURNAME] + last = surname if last: last += "," - return " ".join([x for x in - [raw_data[_PREFIX], last, raw_data[_FIRSTNAME], - raw_data[_PATRONYM], raw_data[_SUFFIX]]]) + return " ".join([prefix, last, first, patronymic, suffix]) def sorted_name(self,name): """ @@ -363,10 +349,6 @@ class NameDisplay: return self.name_grouping_name(db,person.primary_name) - sort_field = (Name.get_surname, Name.get_surname, - Name.get_first_name, Name.get_patronymic, - Name.get_first_name) - def name_grouping_name(self,db,pn): if pn.group_as: return pn.group_as diff --git a/src/RelLib/_Name.py b/src/RelLib/_Name.py index 6dcee4265..18fe0edd5 100644 --- a/src/RelLib/_Name.py +++ b/src/RelLib/_Name.py @@ -55,11 +55,11 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase): A person may have more that one name throughout his or her life. """ - DEF = 0 # locale default - LNFN = 1 # last name first name [patronymic] - FNLN = 2 # first name last name - PTFN = 3 # patronymic last name - FN = 4 # first name + 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 __init__(self,source=None,data=None): """creates a new Name instance, copying from the source if provided""" @@ -105,8 +105,8 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase): self.patronymic = "" self.sname = '@' self.group_as = "" - self.sort_as = self.DEF - self.display_as = self.DEF + self.sort_as = self.LNFN + self.display_as = self.LNFN self.call = '' def serialize(self): @@ -199,8 +199,7 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase): def get_sort_as(self): """ Returns the selected sorting method for the name. The options are - DEF (default for the current locale), LNFN (last name, first name), - or FNLN (first name, last name). + LNFN (last name, first name), FNLN (first name, last name), etc. """ return self.sort_as @@ -215,8 +214,7 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase): def get_display_as(self): """ Returns the selected display format for the name. The options are - DEF (default for the current locale), LNFN (last name, first name), - or FNLN (first name, last name). + LNFN (last name, first name), FNLN (first name, last name), etc. """ return self.display_as