Attribute Types

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

View File

@ -1,4 +1,16 @@
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/Errors.py: warning error for unavailable plugin
* 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.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)

View File

@ -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)

View File

@ -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:

View File

@ -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):
"""

View File

@ -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)

View File

@ -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)

View File

@ -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<attribute%s type="%s" value="%s"' % \
(sp,conf_priv(attr),
_ConstXML.str_for_xml(_ConstXML.attributes,
attr.get_type()),
#const.save_attr(attr.get_type()),
(sp,conf_priv(attr),attr.get_type().xml_str(),
self.fix(attr.get_value())))
slist = attr.get_source_references()
note = attr.get_note()

View File

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

View File

@ -40,6 +40,7 @@ from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _SourceBase import SourceBase
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
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):
"""
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.value = source.value
else:
self.type = (Attribute.CUSTOM,"")
self.type = AttributeType()
self.value = ""
def serialize(self):
return (PrivacyBase.serialize(self),
SourceBase.serialize(self),
NoteBase.serialize(self),
self.type,self.value)
self.type.serialize(),self.value)
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)
SourceBase.unserialize(self,source_list)
NoteBase.unserialize(self,note)
self.type.unserialize(the_type)
return self
def get_text_data_list(self):
@ -121,15 +114,7 @@ class Attribute(BaseObject,PrivacyBase,SourceBase,NoteBase):
def set_type(self,val):
"""sets the type (or key) of the Attribute instance"""
if not type(val) == tuple:
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
self.type.set(val)
def get_type(self):
"""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
from _GrampsType import GrampsType
from _NameType import NameType
from _AttributeType import AttributeType
from _UrlType import UrlType
from _ChildRefType import ChildRefType
from _RepositoryType import RepositoryType

View File

@ -81,40 +81,6 @@ confidence = {
def format_confidence( 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 = {
RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
"between a husband and wife"),
@ -185,16 +151,16 @@ personalConstantEvents = {
}
familyConstantAttributes = {
RelLib.Attribute.NUM_CHILD : "NCHI",
RelLib.AttributeType.NUM_CHILD : "NCHI",
}
personalConstantAttributes = {
RelLib.Attribute.CASTE : "CAST",
RelLib.Attribute.DESCRIPTION : "DSCR",
RelLib.Attribute.ID : "IDNO",
RelLib.Attribute.NATIONAL : "NATI",
RelLib.Attribute.NUM_CHILD : "NCHI",
RelLib.Attribute.SSN : "SSN",
RelLib.AttributeType.CASTE : "CAST",
RelLib.AttributeType.DESCRIPTION : "DSCR",
RelLib.AttributeType.ID : "IDNO",
RelLib.AttributeType.NATIONAL : "NATI",
RelLib.AttributeType.NUM_CHILD : "NCHI",
RelLib.AttributeType.SSN : "SSN",
}
#-------------------------------------------------------------------------