diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index d2f0e7ffc..3c00dd61a 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,23 @@ 2005-03-02 Don Allingham + * src/ChooseParents.py: use integers instead of strings for + relationship types + * src/PedView.py: use integers instead of strings for + relationship types + * src/ReadGedcom.py: use integers instead of strings for + relationship types + * src/ReadXML.py: use integers instead of strings for + relationship types + * src/RelLib.py: use integers instead of strings for + relationship types + * src/SelectChild.py: use integers instead of strings for + relationship types + * src/WriteXML.py: use integers instead of strings for + relationship types + * src/const.py.in: use integers instead of strings for + relationship types + * src/gramps_main.py: call database update function + * src/GrampsBSDDB.py: add database upgrade function + * src/GrampsDbBase.py: add database upgrade function * src/Marriage.py: fix lds menu * src/AddSpouse.py: use ComboBox instead of ComboBoxEntry for handling child/parent relationships diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index 0dd001f79..af1b692d0 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -151,8 +151,8 @@ class ChooseParents: frel = fr break else: - mrel = "Birth" - frel = "Birth" + mrel = RelLib.Person.CHILD_REL_BIRTH + frel = RelLib.Person.CHILD_REL_BIRTH if self.family: self.type = self.family.get_relationship() @@ -172,14 +172,9 @@ class ChooseParents: "on_familyDialog_delete_event" : self.on_delete_event, }) - values = const.child_relations.get_values() - self.keys = [] - for value in values: - self.keys.append(const.child_relations.find_key(value)) - self.keys.sort() - - self.build_list(self.mcombo,mr) - self.build_list(self.fcombo,fr) + self.keys = const.child_rel_list + self.build_list(self.mcombo,mrel) + self.build_list(self.fcombo,frel) self.val = self.top.run() if self.val == gtk.RESPONSE_OK: @@ -192,15 +187,10 @@ class ChooseParents: opt_menu.add_attribute(cell,'text',0) store = gtk.ListStore(str) - sel_index = 0 - index = 0 for val in self.keys: - if _(sel) == val: - sel_index = index - index += 1 store.append(row=[val]) opt_menu.set_model(store) - opt_menu.set_active(sel_index) + opt_menu.set_active(sel) def build_father_list(self): self.father_selection = self.father_list.get_selection() @@ -432,12 +422,12 @@ class ChooseParents: try: mother_rel = self.keys[self.mcombo.get_active()] except KeyError: - mother_rel = "Birth" + mother_rel = RelLib.Person.CHILD_REL_BIRTH try: father_rel = self.keys[self.fcombo.get_active()] except KeyError: - father_rel = "Birth" + father_rel = RelLib.Person.CHILD_REL_BIRTH trans = self.db.transaction_begin() if self.father or self.mother: @@ -592,12 +582,12 @@ class ModifyParents: self.flabel = self.glade.get_widget("flabel") self.mlabel = self.glade.get_widget("mlabel") - self.orig_mrel = _("Birth") - self.orig_frel = _("Birth") + self.orig_mrel = RelLib.Person.CHILD_REL_BIRTH + self.orig_frel = RelLib.Person.CHILD_REL_BIRTH for (f,mr,fr) in self.person.get_parent_family_handle_list(): if f == self.family.get_handle(): - self.orig_mrel = _(mr) - self.orig_frel = _(fr) + self.orig_mrel = mr + self.orig_frel = fr self.glade.signal_autoconnect({ "on_parents_help_clicked" : self.on_help_clicked, @@ -645,11 +635,7 @@ class ModifyParents: self.mcombo.set_sensitive(False) self.glade.get_widget('ok').set_sensitive(False) - values = const.child_relations.get_values() - self.keys = [] - for value in values: - self.keys.append(const.child_relations.find_key(value)) - self.keys.sort() + self.keys = const.child_rel_list self.build_list(self.mcombo,self.orig_mrel) self.build_list(self.fcombo,self.orig_frel) @@ -663,15 +649,10 @@ class ModifyParents: cell = gtk.CellRendererText() store = gtk.ListStore(str) - sel_index = 0 - index = 0 for val in self.keys: - if _(sel) == val: - sel_index = index - index += 1 store.append(row=[val]) opt_menu.set_model(store) - opt_menu.set_active(sel_index) + opt_menu.set_active(sel) def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" diff --git a/gramps2/src/GrampsBSDDB.py b/gramps2/src/GrampsBSDDB.py index 3aa2ebeff..54a5d0e52 100644 --- a/gramps2/src/GrampsBSDDB.py +++ b/gramps2/src/GrampsBSDDB.py @@ -33,7 +33,7 @@ from RelLib import * from GrampsDbBase import * from bsddb import dbshelve, db -_DBVERSION = 1 +_DBVERSION = 2 def find_surname(key,data): return str(data[3].get_surname()) @@ -98,6 +98,9 @@ class GrampsBSDDB(GrampsDbBase): def get_media_cursor(self): return GrampsBSDDBCursor(self.media_map) + def need_upgrade(self): + return self.metadata['version'] < _DBVERSION + def load(self,name,callback,mode="w"): if self.person_map: self.close() @@ -169,15 +172,20 @@ class GrampsBSDDB(GrampsDbBase): self.undodb = db.DB() self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE) - if not self.readonly and self.metadata.get('version') == None: - self.metadata['version'] = _DBVERSION - self.metadata = self.dbopen(name, "meta") self.bookmarks = self.metadata.get('bookmarks') + + gstats = self.metadata.get('gender_stats') + + if not self.readonly and gstats == None: + self.metadata['version'] = _DBVERSION + elif not self.metadata.has_key('version'): + self.metadata['version'] = 0 + if self.bookmarks == None: self.bookmarks = [] - self.genderStats = GenderStats(self.metadata.get('gender_stats')) + self.genderStats = GenderStats(gstats) return 1 def abort_changes(self): @@ -351,3 +359,35 @@ class GrampsBSDDB(GrampsDbBase): return obj else: return None + + def upgrade(self): + child_rel_notrans = [ + "None", "Birth", "Adopted", "Stepchild", + "Sponsored", "Foster", "Unknown", "Other", ] + + version = self.metadata['version'] + if version < 2: + cursor = self.get_person_cursor() + data = cursor.first() + while data: + handle,info = data + person = Person() + person.unserialize(info) + + plist = person.get_parent_family_handle_list() + new_list = [] + for (f,mrel,frel) in plist: + try: + mrel = child_rel_notrans.index(mrel) + except: + mrel = Person.CHILD_REL_BIRTH + try: + frel = child_rel_notrans.index(frel) + except: + frel = Person.CHILD_REL_BIRTH + new_list.append((f,mrel,frel)) + person.parent_family_list = new_list + self.commit_person(person,None) + data = cursor.next() + cursor.close() + self.metadata['version'] = 2 diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 080750987..edb41aa5c 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -165,6 +165,12 @@ class GrampsDbBase: self.place2title = {} self.name_groups = {} + def need_upgrade(self): + return False + + def upgrade(self): + pass + def create_id(self): s = "" for val in [ int(time.time()*10000) & 0x7fffffff, diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index 4e352218c..99f7ee493 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -384,12 +384,14 @@ class Gallery(ImageSelect): image = ImgManip.get_thumbnail_image(media_obj.get_path()) else: image = Utils.find_mime_type_pixbuf(mtype) + if not image: + image = gtk.gdk.pixbuf_new_from_file(const.icon) except gobject.GError,msg: ErrorDialog(str(msg)) image = gtk.gdk.pixbuf_new_from_file(const.icon) except: image = gtk.gdk.pixbuf_new_from_file(const.icon) - + x = image.get_width() y = image.get_height() diff --git a/gramps2/src/ImgManip.py b/gramps2/src/ImgManip.py index f03f34fb2..b4c9a2982 100644 --- a/gramps2/src/ImgManip.py +++ b/gramps2/src/ImgManip.py @@ -110,9 +110,6 @@ def set_thumbnail_image(path): pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR) pixbuf.save(_build_thumb_path(path),"jpeg") except: - import traceback - traceback.print_stack() - print "Could not create thumbnail for",path def get_thumbnail_image(path): diff --git a/gramps2/src/PedView.py b/gramps2/src/PedView.py index 8f02a891f..e3e70d244 100644 --- a/gramps2/src/PedView.py +++ b/gramps2/src/PedView.py @@ -499,8 +499,8 @@ class PedigreeView: else: return if family_handle: - mrel = (m != "Birth") - frel = (f != "Birth") + mrel = m != RelLib.Person.CHILD_REL_BIRTH + frel = f != RelLib.Person.CHILD_REL_BIRTH family = self.parent.db.get_family_from_handle(family_handle) if family != None: diff --git a/gramps2/src/ReadGedcom.py b/gramps2/src/ReadGedcom.py index 20af6991f..9d8f134ca 100644 --- a/gramps2/src/ReadGedcom.py +++ b/gramps2/src/ReadGedcom.py @@ -83,6 +83,10 @@ file_systems = { "SMBFS" : _('Networked Windows file system') } +rel_types = (RelLib.Person.CHILD_REL_BIRTH, + RelLib.Person.CHILD_REL_UNKWN, + RelLib.Person.CHILD_REL_NONE) + #------------------------------------------------------------------------- # # GEDCOM events to GRAMPS events conversion @@ -744,8 +748,8 @@ class GedcomParser: self.barf(level+1) def parse_ftw_relations(self,level): - mrel = "Birth" - frel = "Birth" + mrel = RelLib.Person.CHILD_REL_BIRTH + frel = RelLib.Person.CHILD_REL_BIRTH while 1: matches = self.get_next() @@ -759,14 +763,16 @@ class GedcomParser: # FTW elif matches[1] == "_MREL": if matches[2].lower() != "natural": - mrel = matches[2] + mrel = RelLib.Person.CHILD_REL_BIRTH elif matches[1] == "ADOP": - mrel = "Adopted" - frel = "Adopted" + mrel = RelLib.Person.CHILD_REL_ADOPT + frel = RelLib.Person.CHILD_REL_ADOPT # Legacy elif matches[1] == "_STAT": - mrel = matches[2] - frel = matches[2] + mrel = RelLib.Person.CHILD_REL_BIRTH + frel = RelLib.Person.CHILD_REL_BIRTH + #mrel = matches[2] + #frel = matches[2] # Legacy _PREF elif matches[1][0] == "_": pass @@ -811,7 +817,7 @@ class GedcomParser: if f[0] == self.family.get_handle(): break else: - if (mrel=="Birth" or mrel=="") and (frel=="Birth" or frel==""): + if mrel in rel_types and frel in reltypes: child.set_main_parent_family_handle(self.family.get_handle()) else: if child.get_main_parents_family_handle() == self.family: @@ -963,11 +969,11 @@ class GedcomParser: if f[0] == handle: break else: - if ftype == "" or ftype == "Birth": + if ftype in rel_types: if self.person.get_main_parents_family_handle() == None: self.person.set_main_parent_family_handle(handle) else: - self.person.add_parent_family_handle(handle,"Unknown","Unknown") + self.person.add_parent_family_handle(handle,RelLib.Person.CHILD_REL_UNKWN,RelLib.Person.CHILD_REL_UNKWN) else: if self.person.get_main_parents_family_handle() == handle: self.person.set_main_parent_family_handle(None) @@ -1420,9 +1426,9 @@ class GedcomParser: return (mrel,frel) elif matches[1] == "ADOP": if matches[2] == "HUSB": - mrel = "Birth" + mrel = RelLib.Person.CHILD_REL_BIRTH elif matches[2] == "WIFE": - frel = "Birth" + frel = RelLib.Person.CHILD_REL_BIRTH else: self.barf(level+1) return None diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index 0b81a4ffa..ad8048365 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -796,13 +796,19 @@ class GrampsParser: family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) if attrs.has_key("mrel"): - mrel = attrs["mrel"] + try: + mrel = const.child_rel_notrans[attrs["mrel"]] + except: + mrel = RelLib.Person.CHILD_REL_NONE else: - mrel = "Birth" + mrel = RelLib.Person.CHILD_REL_BIRTH if attrs.has_key("frel"): - frel = attrs["frel"] + try: + frel = const.child_rel_notrans[attrs["frel"]] + except: + frel = RelLib.Person.CHILD_REL_NONE else: - frel = "Birth" + frel = RelLib.Person.CHILD_REL_BIRTH self.person.add_parent_family_handle(family.get_handle(),mrel,frel) def start_parentin(self,attrs): diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 108a34e48..931ae9101 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -325,6 +325,15 @@ class Person(PrimaryObject,DataObj): 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 diff --git a/gramps2/src/SelectChild.py b/gramps2/src/SelectChild.py index 63b3bbcb1..97c916aca 100644 --- a/gramps2/src/SelectChild.py +++ b/gramps2/src/SelectChild.py @@ -90,14 +90,8 @@ class SelectChild: self.mrel = self.xml.get_widget("mrel_combo") self.frel = self.xml.get_widget("frel_combo") - values = const.child_relations.get_values() - self.keys = [] - for value in values: - self.keys.append(const.child_relations.find_key(value)) - self.keys.sort() - - self.build_list(self.mrel,"Birth") - self.build_list(self.frel,"Birth") + self.build_list(self.mrel,RelLib.Person.CHILD_REL_BIRTH) + self.build_list(self.frel,RelLib.Person.CHILD_REL_BIRTH) if self.family: father = self.db.get_person_from_handle(self.family.get_father_handle()) @@ -122,15 +116,10 @@ class SelectChild: opt_menu.add_attribute(cell,'text',0) store = gtk.ListStore(str) - sel_index = 0 - index = 0 - for val in self.keys: - if _(sel) == val: - sel_index = index - index += 1 + for val in const.child_rel_list: store.append(row=[val]) opt_menu.set_model(store) - opt_menu.set_active(sel_index) + opt_menu.set_active(sel) def add_columns(self,tree): column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0) @@ -320,19 +309,20 @@ class SelectChild: self.family.add_child_handle(select_child.get_handle()) - mrel = self.keys[self.mrel.get_active()] + mrel = self.mrel.get_active() mother = self.db.get_person_from_handle(self.family.get_mother_handle()) if mother and mother.get_gender() != RelLib.Person.FEMALE: - if mrel == "Birth": - mrel = "Unknown" + if mrel == RelLib.Person.CHILD_REL_BIRTH: + mrel = RelLib.Person.CHILD_REL_UNKWN - frel = self.keys[self.frel.get_active()] + frel = self.frel.get_active() father = self.db.get_person_from_handle(self.family.get_father_handle()) if father and father.get_gender() !=RelLib.Person.MALE: - if frel == "Birth": - frel = "Unknown" + if frel == RelLib.Person.CHILD_REL_BIRTH: + frel = RelLib.Person.CHILD_REL_UNKWN - select_child.add_parent_family_handle(self.family.get_handle(),mrel,frel) + select_child.add_parent_family_handle(self.family.get_handle(), + mrel,frel) self.db.commit_person(select_child,trans) self.db.commit_family(self.family,trans) @@ -392,87 +382,3 @@ class SelectChild: else: return ("","") -class EditRel: - - def __init__(self,db,child,family,update): - self.db = db - self.update = update - self.child = child - self.family = family - - self.xml = gtk.glade.XML(const.gladeFile,"editrel","gramps") - self.top = self.xml.get_widget('editrel') - self.mdesc = self.xml.get_widget('mrel_desc') - self.fdesc = self.xml.get_widget('frel_desc') - self.mentry = self.xml.get_widget('mrel') - self.fentry = self.xml.get_widget('frel') - self.mcombo = self.xml.get_widget('mrel_combo') - self.fcombo = self.xml.get_widget('frel_combo') - - name = NameDisplay.displayer.display(child) - Utils.set_titles(self.top,self.xml.get_widget('title'), - _('Relationships of %s') % name) - - father = self.db.get_person_from_handle(self.family.get_father_handle()) - mother = self.db.get_person_from_handle(self.family.get_mother_handle()) - - if father: - fname = NameDisplay.displayer.display(father) - val = _("Relationship to %(father)s") % { - 'father' : fname } - self.fdesc.set_text('%s' % val) - self.fcombo.set_sensitive(1) - else: - val = _("Relationship to father") - self.fdesc.set_text('%s' % val) - self.fcombo.set_sensitive(0) - - if mother: - mname = NameDisplay.displayer.display(mother) - val = _("Relationship to %(mother)s") % { - 'mother' : mname } - self.mdesc.set_text('%s' % val) - self.mcombo.set_sensitive(1) - else: - val = _("Relationship to mother") - self.mdesc.set_text('%s' % val) - self.mcombo.set_sensitive(0) - - self.xml.signal_autoconnect({ - "on_ok_clicked" : self.on_ok_clicked, - "destroy_passed_object" : self.close - }) - - f = self.child.get_parent_family(self.family.get_handle()) - if f: - self.fentry.set_text(_(f[2])) - self.mentry.set_text(_(f[1])) - - self.fdesc.set_use_markup(True) - self.mdesc.set_use_markup(True) - self.top.show() - - def close(self,obj): - self.top.destroy() - - def on_ok_clicked(self,obj): - mrel = const.child_relations.find_value(self.mentry.get_text()) - mother = self.db.get_person_from_handle(self.family.get_mother_handle()) - if mother and mother.get_gender() != RelLib.Person.FEMALE: - if mrel == "Birth": - mrel = "Unknown" - - frel = const.child_relations.find_value(self.fentry.get_text()) - father = self.db.get_person_from_handle(self.family.get_father_handle()) - if father and father.get_gender() !=RelLib.Person.MALE: - if frel == "Birth": - frel = "Unknown" - - self.child.change_parent_family_handle(self.family.get_handle(),mrel,frel) - trans = self.db.transaction_begin() - self.db.commit_person(self.child,trans) - n = self.child.get_primary_name().get_regular_name() - self.db.transaction_commit(trans,_("Parent Relationships (%s)") % n) - - self.update() - self.top.destroy() diff --git a/gramps2/src/WriteXML.py b/gramps2/src/WriteXML.py index 15f39c331..955a8a42d 100644 --- a/gramps2/src/WriteXML.py +++ b/gramps2/src/WriteXML.py @@ -300,12 +300,12 @@ class XmlWriter: self.write_url_list(person.get_url_list()) for alt in person.get_parent_family_handle_list(): - if alt[1] != "Birth": - mrel=' mrel="%s"' % alt[1] + if alt[1] != RelLib.Person.CHILD_REL_BIRTH: + mrel=' mrel="%s"' % const.child_rel_notrans[alt[1]] else: mrel='' if alt[2] != "Birth": - frel=' frel="%s"' % alt[2] + frel=' frel="%s"' % const.child_rel_notrans[alt[2]] else: frel='' parent_family = self.db.get_family_from_handle (alt[0]) diff --git a/gramps2/src/const.py.in b/gramps2/src/const.py.in index 895733b0c..b3f6a01ba 100644 --- a/gramps2/src/const.py.in +++ b/gramps2/src/const.py.in @@ -225,6 +225,14 @@ shortopts = "O:i:o:f:a:p:?" # #------------------------------------------------------------------------- +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", diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 388de537a..13e9c9c5b 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1583,9 +1583,10 @@ class Gramps: if res.get_name() == "" and owner.get_name(): self.db.set_researcher(owner) - if callback: - callback(_('Setting up bookmarks...')) self.setup_bookmarks() + if callback and self.db.need_upgrade(): + callback(_('Upgrading database...')) + self.db.upgrade() GrampsKeys.save_last_file(name) self.gtop.get_widget("filter").set_text("")