* src/GrampsDb/_ReadXML.py: new types

* src/GrampsDb/_ConstXML.py: new types
	* src/GrampsDb/_WriteXML.py: new types
	* src/Editors/_EditUrl.py: new types
	* src/Editors/_EditPerson.py: new types
	* src/Editors/_EditRepository.py: new types
	* src/Editors/_EditName.py: new types
	* src/Editors/_EditChildRef.py: new types
	* src/RelLib/__init__.py: new types
	* src/RelLib/_Url.py: new types
	* src/RelLib/_RepositoryType.py: new types
	* src/RelLib/_GrampsType.py: new types
	* src/RelLib/_UrlType.py: new types
	* src/RelLib/_Repository.py: new types
	* src/RelLib/_NameType.py: new types
	* src/RelLib/_ChildRefType.py: new types
	* src/DisplayTabs.py: new types
	* src/GrampsWidgets.py: new types
	* src/Utils.py: new types


svn: r6360
This commit is contained in:
Don Allingham
2006-04-19 03:57:10 +00:00
parent 08cfe67716
commit b82376fb66
20 changed files with 302 additions and 198 deletions

View File

@@ -37,20 +37,24 @@ class ChildRefType(GrampsType):
_CUSTOM = CUSTOM
_DEFAULT = BIRTH
_I2SMAP = {
NONE : _("None"),
BIRTH : _("Birth"),
ADOPTED : _("Adopted"),
STEPCHILD : _("Stepchild"),
SPONSORED : _("Sponsored"),
FOSTER : _("Foster"),
UNKNOWN : _("Unknown"),
CUSTOM : _("Custom"),
}
_DATAMAP = [
(NONE, _("None"), "None"),
(BIRTH, _("Birth"), "Birth"),
(ADOPTED, _("Adopted"), "Adopted"),
(STEPCHILD, _("Stepchild"), "Stepchild"),
(SPONSORED, _("Sponsored"), "Sponsored"),
(FOSTER, _("Foster"), "Foster"),
(UNKNOWN, _("Unknown"), "Unknown"),
(CUSTOM, _("Custom"), "Custom"),
]
_S2IMAP = init_map(_I2SMAP)
_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

@@ -22,19 +22,23 @@
from gettext import gettext as _
def init_map(data):
def init_map(data, key_col, data_col):
new_data = {}
for i in data.keys():
new_data[data[i]] = i
for item in data:
new_data[item[key_col]] = item[data_col]
return new_data
class GrampsType:
_CUSTOM = 0
_DEFAULT = 0
_I2SMAP = {}
_DATAMAP = []
_S2IMAP = init_map(_I2SMAP)
_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):
self.set(value)
@@ -59,6 +63,24 @@ class GrampsType:
self.val = self._DEFAULT
self.string = ''
def set_from_xml_str(self, value):
"""
This method sets the type instance based on the untranslated
string (obtained e.g. from XML).
"""
if self._E2IMAP.has_key(value):
self.val = self._E2IMAP[value]
self.string = ''
else:
self.val = self._CUSTOM
self.string = value
def xml_str(self):
if self.val == self._CUSTOM:
return self.string
else:
return self._I2EMAP[self.val]
def serialize(self):
return (self.val, self.string)
@@ -69,21 +91,9 @@ class GrampsType:
if self.val == self._CUSTOM:
return self.string
else:
return self._I2SMAP.get(self.val,_('UNKNOWN'))
def xml_str(self):
"""
This method returns an untranslated string for non-custom values,
or the value, if it is custom.
"""
# FIXME: this needs to be fixed.
return self.string
return self._I2SMAP.get(self.val,_('Unknown'))
def set_from_xml_str(self,the_str):
"""
This method sets the type instance based on the untranslated
string (obtained e.g. from XML).
"""
return self
def __int__(self):

View File

@@ -20,7 +20,7 @@
# $Id: _Name.py 6326 2006-04-13 11:21:33Z loshawlos $
from _GrampsType import GrampsType
from _GrampsType import GrampsType, init_map
from gettext import gettext as _
class NameType(GrampsType):
@@ -34,15 +34,19 @@ class NameType(GrampsType):
_CUSTOM = CUSTOM
_DEFAULT = BIRTH
_I2SMAP = {
UNKNOWN : _("Unknown"),
CUSTOM : _("Custom"),
AKA : _("Also Known As"),
BIRTH : _("Birth Name"),
MARRIED : _("Married Name"),
}
_DATAMAP = [
(UNKNOWN, _("Unknown"), "Unknown"),
(CUSTOM, _("Custom"), "Custom"),
(AKA, _("Also Known As"), "Also Known As"),
(BIRTH, _("Birth Name"), "Birth Name"),
(MARRIED, _("Married Name"), "Married Name"),
]
_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

