Attribute Types

svn: r6392
This commit is contained in:
Don Allingham 2006-04-21 18:15:23 +00:00
parent 7494dbe642
commit e9f2d922f7
13 changed files with 145 additions and 129 deletions

View File

@ -1,4 +1,16 @@
2006-04-21 Don Allingham <don@gramps-project.org> 2006-04-21 Don Allingham <don@gramps-project.org>
* 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/ViewManager.py: start of cleaned up plugin manager
* src/Errors.py: warning error for unavailable plugin * src/Errors.py: warning error for unavailable plugin
* src/PluginUtils/__init__.py: start of cleaned up plugin manager * src/PluginUtils/__init__.py: start of cleaned up plugin manager

View File

@ -101,13 +101,10 @@ class EditAttribute(EditSecondary):
self.top.get_widget("private"), self.top.get_widget("private"),
self.obj) self.obj)
self.type_selector = MonitoredType( self.type_selector = MonitoredDataType(
self.top.get_widget("attr_menu"), self.top.get_widget("attr_menu"),
self.obj.set_type, self.obj.set_type,
self.obj.get_type, self.obj.get_type,
self.attribute_list(),
RelLib.Attribute.CUSTOM,
custom_values=self.alist,
) )
def _create_tabbed_pages(self): def _create_tabbed_pages(self):
@ -129,7 +126,7 @@ class EditAttribute(EditSecondary):
if not attrib: if not attrib:
label = _("New Attribute") label = _("New Attribute")
else: else:
label = attrib.get_type()[1] label = str(attrib.get_type())
if not label.strip(): if not label.strip():
label = _("New Attribute") label = _("New Attribute")
label = "%s: %s" % (_('Attribute'),label) label = "%s: %s" % (_('Attribute'),label)

View File

