diff --git a/ChangeLog b/ChangeLog index c32a940fc..d8848858b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,36 @@ 2006-04-13 Don Allingham + * src/DataViews/_FamilyView.py: Type class support + * src/DataViews/_PedigreeView.py: Type class support + * src/GrampsDb/_ReadGedcom.py: Type class support + * src/GrampsDb/_ReadXML.py: Type class support + * src/GrampsDb/_DbUtils.py: Type class support + * src/GrampsDb/_ConstXML.py: Type class support + * src/GrampsDb/_WriteXML.py: Type class support + * src/GrampsDb/_GrampsBSDDB.py: Type class support + * src/RelLib/__init__.py: Type class support + * src/RelLib/_Person.py: Type class support + * src/RelLib/_ChildRef.py: Type class support + * src/RelLib/_Name.py: Type class support + * src/Editors/_EditPerson.py: Type class support + * src/Editors/_EditName.py: Type class support + * src/Editors/_EditFamily.py: Type class support + * src/plugins/DumpGenderStats.py: Type class support + * src/plugins/ChangeNames.py: Type class support + * src/plugins/TestcaseGenerator.py: Type class support + * src/plugins/GraphViz.py: Type class support + * src/plugins/Check.py: Type class support + * src/plugins/NavWebPage.py: Type class support + * src/plugins/ChangeTypes.py: Type class support + * src/plugins/summary.glade: Type class support + * src/plugins/PatchNames.py: Type class support + * src/DisplayTabs.py: Type class support + * src/GrampsWidgets.py: Type class support + * src/Utils.py: Type class support + * src/ScratchPad.py: Type class support + * src/GenericFilter.py: Type class support + * src/RelLib/ChildRefType.py: Type class support + * src/RelLib/GrampsType.py: Type class support + * src/RelLib/NameType.py: Type class support * src/GrampsDb/_ReadGedcom.py: handle ASSO tag * src/GrampsDb/_GedTokens.py: handle ASSO tag * example/gedcom/sample.ged: add ASSO tag diff --git a/src/DataViews/_FamilyView.py b/src/DataViews/_FamilyView.py index 76a21c40c..987e4f909 100644 --- a/src/DataViews/_FamilyView.py +++ b/src/DataViews/_FamilyView.py @@ -701,8 +701,8 @@ class FamilyView(PageView.PersonNavView): if family: person = self.dbstate.db.get_person_from_handle(self.dbstate.active.handle) GrampsDb.add_child_to_family(family, child, - (RelLib.ChildRef.CHILD_BIRTH,'') - (RelLib.ChildRef.CHILD_BIRTH,'')) + RelLib.ChildRef(), + RelLib.ChildRef()) def add_parent_family(self, obj, event, handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: diff --git a/src/DataViews/_PedigreeView.py b/src/DataViews/_PedigreeView.py index 1a724d08f..b6f794604 100644 --- a/src/DataViews/_PedigreeView.py +++ b/src/DataViews/_PedigreeView.py @@ -1127,8 +1127,8 @@ class PedigreeView(PageView.PersonNavView): if family != None: for child_ref in family.get_child_ref_list(): if child_ref.ref == person.handle: - mrel = child_ref.mrel != RelLib.ChildRef.CHILD_BIRTH - frel = child_ref.frel != RelLib.ChildRef.CHILD_BIRTH + mrel = child_ref.mrel != RelLib.ChildRefType.BIRTH + frel = child_ref.frel != RelLib.ChildRefType.BIRTH lst[index] = (person,val,family) father_handle = family.get_father_handle() diff --git a/src/DisplayTabs.py b/src/DisplayTabs.py index 682536674..9f7a4e0e3 100644 --- a/src/DisplayTabs.py +++ b/src/DisplayTabs.py @@ -1890,10 +1890,10 @@ class ChildModel(gtk.ListStore): return self.family.get_child_ref_list() def column_father_rel(self, data): - return Utils.format_child_relation(data.get_father_relation()) + return str(data.get_father_relation()) def column_mother_rel(self, data): - return Utils.format_child_relation(data.get_mother_relation()) + return str(data.get_mother_relation()) def column_birth_day(self, data): event_ref = data.get_birth_ref() @@ -2053,13 +2053,10 @@ class NameModel(gtk.ListStore): for obj in obj_list: self.append(row=[ NameDisplay.displayer.display_name(obj), - self.type_name(obj), + str(obj.get_type()), obj, ]) - def type_name(self, obj): - return Utils.format_name_type(obj.get_type()) - #------------------------------------------------------------------------- # # AddressModel diff --git a/src/Editors/_EditFamily.py b/src/Editors/_EditFamily.py index d742f110b..e2c79c19c 100644 --- a/src/Editors/_EditFamily.py +++ b/src/Editors/_EditFamily.py @@ -155,15 +155,22 @@ class ChildEmbedList(EmbeddedList): if not pair[0]: continue name = self._column_names[pair[1]][0] - if pair[1] == 4 or pair[1] == 5: - render = TypeCellRenderer(Utils.child_relations) + if pair[1] == 4: + render = TypeCellRenderer(RelLib.ChildRefType().get_map()) + render.connect('edited',self.frel_edited) column = gtk.TreeViewColumn(name, render, text=pair[1]) + column.set_min_width(100) + elif pair[1] == 5: + render = TypeCellRenderer(RelLib.ChildRefType().get_map()) + render.connect('edited',self.mrel_edited) + column = gtk.TreeViewColumn(name, render, text=pair[1]) + column.set_min_width(100) else: render = gtk.CellRendererText() column = gtk.TreeViewColumn(name, render, text=pair[1]) + column.set_min_width(50) column.set_resizable(True) - column.set_min_width(40) column.set_sort_column_id(self._column_names[pair[1]][1]) self.columns.append(column) self.tree.append_column(column) @@ -177,6 +184,17 @@ class ChildEmbedList(EmbeddedList): """ return len(self.family.get_child_ref_list()) == 0 + def mrel_edited(self, renderer, index, value): + ref = self.family.get_child_ref_list()[int(index)] + new_type = RelLib.ChildRefType(value) + print "Before", str(new_type) + ref.set_mother_relation(new_type) + print "After", str(ref.get_mother_relation()) + + def frel_edited(self, renderer, index, value): + ref = self.family.get_child_ref_list()[int(index)] + ref.set_father_relation(RelLib.ChildRefType(value)) + def get_data(self): """ Normally, get_data returns a list. However, we return family @@ -848,8 +866,8 @@ class EditFamily(EditPrimary): person = self.db.get_person_from_handle(handle) person.add_parent_family_handle( self.obj.handle, - (RelLib.ChildRef.CHILD_BIRTH,''), - (RelLib.ChildRef.CHILD_BIRTH,''), + RelLib.ChildRefType(), + RelLib.ChildRefType(), ) self.db.commit_person(person,trans) diff --git a/src/Editors/_EditName.py b/src/Editors/_EditName.py index e1fa748a8..7e3c6612f 100644 --- a/src/Editors/_EditName.py +++ b/src/Editors/_EditName.py @@ -144,9 +144,10 @@ class EditName(EditSecondary): self.top.get_widget("date_stat"), self.obj.get_date_object(),self.window) - self.obj_combo = MonitoredType( - self.top.get_widget("name_type"), self.obj.set_type, - self.obj.get_type, dict(Utils.name_types), RelLib.Name.CUSTOM) + self.obj_combo = MonitoredDataType( + self.top.get_widget("name_type"), + self.obj.set_type, + self.obj.get_type) self.privacy = PrivacyButton( self.top.get_widget("priv"), self.obj) diff --git a/src/Editors/_EditPerson.py b/src/Editors/_EditPerson.py index e8947fb92..2f55e3643 100644 --- a/src/Editors/_EditPerson.py +++ b/src/Editors/_EditPerson.py @@ -169,12 +169,10 @@ class EditPerson(EditPrimary): ), self.db.readonly) - self.ntype_field = GrampsWidgets.MonitoredType( + self.ntype_field = GrampsWidgets.MonitoredDataType( self.top.get_widget("ntype"), self.pname.set_type, self.pname.get_type, - dict(Utils.name_types), - RelLib.Name.CUSTOM, self.db.readonly) self.marker = GrampsWidgets.MonitoredType( diff --git a/src/GenericFilter.py b/src/GenericFilter.py index 6e497b7a6..63f4ec67f 100644 --- a/src/GenericFilter.py +++ b/src/GenericFilter.py @@ -1448,8 +1448,8 @@ class HaveAltFamilies(Rule): def apply(self,db,person): for (fam,rel1,rel2) in person.get_parent_family_handle_list(): - if rel1 == RelLib.ChildRef.CHILD_ADOPTED \ - or rel2 == RelLib.ChildRef.CHILD_ADOPTED: + if rel1 == RelLib.ChildRefType.CHILD_ADOPTED \ + or rel2 == RelLib.ChildRefType.CHILD_ADOPTED: return True return False diff --git a/src/GrampsDb/_ConstXML.py b/src/GrampsDb/_ConstXML.py index 119a13163..4f2c03f67 100644 --- a/src/GrampsDb/_ConstXML.py +++ b/src/GrampsDb/_ConstXML.py @@ -33,12 +33,12 @@ import RelLib # #------------------------------------------------------------------------- child_relations = ( - (RelLib.ChildRef.CHILD_BIRTH , "Birth"), - (RelLib.ChildRef.CHILD_ADOPTED , "Adopted"), - (RelLib.ChildRef.CHILD_STEPCHILD , "Stepchild"), - (RelLib.ChildRef.CHILD_SPONSORED , "Sponsored"), - (RelLib.ChildRef.CHILD_FOSTER , "Foster"), - (RelLib.ChildRef.CHILD_UNKNOWN , "Unknown"), + (RelLib.ChildRefType.BIRTH , "Birth"), + (RelLib.ChildRefType.ADOPTED , "Adopted"), + (RelLib.ChildRefType.STEPCHILD , "Stepchild"), + (RelLib.ChildRefType.SPONSORED , "Sponsored"), + (RelLib.ChildRefType.FOSTER , "Foster"), + (RelLib.ChildRefType.UNKNOWN , "Unknown"), ) events = ( @@ -111,10 +111,10 @@ family_relations = ( ) name_types = ( - (RelLib.Name.UNKNOWN , "Unknown"), - (RelLib.Name.AKA , "Also Known As"), - (RelLib.Name.BIRTH , "Birth Name"), - (RelLib.Name.MARRIED , "Married Name"), + (RelLib.NameType.UNKNOWN , "Unknown"), + (RelLib.NameType.AKA , "Also Known As"), + (RelLib.NameType.BIRTH , "Birth Name"), + (RelLib.NameType.MARRIED , "Married Name"), ) source_media_types = ( @@ -175,11 +175,11 @@ url_types = ( # mapping from the tuple collection to the appropriate CUSTOM integer custom_types = { - child_relations : RelLib.ChildRef.CHILD_CUSTOM, + child_relations : RelLib.ChildRefType.CUSTOM, events : RelLib.Event.CUSTOM, attributes : RelLib.Attribute.CUSTOM, family_relations : RelLib.Family.CUSTOM, - name_types : RelLib.Name.CUSTOM, + name_types : RelLib.NameType.CUSTOM, source_media_types : RelLib.RepoRef.CUSTOM, event_roles : RelLib.EventRef.CUSTOM, repository_types : RelLib.Repository.CUSTOM, diff --git a/src/GrampsDb/_DbUtils.py b/src/GrampsDb/_DbUtils.py index f044f6856..f8b8d36cf 100644 --- a/src/GrampsDb/_DbUtils.py +++ b/src/GrampsDb/_DbUtils.py @@ -119,8 +119,8 @@ def remove_child_from_family(db, person_handle, family_handle, trans=None): def add_child_to_family(db, family, child, - mrel=(RelLib.ChildRef.CHILD_BIRTH,''), - frel=(RelLib.ChildRef.CHILD_BIRTH,''), + mrel=RelLib.ChildRefType(), + frel=RelLib.ChildRefType(), trans=None): family.add_child_handle(child.handle) diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index 95178f723..d1e02193f 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -1401,20 +1401,20 @@ class GrampsBSDDB(GrampsDbBase): # In all Name instances, convert type from string to a tuple name_conversion = { - "Also Known As" : (Name.AKA,""), - "Birth Name" : (Name.BIRTH,""), - "Married Name" : (Name.MARRIED,""), - "Other Name" : (Name.CUSTOM,_("Other Name")), + "Also Known As" : (NameType.AKA,""), + "Birth Name" : (NameType.BIRTH,""), + "Married Name" : (NameType.MARRIED,""), + "Other Name" : (NameType.CUSTOM,_("Other Name")), } for name in [person.primary_name] + person.alternate_names: old_type = name.type if old_type: if name_conversion.has_key(old_type): - new_type = name_conversion[old_type] + new_type = NameType(name_conversion[old_type]) else: - new_type = (Name.CUSTOM,old_type) + new_type = NameType((NameType.CUSTOM,old_type)) else: - new_type = (Name.UNKNOWN,"") + new_type = NameType((NameType.UNKNOWN,"")) name.type = new_type # Change parent_family_list into list of handles diff --git a/src/GrampsDb/_ReadGedcom.py b/src/GrampsDb/_ReadGedcom.py index fcf6e0024..c85e6c21d 100644 --- a/src/GrampsDb/_ReadGedcom.py +++ b/src/GrampsDb/_ReadGedcom.py @@ -120,6 +120,10 @@ ANSEL = 1 UNICODE = 2 UPDATE = 25 +_TYPE_BIRTH = RelLib.ChildRefType() +_TYPE_ADOPT = RelLib.ChildRefType(RelLib.ChildRefType.ADOPTED) +_TYPE_FOSTER = RelLib.ChildRefType(RelLib.ChildRefType.FOSTER) + file_systems = { 'VFAT' : _('Windows 9x file system'), 'FAT' : _('Windows 9x file system'), @@ -128,16 +132,17 @@ file_systems = { "SMBFS" : _('Networked Windows file system') } -rel_types = ((RelLib.ChildRef.CHILD_BIRTH,''), - (RelLib.ChildRef.CHILD_UNKNOWN,''), - (RelLib.ChildRef.CHILD_NONE,'')) +rel_types = (RelLib.ChildRefType.BIRTH, + RelLib.ChildRefType.UNKNOWN, + RelLib.ChildRefType.NONE, + ) pedi_type = { - 'birth' : (RelLib.ChildRef.CHILD_BIRTH,''), - 'natural': (RelLib.ChildRef.CHILD_BIRTH,''), - 'step' : (RelLib.ChildRef.CHILD_ADOPTED,''), - 'adopted': (RelLib.ChildRef.CHILD_ADOPTED,''), - 'foster' : (RelLib.ChildRef.CHILD_FOSTER,''), + 'birth' : RelLib.ChildRefType(), + 'natural': RelLib.ChildRefType(), + 'step' : _TYPE_ADOPT, + 'adopted': _TYPE_ADOPT, + 'foster' : _TYPE_FOSTER, } lds_status = { @@ -1046,8 +1051,8 @@ class GedcomParser: self.barf(level+1) def parse_ftw_relations(self,level): - mrel = (RelLib.ChildRef.CHILD_BIRTH,'') - frel = (RelLib.ChildRef.CHILD_BIRTH,'') + mrel = RelLib.ChildRefType() + frel = RelLib.ChildRefType() while True: matches = self.get_next() @@ -1056,17 +1061,17 @@ class GedcomParser: return (mrel,frel) # FTW elif matches[1] == TOKEN__FREL: - frel = pedi_type.get(matches[2].lower(),(RelLib.ChildRef.CHILD_BIRTH,'')) + frel = pedi_type.get(matches[2].lower(),_TYPE_BIRTH) # FTW elif matches[1] == TOKEN__MREL: - mrel = pedi_type.get(matches[2].lower(),(RelLib.ChildRef.CHILD_BIRTH,'')) + mrel = pedi_type.get(matches[2].lower(),_TYPE_BIRTH) elif matches[1] == TOKEN_ADOP: - mrel = (RelLib.ChildRef.CHILD_ADOPTED,'') - frel = (RelLib.ChildRef.CHILD_ADOPTED,'') + mrel = _TYPE_ADOPT + frel = _TYPE_ADOPT # Legacy elif matches[1] == TOKEN__STAT: - mrel = (RelLib.ChildRef.CHILD_BIRTH,'') - frel = (RelLib.ChildRef.CHILD_BIRTH,'') + mrel = _TYPE_BIRTH + frel = _TYPE_BIRTH # Legacy _PREF elif matches[1][0] == TOKEN_UNKNOWN: pass @@ -1226,7 +1231,7 @@ class GedcomParser: return None def parse_famc_type(self,level,person): - ftype = (RelLib.ChildRef.CHILD_BIRTH,'') + ftype = _TYPE_BIRTH note = "" while True: matches = self.get_next() @@ -1528,7 +1533,7 @@ class GedcomParser: if self.person.get_main_parents_family_handle() == handle: self.person.set_main_parent_family_handle(None) self.person.add_parent_family_handle(handle) - if mrel[0] != RelLib.ChildRef.BIRTH or frel[0] != RelLib.ChildRef.BIRTH: + if mrel != RelLib.ChildRefType.BIRTH or frel != RelLib.ChildRefType.BIRTH: print "NOT FIXED YET" elif matches[1] == TOKEN_PLAC: val = matches[2] @@ -1555,8 +1560,8 @@ class GedcomParser: self.barf(level+1) def parse_adopt_famc(self,level): - mrel = RelLib.ChildRef.CHILD_ADOPTED - frel = RelLib.ChildRef.CHILD_ADOPTED + mrel = _TYPE_ADOPT + frel = _TYPE_ADOPT while True: matches = self.get_next() if int(matches[0]) < level: @@ -1564,9 +1569,9 @@ class GedcomParser: return (mrel,frel) elif matches[1] == TOKEN_ADOP: if matches[2] == "HUSB": - mrel = RelLib.ChildRef.CHILD_BIRTH + mrel = _TYPE_BIRTH elif matches[2] == "WIFE": - frel = RelLib.ChildRef.CHILD_BIRTH + frel = _TYPE_BIRTH else: self.barf(level+1) return None @@ -2117,7 +2122,7 @@ class GedcomParser: if f[0] == handle: break else: - if ftype in rel_types: + if int(ftype) in rel_types: state.person.add_parent_family_handle(handle) else: if state.person.get_main_parents_family_handle() == handle: diff --git a/src/GrampsDb/_ReadXML.py b/src/GrampsDb/_ReadXML.py index a99a6ef2b..708e62563 100644 --- a/src/GrampsDb/_ReadXML.py +++ b/src/GrampsDb/_ReadXML.py @@ -917,8 +917,8 @@ class GrampsParser: frel = _ConstXML.tuple_from_xml(_ConstXML.child_relations, attrs.get('frel','Birth')) - if mrel[0] != RelLib.ChildRef.CHILD_BIRTH or \ - frel[0] != RelLib.ChildRef.CHILD_BIRTH: + if mrel != RelLib.ChildRefType.CHILD_BIRTH or \ + frel != RelLib.ChildRefType.CHILD_BIRTH: childref = RelLib.ChildRef() childref.ref = self.person.handle childref.set_mother_relation(mrel) diff --git a/src/GrampsDb/_WriteXML.py b/src/GrampsDb/_WriteXML.py index ec7b15d02..58b617f7d 100644 --- a/src/GrampsDb/_WriteXML.py +++ b/src/GrampsDb/_WriteXML.py @@ -424,12 +424,12 @@ class XmlWriter: else: continue - if mval[0] != RelLib.ChildRef.CHILD_BIRTH: + if mval != RelLib.ChildRefType.BIRTH: mrel=' mrel="%s"' % _ConstXML.str_for_xml( _ConstXML.child_relations,mval) else: mrel='' - if fval[0] != RelLib.ChildRef.CHILD_BIRTH: + if fval != RelLib.ChildRefType.BIRTH: frel=' frel="%s"' % _ConstXML.str_for_xml( _ConstXML.child_relations,fval) else: diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index 7c89454fe..fe971719e 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -343,6 +343,39 @@ class MonitoredType: def on_change(self, obj): self.set_val(self.sel.get_values()) +class MonitoredDataType: + + def __init__(self, obj, set_val, get_val, readonly=False, custom_values=None): + + self.set_val = set_val + self.get_val = get_val + + self.obj = obj + + val = get_val() + if val: + default = int(val) + else: + default = None + + self.sel = AutoComp.StandardCustomSelector( + get_val().get_map(), + obj, + get_val().get_custom(), + default, + additional=custom_values) + + self.set_val(self.sel.get_values()) + self.obj.set_sensitive(not readonly) + self.obj.connect('changed', self.on_change) + + def update(self): + if self.get_val(): + self.sel.set_values(self.get_val()) + + def on_change(self, obj): + self.set_val(self.sel.get_values()) + class MonitoredMenu: def __init__(self, obj, set_val, get_val, mapping, diff --git a/src/RelLib/Makefile.am b/src/RelLib/Makefile.am index e6dcda216..c2ff56939 100644 --- a/src/RelLib/Makefile.am +++ b/src/RelLib/Makefile.am @@ -18,6 +18,7 @@ pkgdata_PYTHON = \ _EventRef.py\ _Family.py\ _GenderStats.py\ + _GrampsType.py\ __init__.py\ _LdsOrdBase.py\ _LdsOrd.py\ @@ -27,6 +28,7 @@ pkgdata_PYTHON = \ _MediaObject.py\ _MediaRef.py\ _Name.py\ + _NameType.py\ _NoteBase.py\ _Note.py\ _Person.py\ @@ -47,7 +49,8 @@ pkgdata_PYTHON = \ _Witness.py\ _SourceBase.py\ _RefBase.py\ - _ChildRef.py + _ChildRef.py\ + _ChildRefType.py pkgpyexecdir = @pkgpyexecdir@/RelLib pkgpythondir = @pkgpythondir@/RelLib diff --git a/src/RelLib/_ChildRef.py b/src/RelLib/_ChildRef.py index 35f934ab7..800292230 100644 --- a/src/RelLib/_ChildRef.py +++ b/src/RelLib/_ChildRef.py @@ -34,6 +34,7 @@ from _PrivacyBase import PrivacyBase from _SourceBase import SourceBase from _NoteBase import NoteBase from _RefBase import RefBase +from _ChildRefType import ChildRefType #------------------------------------------------------------------------- # @@ -49,15 +50,6 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): Examples would be: godparent, friend, etc. """ - CHILD_NONE = 0 - CHILD_BIRTH = 1 - CHILD_ADOPTED = 2 - CHILD_STEPCHILD = 3 - CHILD_SPONSORED = 4 - CHILD_FOSTER = 5 - CHILD_UNKNOWN = 6 - CHILD_CUSTOM = 7 - def __init__(self,source=None): BaseObject.__init__(self) PrivacyBase.__init__(self,source) @@ -68,22 +60,25 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): self.frel = source.frel self.mrel = source.mrel else: - self.frel = (ChildRef.CHILD_BIRTH,'') - self.mrel = (ChildRef.CHILD_BIRTH,'') + self.frel = ChildRefType() + self.mrel = ChildRefType() def serialize(self): return (PrivacyBase.serialize(self), SourceBase.serialize(self), NoteBase.serialize(self), RefBase.serialize(self), - self.frel,self.mrel) + self.frel.serialize(), + self.mrel.serialize()) def unserialize(self,data): - (privacy,source_list,note,ref,self.frel,self.mrel) = data + (privacy,source_list,note,ref,frel,mrel) = data PrivacyBase.unserialize(self,privacy) SourceBase.unserialize(self,source_list) NoteBase.unserialize(self,note) RefBase.unserialize(self,ref) + self.frel.unserialize(frel) + self.mrel.unserialize(mrel) return self def get_text_data_list(self): @@ -93,7 +88,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): @return: Returns the list of all textual attributes of the object. @rtype: list """ - return [self.rel] + return [self.rel, str(self.frel), str(mrel)] def get_text_data_child_list(self): """ @@ -132,6 +127,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): def set_mother_relation(self,rel): """Sets relation between the person and mother""" + assert(isinstance(rel,ChildRefType)) self.mrel = rel def get_mother_relation(self): @@ -140,6 +136,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): def set_father_relation(self,frel): """Sets relation between the person and father""" + assert(isinstance(frel,ChildRefType)) self.frel = frel def get_father_relation(self): diff --git a/src/RelLib/_ChildRefType.py b/src/RelLib/_ChildRefType.py new file mode 100644 index 000000000..a11460a77 --- /dev/null +++ b/src/RelLib/_ChildRefType.py @@ -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 ChildRefType(GrampsType): + + NONE = 0 + BIRTH = 1 + ADOPTED = 2 + STEPCHILD = 3 + SPONSORED = 4 + FOSTER = 5 + UNKNOWN = 6 + CUSTOM = 7 + + _CUSTOM = CUSTOM + _DEFAULT = BIRTH + + _I2SMAP = { + NONE : _("None"), + BIRTH : _("Birth"), + ADOPTED : _("Adopted"), + STEPCHILD : _("Stepchild"), + SPONSORED : _("Sponsored"), + FOSTER : _("Foster"), + UNKNOWN : _("Unknown"), + CUSTOM : _("Custom"), + } + + _S2IMAP = init_map(_I2SMAP) + + def __init__(self, value=None): + GrampsType.__init__(self, value) + + diff --git a/src/RelLib/_GrampsType.py b/src/RelLib/_GrampsType.py new file mode 100644 index 000000000..b657ba194 --- /dev/null +++ b/src/RelLib/_GrampsType.py @@ -0,0 +1,96 @@ +# +# 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 gettext import gettext as _ + +def init_map(data): + new_data = {} + for i in data.keys(): + new_data[data[i]] = i + return new_data + +class GrampsType: + + _CUSTOM = 0 + _DEFAULT = 0 + _I2SMAP = {} + + _S2IMAP = init_map(_I2SMAP) + + def __init__(self, value=None): + self.set(value) + + def set(self, value): + if type(value) == tuple: + self.val = value[0] + self.string = value[1] + elif type(value) == int: + self.val = value + self.string = '' + elif type(value) == str: + self.val = self._S2IMAP.get(value,self._CUSTOM) + if self.val == self._CUSTOM: + self.string = value + else: + self.string = '' + else: + self.val = self._DEFAULT + self.string = '' + + def serialize(self): + return (self.val, self.string) + + def unserialize(self, data): + self.val, self.string = data + + def __str__(self): + if self.val == self._CUSTOM: + return self.string + else: + return self._I2SMAP.get(self.val,_('UNKNOWN')) + + def __int__(self): + return self.val + + def get_map(self): + return self._I2SMAP + + def get_custom(self): + return self._CUSTOM + + def __cmp__(self, value): + if type(value) == int: + return cmp(self.val,value) + elif type(value) == str: + if self.val == self._CUSTOM: + return cmp(self.string,value) + else: + return cmp(self._I2SMAP.get(self.val),value) + elif type(value) == tuple: + return cmp((self.val,self.string),value) + else: + if value.val == self._CUSTOM: + return cmp(self.string,value.string) + else: + return cmp(self.val,value.val) + + diff --git a/src/RelLib/_Name.py b/src/RelLib/_Name.py index f3d5915d3..236fa1a65 100644 --- a/src/RelLib/_Name.py +++ b/src/RelLib/_Name.py @@ -41,6 +41,7 @@ from _PrivacyBase import PrivacyBase from _SourceBase import SourceBase from _NoteBase import NoteBase from _DateBase import DateBase +from _NameType import NameType #------------------------------------------------------------------------- # @@ -60,20 +61,15 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): PTFN = 3 # patronymic last name FN = 4 # first name - UNKNOWN = -1 - CUSTOM = 0 - AKA = 1 - BIRTH = 2 - MARRIED = 3 - def __init__(self,source=None,data=None): """creates a new Name instance, copying from the source if provided""" BaseObject.__init__(self) if data: (privacy,source_list,note,date, self.first_name,self.surname,self.suffix,self.title, - self.type,self.prefix,self.patronymic,self.sname, + name_type,self.prefix,self.patronymic,self.sname, self.group_as,self.sort_as,self.display_as) = data + self.type = NameType(name_type) PrivacyBase.unserialize(self,privacy) SourceBase.unserialize(self,source_list) NoteBase.unserialize(self,note) @@ -103,7 +99,7 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): self.surname = "" self.suffix = "" self.title = "" - self.type = (Name.BIRTH,"") + self.type = NameType() self.prefix = "" self.patronymic = "" self.sname = '@' @@ -117,14 +113,15 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): NoteBase.serialize(self), DateBase.serialize(self), self.first_name,self.surname,self.suffix,self.title, - self.type,self.prefix,self.patronymic,self.sname, + self.type.serialize(),self.prefix,self.patronymic,self.sname, self.group_as,self.sort_as,self.display_as) def unserialize(self,data): (privacy,source_list,note,date, self.first_name,self.surname,self.suffix,self.title, - self.type,self.prefix,self.patronymic,self.sname, + name_type,self.prefix,self.patronymic,self.sname, self.group_as,self.sort_as,self.display_as) = data + self.type = NameType(name_type) PrivacyBase.unserialize(self,privacy) SourceBase.unserialize(self,source_list) NoteBase.unserialize(self,note) @@ -139,7 +136,7 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): @rtype: list """ return [self.first_name,self.surname,self.suffix,self.title, - self.type[1],self.prefix,self.patronymic] + str(self.type),self.prefix,self.patronymic] def get_text_data_child_list(self): """ @@ -237,15 +234,10 @@ class Name(BaseObject,PrivacyBase,SourceBase,NoteBase,DateBase): def set_type(self,the_type): """sets the type of the Name instance""" - if not type(the_type) == tuple: - if the_type in [self.UNKNOWN,self.CUSTOM,self.AKA,self.BIRTH,self.MARRIED]: - warn( "set_type now takes a tuple", DeprecationWarning, 2) - # Wrapper for old API - # remove when transitition done. - the_type = (the_type,'') - else: - assert type(the_type) == tuple - self.type = the_type + if type(the_type) == tuple: + self.type = NameType(the_type) + else: + self.type = the_type def get_type(self): """returns the type of the Name instance""" diff --git a/src/RelLib/_NameType.py b/src/RelLib/_NameType.py new file mode 100644 index 000000000..a440e3da0 --- /dev/null +++ b/src/RelLib/_NameType.py @@ -0,0 +1,48 @@ +# +# 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 +from gettext import gettext as _ + +class NameType(GrampsType): + + UNKNOWN = -1 + CUSTOM = 0 + AKA = 1 + BIRTH = 2 + MARRIED = 3 + + _CUSTOM = CUSTOM + _DEFAULT = BIRTH + + _I2SMAP = { + UNKNOWN : _("Unknown"), + CUSTOM : _("Custom"), + AKA : _("Also Known As"), + BIRTH : _("Birth Name"), + MARRIED : _("Married Name"), + } + + def __init__(self, value=None): + GrampsType.__init__(self, value) + + diff --git a/src/RelLib/_Person.py b/src/RelLib/_Person.py index 4f33af318..ac0410240 100644 --- a/src/RelLib/_Person.py +++ b/src/RelLib/_Person.py @@ -45,9 +45,11 @@ from _AddressBase import AddressBase from _LdsOrdBase import LdsOrdBase from _UrlBase import UrlBase from _Name import Name +from _NameType import NameType from _EventRef import EventRef from _LdsOrd import LdsOrd from _PersonRef import PersonRef + #------------------------------------------------------------------------- # # Person class diff --git a/src/RelLib/__init__.py b/src/RelLib/__init__.py index a94bb7fde..fa34e6a16 100644 --- a/src/RelLib/__init__.py +++ b/src/RelLib/__init__.py @@ -36,12 +36,14 @@ from _EventRef import EventRef from _LdsOrd import LdsOrd from _MediaRef import MediaRef from _Name import Name +from _NameType import NameType from _Note import Note from _RepoRef import RepoRef from _SourceRef import SourceRef from _Url import Url from _Witness import Witness from _ChildRef import ChildRef +from _ChildRefType import ChildRefType # Primary objects from _PrimaryObject import PrimaryObject @@ -57,3 +59,7 @@ from _Repository import Repository # These are actually metadata from _GenderStats import GenderStats from _Researcher import Researcher + +# Type classes +from _GrampsType import GrampsType +from _EventType import PersonEventType diff --git a/src/ScratchPad.py b/src/ScratchPad.py index fbfabb75d..ce0ea22a8 100644 --- a/src/ScratchPad.py +++ b/src/ScratchPad.py @@ -470,11 +470,7 @@ class ScratchPadName(ScratchPadGrampsTypeWrapper): ScratchPadGrampsTypeWrapper.__init__(self,dbstate,obj) self._type = _("Name") self._title = self._obj.get_name() - value = self._obj.get_type() - if value == RelLib.Name.CUSTOM: - self._value = value[1] - else: - self._value = Utils.name_types[value[0]] + self._value = str(self._obj.get_type()) def tooltip(self): global escape diff --git a/src/Utils.py b/src/Utils.py index f55aaff8c..3a841b26c 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -71,20 +71,20 @@ gender = { def format_gender( type): return gender.get(type[0],_("Invalid")) -child_relations = { - RelLib.ChildRef.CHILD_NONE : _("None"), - RelLib.ChildRef.CHILD_BIRTH : _("Birth"), - RelLib.ChildRef.CHILD_ADOPTED : _("Adopted"), - RelLib.ChildRef.CHILD_STEPCHILD : _("Stepchild"), - RelLib.ChildRef.CHILD_SPONSORED : _("Sponsored"), - RelLib.ChildRef.CHILD_FOSTER : _("Foster"), - RelLib.ChildRef.CHILD_UNKNOWN : _("Unknown"), - RelLib.ChildRef.CHILD_CUSTOM : _("Custom"), - } -def format_child_relation( type): - if type[0] == RelLib.ChildRef.CHILD_CUSTOM: - return type[1] - return child_relations.get(type[0],_("Invalid id %d ('%s')")%type) +# child_relations = { +# RelLib.ChildRef.CHILD_NONE : _("None"), +# RelLib.ChildRef.CHILD_BIRTH : _("Birth"), +# RelLib.ChildRef.CHILD_ADOPTED : _("Adopted"), +# RelLib.ChildRef.CHILD_STEPCHILD : _("Stepchild"), +# RelLib.ChildRef.CHILD_SPONSORED : _("Sponsored"), +# RelLib.ChildRef.CHILD_FOSTER : _("Foster"), +# RelLib.ChildRef.CHILD_UNKNOWN : _("Unknown"), +# RelLib.ChildRef.CHILD_CUSTOM : _("Custom"), +# } +# def format_child_relation( type): +# if type[0] == RelLib.ChildRef.CHILD_CUSTOM: +# return type[1] +# return child_relations.get(type[0],_("Invalid id %d ('%s')")%type) confidence = { RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"), @@ -225,17 +225,18 @@ family_rel_descriptions = { "a man and woman"), } -name_types = { - RelLib.Name.UNKNOWN : _("Unknown"), - RelLib.Name.CUSTOM : _("Custom"), - RelLib.Name.AKA : _("Also Known As"), - RelLib.Name.BIRTH : _("Birth Name"), - RelLib.Name.MARRIED : _("Married Name"), - } -def format_name_type( type): - if type[0] == RelLib.Name.CUSTOM: - return type[1] - return name_types.get(type[0],_("Invalid id %d ('%s')")%type) +# name_types = { +# RelLib.NameType.UNKNOWN : _("Unknown"), +# RelLib.NameType.CUSTOM : _("Custom"), +# RelLib.NameType.AKA : _("Also Known As"), +# RelLib.NameType.BIRTH : _("Birth Name"), +# RelLib.NameType.MARRIED : _("Married Name"), +# } +# def format_name_type( type): +# assert(False) +# if type[0] == RelLib.Name.CUSTOM: +# return type[1] +# return name_types.get(type[0],_("Invalid id %d ('%s')")%type) web_types = { RelLib.Url.UNKNOWN : _("Unknown"), @@ -1228,6 +1229,7 @@ class ProgressMeter: """ Specify the title and the current pass header. """ + self.old_val = -1 self.ptop = gtk.Dialog() self.ptop.connect('delete_event',self.warn) self.ptop.set_has_separator(False) @@ -1272,10 +1274,12 @@ class ProgressMeter: if (self.pbar_index > self.pbar_max): self.pbar_index = self.pbar_max - val = self.pbar_index/self.pbar_max - - self.pbar.set_text("%d of %d (%.1f%%)" % (self.pbar_index,self.pbar_max,(val*100))) - self.pbar.set_fraction(val) + val = int(100*self.pbar_index/self.pbar_max) + + if val != self.old_val: + self.pbar.set_text("%d%%" % val) + self.pbar.set_fraction(val/100.0) + self.old_val = val while gtk.events_pending(): gtk.main_iteration() diff --git a/src/plugins/ChangeNames.py b/src/plugins/ChangeNames.py index 8de36b93e..264af11d9 100644 --- a/src/plugins/ChangeNames.py +++ b/src/plugins/ChangeNames.py @@ -57,12 +57,12 @@ from PluginUtils import Tool, register_tool # ChangeNames # #------------------------------------------------------------------------- -class ChangeNames(Tool.Tool, ManagedWindow,ManagedWindow): +class ChangeNames(Tool.Tool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): Tool.Tool.__init__(self, dbstate, options_class, name) - ManagedWindow.ManagedWindow.__init__(self, uistate, []. self) + ManagedWindow.ManagedWindow.__init__(self, uistate, [], self) self.cb = callback @@ -167,7 +167,7 @@ class ChangeNames(Tool.Tool, ManagedWindow,ManagedWindow): self.db.request_rebuild() self.parent.bookmarks.redraw() self.close(obj) - self.cb(None,1) + self.cb() #------------------------------------------------------------------------ # diff --git a/src/plugins/ChangeTypes.py b/src/plugins/ChangeTypes.py index 5d528196f..8878081a2 100644 --- a/src/plugins/ChangeTypes.py +++ b/src/plugins/ChangeTypes.py @@ -78,8 +78,8 @@ class ChangeTypes(Tool.Tool, ManagedWindow.ManagedWindow): self.auto1 = self.glade.get_widget("original") self.auto2 = self.glade.get_widget("new") - AutoComp.fill_combo(self.auto1,const.personalEvents) - AutoComp.fill_combo(self.auto2,const.personalEvents) + AutoComp.fill_combo(self.auto1,Utils.personal_events) + AutoComp.fill_combo(self.auto2,Utils.personal_events) # Need to display localized event names self.auto1.child.set_text(const.display_event( self.options.handler.options_dict['fromtype'])) diff --git a/src/plugins/Check.py b/src/plugins/Check.py index 9158cfd87..f864198ee 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -236,7 +236,6 @@ class CheckIntegrity: self.db.commit_person(p,self.trans) self.progress.step() - def fix_encoding(self): self.progress.set_pass(_('Looking for character encoding errors'), self.db.get_number_of_media_objects()) @@ -887,6 +886,7 @@ class Report(ManagedWindow.ManagedWindow): base = os.path.dirname(__file__) glade_file = base + os.sep + "summary.glade" topDialog = gtk.glade.XML(glade_file,"summary","gramps") + topDialog.get_widget("close").connect('clicked',self.close) self.window = topDialog.get_widget("summary") textwindow = topDialog.get_widget("textwindow") diff --git a/src/plugins/DumpGenderStats.py b/src/plugins/DumpGenderStats.py index 71bebd738..39bce2ba2 100644 --- a/src/plugins/DumpGenderStats.py +++ b/src/plugins/DumpGenderStats.py @@ -24,6 +24,8 @@ import gtk import ListModel +import ManagedWindow + from PluginUtils import Tool, register_tool _GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ] @@ -32,20 +34,24 @@ _GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ] # # #------------------------------------------------------------------------- -class DumpGenderStats(Tool.Tool): - def __init__(self,db,person,options_class,name,callback=None,parent=None): - Tool.Tool.__init__(self,db,person,options_class,name) +class DumpGenderStats(Tool.Tool, ManagedWindow.ManagedWindow): + + def __init__(self, dbstate, uistate, options_class, name, callback=None): + + Tool.Tool.__init__(self, dbstate, options_class, name) + + ManagedWindow.ManagedWindow.__init__(self, uistate, [], self) stats_list = [] - for name in db.genderStats.stats.keys(): + for name in dbstate.db.genderStats.stats.keys(): stats_list.append( (name,) - + db.genderStats.stats[name] - + (_GENDER[db.genderStats.guess_gender(name)],) + + dbstate.db.genderStats.stats[name] + + (_GENDER[dbstate.db.genderStats.guess_gender(name)],) ) - if parent: + if uistate: titles = [ (_('Name'),1,100), (_('Male'),2,70), (_('Female'),3,70), (_('Unknown'),4,70), @@ -56,14 +62,14 @@ class DumpGenderStats(Tool.Tool): model = ListModel.ListModel(treeview,titles) for entry in stats_list: model.add(entry,entry[0]) - w = gtk.Window() - w.set_transient_for(parent.topWindow) - w.set_position(gtk.WIN_POS_MOUSE) - w.set_default_size(400,300) + + self.window = gtk.Window() + self.window.set_default_size(400,300) s = gtk.ScrolledWindow() s.add(treeview) - w.add(s) - w.show_all() + self.window.add(s) + self.window.show_all() + else: print "\t%s\t%s\t%s\t%s\t%s\n" % ( 'Name','Male','Female','Unknown','Guess') diff --git a/src/plugins/GraphViz.py b/src/plugins/GraphViz.py index dba49de78..42bfb07b6 100644 --- a/src/plugins/GraphViz.py +++ b/src/plugins/GraphViz.py @@ -248,8 +248,8 @@ class GraphViz: family = self.database.get_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() - fadopted = frel != RelLib.ChildRef.CHILD_BIRTH - madopted = mrel != RelLib.ChildRef.CHILD_BIRTH + fadopted = frel != RelLib.ChildRefType.BIRTH + madopted = mrel != RelLib.ChildRefType.BIRTH famid = family.get_gramps_id().replace('-','_') if (self.show_families and (father_handle and person_dict.has_key(father_handle) or diff --git a/src/plugins/NavWebPage.py b/src/plugins/NavWebPage.py index f76501eb8..0d191fedc 100644 --- a/src/plugins/NavWebPage.py +++ b/src/plugins/NavWebPage.py @@ -1764,7 +1764,7 @@ class IndividualPage(BasePage): val) else: of.write(nameof(person,self.exclude_private)) - if rel != RelLib.ChildRef.CHILD_BIRTH: + if rel != RelLib.ChildRefType.BIRTH: of.write('   (%s)' % Utils.format_child_relation(rel)) of.write('\n') diff --git a/src/plugins/PatchNames.py b/src/plugins/PatchNames.py index d54cdc5c0..1335826c6 100644 --- a/src/plugins/PatchNames.py +++ b/src/plugins/PatchNames.py @@ -89,7 +89,9 @@ _sn_prefix_re = re.compile("^\s*(%s)\s+(.*)" % '|'.join(prefix_list), class PatchNames(Tool.Tool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): + Tool.Tool.__init__(self, dbstate, options_class, name) + ManagedWindow.ManagedWindow.__init__(self, uistate, [], self) self.cb = callback self.trans = self.db.transaction_begin() diff --git a/src/plugins/TestcaseGenerator.py b/src/plugins/TestcaseGenerator.py index 1cd07337a..e1364e8f6 100644 --- a/src/plugins/TestcaseGenerator.py +++ b/src/plugins/TestcaseGenerator.py @@ -520,7 +520,7 @@ class TestcaseGenerator(Tool.Tool): person2.add_family_handle(fam_h) self.db.commit_person(person2,self.trans) child = self.db.get_person_from_handle(child_h) - child.add_parent_family_handle(fam_h,(RelLib.ChildRef.CHILD_BIRTH,''),(RelLib.ChildRef.CHILD_BIRTH,'')) + child.add_parent_family_handle(fam_h,RelLib.ChildRefType(),RelLib.ChildRefType()) self.db.commit_person(child,self.trans) self.commit_transaction() # COMMIT TRANSACTION STEP diff --git a/src/plugins/summary.glade b/src/plugins/summary.glade index 77447e4df..6a3d8fc84 100644 --- a/src/plugins/summary.glade +++ b/src/plugins/summary.glade @@ -18,6 +18,8 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True + False False @@ -33,7 +35,7 @@ GTK_BUTTONBOX_END - + True True True @@ -74,6 +76,10 @@ 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 8