@@ -40,6 +40,7 @@ from _PrimaryObject import PrimaryObject
from _NoteBase import NoteBase
from _AddressBase import AddressBase
from _UrlBase import UrlBase
from _RepositoryType import RepositoryType
#-------------------------------------------------------------------------
#
@@ -49,29 +50,18 @@ from _UrlBase import UrlBase
class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase):
"""A location where collections of Sources are found"""
UNKNOWN = -1
CUSTOM = 0
LIBRARY = 1
CEMETERY = 2
CHURCH = 3
ARCHIVE = 4
ALBUM = 5
WEBSITE = 6
BOOKSTORE = 7
COLLECTION = 8
SAFE = 9
def __init__(self):
"""creates a new Repository instance"""
PrimaryObject.__init__(self)
NoteBase.__init__(self)
AddressBase.__init__(self)
UrlBase.__init__(self)
self.type = (Repository.LIBRARY,"")
self.type = RepositoryType()
self.name = ""
def serialize(self):
return (self.handle, self.gramps_id, self.type, unicode(self.name),
return (self.handle, self.gramps_id, self.type.serialize(),
unicode(self.name),
NoteBase.serialize(self),
AddressBase.serialize(self),
UrlBase.serialize(self),
@@ -82,9 +72,10 @@ class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase):
Converts the data held in a tuple created by the serialize method
back into the data in an Repository structure.
"""
(self.handle, self.gramps_id, self.type, self.name, note,
(self.handle, self.gramps_id, the_type, self.name, note,
address_list, urls ,self.marker, self.private) = data
self.type = RepositoryType(the_type)
NoteBase.unserialize(self,note)
AddressBase.unserialize(self,address_list)
UrlBase.unserialize(self,urls)
@@ -96,7 +87,7 @@ class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase):
@return: Returns the list of all textual attributes of the object.
@rtype: list
"""
return [self.name,self.type[1]]
return [self.name,str(self.type)]
def get_text_data_child_list(self):
"""
@@ -149,15 +140,10 @@ class Repository(PrimaryObject,NoteBase,AddressBase,UrlBase):
@param type: descriptive type of the Repository
@type type: str
"""
if not type(the_type) == tuple:
warn( "set_type now takes a tuple", DeprecationWarning, 2)
# Wrapper for old API
# remove when transitition done.
if the_type in range(-1,10):
the_type = (the_type,'')
else:
the_type = (Repository.CUSTOM,the_type)
self.type = the_type
if type(the_type) == tuple:
self.type = NameType(the_type)
else:
self.type = the_type
def get_type(self):
"""

View File

@@ -0,0 +1,64 @@
#
# 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 RepositoryType(GrampsType):
UNKNOWN = -1
CUSTOM = 0
LIBRARY = 1
CEMETERY = 2
CHURCH = 3
ARCHIVE = 4
ALBUM = 5
WEBSITE = 6
BOOKSTORE = 7
COLLECTION = 8
SAFE = 9
_CUSTOM = CUSTOM
_DEFAULT = LIBRARY
_DATAMAP = [
(UNKNOWN, _("Unknown"), "Unknown"),
(CUSTOM, _("Custom"), "Custom"),
(LIBRARY, _("Library"), "Library"),
(CEMETERY, _("Cemetery"), "Cemetery"),
(CHURCH, _("Church"), "Church"),
(ARCHIVE, _("Archive"), "Archive"),
(ALBUM, _("Album"), "Album"),
(WEBSITE, _("Web site"), "Web site"),
(BOOKSTORE, _("Bookstore"), "Bookstore"),
(COLLECTION, _("Collection"), "Collection"),
(SAFE, _("Safe"), "Safe"),
]
_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

@@ -38,6 +38,7 @@ from warnings import warn
#-------------------------------------------------------------------------
from _BaseObject import BaseObject
from _PrivacyBase import PrivacyBase
from _UrlType import UrlType
#-------------------------------------------------------------------------
#
@@ -48,13 +49,6 @@ class Url(BaseObject,PrivacyBase):
"""Contains information related to internet Uniform Resource Locators,
allowing gramps to store information about internet resources"""
UNKNOWN = -1
CUSTOM = 0
EMAIL = 1
WEB_HOME = 2
WEB_SEARCH = 3
WEB_FTP = 4
def __init__(self,source=None):
"""creates a new URL instance, copying from the source if present"""
BaseObject.__init__(self)
@@ -66,13 +60,14 @@ class Url(BaseObject,PrivacyBase):
else:
self.path = ""
self.desc = ""
self.type = (Url.CUSTOM,"")
self.type = UrlType()
def serialize(self):
return (self.private,self.path,self.desc,self.type)
return (self.private,self.path,self.desc,self.type.serialize())
def unserialize(self,data):
(self.private,self.path,self.desc,self.type) = data
(self.private,self.path,self.desc,type_value) = data
self.type.unserialize(type_value)
return self
def get_text_data_list(self):
@@ -105,15 +100,12 @@ class Url(BaseObject,PrivacyBase):
@param type: descriptive type of the Url
@type type: str
"""
if not type(the_type) == tuple:
warn( "set_type now takes a tuple", DeprecationWarning, 2)
# Wrapper for old API
# remove when transitition done.
if the_type in range(-1,5):
the_type = (the_type,'')
else:
the_type = (Url.CUSTOM,the_type)
self.type = the_type
if type(the_type) == tuple:
self.type = UrlType(the_type)
else:
print the_type
assert(isinstance(the_type,UrlType))
self.type = the_type
def get_type(self):
"""

56
src/RelLib/_UrlType.py Normal file
View File

@@ -0,0 +1,56 @@
#
# 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 UrlType(GrampsType):
UNKNOWN = -1
CUSTOM = 0
EMAIL = 1
WEB_HOME = 2
WEB_SEARCH = 3
WEB_FTP = 4
_CUSTOM = CUSTOM
_DEFAULT = UNKNOWN
_DATAMAP = [
(UNKNOWN, _("Unknown"), "Unknown"),
(CUSTOM, _("Custom"), "Custom"),
(EMAIL, _("E-mail"), "E-mail"),
(WEB_HOME, _("Web Home"), "Web Home"),
(WEB_SEARCH, _("Web Search"), "Web Search"),
(WEB_FTP, _("FTP"), "FTP"),
]
_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,5 +61,7 @@ from _Researcher import Researcher
# Type classes
from _GrampsType import GrampsType
from _NameType import NameType
from _UrlType import UrlType
from _ChildRefType import ChildRefType
from _RepositoryType import RepositoryType