From f477a3cdf34dae1bdaa6eca7f1ff21f4568d8f5e Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 13 Apr 2006 16:16:00 +0000 Subject: [PATCH] Start childref conversion svn: r6327 --- ChangeLog | 3 + src/DataViews/_FamilyView.py | 22 ++- src/DisplayModels.py | 1 + src/DisplayTabs.py | 98 +++++++++-- src/Editors/_EditFamily.py | 69 ++++---- src/Editors/_EditPerson.py | 5 + src/Editors/__init__.py | 1 + src/GrampsDb/_ReadGedcom.py | 4 +- src/GrampsDb/_ReadXML.py | 31 +++- src/RelLib/_ChildRef.py | 2 +- src/RelLib/_Family.py | 1 + src/RelLib/__init__.py | 1 + src/glade/gramps.glade | 307 +++++++++++++++++++++++++++++++++++ src/plugins/Check.py | 9 +- 14 files changed, 486 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc3276418..ed523b499 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2006-04-13 Don Allingham + * various: start childref conversion + 2006-04-13 Martin Hawlisch * src/RelLib/*: fix different typos. * src/DataViews/_FamilyView.py: adapt changes in RelLib diff --git a/src/DataViews/_FamilyView.py b/src/DataViews/_FamilyView.py index 8c99f44e1..5c55a2925 100644 --- a/src/DataViews/_FamilyView.py +++ b/src/DataViews/_FamilyView.py @@ -466,13 +466,19 @@ class FamilyView(PageView.PersonNavView): if self.show_siblings: active = self.dbstate.active.handle - - child_list = [handle for handle in family.get_child_handle_list()\ - if handle != active] + + print family.get_child_ref_list() + + child_list = [ref.ref for ref in family.get_child_ref_list()\ + if ref.ref != active] + + print child_list + label = _("Siblings") if child_list: - for child in child_list: - self.write_child(label, child) + for child_handle in child_list: + print child_handle + self.write_child(label, child_handle) label = u"" self.row += 1 @@ -708,8 +714,10 @@ class FamilyView(PageView.PersonNavView): from Editors import EditFamily family = RelLib.Family() person = self.dbstate.active - - family.add_child_handle(person.handle) + + ref = RelLib.ChildRef() + ref.ref = person.handle + family.add_child_ref(ref) try: EditFamily(self.dbstate, self.uistate, [], family) diff --git a/src/DisplayModels.py b/src/DisplayModels.py index 550323d7c..2a5b350ad 100644 --- a/src/DisplayModels.py +++ b/src/DisplayModels.py @@ -779,3 +779,4 @@ class RepositoryModel(BaseModel): # except: # log.error("Failed to create tooltip.", exc_info=True) # return t + diff --git a/src/DisplayTabs.py b/src/DisplayTabs.py index 5b9f5143d..13b1e4a6e 100644 --- a/src/DisplayTabs.py +++ b/src/DisplayTabs.py @@ -1193,6 +1193,63 @@ class AddrEmbedList(EmbeddedList): def edit_callback(self, name): self.rebuild() +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +class PersonRefEmbedList(EmbeddedList): + + _HANDLE_COL = 3 + _DND_TYPE = DdTargets.ADDRESS + + _column_names = [ + (_('Name'), 0, 250), + (_('ID'), 1, 100), + (_('Relationship'), 2, 100), + ] + + def __init__(self, dbstate, uistate, track, data): + self.data = data + EmbeddedList.__init__(self, dbstate, uistate, track, + _('Relationships'), PersonRefModel) + + def get_data(self): + return self.data + + def column_order(self): + return ((1, 0), (1, 1), (1, 2)) + + def add_button_clicked(self, obj): + from Editors import EditPersonRef + + try: + ref = RelLib.PersonRef() + ref.rel = _('Godfather') + EditPersonRef( + self.dbstate, self.uistate, self.track, + ref, self.add_callback) + except Errors.WindowActiveError: + pass + + def add_callback(self, name): + self.get_data().append(name) + self.rebuild() + + def edit_button_clicked(self, obj): + from Editors import EditPersonRef + + try: + ref = self.get_selected() + EditPersonRef( + self.dbstate, self.uistate, self.track, + ref, self.edit_callback) + except Errors.WindowActiveError: + pass + + def edit_callback(self, name): + self.rebuild() + #------------------------------------------------------------------------- # @@ -1811,14 +1868,15 @@ class ChildModel(gtk.ListStore): str, str, str, str, str, str, int, int) self.db = db index = 1 - for child_handle in self.get_data(): - child = db.get_person_from_handle(child_handle) + for child_ref in self.get_data(): + print child_ref, child_ref.ref + child = db.get_person_from_handle(child_ref.ref) self.append(row=[index, child.get_gramps_id(), NameDisplay.displayer.display(child), Utils.gender[child.get_gender()], - self.column_father_rel(child), - self.column_mother_rel(child), + self.column_father_rel(child_ref), + self.column_mother_rel(child_ref), self.column_birth_day(child), self.column_death_day(child), self.column_birth_place(child), @@ -1831,21 +1889,13 @@ class ChildModel(gtk.ListStore): index += 1 def get_data(self): - return self.family.get_child_handle_list() + return self.family.get_child_ref_list() def column_father_rel(self, data): - fhandle = self.family.handle - for (handle, mrel, frel) in data.get_parent_family_handle_list(): - if handle == fhandle: - return Utils.format_child_relation(frel) - return "" + return Utils.format_child_relation(data.get_father_relation()) def column_mother_rel(self, data): - fhandle = self.family.handle - for (handle, mrel, frel) in data.get_parent_family_handle_list(): - if handle == fhandle: - return Utils.format_child_relation(mrel) - return "" + return Utils.format_child_relation(data.get_mother_relation()) def column_birth_day(self, data): event_ref = data.get_birth_ref() @@ -2032,6 +2082,24 @@ class AddressModel(gtk.ListStore): obj, ]) +#------------------------------------------------------------------------- +# +# PersonRefModel +# +#------------------------------------------------------------------------- +class PersonRefModel(gtk.ListStore): + + def __init__(self, obj_list, db): + gtk.ListStore.__init__(self, str, str, str, object) + self.db = db + for obj in obj_list: + p = self.db.get_person_from_handle(obj.ref) + if p: + data = [NameDisplay.displayer.display(p), p.gramps_id, obj.rel, obj] + else: + data = ['unknown','unknown',obj.rel,obj] + self.append(row=data) + #------------------------------------------------------------------------- # # LocationModel diff --git a/src/Editors/_EditFamily.py b/src/Editors/_EditFamily.py index 807fc5451..85bdaeac1 100644 --- a/src/Editors/_EditFamily.py +++ b/src/Editors/_EditFamily.py @@ -115,22 +115,22 @@ class ChildEmbedList(EmbeddedList): """ returns the index of the object within the associated data """ - return self.family.get_child_handle_list().index(obj) + return self.family.get_child_ref_list().index(obj) def _find_row(self,x,y): row = self.tree.get_path_at_pos(x,y) if row == None: - return len(self.family.get_child_handle_list()) + return len(self.family.get_child_ref_list()) else: return row[0][0] def _handle_drag(self, row, obj): - self.family.get_child_handle_list().insert(row,obj) + self.family.get_child_ref_list().insert(row,obj) self.changed = True self.rebuild() def _move(self, row_from, row_to, obj): - dlist = self.family.get_child_handle_list() + dlist = self.family.get_child_ref_list() if row_from < row_to: dlist.insert(row_to,obj) del dlist[row_from] @@ -175,7 +175,7 @@ class ChildEmbedList(EmbeddedList): """ The list is considered empty if the child list is empty. """ - return len(self.family.get_child_handle_list()) == 0 + return len(self.family.get_child_ref_list()) == 0 def get_data(self): """ @@ -204,7 +204,9 @@ class ChildEmbedList(EmbeddedList): EditPerson(self.dbstate,self.uistate,[],person, self.new_child_added) def new_child_added(self, person): - self.family.add_child_handle(person.get_handle()) + ref = RelLib.ChildRef() + ref.ref = person.get_handle() + self.family.add_child_ref(ref) self.rebuild() def share_button_clicked(self,obj): @@ -212,15 +214,17 @@ class ChildEmbedList(EmbeddedList): # it only makes sense to skip those who are already in the family - skip = [self.family.get_father_handle(), - self.family.get_mother_handle()] + self.family.get_child_handle_list() + skip = [self.family.get_father_handle(), self.family.get_mother_handle()] + \ + [x.ref for x in self.family.get_child_ref_list() ] sel = SelectPerson(self.dbstate.db, "Select Child", skip=[ x for x in skip if x]) person = sel.run() if person: - self.family.add_child_handle(person.get_handle()) + ref = RelLib.ChildRef() + ref.ref = person.get_handle() + self.family.add_child_ref(ref) self.rebuild() # def add_button_clicked(self,obj): @@ -265,9 +269,9 @@ class ChildEmbedList(EmbeddedList): skip=[ x for x in skip if x]) def del_button_clicked(self,obj): - handle = self.get_selected() - if handle: - self.family.remove_child_handle(handle) + ref = self.get_selected() + if ref: + self.family.remove_child_ref(ref) self.rebuild() def edit_button_clicked(self,obj): @@ -345,7 +349,7 @@ class EditFamily(EditPrimary): if self.added and self.obj.get_father_handle() == None and \ self.obj.get_mother_handle() == None and \ - len(self.obj.get_child_handle_list()) == 1: + len(self.obj.get_child_ref_list()) == 1: self.add_parent = True if not Config.get_family_warn(): for i in self.hidden: @@ -449,7 +453,9 @@ class EditFamily(EditPrimary): mhandle = self.obj.get_mother_handle() self.update_mother(mhandle) - self.phandles = [mhandle, fhandle] + self.obj.get_child_handle_list() + self.phandles = [mhandle, fhandle] + \ + [ x.ref for x in self.obj.get_child_ref_list()] + self.phandles = [handle for handle in self.phandles if handle] self.mbutton.connect('clicked',self.mother_clicked) @@ -487,6 +493,11 @@ class EditFamily(EditPrimary): GalleryTab(self.dbstate, self.uistate, self.track, self.obj.get_media_list())) + self.pref_list = self._add_tab( + notebook, + PersonRefEmbedList(self.dbstate, self.uistate, self.track, + self.obj.child_ref_list)) + self.lds_list = self._add_tab( notebook, FamilyLdsEmbedList(self.dbstate,self.uistate,self.track, @@ -541,7 +552,7 @@ class EditFamily(EditPrimary): data_filter = FastFemaleFilter(self.dbstate.db) sel = SelectPerson(self.dbstate.db, "Select Mother", filter=data_filter, - skip=self.obj.get_child_handle_list()) + skip=[x.ref for x in self.obj.get_child_ref_list()]) person = sel.run() if person: @@ -612,7 +623,7 @@ class EditFamily(EditPrimary): data_filter = FastMaleFilter(self.dbstate.db) sel = SelectPerson(self.dbstate.db, "Select Father", filter=data_filter, - skip=self.obj.get_child_handle_list()) + skip=[x.ref for x in self.obj.get_child_ref_list()]) person = sel.run() if person: @@ -636,9 +647,9 @@ class EditFamily(EditPrimary): common = list(mfam.intersection(ffam)) if len(common) > 0: if self.add_parent: - clist = self.obj.get_child_handle_list() + clist = self.obj.get_child_ref_list() self.obj = self.dbstate.db.get_family_from_handle(common[0]) - self.obj.add_child_handle(clist[0]) + self.obj.add_child_ref(clist[0]) self.close_window() try: EditFamily(self.dbstate,self.uistate,[],self.obj) @@ -657,8 +668,8 @@ class EditFamily(EditPrimary): if fam.get_mother_handle() == None: self.close_window() try: - clist = self.obj.get_child_handle_list() - fam.add_child_handle(clist[-1]) + clist = self.obj.get_child_ref_list() + fam.add_child_ref(clist[-1]) EditFamily(self.dbstate,self.uistate,[],fam) except Errors.WindowActiveError: pass @@ -669,8 +680,8 @@ class EditFamily(EditPrimary): if fam.get_father_handle() == None: self.close_window() try: - clist = self.obj.get_child_handle_list() - fam.add_child_handle(clist[-1]) + clist = self.obj.get_child_ref_list() + fam.add_child_ref(clist[-1]) EditFamily(self.dbstate,self.uistate,[],fam) except Errors.WindowActiveError: pass @@ -769,7 +780,7 @@ class EditFamily(EditPrimary): def object_is_empty(self): return self.obj.get_father_handle() == None and \ self.obj.get_mother_handle() == None and \ - len(self.obj.get_child_handle_list()) == 0 + len(self.obj.get_child_ref_list()) == 0 def save(self,*obj): @@ -796,14 +807,10 @@ class EditFamily(EditPrimary): self.db.commit_person(parent,trans) # for each child, add the family handle to the child - for handle in self.obj.get_child_handle_list(): + for ref in self.obj.get_child_ref_list(): child = self.db.get_person_from_handle(handle) # fix - relationships need to be extracted from the list - child.add_parent_family_handle( - self.obj.handle, - (RelLib.ChildRef.CHILD_BIRTH,''), - (RelLib.ChildRef.CHILD_BIRTH,''), - ) + child.add_parent_family_ref(ref) self.db.commit_person(child,trans) self.db.add_family(self.obj,trans) @@ -827,8 +834,8 @@ class EditFamily(EditPrimary): self.fix_parent_handles(original.get_mother_handle(), self.obj.get_mother_handle(),trans) - orig_set = set(original.get_child_handle_list()) - new_set = set(self.obj.get_child_handle_list()) + orig_set = set(original.get_child_ref_list()) + new_set = set(self.obj.get_child_ref_list()) # remove the family from children which have been removed for handle in orig_set.difference(new_set): diff --git a/src/Editors/_EditPerson.py b/src/Editors/_EditPerson.py index d6cb6f9c2..dd20e885d 100644 --- a/src/Editors/_EditPerson.py +++ b/src/Editors/_EditPerson.py @@ -281,6 +281,11 @@ class EditPerson(EditPrimary): WebEmbedList(self.dbstate, self.uistate, self.track, self.obj.get_url_list())) + self.pref_list = self._add_tab( + notebook, + PersonRefEmbedList(self.dbstate, self.uistate, self.track, + self.obj.get_person_ref_list())) + self.lds_list = self._add_tab( notebook, LdsEmbedList(self.dbstate, self.uistate, self.track, diff --git a/src/Editors/__init__.py b/src/Editors/__init__.py index 2d496f8d5..832dfab70 100644 --- a/src/Editors/__init__.py +++ b/src/Editors/__init__.py @@ -35,4 +35,5 @@ from _EditRepoRef import * from _EditSource import * from _EditSourceRef import * from _EditUrl import * +from _EditPersonRef import * diff --git a/src/GrampsDb/_ReadGedcom.py b/src/GrampsDb/_ReadGedcom.py index 375482602..5cca153e1 100644 --- a/src/GrampsDb/_ReadGedcom.py +++ b/src/GrampsDb/_ReadGedcom.py @@ -2103,9 +2103,7 @@ class GedcomParser: break else: if ftype in rel_types: - state.person.add_parent_family_handle( - handle, (RelLib.ChildRef.CHILD_BIRTH,''), - (RelLib.ChildRef.CHILD_BIRTH,'')) + state.person.add_parent_family_handle(handle) else: if state.person.get_main_parents_family_handle() == handle: state.person.set_main_parent_family_handle(None) diff --git a/src/GrampsDb/_ReadXML.py b/src/GrampsDb/_ReadXML.py index 4cfaba37b..a99a6ef2b 100644 --- a/src/GrampsDb/_ReadXML.py +++ b/src/GrampsDb/_ReadXML.py @@ -157,11 +157,11 @@ def importData(database, filename, callback=None,cl=0,use_trans=False): ErrorDialog(_("Error reading %s") % filename, _("The file is probably either corrupt or not a valid GRAMPS database.")) return - except: - if cl: - import traceback - traceback.print_exc() - os._exit(1) +# except: +# if cl: +# import traceback +# traceback.print_exc() +# os._exit(1) xml_file.close() @@ -274,6 +274,7 @@ class GrampsParser: self.gid2oid = {} self.gid2sid = {} self.gid2rid = {} + self.childref_map = {} self.change = change self.dp = DateHandler.parser self.place_names = sets.Set() @@ -846,7 +847,13 @@ class GrampsParser: except KeyError: person = self.find_person_by_gramps_id(self.map_gid(attrs["ref"])) handle = person_handle - self.family.add_child_handle(handle) + + if self.childref_map.has_key((self.family.handle,handle)): + self.family.add_child_ref(self.childref_map[(self.family.handle,handle)]) + else: + ref = RelLib.ChildRef() + ref.ref = handle + self.family.add_child_ref(ref) def start_url(self,attrs): if not attrs.has_key("href"): @@ -904,12 +911,20 @@ class GrampsParser: except KeyError: family = self.find_family_by_gramps_id(self.map_fid(attrs["ref"])) handle = family.handle - + mrel = _ConstXML.tuple_from_xml(_ConstXML.child_relations, attrs.get('mrel','Birth')) frel = _ConstXML.tuple_from_xml(_ConstXML.child_relations, attrs.get('frel','Birth')) - self.person.add_parent_family_handle(handle,mrel,frel) + + if mrel[0] != RelLib.ChildRef.CHILD_BIRTH or \ + frel[0] != RelLib.ChildRef.CHILD_BIRTH: + childref = RelLib.ChildRef() + childref.ref = self.person.handle + childref.set_mother_relation(mrel) + childref.set_father_relation(frel) + self.childref_map[(handle,self.person.handle)] = childref + self.person.add_parent_family_handle(handle) def start_parentin(self,attrs): try: diff --git a/src/RelLib/_ChildRef.py b/src/RelLib/_ChildRef.py index acda200f3..8f7208ac3 100644 --- a/src/RelLib/_ChildRef.py +++ b/src/RelLib/_ChildRef.py @@ -140,7 +140,7 @@ class ChildRef(BaseObject,PrivacyBase,SourceBase,NoteBase,RefBase): def set_father_relation(self,frel): """Sets relation between the person and father""" - self.fmrel = rel + self.frel = frel def get_father_relation(self): """Returns the relation between the person and father""" diff --git a/src/RelLib/_Family.py b/src/RelLib/_Family.py index dd14d1187..09930a739 100644 --- a/src/RelLib/_Family.py +++ b/src/RelLib/_Family.py @@ -377,6 +377,7 @@ class Family(PrimaryObject,SourceBase,NoteBase,MediaBase,AttributeBase, """ if child_ref and not isinstance(child_ref,ChildRef): raise ValueError("expecting ChildRef instance") + assert(child_ref.ref) self.child_ref_list.append(child_ref) def remove_child_ref(self,child_ref): diff --git a/src/RelLib/__init__.py b/src/RelLib/__init__.py index a303a2b13..a94bb7fde 100644 --- a/src/RelLib/__init__.py +++ b/src/RelLib/__init__.py @@ -46,6 +46,7 @@ from _ChildRef import ChildRef # Primary objects from _PrimaryObject import PrimaryObject from _Person import Person +from _PersonRef import PersonRef from _Family import Family from _Event import Event from _Place import Place diff --git a/src/glade/gramps.glade b/src/glade/gramps.glade index 1bccab997..31a9c8672 100644 --- a/src/glade/gramps.glade +++ b/src/glade/gramps.glade @@ -16353,4 +16353,311 @@ You should select parents before adding any new information. If you select paren + + True + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 600 + 450 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + False + + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + + True + Accept changes and close window + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + + + True + True + True + gtk-help + True + GTK_RELIEF_NORMAL + True + -11 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + + False + True + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 10 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 12 + True + 2 + 7 + False + 6 + 12 + + + + True + _Person: + True + False + GTK_JUSTIFY_CENTER + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + _Relationship: + True + False + GTK_JUSTIFY_CENTER + False + False + 0 + 0.5 + 0 + 0 + relationship + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 6 + 1 + 2 + + + + + + + True + True + GTK_RELIEF_NONE + True + False + False + + + + True + 1 + gtk-dialog-authentication + 0.5 + 0.5 + 0 + 0 + + + + + 6 + 7 + 1 + 2 + + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 6 + 0 + 1 + fill + + + + + + + True + True + GTK_RELIEF_NORMAL + True + + + + True + gtk-index + 4 + 0.5 + 0.5 + 0 + 0 + + + + + 6 + 7 + 0 + 1 + fill + + + + + + 0 + False + True + + + + + 0 + True + True + + + + + + diff --git a/src/plugins/Check.py b/src/plugins/Check.py index cefedee70..5b698fc35 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -143,7 +143,6 @@ class Check(Tool.Tool): Tool.Tool.__init__(self, dbstate, options_class, name) - # def runTool(database,active_person,callback,parent=None): cli = uistate == None if self.db.readonly: @@ -213,7 +212,10 @@ class CheckIntegrity: self.progress = Utils.ProgressMeter(_('Checking database'),'') def family_errors(self): - return len(self.broken_parent_links) + len(self.broken_links) + len(self.empty_family) + len(self.duplicate_links) + return len(self.broken_parent_links) + \ + len(self.broken_links) + \ + len(self.empty_family) + \ + len(self.duplicate_links) def cleanup_duplicate_spouses(self): @@ -885,10 +887,11 @@ class Report(ManagedWindow.ManagedWindow): glade_file = base + os.sep + "summary.glade" topDialog = gtk.glade.XML(glade_file,"summary","gramps") + self.window = topDialog.get_widget("summary") textwindow = topDialog.get_widget("textwindow") textwindow.get_buffer().set_text(text) - Utils.set_titles(topDialog.get_widget("summary"), + Utils.set_titles(self.window, topDialog.get_widget("title"), _("Integrity Check Results"))