* src/const.py.in: Get rid of TransTable use in favor of int contsants.

* src/GrampsBSDDB.py (upgrade_2): Use proper constants.
* src/RelLib.py: Move constants out to const.py.in.


svn: r4716
This commit is contained in:
Alex Roitman 2005-05-27 20:09:28 +00:00
parent 9eaf68f135
commit f1e31b8270
4 changed files with 221 additions and 260 deletions

View File

@ -8,6 +8,9 @@
* src/const.py.in: Define integer constants for standard events.
* gramps.glade: Resolve merge conflicts.
* src/GrampsBSDDB.py (upgrade_*): Use transaction for commits.
* src/const.py.in: Get rid of TransTable use in favor of int contsants.
* src/GrampsBSDDB.py (upgrade_2): Use proper constants.
* src/RelLib.py: Move constants out to const.py.in.
2005-05-27 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/EditRepository.py: polish Repository Ref UI

View File

@ -514,11 +514,11 @@ class GrampsBSDDB(GrampsDbBase):
try:
mrel = child_rel_notrans.index(mrel)
except:
mrel = Person.CHILD_REL_BIRTH
mrel = const.CHILD_BIRTH
try:
frel = child_rel_notrans.index(frel)
except:
frel = Person.CHILD_REL_BIRTH
frel = const.CHILD_BIRTH
new_list.append((f,mrel,frel))
person.parent_family_list = new_list
self.commit_person(person,trans)

View File