@ -84,15 +84,15 @@ import RelLib
# (RelLib.Event.WILL , "Will"), # (RelLib.Event.WILL , "Will"),
# ) # )
attributes = ( # attributes = (
(RelLib.Attribute.UNKNOWN , "Unknown"), # (RelLib.Attribute.UNKNOWN , "Unknown"),
(RelLib.Attribute.CASTE , "Caste"), # (RelLib.Attribute.CASTE , "Caste"),
(RelLib.Attribute.DESCRIPTION , "Description"), # (RelLib.Attribute.DESCRIPTION , "Description"),
(RelLib.Attribute.ID , "Identification Number"), # (RelLib.Attribute.ID , "Identification Number"),
(RelLib.Attribute.NATIONAL , "National Origin"), # (RelLib.Attribute.NATIONAL , "National Origin"),
(RelLib.Attribute.NUM_CHILD , "Number of Children"), # (RelLib.Attribute.NUM_CHILD , "Number of Children"),
(RelLib.Attribute.SSN , "Social Security Number"), # (RelLib.Attribute.SSN , "Social Security Number"),
) # )
## family_relations = ( ## family_relations = (
## (RelLib.Family.MARRIED , "Married"), ## (RelLib.Family.MARRIED , "Married"),
@ -165,9 +165,9 @@ attributes = (
# ) # )
# mapping from the tuple collection to the appropriate CUSTOM integer # mapping from the tuple collection to the appropriate CUSTOM integer
custom_types = { #custom_types = {
# events : RelLib.Event.CUSTOM, # events : RelLib.Event.CUSTOM,
attributes : RelLib.Attribute.CUSTOM, # attributes : RelLib.Attribute.CUSTOM,
# family_relations : RelLib.Family.CUSTOM, # family_relations : RelLib.Family.CUSTOM,
# name_types : RelLib.NameType.CUSTOM, # name_types : RelLib.NameType.CUSTOM,
# source_media_types : RelLib.RepoRef.CUSTOM, # source_media_types : RelLib.RepoRef.CUSTOM,
@ -175,42 +175,42 @@ custom_types = {
# repository_types : RelLib.Repository.CUSTOM, # repository_types : RelLib.Repository.CUSTOM,
# marker_types : RelLib.PrimaryObject.MARKER_CUSTOM, # marker_types : RelLib.PrimaryObject.MARKER_CUSTOM,
# url_types : RelLib.Url.CUSTOM, # url_types : RelLib.Url.CUSTOM,
} # }
def str_for_xml(tuples,the_tuple): # def str_for_xml(tuples,the_tuple):
""" # """
This function checks the_tuple against the collection of tuples # This function checks the_tuple against the collection of tuples
and returns the string to store in the XML file. # and returns the string to store in the XML file.
""" # """
# use list comprehension to quickly find a match, if any # # use list comprehension to quickly find a match, if any
match_list = [ item for item in tuples if item[0] == the_tuple[0] ] # 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, # # If match_list is not empty, then we have got a match,
# so we simply return the string of that standard item # # so we simply return the string of that standard item
if match_list: # if match_list:
return match_list[0][1] # return match_list[0][1]
# empty match_list means there's nothing with that integer, # # empty match_list means there's nothing with that integer,
# so we simply return the string from the_tuple # # so we simply return the string from the_tuple
else: # else:
return the_tuple[1] # return the_tuple[1]
def tuple_from_xml(tuples,the_str): # def tuple_from_xml(tuples,the_str):
""" # """
This function checks the_str against the collection of tuples # This function checks the_str against the collection of tuples
and returns the tuple to use for the type internally. # and returns the tuple to use for the type internally.
""" # """
# use list comprehension to quickly find a match, if any # # use list comprehension to quickly find a match, if any
match_list = [ item for item in tuples if item[1] == the_str ] # match_list = [ item for item in tuples if item[1] == the_str ]
# If match_list is not empty, then we have got a match, # # 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. # # so we return the tuple made from the only item in the list.
if match_list: # if match_list:
return (match_list[0][0],'') # return (match_list[0][0],'')
# empty match_list means there's nothing with that string, # # empty match_list means there's nothing with that string,
# so we return the tuple of custom type and the original string # # so we return the tuple of custom type and the original string
else: # else:
return (custom_types[tuples],the_str) # return (custom_types[tuples],the_str)

View File

@ -1557,12 +1557,12 @@ class BdbTransaction(Transaction):
self.reference_add = [] self.reference_add = []
_attribute_conversion_9 = { _attribute_conversion_9 = {
"Caste" : (Attribute.CASTE,""), "Caste" : AttributeType.CASTE,
"Description" : (Attribute.DESCRIPTION,""), "Description" : AttributeType.DESCRIPTION,
"Identification Number" : (Attribute.ID,""), "Identification Number" : AttributeType.ID,
"National Origin" : (Attribute.NATIONAL,""), "National Origin" : AttributeType.NATIONAL,
"Number of Children" : (Attribute.NUM_CHILD,""), "Number of Children" : AttributeType.NUM_CHILD,
"Social Security Number" : (Attribute.SSN,""), "Social Security Number" : AttributeType.SSN,
} }
def convert_attribute_9(attribute): def convert_attribute_9(attribute):
@ -1573,8 +1573,8 @@ def convert_attribute_9(attribute):
else: else:
new_type = (Attribute.CUSTOM,old_type) new_type = (Attribute.CUSTOM,old_type)
else: else:
new_type = (Attribute.UNKNOWN,"") new_type = Attribute.UNKNOWN
attribute.type = new_type attribute.type.set_type(new_type)
def convert_mediaref_9(media_ref): def convert_mediaref_9(media_ref):
for attribute in media_ref.attribute_list: for attribute in media_ref.attribute_list:

View File

@ -410,7 +410,7 @@ class GrampsDbBase(GrampsDBCallback):
self.genderStats.count_person(person, self) self.genderStats.count_person(person, self)
for attr in person.attribute_list: 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)) self.marker_names.add(str(person.marker))
@ -475,7 +475,7 @@ class GrampsDbBase(GrampsDBCallback):
transaction, change_time) transaction, change_time)
for attr in family.attribute_list: 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): def commit_repository(self, repository, transaction, change_time=None):
""" """

View File

@ -1116,7 +1116,7 @@ class GedcomParser:
self.family.add_child_ref(ref) self.family.add_child_ref(ref)
elif matches[1] == TOKEN_NCHI: elif matches[1] == TOKEN_NCHI:
a = RelLib.Attribute() a = RelLib.Attribute()
a.set_type((RelLib.Attribute.NUM_CHILD,'')) a.set_type(RelLib.Attribute.NUM_CHILD)
a.set_value(matches[2]) a.set_value(matches[2])
self.family.add_attribute(a) self.family.add_attribute(a)
elif matches[1] == TOKEN_SOUR: elif matches[1] == TOKEN_SOUR:
@ -2245,7 +2245,7 @@ class GedcomParser:
if atype == RelLib.Attribute.CUSTOM: if atype == RelLib.Attribute.CUSTOM:
attr.set_type((atype,n)) attr.set_type((atype,n))
else: else:
attr.set_type((atype,'')) attr.set_type(atype)
attr.set_value(matches[2]) attr.set_value(matches[2])
state.person.add_attribute(attr) state.person.add_attribute(attr)

