From 90832a683eb51c96208e059fe9bdac650e38416a Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 19 Apr 2006 18:27:51 +0000 Subject: [PATCH] In .: * src/RelLib/Makefile.am: Ship new file. * src/PluginUtils/_ReportUtils.py: Use fam relations from new module. * src/Relationship.py: Use family relations from new module. * src/Utils.py: Remove family relations. * src/RelLib/__init__.py: Expose new module. * src/RelLib/_Family.py: Adapt to new types. * src/GrampsDb/_ReadXML.py: Adapt to new types. * src/GrampsDb/_ConstXML.py: Remove family relations. * src/RelLib/_FamilyRelType.py: Add new class In po: 2006-04-19 Alex Roitman * POTFILES.in: Add new files. svn: r6369 --- ChangeLog | 9 ++++++ po/ChangeLog | 3 ++ po/POTFILES.in | 4 +++ src/GrampsDb/_ConstXML.py | 14 ++++----- src/GrampsDb/_ReadXML.py | 17 ++++++----- src/PluginUtils/_ReportUtils.py | 16 +++++------ src/RelLib/Makefile.am | 3 +- src/RelLib/_Family.py | 33 ++++++++++------------ src/RelLib/_FamilyRelType.py | 50 +++++++++++++++++++++++++++++++++ src/RelLib/__init__.py | 2 +- src/Relationship.py | 10 +++---- src/Utils.py | 42 +++++++++++++-------------- 12 files changed, 135 insertions(+), 68 deletions(-) create mode 100644 src/RelLib/_FamilyRelType.py diff --git a/ChangeLog b/ChangeLog index 16ac923a6..d9ce71f00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ 2006-04-19 Alex Roitman + * src/RelLib/Makefile.am: Ship new file. + * src/PluginUtils/_ReportUtils.py: Use fam relations from new module. + * src/Relationship.py: Use family relations from new module. + * src/Utils.py: Remove family relations. + * src/RelLib/__init__.py: Expose new module. + * src/RelLib/_Family.py: Adapt to new types. + * src/GrampsDb/_ReadXML.py: Adapt to new types. + * src/GrampsDb/_ConstXML.py: Remove family relations. + * src/RelLib/_FamilyRelType.py: Add new class * src/RelLib/_Event.py: Add "personal" attribute to events. * src/RelLib/_Event.py: Revert this change. diff --git a/po/ChangeLog b/po/ChangeLog index 9c6cf32eb..3e5567127 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,6 @@ +2006-04-19 Alex Roitman + * POTFILES.in: Add new files. + 2006-04-06 Alex Roitman * POTFILES.in: Add new files to the list. * gramps.pot: regenerate the template. diff --git a/po/POTFILES.in b/po/POTFILES.in index 41829c3d5..65060375f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -280,6 +280,10 @@ src/RelLib/_Url.py src/RelLib/_Witness.py src/TreeViews/__init__.py src/TreeViews/_PersonTreeView.py +src/RelLib/_FamilyRelType.py +src/RelLib/_UrlType.py +src/RelLib/_NameType.py +src/RelLib/_ChildRefType.py # # Glade files # diff --git a/src/GrampsDb/_ConstXML.py b/src/GrampsDb/_ConstXML.py index 754b29687..0bcb5f921 100644 --- a/src/GrampsDb/_ConstXML.py +++ b/src/GrampsDb/_ConstXML.py @@ -94,12 +94,12 @@ attributes = ( (RelLib.Attribute.SSN , "Social Security Number"), ) -family_relations = ( - (RelLib.Family.MARRIED , "Married"), - (RelLib.Family.UNMARRIED , "Unmarried"), - (RelLib.Family.CIVIL_UNION , "Civil Union"), - (RelLib.Family.UNKNOWN , "Unknown"), - ) +## family_relations = ( +## (RelLib.Family.MARRIED , "Married"), +## (RelLib.Family.UNMARRIED , "Unmarried"), +## (RelLib.Family.CIVIL_UNION , "Civil Union"), +## (RelLib.Family.UNKNOWN , "Unknown"), +## ) # name_types = ( # (RelLib.NameType.UNKNOWN , "Unknown"), @@ -168,7 +168,7 @@ marker_types = ( custom_types = { events : RelLib.Event.CUSTOM, attributes : RelLib.Attribute.CUSTOM, - family_relations : RelLib.Family.CUSTOM, +# family_relations : RelLib.Family.CUSTOM, # name_types : RelLib.NameType.CUSTOM, source_media_types : RelLib.RepoRef.CUSTOM, event_roles : RelLib.EventRef.CUSTOM, diff --git a/src/GrampsDb/_ReadXML.py b/src/GrampsDb/_ReadXML.py index 37ab0c6ca..d6a0cdb0a 100644 --- a/src/GrampsDb/_ReadXML.py +++ b/src/GrampsDb/_ReadXML.py @@ -769,18 +769,21 @@ class GrampsParser: self.eventref.private = bool(attrs.get('priv')) self.eventref.role = _ConstXML.tuple_from_xml(_ConstXML.event_roles, attrs.get('role','')) + # We count here on events being already parsed prior to parsing + # people or families. This code will fail if this is not true. + event = self.db.get_event_from_handle(self.eventref.ref) if self.family: + event.personal = False self.family.add_event_ref(self.eventref) elif self.person: - # We count here on events being already parsed prior - # to parsing people. This will fail if this is not true. - event = self.db.get_event_from_handle(self.eventref.ref) + event.personal = True if event.type[0] == RelLib.Event.BIRTH: self.person.birth_ref = self.eventref elif event.type[0] == RelLib.Event.DEATH: self.person.death_ref = self.eventref else: self.person.add_event_ref(self.eventref) + def start_attribute(self,attrs): self.attribute = RelLib.Attribute() @@ -919,8 +922,8 @@ class GrampsParser: self.family = self.find_family_by_gramps_id(gramps_id) # GRAMPS LEGACY: the type now belongs to tag # Here we need to support old format of - self.family.type = _ConstXML.tuple_from_xml( - _ConstXML.family_relations,attrs.get("type",'Unknown')) + self.family.type = RelLib.FamilyRelType().set_from_xml_str( + attrs.get("type",'Unknown')) # Old and new markers: complete=1 and marker=word both have to work if attrs.get('complete'): # this is only true for complete=1 @@ -930,8 +933,8 @@ class GrampsParser: _ConstXML.marker_types,attrs.get("marker",'')) def start_rel(self,attrs): - self.family.type = _ConstXML.tuple_from_xml( - _ConstXML.family_relations,attrs.get("type",'Unknown')) + self.family.type = RelLib.FamilyRelType().set_from_xml_str( + attrs.get("type",'Unknown')) def start_file(self,attrs): self.object.mime = attrs['mime'] diff --git a/src/PluginUtils/_ReportUtils.py b/src/PluginUtils/_ReportUtils.py index d76a55bcc..14043b769 100644 --- a/src/PluginUtils/_ReportUtils.py +++ b/src/PluginUtils/_ReportUtils.py @@ -815,10 +815,10 @@ child_mother = { # #------------------------------------------------------------------------- _rtype = { - RelLib.Family.UNMARRIED : _("unmarried"), - RelLib.Family.CIVIL_UNION : _("civil union"), - RelLib.Family.UNKNOWN : _("Unknown"), - RelLib.Family.CUSTOM : _("Other"), + RelLib.FamilyRelType.UNMARRIED : _("unmarried"), + RelLib.FamilyRelType.CIVIL_UNION : _("civil union"), + RelLib.FamilyRelType.UNKNOWN : _("Unknown"), + RelLib.FamilyRelType.CUSTOM : _("Other"), } #------------------------------------------------------------------------- @@ -1680,14 +1680,14 @@ def married_rel_str(database,person,family,is_first=True): relationship = family.get_relationship()[0] if is_first: - if relationship == RelLib.Family.MARRIED: + if relationship == RelLib.FamilyRelType.MARRIED: if person.get_gender() == RelLib.Person.MALE: text = _('He married %(spouse)s.') % values elif person.get_gender() == RelLib.Person.FEMALE: text = _('She married %(spouse)s.') % values else: text = _('This person married %(spouse)s.') % values - elif relationship == RelLib.Family.UNMARRIED: + elif relationship == RelLib.FamilyRelType.UNMARRIED: if person.get_gender() == RelLib.Person.MALE: text = _('He had an unmarried relationship with %(spouse)s.') % values elif person.get_gender() == RelLib.Person.FEMALE: @@ -1702,14 +1702,14 @@ def married_rel_str(database,person,family,is_first=True): else: text = _('This person had relationship with %(spouse)s.') % values else: - if relationship == RelLib.Family.MARRIED: + if relationship == RelLib.FamilyRelType.MARRIED: if person.get_gender() == RelLib.Person.MALE: text = _('He also married %(spouse)s.') % values elif person.get_gender() == RelLib.Person.FEMALE: text = _('She also married %(spouse)s.') % values else: text = _('This person also married %(spouse)s.') % values - elif relationship == RelLib.Family.UNMARRIED: + elif relationship == RelLib.FamilyRelType.UNMARRIED: if person.get_gender() == RelLib.Person.MALE: text = _('He had an unmarried relationship with %(spouse)s.') % values elif person.get_gender() == RelLib.Person.FEMALE: diff --git a/src/RelLib/Makefile.am b/src/RelLib/Makefile.am index 1f76f65c9..6abf7ada9 100644 --- a/src/RelLib/Makefile.am +++ b/src/RelLib/Makefile.am @@ -51,7 +51,8 @@ pkgdata_PYTHON = \ _SourceBase.py\ _RefBase.py\ _ChildRef.py\ - _ChildRefType.py + _ChildRefType.py\ + _FamilyRelType.py pkgpyexecdir = @pkgpyexecdir@/RelLib pkgpythondir = @pkgpythondir@/RelLib diff --git a/src/RelLib/_Family.py b/src/RelLib/_Family.py index 7def4a1dd..ad860b6a9 100644 --- a/src/RelLib/_Family.py +++ b/src/RelLib/_Family.py @@ -44,6 +44,7 @@ from _AttributeBase import AttributeBase from _EventRef import EventRef from _LdsOrdBase import LdsOrdBase from _ChildRef import ChildRef +from _FamilyRelType import FamilyRelType #------------------------------------------------------------------------- # @@ -73,12 +74,6 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, or the changes will be lost. """ - MARRIED = 0 - UNMARRIED = 1 - CIVIL_UNION = 2 - UNKNOWN = 3 - CUSTOM = 4 - def __init__(self): """ Creates a new Family instance. After initialization, most @@ -94,7 +89,7 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, self.father_handle = None self.mother_handle = None self.child_ref_list = [] - self.type = (Family.MARRIED,'') + self.type = (FamilyRelType.MARRIED,'') self.event_ref_list = [] self.lds_seal = None self.complete = 0 @@ -287,17 +282,17 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, first item is an integer constant and whose second item is the string. The valid values are: - - C{Family.MARRIED} : indicates a legally recognized married + - C{FamilyRelType.MARRIED} : indicates a legally recognized married relationship between two individuals. This may be either an opposite or a same sex relationship. - - C{Family.UNMARRIED} : indicates a relationship between two + - C{FamilyRelType.UNMARRIED} : indicates a relationship between two individuals that is not a legally recognized relationship. - - C{Family.CIVIL_UNION} : indicates a legally recongnized, + - C{FamilyRelType.CIVIL_UNION} : indicates a legally recongnized, non-married relationship between two individuals of the same sex. - - C{Family.UNKNOWN} : indicates that the type of relationship + - C{FamilyRelType.UNKNOWN} : indicates that the type of relationship between the two individuals is not know. - - C{Family.CUSTOM} : indicates that the type of relationship + - C{FamilyRelType.CUSTOM} : indicates that the type of relationship between the two individuals does not match any of the other types. @@ -305,15 +300,17 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, between the father and mother of the relationship. @type relationship_type: tuple """ - if not type(relationship_type) == tuple: - if relationship_type in [Family.MARRIED,Family.UNMARRIED, - Family.CIVIL_UNION,Family.UNKNOWN, - Family.CUSTOM]: - warn( "set_relationship now takes a tuple", + if not isinstance(relationship_type,FamilyRelType): + if relationship_type in [FamilyRelType.MARRIED, + FamilyRelType.UNMARRIED, + FamilyRelType.CIVIL_UNION, + FamilyRelType.UNKNOWN, + FamilyRelType.CUSTOM]: + warn( "set_relationship now takes a FamilyRelType instance", DeprecationWarning, 2) # Wrapper for old API # remove when transitition done. - relationship_type = (relationship_type,'') + relationship_type = FamilyRelType(relationship_type) else: assert type(relationship_type) == tuple self.type = relationship_type diff --git a/src/RelLib/_FamilyRelType.py b/src/RelLib/_FamilyRelType.py new file mode 100644 index 000000000..af1431a04 --- /dev/null +++ b/src/RelLib/_FamilyRelType.py @@ -0,0 +1,50 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# 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 +# 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: _Name.py 6326 2006-04-13 11:21:33Z loshawlos $ + +from _GrampsType import GrampsType, init_map +from gettext import gettext as _ + +class FamilyRelType(GrampsType): + + MARRIED = 0 + UNMARRIED = 1 + CIVIL_UNION = 2 + UNKNOWN = 3 + CUSTOM = 4 + + _CUSTOM = CUSTOM + _DEFAULT = MARRIED + + _DATAMAP = [ + (UNKNOWN, _("Unknown"), "Unknown"), + (CUSTOM, _("Custom"), "Custom"), + (CIVIL_UNION, _("Civil Union"), "Civil Union"), + (UNMARRIED, _("Unmarried"), "Unmarried"), + (MARRIED, _("Married"), "Married"), + ] + + _I2SMAP = init_map(_DATAMAP, 0, 1) + _S2IMAP = init_map(_DATAMAP, 1, 0) + _I2EMAP = init_map(_DATAMAP, 0, 2) + _E2IMAP = init_map(_DATAMAP, 2, 0) + + def __init__(self, value=None): + GrampsType.__init__(self, value) diff --git a/src/RelLib/__init__.py b/src/RelLib/__init__.py index 79fce4253..00d1f9c48 100644 --- a/src/RelLib/__init__.py +++ b/src/RelLib/__init__.py @@ -65,4 +65,4 @@ from _UrlType import UrlType from _ChildRefType import ChildRefType from _RepositoryType import RepositoryType from _EventType import EventType - +from _FamilyRelType import FamilyRelType diff --git a/src/Relationship.py b/src/Relationship.py index dc6a97751..4ed9a0cd6 100644 --- a/src/Relationship.py +++ b/src/Relationship.py @@ -260,33 +260,33 @@ class RelationshipCalculator: gender = RelLib.Person.FEMALE # Person's gender is unknown, try guessing from spouse's elif orig.get_gender() == RelLib.Person.MALE: - if family_rel == RelLib.Family.CIVIL_UNION: + if family_rel == RelLib.FamilyRelType.CIVIL_UNION: gender = RelLib.Person.MALE else: gender = RelLib.Person.FEMALE elif orig.get_gender() == RelLib.Person.FEMALE: - if family_rel == RelLib.Family.CIVIL_UNION: + if family_rel == RelLib.FamilyRelType.CIVIL_UNION: gender = RelLib.Person.FEMALE else: gender = RelLib.Person.MALE else: gender = RelLib.Person.UNKNOWN - if family_rel == RelLib.Family.MARRIED: + if family_rel == RelLib.FamilyRelType.MARRIED: if gender == RelLib.Person.MALE: return _("husband") elif gender == RelLib.Person.FEMALE: return _("wife") else: return _("gender unknown|spouse") - elif family_rel == RelLib.Family.UNMARRIED: + elif family_rel == RelLib.FamilyRelType.UNMARRIED: if gender == RelLib.Person.MALE: return _("unmarried|husband") elif gender == RelLib.Person.FEMALE: return _("unmarried|wife") else: return _("gender unknown,unmarried|spouse") - elif family_rel == RelLib.Family.CIVIL_UNION: + elif family_rel == RelLib.FamilyRelType.CIVIL_UNION: if gender == RelLib.Person.MALE: return _("male,civil union|partner") elif gender == RelLib.Person.FEMALE: diff --git a/src/Utils.py b/src/Utils.py index 062f356d6..5ad63865e 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -185,29 +185,29 @@ def format_attribute( type): val = family_attributes.get(type[0],_("Invalid id %d ('%s')")%type) return val -family_relations = { - RelLib.Family.MARRIED : _("Married"), - RelLib.Family.UNMARRIED : _("Unmarried"), - RelLib.Family.CIVIL_UNION : _("Civil Union"), - RelLib.Family.UNKNOWN : _("Unknown"), - RelLib.Family.CUSTOM : _("Other"), - } -def format_family_relation( type): - if type[0] == RelLib.Family.CUSTOM: - return type[1] - return family_relations.get(type[0],_("Invalid id %d ('%s')")%type) +## family_relations = { +## RelLib.Family.MARRIED : _("Married"), +## RelLib.Family.UNMARRIED : _("Unmarried"), +## RelLib.Family.CIVIL_UNION : _("Civil Union"), +## RelLib.Family.UNKNOWN : _("Unknown"), +## RelLib.Family.CUSTOM : _("Other"), +## } +## def format_family_relation( type): +## if type[0] == RelLib.Family.CUSTOM: +## return type[1] +## return family_relations.get(type[0],_("Invalid id %d ('%s')")%type) family_rel_descriptions = { - RelLib.Family.MARRIED : _("A legal or common-law relationship " - "between a husband and wife"), - RelLib.Family.UNMARRIED : _("No legal or common-law relationship " - "between man and woman"), - RelLib.Family.CIVIL_UNION : _("An established relationship between " - "members of the same sex"), - RelLib.Family.UNKNOWN : _("Unknown relationship between a man " - "and woman"), - RelLib.Family.CUSTOM : _("An unspecified relationship " - "a man and woman"), + RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship " + "between a husband and wife"), + RelLib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship " + "between man and woman"), + RelLib.FamilyRelType.CIVIL_UNION : _("An established relationship between " + "members of the same sex"), + RelLib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man " + "and woman"), + RelLib.FamilyRelType.CUSTOM : _("An unspecified relationship " + "a man and woman"), } source_media_types = {