@ -50,11 +50,6 @@ import DateHandler
# Confidence levels
#
#-------------------------------------------------------------------------
CONF_VERY_HIGH = 4
CONF_HIGH = 3
CONF_NORMAL = 2
CONF_LOW = 1
CONF_VERY_LOW = 0
#-------------------------------------------------------------------------
#
@ -895,19 +890,6 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
@sort: serialize, unserialize, get_*, set_*, add_*, remove_*
"""
UNKNOWN = 2
MALE = 1
FEMALE = 0
CHILD_REL_NONE = 0
CHILD_REL_BIRTH = 1
CHILD_REL_ADOPT = 2
CHILD_REL_STEP = 3
CHILD_REL_SPONS = 4
CHILD_REL_FOST = 5
CHILD_REL_UNKWN = 6
CHILD_REL_OTHER = 7
def __init__(self):
"""
Creates a new Person instance. After initialization, most
@ -924,7 +906,7 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
self.parent_family_list = []
self.nickname = ""
self.alternate_names = []
self.gender = Person.UNKNOWN
self.gender = const.UNKNOWN
self.death_ref = None
self.birth_ref = None
self.address_list = []
@ -1231,9 +1213,9 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
@param gender: Assigns the Person's gender to one of the
following constants::
Person.MALE
Person.FEMALE
Person.UNKNOWN
const.MALE
const.FEMALE
const.UNKNOWN
@type gender: int
"""
# if the db object has been assigned, update the
@ -1249,9 +1231,9 @@ class Person(PrimaryObject,PrivateSourceNote,MediaBase,AttributeBase):
Returns the gender of the Person
@returns: Returns one of the following constants::
Person.MALE
Person.FEMALE
Person.UNKNOWN
const.MALE
const.FEMALE
const.UNKNOWN
@rtype: int
"""
return self.gender
@ -1758,12 +1740,6 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
or the changes will be lost.
"""
MARRIED = 0
UNMARRIED = 1
CIVIL_UNION = 2
UNKNOWN = 3
OTHER = 4
def __init__(self):
"""
Creates a new Family instance. After initialization, most
@ -1777,7 +1753,7 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
self.father_handle = None
self.mother_handle = None
self.child_list = []
self.type = Family.MARRIED
self.type = const.FAMILY_MARRIED
self.event_ref_list = []
self.lds_seal = None
self.complete = 0
@ -1964,17 +1940,17 @@ class Family(PrimaryObject,SourceNote,MediaBase,AttributeBase):
Sets the relationship type between the people identified as the
father and mother in the relationship. The valid values are:
- C{Family.MARRIED} : indicates a legally recognized married
- C{const.FAMILY_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{const_FAMILY_UNMARRIED} : indicates a relationship between two
individuals that is not a legally recognized relationship.
- C{Family.CIVIL_UNION} : indicates a legally recongnized,
- C{const_FAMILY_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{const.FAMILY_UNKNOWN} : indicates that the type of relationship
between the two individuals is not know.
- C{Family.OTHER} : indicates that the type of relationship
- C{const.FAMILY_CUSTOM} : indicates that the type of relationship
between the two individuals does not match any of the
other types.
@ -4114,7 +4090,7 @@ class SourceRef(BaseObject,DateBase,PrivacyBase,NoteBase):
self.page = source.page
self.text = source.text
else:
self.confidence = CONF_NORMAL
self.confidence = const.CONF_NORMAL
self.ref = None
self.page = ""
self.note = Note()
@ -4215,16 +4191,6 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
to the refereneced event.
"""
ROLE_UNKNOWN = -1
ROLE_CUSTOM = 0
ROLE_PRIMARY = 1
ROLE_CLERGY = 2
ROLE_CELEBRANT = 3
ROLE_AIDE = 4
ROLE_BRIDE = 5
ROLE_GROOM = 6
ROLE_WITNESS = 7
def __init__(self,source=None):
"""
Creates a new EventRef instance, copying from the source if present.
@ -4237,7 +4203,7 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
self.role_str = source.role_str
else:
self.ref = None
self.role_int = self.ROLE_CUSTOM
self.role_int = const.ROLE_CUSTOM
self.role_str = ""
def get_text_data_list(self):
@ -4290,7 +4256,7 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
Returns the integer corresponding to the preset role.
If custom then the string is returned.
"""
if self.role_int == self.ROLE_CUSTOM:
if self.role_int == const.ROLE_CUSTOM:
return self.role_str
else:
return self.role_int
@ -4301,7 +4267,7 @@ class EventRef(BaseObject,PrivacyBase,NoteBase):
If integer, it is set as is. If string, it is recorded as custom role.
"""
if type(role) == str:
self.role_int = self.ROLE_CUSTOM
self.role_int = const.ROLE_CUSTOM
self.role_str = role
elif type(role) == int:
self.role_int = role
@ -4351,11 +4317,11 @@ class GenderStats:
else:
increment = -1
if gender == Person.MALE:
if gender == const.MALE:
male += increment
elif gender == Person.FEMALE:
elif gender == const.FEMALE:
female += increment
elif gender == Person.UNKNOWN:
elif gender == const.UNKNOWN:
unknown += increment
self.stats[name] = (male, female, unknown)
@ -4367,42 +4333,27 @@ class GenderStats:
def guess_gender (self, name):
name = self._get_key_from_name (name)
if not name or not self.stats.has_key (name):
return Person.UNKNOWN
return const.UNKNOWN
(male, female, unknown) = self.stats[name]
if unknown == 0:
if male and not female:
return Person.MALE
return const.MALE
if female and not male:
return Person.FEMALE
return const.FEMALE
if male > (2 * female):
return Person.MALE
return const.MALE
if female > (2 * male):
return Person.FEMALE
return const.FEMALE
return Person.UNKNOWN
return const.UNKNOWN
class RepoRef(BaseObject,NoteBase):
"""
Repository reference class.
"""
MEDIA_TYPE_CUSTOM = 0
MEDIA_TYPE_AUDIO = 1
MEDIA_TYPE_BOOK = 2
MEDIA_TYPE_CARD = 3
MEDIA_TYPE_ELECTRONIC = 4
MEDIA_TYPE_FICHE = 5
MEDIA_TYPE_FILM = 6
MEDIA_TYPE_MAGAZINE = 7
MEDIA_TYPE_MANUSCRIPT = 8
MEDIA_TYPE_MAP = 9
MEDIA_TYPE_NEWSPAPER = 10
MEDIA_TYPE_PHOTO = 11
MEDIA_TYPE_THOMBSTOBE = 12
MEDIA_TYPE_VIDEO = 13
def __init__(self,source=None):
NoteBase.__init__(self)
if source:
@ -4413,7 +4364,7 @@ class RepoRef(BaseObject,NoteBase):
else:
self.ref = None
self.call_number = ""
self.media_type_int = self.MEDIA_TYPE_CUSTOM
self.media_type_int = const.SRC_MEDIA_CUSTOM
self.media_type_str = ""
def get_text_data_list(self):
@ -4472,7 +4423,7 @@ class RepoRef(BaseObject,NoteBase):
return self.call_number
def get_media_type(self):
if self.media_type_int == self.MEDIA_TYPE_CUSTOM:
if self.media_type_int == const.SRC_MEDIA_CUSTOM:
return self.media_type_str
else:
return self.media_type_int
@ -4482,7 +4433,7 @@ class RepoRef(BaseObject,NoteBase):
self.media_type_int = media_type
self.media_type_str = ""
else:
self.media_type_int = self.MEDIA_TYPE_CUSTOM
self.media_type_int = const.SRC_MEDIA_CUSTOM
self.media_type_str = media_type
class Repository(PrimaryObject,NoteBase):
@ -4730,12 +4681,12 @@ if __name__ == "__main__":
rr1 = RepoRef()
rr1.set_reference_handle('ref-handle')
rr1.set_call_number('call-number')
rr1.set_media_type(RepoRef.MEDIA_TYPE_BOOK)
rr1.set_media_type(const.SRC_MEDIA_BOOK)
rr1.set_note('some note')
assert rr1.get_reference_handle() == 'ref-handle'
assert rr1.get_call_number() == 'call-number'
assert rr1.get_media_type() == RepoRef.MEDIA_TYPE_BOOK
assert rr1.get_media_type() == const.SRC_MEDIA_BOOK
assert rr1.get_note() == 'some note'
unittest.main()

View File

@ -35,7 +35,6 @@ import os
#
#-------------------------------------------------------------------------
from gettext import gettext as _
from TransTable import TransTable
#-------------------------------------------------------------------------
#
@ -164,9 +163,6 @@ translators = _('TRANSLATORS: Translate this to your name in your native languag
#-------------------------------------------------------------------------
thumbScale = 96.0
xmlFile = "data.gramps"
male = _("male")
female = _("female")
unknown = _("unknown")
#-------------------------------------------------------------------------
#
@ -225,41 +221,62 @@ shortopts = "O:i:o:f:a:p:?"
#-------------------------------------------------------------------------
#
# Constants
# Gender constants
#
#-------------------------------------------------------------------------
UNKNOWN = 2
MALE = 1
FEMALE = 0
child_rel_list = [
_("None"), _("Birth"), _("Adopted"), _("Stepchild"),
_("Sponsored"), _("Foster"), _("Unknown"), _("Other"), ]
child_rel_notrans = [
"None", "Birth", "Adopted", "Stepchild",
"Sponsored", "Foster", "Unknown", "Other", ]
child_relations = TransTable( {
_("Birth") : "Birth",
_("Adopted") : "Adopted",
_("Stepchild") : "Stepchild",
_("Sponsored") : "Sponsored",
_("Foster") : "Foster",
_("None") : "None",
_("Unknown") : "Unknown",
_("Other") : "Other",
})
gender = {
MALE : _("male"),
FEMALE : _("female"),
UNKNOWN : _("unknown"),
}
#-------------------------------------------------------------------------
#
# Confidence
# Child relation constants
#
#-------------------------------------------------------------------------
confidence = [
_("Very High"),
_("High"),
_("Normal"),
_("Low"),
_("Very Low")
]
CHILD_NONE = 0
CHILD_BIRTH = 1
CHILD_ADOPTED = 2
CHILD_STEPCHILD = 3
CHILD_SPONSORED = 4
CHILD_FOSTER = 5
CHILD_UNKNOWN = 6
CHILD_CUSTOM = 7
child_relations = {
CHILD_NONE : _("None"),
CHILD_BIRTH : _("Birth"),
CHILD_ADOPTED : _("Adopted"),
CHILD_STEPCHILD : _("Stepchild"),
CHILD_SPONSORED : _("Sponsored"),
CHILD_FOSTER : _("Foster"),
CHILD_UNKNOWN : _("Unknown"),
CHILD_CUSTOM : _("Custom"),
}
#-------------------------------------------------------------------------
#
# Confidence constants
#
#-------------------------------------------------------------------------
CONF_VERY_HIGH = 4
CONF_HIGH = 3
CONF_NORMAL = 2
CONF_LOW = 1
CONF_VERY_LOW = 0
confidence = {
CONF_VERY_HIGH : _("Very High"),
CONF_HIGH : _("High"),
CONF_NORMAL : _("Normal"),
CONF_LOW : _("Low"),
CONF_VERY_LOW : _("Very Low"),
}
#-------------------------------------------------------------------------
#
@ -419,121 +436,165 @@ personal_events = {
EVENT_WILL : _("Will")
}
#-------------------------------------------------------------------------
#
# Attribute constants
#
#-------------------------------------------------------------------------
ATTR_UNKNOWN = -1
ATTR_CUSTOM = 0
ATTR_CASTE = 1
ATTR_DESCRIPTION = 2
ATTR_ID = 3
ATTR_NATIONAL = 4
ATTR_NUM_CHILD = 5
ATTR_SSN = 6
#-------------------------------------------------------------------------
#
# Merged functions for events: personal, family, whatever else
# there might be in the future.
#
#-------------------------------------------------------------------------
def display_event(st):
if personal_events.has_key(st):
return personal_events.find_value(st)
if family_events.has_key(st):
return family_events.find_value(st)
return _(st)
personal_attributes = {
ATTR_UNKNOWN : _("Unknown"),
ATTR_CUSTOM : _("Custom"),
ATTR_CASTE : _("Caste"),
ATTR_DESCRIPTION : _("Description"),
ATTR_ID : _("Identification Number"),
ATTR_NATIONAL : _("National Origin"),
ATTR_NUM_CHILD : _("Number of Children"),
ATTR_SSN : _("Social Security Number"),
}
def save_event(st):
if personal_events.has_value(st):
return personal_events.find_key(st)
if family_events.has_value(st):
return family_events.find_key(st)
return st
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
personalConstantAttributes = {
"Caste" : "CAST",
"Description" : "DSCR",
"Identification Number" : "IDNO",
"National Origin" : "NATI",
"Number of Children" : "NCHI",
"Social Security Number": "SSN"
ATTR_CASTE : "CAST",
ATTR_DESCRIPTION : "DSCR",
ATTR_ID : "IDNO",
ATTR_NATIONAL : "NATI",
ATTR_NUM_CHILD : "NCHI",
ATTR_SSN : "SSN",
}
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
personal_attributes = TransTable({
"Caste" : _("Caste"),
"Description" : _("Description"),
"Identification Number" : _("Identification Number"),
"National Origin" : _("National Origin"),
"Number of Children" : _("Number of Children"),
"Social Security Number": _("Social Security Number")
})
def display_pattr(st):
return personal_attributes.find_value(st)
def save_pattr(st):
return personal_attributes.find_key(st)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
familyConstantAttributes = {
"Number of Children" : "NCHI",
ATTR_NUM_CHILD : "NCHI",
}
family_attributes = TransTable({"Number of Children" : _("Number of Children")})
def display_fattr(st):
return family_attributes.find_value(st)
#-------------------------------------------------------------------------
#
# Merged functions for attributes: personal, family, whatever else
# there might be in the future.
#
#-------------------------------------------------------------------------
def display_attr(st):
if personal_attributes.has_value(st):
return personal_attributes.find_value(st)
if family_attributes.has_value(st):
return family_attributes.find_value(st)
return _(st)
def save_attr(st):
if personal_attributes.has_value(st):
return personal_attributes.find_key(st)
if family_attributes.has_value(st):
return family_attributes.find_key(st)
return st
family_attributes = {
ATTR_UNKNOWN : _("Unknown"),
ATTR_CUSTOM : _("Custom"),
ATTR_NUM_CHILD : _("Number of Children"),
}
#-------------------------------------------------------------------------
#
# Family Relationship Translation table
#
#-------------------------------------------------------------------------
FAMILY_MARRIED = 0
FAMILY_UNMARRIED = 1
FAMILY_CIVIL_UNION = 2
FAMILY_UNKNOWN = 3
FAMILY_CUSTOM = 4
family_relations = {
FAMILY_MARRIED : _("Married"),
FAMILY_UNMARRIED : _("Unmarried"),
FAMILY_CIVIL_UNION : _("Civil Union"),
FAMILY_UNKNOWN : _("Unknown"),
FAMILY_CUSTOM : _("Other"),
}
family_relations = [
(_("Married"), _("A legal or common-law relationship between a husband and wife")),
(_("Unmarried"), _("No legal or common-law relationship between man and woman")),
(_("Civil Union"), _("An established relationship between members of the same sex")),
(_("Unknown"), _("Unknown relationship between a man and woman")),
(_("Other"), _("An unspecified relationship between a man and woman"))
]
family_rel_descriptions = {
FAMILY_MARRIED : _("A legal or common-law relationship "
"between a husband and wife"),
FAMILY_UNMARRIED : _("No legal or common-law relationship "
"between man and woman"),
FAMILY_CIVIL_UNION : _("An established relationship between "
"members of the same sex"),
FAMILY_UNKNOWN : _("Unknown relationship between a man and woman"),
FAMILY_CUSTOM : _("An unspecified relationship between "
"a man and woman"),
}
#-------------------------------------------------------------------------
#
# Name constants
#
#-------------------------------------------------------------------------
NAME_UNKNOWN = -1
NAME_CUSTOM = 0
NAME_AKA = 1
NAME_BIRTH = 2
NAME_MARRIED = 3
NameTypesMap = ({
NAME_UNKNOWN : _("Unknown"),
NAME_CUSTOM : _("Custom"),
NAME_AKA : _("Also Known As"),
NAME_BIRTH : _("Birth Name"),
NAME_MARRIED : _("Married Name"),
}
#-------------------------------------------------------------------------
#
# Role constants
#
#-------------------------------------------------------------------------
ROLE_UNKNOWN = -1
ROLE_CUSTOM = 0
ROLE_PRIMARY = 1
ROLE_CLERGY = 2
ROLE_CELEBRANT = 3
ROLE_AIDE = 4
ROLE_BRIDE = 5
ROLE_GROOM = 6
ROLE_WITNESS = 7
event_roles = {
ROLE_UNKNOWN : _("Unknown"),
ROLE_CUSTOM : _("Custom"),
ROLE_PRIMARY : _("Primary participant"),
ROLE_CLERGY : _("Clergy personnel"),
ROLE_CELEBRANT : _("Celebrant"),
ROLE_AIDE : _("Aide"),
ROLE_BRIDE : _("Bride"),
ROLE_GROOM : _("Groom"),
ROLE_WITNESS : _("Witness"),
}
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def save_frel(st):
try:
return family_relations[st][0]
except:
return _("Unknown")
SRC_MEDIA_UNKNOWN = -1
SRC_MEDIA_CUSTOM = 0
SRC_MEDIA_AUDIO = 1
SRC_MEDIA_BOOK = 2
SRC_MEDIA_CARD = 3
SRC_MEDIA_ELECTRONIC = 4
SRC_MEDIA_FICHE = 5
SRC_MEDIA_FILM = 6
SRC_MEDIA_MAGAZINE = 7
SRC_MEDIA_MANUSCRIPT = 8
SRC_MEDIA_MAP = 9
SRC_MEDIA_NEWSPAPER = 10
SRC_MEDIA_PHOTO = 11
SRC_MEDIA_THOMBSTOBE = 12
SRC_MEDIA_VIDEO = 13
source_media_types = {
SRC_MEDIA_UNKNOWN : _("Unknown"),
SRC_MEDIA_CUSTOM : _("Custom"),
SRC_MEDIA_AUDIO : _("Audio"),
SRC_MEDIA_BOOK : _("Book"),
SRC_MEDIA_CARD : _("Card"),
SRC_MEDIA_ELECTRONIC : _("Electronic"),
SRC_MEDIA_FICHE : _("Fiche"),
SRC_MEDIA_FILM : _("Film"),
SRC_MEDIA_MAGAZINE : _("Magazine"),
SRC_MEDIA_MANUSCRIPT : _("Manuscript"),
SRC_MEDIA_MAP : _("Map"),
SRC_MEDIA_NEWSPAPER : _("Newspaper"),
SRC_MEDIA_PHOTO : _("Photo"),
SRC_MEDIA_THOMBSTOBE : _("Thombstone"),
SRC_MEDIA_VIDEO : _("Video"),
}
#-------------------------------------------------------------------------
#
@ -541,60 +602,6 @@ def save_frel(st):
#
#-------------------------------------------------------------------------
NameTypesMap = TransTable({
"Also Known As" : _("Also Known As"),
"Birth Name" : _("Birth Name"),
"Married Name" : _("Married Name"),
"Other Name" : _("Other Name"),
})
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def init_personal_event_list():
return
p = personal_events.get_values()
p.sort()
return p
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def init_marriage_event_list():
return
p = family_events.get_values()
p.sort()
return p
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def init_personal_attribute_list():
p = personal_attributes.get_values()
p.sort()
return p
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def init_family_attribute_list():
p = family_attributes.get_values()
p.sort()
return p
personalEvents = [] #init_personal_event_list()
personalAttributes = init_personal_attribute_list()
marriageEvents = [] #init_marriage_event_list()
defaultMarriageEvent = "" #family_events.find_value("Marriage")
familyAttributes = init_family_attribute_list()
places = []
surnames = []