View File

@ -59,7 +59,6 @@ import const
import Utils import Utils
import DateHandler import DateHandler
import NameDisplay import NameDisplay
import _ConstXML
from _GrampsDbBase import \ from _GrampsDbBase import \
PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\ PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\
MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY
@ -788,8 +787,8 @@ class GrampsParser:
self.attribute = RelLib.Attribute() self.attribute = RelLib.Attribute()
self.attribute.conf = int(attrs.get("conf",2)) self.attribute.conf = int(attrs.get("conf",2))
self.attribute.private = bool(attrs.get("priv")) self.attribute.private = bool(attrs.get("priv"))
self.attribute.type = _ConstXML.tuple_from_xml(_ConstXML.attributes, self.attribute.type = RelLib.AttributeType()
attrs.get("type",'')) self.attribute.type.set_from_xml_str(attrs.get("type",''))
self.attribute.value = attrs.get("value",'') self.attribute.value = attrs.get("value",'')
if self.photo: if self.photo:
self.photo.add_attribute(self.attribute) self.photo.add_attribute(self.attribute)

View File

@ -59,7 +59,6 @@ import gtk
import const import const
import RelLib import RelLib
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
import _ConstXML
from _GrampsDbBase import \ from _GrampsDbBase import \
PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\ PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\
MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY
@ -845,10 +844,7 @@ class XmlWriter:
sp = ' ' * indent sp = ' ' * indent
for attr in list: for attr in list:
self.g.write('%s<attribute%s type="%s" value="%s"' % \ self.g.write('%s<attribute%s type="%s" value="%s"' % \
(sp,conf_priv(attr), (sp,conf_priv(attr),attr.get_type().xml_str(),
_ConstXML.str_for_xml(_ConstXML.attributes,
attr.get_type()),
#const.save_attr(attr.get_type()),
self.fix(attr.get_value()))) self.fix(attr.get_value())))
slist = attr.get_source_references() slist = attr.get_source_references()
note = attr.get_note() note = attr.get_note()

View File

@ -53,6 +53,7 @@ pkgdata_PYTHON = \
_SourceBase.py\ _SourceBase.py\
_RefBase.py\ _RefBase.py\
_ChildRef.py\ _ChildRef.py\
_AttributeType.py\
_ChildRefType.py\ _ChildRefType.py\
_FamilyRelType.py\ _FamilyRelType.py\
_SourceMediaType.py\ _SourceMediaType.py\

View File

@ -40,6 +40,7 @@ from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase from _SourceBase import SourceBase
from _NoteBase import NoteBase from _NoteBase import NoteBase
from _AttributeType import AttributeType
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -50,15 +51,6 @@ class Attribute(BaseObject,PrivacyBase,SourceBase,NoteBase):
"""Provides a simple key/value pair for describing properties. Used """Provides a simple key/value pair for describing properties. Used
by the Person and Family objects to store descriptive information.""" by the Person and Family objects to store descriptive information."""
UNKNOWN = -1
CUSTOM = 0
CASTE = 1
DESCRIPTION = 2
ID = 3
NATIONAL = 4
NUM_CHILD = 5
SSN = 6
def __init__(self,source=None): def __init__(self,source=None):
""" """
Creates a new Attribute object, copying from the source if provided. Creates a new Attribute object, copying from the source if provided.
@ -72,20 +64,21 @@ class Attribute(BaseObject,PrivacyBase,SourceBase,NoteBase):
self.type = source.type self.type = source.type
self.value = source.value self.value = source.value
else: else:
self.type = (Attribute.CUSTOM,"") self.type = AttributeType()
self.value = "" self.value = ""
def serialize(self): def serialize(self):
return (PrivacyBase.serialize(self), return (PrivacyBase.serialize(self),
SourceBase.serialize(self), SourceBase.serialize(self),
NoteBase.serialize(self), NoteBase.serialize(self),
self.type,self.value) self.type.serialize(),self.value)
def unserialize(self,data): def unserialize(self,data):
(privacy,source_list,note,self.type,self.value) = data (privacy,source_list,note,the_type,self.value) = data
PrivacyBase.unserialize(self,privacy) PrivacyBase.unserialize(self,privacy)
SourceBase.unserialize(self,source_list) SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note) NoteBase.unserialize(self,note)
self.type.unserialize(the_type)
return self return self
def get_text_data_list(self): def get_text_data_list(self):
@ -121,15 +114,7 @@ class Attribute(BaseObject,PrivacyBase,SourceBase,NoteBase):
def set_type(self,val): def set_type(self,val):
"""sets the type (or key) of the Attribute instance""" """sets the type (or key) of the Attribute instance"""
if not type(val) == tuple: self.type.set(val)
warn( "set_type now takes a tuple", DeprecationWarning, 2)
# Wrapper for old API
# remove when transitition done.
if val in range(-1,7):
val = (val,'')
else:
val = (Attribute.CUSTOM,val)
self.type = val
def get_type(self): def get_type(self):
"""returns the type (or key) or the Attribute instance""" """returns the type (or key) or the Attribute instance"""

