From 015d6027224466dc37ba9e2aa01281b3c0acd5a4 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 2 Jun 2005 03:20:42 +0000 Subject: [PATCH] * src/EditPerson.py: Start event_ref integration * src/EventEdit.py: Start event_ref integration * src/ListModel.py: Start event_ref integration * src/PersonModel.py: Start event_ref integration * src/ListBox.py: Start event_ref integration svn: r4754 --- gramps2/ChangeLog | 7 +++++ gramps2/src/EditPerson.py | 22 +++++++------- gramps2/src/EventEdit.py | 39 ++++++++++++------------ gramps2/src/ListBox.py | 62 ++++++++++++++++++++++++++------------ gramps2/src/ListModel.py | 2 +- gramps2/src/PeopleModel.py | 25 ++++++++------- 6 files changed, 95 insertions(+), 62 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index a93cae0f7..74b71bcde 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2005-06-01 Don Allingham + * src/EditPerson.py: Start event_ref integration + * src/EventEdit.py: Start event_ref integration + * src/ListModel.py: Start event_ref integration + * src/PersonModel.py: Start event_ref integration + * src/ListBox.py: Start event_ref integration + 2005-06-01 Alex Roitman * src/AutoComp.py (StandardCustomSelector): Provide an option to use an existing ComboBoxEntry instance; add set_values method. diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index ec673f638..cb74a8b04 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -853,16 +853,16 @@ class EditPerson: self.person.set_birth_ref(None) self.person.set_death_ref(None) eref_list = self.event_box.data[:] - for event_ref in eref_list: - if event_ref and event_ref.ref: - event = self.db.get_event_from_handle(event_ref.ref) - if event.get_name() == "Birth": - self.person.set_birth_ref(event_ref) - self.event_box.data.remove(event_ref) - if event.get_name() == "Death": - self.person.set_death_ref(event_ref) - self.event_box.data.remove(event_ref) - eref_list = [event_ref for event_ref in self.event_box.data] + print eref_list + for (event_ref,event) in eref_list: + print event.handle + if event.get_type()[0] == RelLib.Event.BIRTH: + self.person.set_birth_ref(event_ref) + self.event_box.data.remove(event_ref) + if event.get_type()[0] == RelLib.Event.DEATH: + self.person.set_death_ref(event_ref) + self.event_box.data.remove(event_ref) + eref_list = [event_ref for (event_ref,event) in self.event_box.data] self.person.set_event_ref_list(eref_list) def on_apply_person_clicked(self,obj): @@ -1036,7 +1036,7 @@ class EditPerson: self.db.commit_person(self.person, trans) n = self.person.get_primary_name().get_regular_name() - for event in self.event_box.get_changed_objects(): + for (event_ref,event) in self.event_box.get_changed_objects(): self.db.commit_event(event,trans) self.db.transaction_commit(trans,_("Edit Person (%s)") % n) diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index d4167ca16..2f5e7519f 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -178,7 +178,10 @@ class EventEditor: self.witnesslist, self, self.top, self.window, self.wlist, add_witness, edit_witness, del_witness) - AutoComp.fill_combo(self.event_menu,self.elist) + #AutoComp.fill_combo(self.event_menu,self.elist) + + self.eventmapper = AutoComp.StandardCustomSelector( + Utils.personal_events, self.event_menu, RelLib.Event.CUSTOM) AutoComp.fill_entry(self.place_field,self.pmap.keys()) if event != None: @@ -219,6 +222,7 @@ class EventEditor: self.window) if not event: event = RelLib.Event() + event.set_handle(Utils.create_id()) self.icon_list = self.top.get_widget("iconlist") self.gallery = ImageSelect.Gallery(event, self.db.commit_event, self.path, self.icon_list, @@ -316,13 +320,7 @@ class EventEditor: def on_event_edit_ok_clicked(self,obj): - ename = unicode(self.event_menu.child.get_text()) - - if not ename.strip(): - ErrorDialog(_("Event does not have a type"), - _("You must specify an event type " - "before you can save the event")) - return + event_data = self.eventmapper.get_values() #self.date = self.dp.parse(unicode(self.date_field.get_text())) ecause = unicode(self.cause_field.get_text()) @@ -336,23 +334,24 @@ class EventEditor: edesc = unicode(self.descr_field.get_text()) epriv = self.priv.get_active() - if ename not in self.elist: - WarningDialog( - _('New event type created'), - _('The "%s" event type has been added to this database.\n' - 'It will now appear in the event menus for this database') % ename) - self.elist.append(ename) - self.elist.sort() +# if ename not in self.elist: +# WarningDialog( +# _('New event type created'), +# _('The "%s" event type has been added to this database.\n' +# 'It will now appear in the event menus for this database') % ename) +# self.elist.append(ename) +# self.elist.sort() just_added = False if self.event == None: self.event = RelLib.Event() self.event.set_handle(Utils.create_id()) self.event.set_source_reference_list(self.srcreflist) - self.event.set_witness_list(self.witnesslist) + #self.event.set_witness_list(self.witnesslist) + self.event.set_type(event_data) just_added = True - self.update_event(ename,self.date,eplace_obj,edesc,enote,eformat, + self.update_event(event_data,self.date,eplace_obj,edesc,enote,eformat, epriv,ecause) self.close(obj) @@ -360,6 +359,8 @@ class EventEditor: self.callback(self.event) def update_event(self,the_type,date,place,desc,note,format,priv,cause): + print self.event + if place: if self.event.get_place_handle() != place.get_handle(): self.event.set_place_handle(place.get_handle()) @@ -388,7 +389,7 @@ class EventEditor: dobj = self.event.get_date_object() self.event.set_source_reference_list(self.srcreflist) - self.event.set_witness_list(self.witnesslist) + #self.event.set_witness_list(self.witnesslist) if not dobj.is_equal(date): self.event.set_date_object(date) @@ -412,8 +413,6 @@ class EventEditor: else: Utils.unbold_label(self.notes_label) - - class EventRefEditor: def __init__(self, eventref, referent, database, update, parent): diff --git a/gramps2/src/ListBox.py b/gramps2/src/ListBox.py index b75aa7ad4..9ad89943a 100644 --- a/gramps2/src/ListBox.py +++ b/gramps2/src/ListBox.py @@ -45,7 +45,7 @@ from ListModel import ListModel, NOSORT, COMBO, TEXT, TOGGLE from DdTargets import DdTargets import const -import TransTable +import RelLib import UrlEdit import NameEdit import NoteEdit @@ -82,6 +82,8 @@ class ListBox: return list(self.change_list) def add_object(self,item): + import traceback + traceback.print_stack() self.data.append(item) self.change_list.add(item) @@ -242,17 +244,19 @@ class EventListBox(ReorderListBox): def __init__(self,parent,person,obj,label,button_list): - self.trans = TransTable.TransTable(self.titles) - self.data = [] - if person.get_birth_ref(): - event = parent.db.get_event_from_handle(person.get_birth_ref().ref) - self.data.append(event) - if person.get_death_ref(): - event = parent.db.get_event_from_handle(person.get_death_ref().ref) - self.data.append(event) + birth_ref = person.get_birth_ref() + death_ref = person.get_death_ref() + if birth_ref: + self.data.append((birth_ref, + parent.db.get_event_from_handle(birth_ref.ref))) + if death_ref: + self.data.append((death_ref, + parent.db.get_event_from_handle(death_ref.ref))) + self for event_ref in person.get_event_ref_list(): - self.data.append(parent.db.get_event_from_handle(event_ref.ref)) + self.data.append((event_ref, + parent.db.get_event_from_handle(event_ref.ref))) eventnames = Utils.personal_events.values() @@ -270,26 +274,26 @@ class EventListBox(ReorderListBox): button_list, evalues, DdTargets.EVENT) def set_name(self,index,value): - self.data[index].set_name(value) + self.data[index][1].set_name(value) self.change_list.add(self.data[index]) def set_description(self,index,value): - self.data[index].set_description(value) + self.data[index][1].set_description(value) self.change_list.add(self.data[index]) def set_place(self,index,value): - self.data[index].set_description(value) + self.data[index][1].set_description(value) self.change_list.add(self.data[index]) def set_date(self,index,value): - self.data[index].set_date(value) + self.data[index][1].set_date(value) self.change_list.add(self.data[index]) def add(self,obj): """Brings up the EventEditor for a new event""" EventEdit.EventEditor( self.parent, self.name, Utils.personal_events, - Utils.personal_events, None, None, 0, + None, None, False, self.edit_callback, noedit=self.db.readonly) def update(self,obj): @@ -299,11 +303,12 @@ class EventListBox(ReorderListBox): event = self.list_model.get_object(node) EventEdit.EventEditor( self.parent, self.name, Utils.personal_events, - Utils.personal_events, event, None, 0, + event, None, False, self.edit_callback, noedit=self.db.readonly) - def display_data(self,event): - + def display_data(self,event_tuple): + print event_tuple + (event_ref, event) = event_tuple pid = event.get_place_handle() if pid: pname = self.db.get_place_from_handle(pid).get_title() @@ -311,7 +316,12 @@ class EventListBox(ReorderListBox): pname = u'' has_note = event.get_note() has_source = len(event.get_source_references())> 0 - return [const.display_pevent(event.get_name()), + etype = event.get_type() + if etype[0] == RelLib.Event.CUSTOM: + name = etype[1] + else: + name = Utils.personal_events[etype[0]] + return [name, event.get_description(), event.get_date(), pname, has_source, has_note] @@ -326,6 +336,20 @@ class EventListBox(ReorderListBox): foo.set_place_handle(place.get_handle()) self.data.insert(row,foo.get_handle()) + def edit_callback(self,data): + self.changed = True + ref = RelLib.EventRef() + ref.ref = data + new_data = (ref,data) + self.change_list.add(new_data) + if new_data not in self.data: + self.data.append(new_data) + self.redraw() + try: + self.list_model.select_iter(self.node_map[new_data]) + except: + print "Edit callback failed" + class NameListBox(ReorderListBox): def __init__(self,parent,person,obj,label,button_list): diff --git a/gramps2/src/ListModel.py b/gramps2/src/ListModel.py index 2bcc5c813..9bd13cfaa 100644 --- a/gramps2/src/ListModel.py +++ b/gramps2/src/ListModel.py @@ -42,7 +42,7 @@ class ListModel: self.mylist = [] self.data_index = 0 for l in dlist: - if l[0] == TOGGLE: + if l[3] == TOGGLE: self.mylist.append(TYPE_BOOLEAN) else: self.mylist.append(TYPE_STRING) diff --git a/gramps2/src/PeopleModel.py b/gramps2/src/PeopleModel.py index 5f046c4ce..e56cd45ac 100644 --- a/gramps2/src/PeopleModel.py +++ b/gramps2/src/PeopleModel.py @@ -297,24 +297,27 @@ class PeopleModel(gtk.GenericTreeModel): def column_birth_day(self,data,node): if data[_BIRTH_COL]: - birth = self.db.get_event_from_handle(data[_BIRTH_COL]) + birth = self.db.get_event_from_handle(data[_BIRTH_COL].ref) if birth.get_date() and birth.get_date() != "": return cgi.escape(birth.get_date()) - for event_handle in data[_EVENT_COL]: - event = self.db.get_event_from_handle(event_handle) - if event.name in ["Baptism", "Christening"] and event.get_date() != "": + for event_ref in data[_EVENT_COL]: + print event_ref, event_ref.ref + event = self.db.get_event_from_handle(event_ref.ref) + print "Event",event + if (event.get_type() in [RelLib.Event.BAPTISM, RelLib.Event.CHRISTEN] + and event.get_date() != ""): return "" + cgi.escape(event.get_date()) + "" return u"" def column_death_day(self,data,node): if data[_DEATH_COL]: - death = self.db.get_event_from_handle(data[_DEATH_COL]) + death = self.db.get_event_from_handle(data[_DEATH_COL].ref) if death.get_date() and death.get_date() != "": return cgi.escape(death.get_date()) - for event_handle in data[_EVENT_COL]: + for event_handle in data[_EVENT_COL].ref: event = self.db.get_event_from_handle(event_handle) if event.name in ["Burial", "Cremation"] and event.get_date() != "": return "" + cgi.escape(event.get_date()) + "" @@ -323,13 +326,13 @@ class PeopleModel(gtk.GenericTreeModel): def column_cause_of_death(self,data,node): if data[_DEATH_COL]: - return self.db.get_event_from_handle(data[_DEATH_COL]).get_cause() + return self.db.get_event_from_handle(data[_DEATH_COL].ref).get_cause() else: return u"" def column_birth_place(self,data,node): if data[_BIRTH_COL]: - event = self.db.get_event_from_handle(data[_BIRTH_COL]) + event = self.db.get_event_from_handle(data[_BIRTH_COL].ref) if event: place_handle = event.get_place_handle() if place_handle: @@ -337,7 +340,7 @@ class PeopleModel(gtk.GenericTreeModel): if place_title != "": return cgi.escape(place_title) - for event_handle in data[_EVENT_COL]: + for event_handle in data[_EVENT_COL].ref: event = self.db.get_event_from_handle(event_handle) if event.name in ["Baptism", "Christening"]: place_handle = event.get_place_handle() @@ -350,7 +353,7 @@ class PeopleModel(gtk.GenericTreeModel): def column_death_place(self,data,node): if data[_DEATH_COL]: - event = self.db.get_event_from_handle(data[_DEATH_COL]) + event = self.db.get_event_from_handle(data[_DEATH_COL].ref) if event: place_handle = event.get_place_handle() if place_handle: @@ -358,7 +361,7 @@ class PeopleModel(gtk.GenericTreeModel): if place_title != "": return cgi.escape(place_title) - for event_handle in data[_EVENT_COL]: + for event_handle in data[_EVENT_COL].ref: event = self.db.get_event_from_handle(event_handle) if event.name in ["Burial", "Cremation"]: place_handle = event.get_place_handle()