From e9f2d922f725f329c690bf619f3059137923b4b8 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 21 Apr 2006 18:15:23 +0000 Subject: [PATCH] Attribute Types svn: r6392 --- gramps2/ChangeLog | 12 ++++ gramps2/src/Editors/_EditAttribute.py | 7 +-- gramps2/src/GrampsDb/_ConstXML.py | 84 +++++++++++++-------------- gramps2/src/GrampsDb/_GrampsBSDDB.py | 16 ++--- gramps2/src/GrampsDb/_GrampsDbBase.py | 4 +- gramps2/src/GrampsDb/_ReadGedcom.py | 4 +- gramps2/src/GrampsDb/_ReadXML.py | 5 +- gramps2/src/GrampsDb/_WriteXML.py | 6 +- gramps2/src/RelLib/Makefile.am | 1 + gramps2/src/RelLib/_Attribute.py | 27 ++------- gramps2/src/RelLib/_AttributeType.py | 59 +++++++++++++++++++ gramps2/src/RelLib/__init__.py | 1 + gramps2/src/Utils.py | 48 +++------------ 13 files changed, 145 insertions(+), 129 deletions(-) create mode 100644 gramps2/src/RelLib/_AttributeType.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 33eabfa72..b0b90f119 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,16 @@ 2006-04-21 Don Allingham + * src/GrampsDb/_GrampsDbBase.py: AttributeType changes + * src/GrampsDb/_ReadGedcom.py: AttributeType changes + * src/GrampsDb/_ReadXML.py: AttributeType changes + * src/GrampsDb/_ConstXML.py: AttributeType changes + * src/GrampsDb/_WriteXML.py: AttributeType changes + * src/GrampsDb/_GrampsBSDDB.py: AttributeType changes + * src/RelLib/__init__.py: AttributeType changes + * src/RelLib/_AttributeType.py: AttributeType changes + * src/RelLib/_Attribute.py: AttributeType changes + * src/RelLib/Makefile.am: AttributeType changes + * src/Editors/_EditAttribute.py: AttributeType changes + * src/Utils.py: AttributeType changes * src/ViewManager.py: start of cleaned up plugin manager * src/Errors.py: warning error for unavailable plugin * src/PluginUtils/__init__.py: start of cleaned up plugin manager diff --git a/gramps2/src/Editors/_EditAttribute.py b/gramps2/src/Editors/_EditAttribute.py index fa7fd41b6..3062e15b5 100644 --- a/gramps2/src/Editors/_EditAttribute.py +++ b/gramps2/src/Editors/_EditAttribute.py @@ -101,13 +101,10 @@ class EditAttribute(EditSecondary): self.top.get_widget("private"), self.obj) - self.type_selector = MonitoredType( + self.type_selector = MonitoredDataType( self.top.get_widget("attr_menu"), self.obj.set_type, self.obj.get_type, - self.attribute_list(), - RelLib.Attribute.CUSTOM, - custom_values=self.alist, ) def _create_tabbed_pages(self): @@ -129,7 +126,7 @@ class EditAttribute(EditSecondary): if not attrib: label = _("New Attribute") else: - label = attrib.get_type()[1] + label = str(attrib.get_type()) if not label.strip(): label = _("New Attribute") label = "%s: %s" % (_('Attribute'),label) diff --git a/gramps2/src/GrampsDb/_ConstXML.py b/gramps2/src/GrampsDb/_ConstXML.py index 8132ed38d..135dba966 100644 --- a/gramps2/src/GrampsDb/_ConstXML.py +++ b/gramps2/src/GrampsDb/_ConstXML.py @@ -84,15 +84,15 @@ import RelLib # (RelLib.Event.WILL , "Will"), # ) -attributes = ( - (RelLib.Attribute.UNKNOWN , "Unknown"), - (RelLib.Attribute.CASTE , "Caste"), - (RelLib.Attribute.DESCRIPTION , "Description"), - (RelLib.Attribute.ID , "Identification Number"), - (RelLib.Attribute.NATIONAL , "National Origin"), - (RelLib.Attribute.NUM_CHILD , "Number of Children"), - (RelLib.Attribute.SSN , "Social Security Number"), - ) +# attributes = ( +# (RelLib.Attribute.UNKNOWN , "Unknown"), +# (RelLib.Attribute.CASTE , "Caste"), +# (RelLib.Attribute.DESCRIPTION , "Description"), +# (RelLib.Attribute.ID , "Identification Number"), +# (RelLib.Attribute.NATIONAL , "National Origin"), +# (RelLib.Attribute.NUM_CHILD , "Number of Children"), +# (RelLib.Attribute.SSN , "Social Security Number"), +# ) ## family_relations = ( ## (RelLib.Family.MARRIED , "Married"), @@ -165,9 +165,9 @@ attributes = ( # ) # mapping from the tuple collection to the appropriate CUSTOM integer -custom_types = { +#custom_types = { # events : RelLib.Event.CUSTOM, - attributes : RelLib.Attribute.CUSTOM, +# attributes : RelLib.Attribute.CUSTOM, # family_relations : RelLib.Family.CUSTOM, # name_types : RelLib.NameType.CUSTOM, # source_media_types : RelLib.RepoRef.CUSTOM, @@ -175,42 +175,42 @@ custom_types = { # repository_types : RelLib.Repository.CUSTOM, # marker_types : RelLib.PrimaryObject.MARKER_CUSTOM, # url_types : RelLib.Url.CUSTOM, - } +# } -def str_for_xml(tuples,the_tuple): - """ - This function checks the_tuple against the collection of tuples - and returns the string to store in the XML file. - """ +# def str_for_xml(tuples,the_tuple): +# """ +# This function checks the_tuple against the collection of tuples +# and returns the string to store in the XML file. +# """ - # use list comprehension to quickly find a match, if any - match_list = [ item for item in tuples if item[0] == the_tuple[0] ] +# # use list comprehension to quickly find a match, if any +# match_list = [ item for item in tuples if item[0] == the_tuple[0] ] - # If match_list is not empty, then we have got a match, - # so we simply return the string of that standard item - if match_list: - return match_list[0][1] +# # If match_list is not empty, then we have got a match, +# # so we simply return the string of that standard item +# if match_list: +# return match_list[0][1] - # empty match_list means there's nothing with that integer, - # so we simply return the string from the_tuple - else: - return the_tuple[1] +# # empty match_list means there's nothing with that integer, +# # so we simply return the string from the_tuple +# else: +# return the_tuple[1] -def tuple_from_xml(tuples,the_str): - """ - This function checks the_str against the collection of tuples - and returns the tuple to use for the type internally. - """ +# def tuple_from_xml(tuples,the_str): +# """ +# This function checks the_str against the collection of tuples +# and returns the tuple to use for the type internally. +# """ - # use list comprehension to quickly find a match, if any - match_list = [ item for item in tuples if item[1] == the_str ] +# # use list comprehension to quickly find a match, if any +# match_list = [ item for item in tuples if item[1] == the_str ] - # If match_list is not empty, then we have got a match, - # so we return the tuple made from the only item in the list. - if match_list: - return (match_list[0][0],'') +# # If match_list is not empty, then we have got a match, +# # so we return the tuple made from the only item in the list. +# if match_list: +# return (match_list[0][0],'') - # empty match_list means there's nothing with that string, - # so we return the tuple of custom type and the original string - else: - return (custom_types[tuples],the_str) +# # empty match_list means there's nothing with that string, +# # so we return the tuple of custom type and the original string +# else: +# return (custom_types[tuples],the_str) diff --git a/gramps2/src/GrampsDb/_GrampsBSDDB.py b/gramps2/src/GrampsDb/_GrampsBSDDB.py index 6111d9eaf..da9728579 100644 --- a/gramps2/src/GrampsDb/_GrampsBSDDB.py +++ b/gramps2/src/GrampsDb/_GrampsBSDDB.py @@ -1557,12 +1557,12 @@ class BdbTransaction(Transaction): self.reference_add = [] _attribute_conversion_9 = { - "Caste" : (Attribute.CASTE,""), - "Description" : (Attribute.DESCRIPTION,""), - "Identification Number" : (Attribute.ID,""), - "National Origin" : (Attribute.NATIONAL,""), - "Number of Children" : (Attribute.NUM_CHILD,""), - "Social Security Number" : (Attribute.SSN,""), + "Caste" : AttributeType.CASTE, + "Description" : AttributeType.DESCRIPTION, + "Identification Number" : AttributeType.ID, + "National Origin" : AttributeType.NATIONAL, + "Number of Children" : AttributeType.NUM_CHILD, + "Social Security Number" : AttributeType.SSN, } def convert_attribute_9(attribute): @@ -1573,8 +1573,8 @@ def convert_attribute_9(attribute): else: new_type = (Attribute.CUSTOM,old_type) else: - new_type = (Attribute.UNKNOWN,"") - attribute.type = new_type + new_type = Attribute.UNKNOWN + attribute.type.set_type(new_type) def convert_mediaref_9(media_ref): for attribute in media_ref.attribute_list: diff --git a/gramps2/src/GrampsDb/_GrampsDbBase.py b/gramps2/src/GrampsDb/_GrampsDbBase.py index 34c6b3364..eec106aae 100644 --- a/gramps2/src/GrampsDb/_GrampsDbBase.py +++ b/gramps2/src/GrampsDb/_GrampsDbBase.py @@ -410,7 +410,7 @@ class GrampsDbBase(GrampsDBCallback): self.genderStats.count_person(person, self) for attr in person.attribute_list: - self.individual_attributes.add(attr.type) + self.individual_attributes.add(str(attr.type)) self.marker_names.add(str(person.marker)) @@ -475,7 +475,7 @@ class GrampsDbBase(GrampsDBCallback): transaction, change_time) for attr in family.attribute_list: - self.family_attributes.add(attr.type) + self.family_attributes.add(str(attr.type)) def commit_repository(self, repository, transaction, change_time=None): """ diff --git a/gramps2/src/GrampsDb/_ReadGedcom.py b/gramps2/src/GrampsDb/_ReadGedcom.py index e92bf69db..b0f4a57b7 100644 --- a/gramps2/src/GrampsDb/_ReadGedcom.py +++ b/gramps2/src/GrampsDb/_ReadGedcom.py @@ -1116,7 +1116,7 @@ class GedcomParser: self.family.add_child_ref(ref) elif matches[1] == TOKEN_NCHI: a = RelLib.Attribute() - a.set_type((RelLib.Attribute.NUM_CHILD,'')) + a.set_type(RelLib.Attribute.NUM_CHILD) a.set_value(matches[2]) self.family.add_attribute(a) elif matches[1] == TOKEN_SOUR: @@ -2245,7 +2245,7 @@ class GedcomParser: if atype == RelLib.Attribute.CUSTOM: attr.set_type((atype,n)) else: - attr.set_type((atype,'')) + attr.set_type(atype) attr.set_value(matches[2]) state.person.add_attribute(attr) diff --git a/gramps2/src/GrampsDb/_ReadXML.py b/gramps2/src/GrampsDb/_ReadXML.py index 66a29b8e1..ea9d0ad19 100644 --- a/gramps2/src/GrampsDb/_ReadXML.py +++ b/gramps2/src/GrampsDb/_ReadXML.py @@ -59,7 +59,6 @@ import const import Utils import DateHandler import NameDisplay -import _ConstXML from _GrampsDbBase import \ PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\ MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY @@ -788,8 +787,8 @@ class GrampsParser: self.attribute = RelLib.Attribute() self.attribute.conf = int(attrs.get("conf",2)) self.attribute.private = bool(attrs.get("priv")) - self.attribute.type = _ConstXML.tuple_from_xml(_ConstXML.attributes, - attrs.get("type",'')) + self.attribute.type = RelLib.AttributeType() + self.attribute.type.set_from_xml_str(attrs.get("type",'')) self.attribute.value = attrs.get("value",'') if self.photo: self.photo.add_attribute(self.attribute) diff --git a/gramps2/src/GrampsDb/_WriteXML.py b/gramps2/src/GrampsDb/_WriteXML.py index c93b5af35..73d6a46d4 100644 --- a/gramps2/src/GrampsDb/_WriteXML.py +++ b/gramps2/src/GrampsDb/_WriteXML.py @@ -59,7 +59,6 @@ import gtk import const import RelLib from QuestionDialog import ErrorDialog -import _ConstXML from _GrampsDbBase import \ PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\ MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY @@ -845,10 +844,7 @@ class XmlWriter: sp = ' ' * indent for attr in list: self.g.write('%s