View File

@ -0,0 +1,59 @@
#
# 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 AttributeType(GrampsType):
UNKNOWN = -1
CUSTOM = 0
CASTE = 1
DESCRIPTION = 2
ID = 3
NATIONAL = 4
NUM_CHILD = 5
SSN = 6
_CUSTOM = CUSTOM
_DEFAULT = ID
_DATAMAP = [
(UNKNOWN , _("Unknown"), "Unknown"),
(CUSTOM , _("Custom"), "Custom"),
(CASTE , _("Caste"), "Caste"),
(DESCRIPTION , _("Description"), "Description"),
(ID , _("Identification Number"), "Identification Number"),
(NATIONAL , _("National Origin"), "National Origin"),
(NUM_CHILD , _("Number of Children"), "Number of Children"),
(SSN , _("Social Security Number"), "Social Security Number"),
(NUM_CHILD , _("Number of Children"), "Number of Children"),
]
_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)

View File

@ -61,6 +61,7 @@ from _Researcher import Researcher
# Type classes # Type classes
from _GrampsType import GrampsType from _GrampsType import GrampsType
from _NameType import NameType from _NameType import NameType
from _AttributeType import AttributeType
from _UrlType import UrlType from _UrlType import UrlType
from _ChildRefType import ChildRefType from _ChildRefType import ChildRefType
from _RepositoryType import RepositoryType from _RepositoryType import RepositoryType

View File

@ -81,40 +81,6 @@ confidence = {
def format_confidence( type): def format_confidence( type):
return confidence.get(type[0],_("Invalid id %d ('%s')")%type) return confidence.get(type[0],_("Invalid id %d ('%s')")%type)
personal_attributes = {
RelLib.Attribute.UNKNOWN : _("Unknown"),
RelLib.Attribute.CUSTOM : _("Custom"),
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"),
}
def format_personal_attribute( type):
if type[0] == RelLib.Attribute.CUSTOM:
return type[1]
return personal_attributes.get(type[0],_("Invalid id %d ('%s')")%type)
family_attributes = {
RelLib.Attribute.UNKNOWN : _("Unknown"),
RelLib.Attribute.CUSTOM : _("Custom"),
RelLib.Attribute.NUM_CHILD : _("Number of Children"),
}
def format_family_attribute( type):
if type[0] == RelLib.Attribute.CUSTOM:
return type[1]
return family_attributes.get(type[0],_("Invalid id %d ('%s')")%type)
def format_attribute( type):
if type[0] == RelLib.Attribute.CUSTOM:
return type[1]
val = personal_attributes.get(type[0])
if not val:
val = family_attributes.get(type[0],_("Invalid id %d ('%s')")%type)
return val
family_rel_descriptions = { family_rel_descriptions = {
RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship " RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
"between a husband and wife"), "between a husband and wife"),
@ -185,16 +151,16 @@ personalConstantEvents = {
} }
familyConstantAttributes = { familyConstantAttributes = {
RelLib.Attribute.NUM_CHILD : "NCHI", RelLib.AttributeType.NUM_CHILD : "NCHI",
} }
personalConstantAttributes = { personalConstantAttributes = {
RelLib.Attribute.CASTE : "CAST", RelLib.AttributeType.CASTE : "CAST",
RelLib.Attribute.DESCRIPTION : "DSCR", RelLib.AttributeType.DESCRIPTION : "DSCR",
RelLib.Attribute.ID : "IDNO", RelLib.AttributeType.ID : "IDNO",
RelLib.Attribute.NATIONAL : "NATI", RelLib.AttributeType.NATIONAL : "NATI",
RelLib.Attribute.NUM_CHILD : "NCHI", RelLib.AttributeType.NUM_CHILD : "NCHI",
RelLib.Attribute.SSN : "SSN", RelLib.AttributeType.SSN : "SSN",
} }
#------------------------------------------------------------------------- #-------------------------------------------------------------------------