From 8b8d35906258ce4e057238b32d9dbb63637b1da5 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 6 Feb 2006 23:44:09 +0000 Subject: [PATCH] * src/EditFamily.py: Complete save operation, handle new family * src/EditMedia.py: Add file selector button * src/FamilyList.py: Save properly * src/edit_person.glade: lock icon * src/gramps.glade: file selector button svn: r5892 --- ChangeLog | 7 + src/EditFamily.py | 84 ++++++++-- src/EditMedia.py | 27 +++- src/FamilyList.py | 3 +- src/TreeViews/_PersonTreeView.py | 38 +++-- src/edit_person.glade | 3 +- src/gramps.glade | 267 +++++++++++++++++-------------- 7 files changed, 270 insertions(+), 159 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ea2a3c0b..427133649 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-02-06 Don Allingham + * src/EditFamily.py: Complete save operation, handle new family + * src/EditMedia.py: Add file selector button + * src/FamilyList.py: Save properly + * src/edit_person.glade: lock icon + * src/gramps.glade: file selector button + 2006-02-06 Alex Roitman * src/GrampsDb/_GrampsBSDDB.py (transaction_commit): Typo. diff --git a/src/EditFamily.py b/src/EditFamily.py index 38f19e2c0..e5d03e77c 100644 --- a/src/EditFamily.py +++ b/src/EditFamily.py @@ -30,11 +30,22 @@ import os import sys from gettext import gettext as _ +#------------------------------------------------------------------------- +# +# 2.4 provides a built in set. We want to use this, but need to handle +# older versions of python as well +# +#------------------------------------------------------------------------- try: set() except: from sets import Set as set +#------------------------------------------------------------------------- +# +# enable logging for error handling +# +#------------------------------------------------------------------------- import logging log = logging.getLogger(".") @@ -70,6 +81,10 @@ from GrampsWidgets import * from ObjectSelector import PersonSelector,PersonFilterSpec class ChildEmbedList(EmbeddedList): + """ + The child embed list is specific to the Edit Family dialog, so it + is contained here instead of in DisplayTabs. + """ _HANDLE_COL = 10 _DND_TYPE = DdTargets.PERSON_LINK @@ -88,11 +103,20 @@ class ChildEmbedList(EmbeddedList): ] def __init__(self,dbstate,uistate,track,family): + """ + Create the object, storing the passed family value + """ self.family = family EmbeddedList.__init__(self, dbstate, uistate, track, _('Children'), ChildModel) def build_columns(self): + """ + We can't use the default build_columns in the base class, because + we are using the custom TypeCellRenderer to handle father parent + relationships. The Paternal and Maternal columns (columns 4 and 5) + use this. + """ for column in self.columns: self.tree.remove_column(column) self.columns = [] @@ -115,12 +139,19 @@ class ChildEmbedList(EmbeddedList): self.tree.append_column(column) def get_icon_name(self): - return 'gramps-person' + return 'gramps-family' def is_empty(self): + """ + The list is considered empty if the child list is empty. + """ return len(self.family.get_child_handle_list()) == 0 def get_data(self): + """ + Normally, get_data returns a list. However, we return family + object here instead. + """ return self.family def column_order(self): @@ -173,8 +204,7 @@ class EditFamily(DisplayState.ManagedWindow): return self.build_interface() - if self.family: - self.load_data() + self.load_data() self.mname = None self.fname = None @@ -207,7 +237,10 @@ class EditFamily(DisplayState.ManagedWindow): return ('Edit Family','Undefined Submenu') def build_window_key(self,obj): - return id(self.family.handle) + if self.family.handle: + return id(self.family.handle) + else: + return id(self) def build_interface(self): @@ -248,7 +281,8 @@ class EditFamily(DisplayState.ManagedWindow): private.connect('toggled', self.privacy_toggled) gid = self.top.get_widget('gid') - gid.set_text(self.family.get_gramps_id()) + if self.family.get_gramps_id(): + gid.set_text(self.family.get_gramps_id()) gid.connect('changed', lambda x: self.family.set_gramps_id(x.get_text())) @@ -338,11 +372,13 @@ class EditFamily(DisplayState.ManagedWindow): self.mdeath, self.mbutton) def on_change_mother(self, selector_window, select_result): + print select_result if select_result.is_person(): try: - self.update_mother( - self.dbstate.db.get_person_from_gramps_id( - select_result.get_gramps_id()).get_handle()) + gid = select_result.get_gramps_id() + person = self.dbstate.db.get_person_from_gramps_id(gid) + self.family.set_mother_handle(person.get_handle()) + self.update_mother(person.get_handle()) except: log.warn( "Failed to update mother: \n" @@ -391,9 +427,10 @@ class EditFamily(DisplayState.ManagedWindow): def on_change_father(self, selector_window, select_result): if select_result.is_person(): try: - self.update_father( - self.dbstate.db.get_person_from_gramps_id( - select_result.get_gramps_id()).get_handle()) + gid = select_result.get_gramps_id() + person = self.dbstate.db.get_person_from_gramps_id(gid) + self.family.set_father_handle(person.get_handle()) + self.update_father(person.get_handle()) except: log.warn("Failed to update father: \n" "gramps_id returned from selector was: %s\n" @@ -483,7 +520,7 @@ class EditFamily(DisplayState.ManagedWindow): birth_obj.set_text(birth) death_obj.set_text(death) - def fix_parent_handles(self,orig_handle, new_handle): + def fix_parent_handles(self,orig_handle, new_handle, trans): if orig_handle != new_handle: if orig_handle: person = self.dbstate.db.get_person_from_handle(orig_handle) @@ -496,16 +533,24 @@ class EditFamily(DisplayState.ManagedWindow): self.dbstate.db.commit_person(person,trans) def apply_changes(self,obj): - original = self.dbstate.db.get_family_from_handle(self.family.handle) + if self.family.handle: + original = self.dbstate.db.get_family_from_handle(self.family.handle) + else: + original = None - if cmp(original.serialize(),self.family.serialize()): + if not original: + print self.family.serialize() + trans = self.dbstate.db.transaction_begin() + self.dbstate.db.add_family(self.family,trans) + self.dbstate.db.transaction_commit(trans,_("Edit Family")) + elif cmp(original.serialize(),self.family.serialize()): trans = self.dbstate.db.transaction_begin() self.fix_parent_handles(original.get_father_handle(), - self.family.get_father_handle()) + self.family.get_father_handle(),trans) self.fix_parent_handles(original.get_mother_handle(), - self.family.get_mother_handle()) + self.family.get_mother_handle(),trans) orig_set = set(original.get_child_handle_list()) new_set = set(self.family.get_child_handle_list()) @@ -513,7 +558,10 @@ class EditFamily(DisplayState.ManagedWindow): # remove the family from children which have been removed for handle in orig_set.difference(new_set): person = self.dbstate.db.get_person_from_handle(handle) + print person.get_primary_name().get_name() + print person.get_parent_family_handle_list() person.remove_parent_family_handle(self.family.handle) + print person.get_parent_family_handle_list() self.dbstate.db.commit_person(person,trans) # add the family from children which have been removed @@ -522,9 +570,11 @@ class EditFamily(DisplayState.ManagedWindow): #person.remove_parent_family_handle(self.family.handle) #self.dbstate.db.commit_person(person,trans) + self.dbstate.db.commit_family(self.family,trans) self.dbstate.db.transaction_commit(trans,_("Edit Family")) + self.close_window() - def close_window(self,obj): + def close_window(self,*obj): for key in self.signal_keys: self.dbstate.db.disconnect(key) self.close() diff --git a/src/EditMedia.py b/src/EditMedia.py index 5b2d06c4b..74bba8bc5 100644 --- a/src/EditMedia.py +++ b/src/EditMedia.py @@ -26,6 +26,7 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import os #------------------------------------------------------------------------- # @@ -70,7 +71,6 @@ _drag_targets = [ class EditMedia(DisplayState.ManagedWindow): def __init__(self,state,uistate,track,obj): - #self.parent = parent self.dp = DateHandler.parser self.dd = DateHandler.displayer @@ -108,6 +108,9 @@ class EditMedia(DisplayState.ManagedWindow): title = _('Media Properties Editor') self.window = self.change_dialog.get_widget('change_global') + self.select = self.change_dialog.get_widget('file_select') + self.select.connect('clicked', self.select_file) + self.date_entry = self.change_dialog.get_widget('date') self.date_entry.set_editable(mode) @@ -186,6 +189,25 @@ class EditMedia(DisplayState.ManagedWindow): def on_delete_event(self,obj,b): self.close() + def select_file(self,obj): + f = gtk.FileChooserDialog(_('Select Media Object'), + action=gtk.FILE_CHOOSER_ACTION_OPEN, + buttons=(gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) + + text = self.file_path.get_text() + name = os.path.basename(text) + path = os.path.dirname(text) + + f.set_filename(path) + + status = f.run() + if status == gtk.RESPONSE_OK: + self.file_path.set_text(f.get_filename()) + f.destroy() + def close_window(self,obj): if self.idle != None: gobject.source_remove(self.idle) @@ -193,7 +215,8 @@ class EditMedia(DisplayState.ManagedWindow): def update_info(self): fname = self.obj.get_path() - self.change_dialog.get_widget("path").set_text(fname) + self.file_path = self.change_dialog.get_widget("path") + self.file_path.set_text(fname) def on_apply_clicked(self, obj): desc = unicode(self.descr_window.get_text()) diff --git a/src/FamilyList.py b/src/FamilyList.py index 2656da940..dd3fbc6d1 100644 --- a/src/FamilyList.py +++ b/src/FamilyList.py @@ -113,7 +113,8 @@ class FamilyListView(PageView.ListView): def add(self,obj): import EditFamily - EditFamily.EditFamily(self.dbstate,self.uistate,[],None) + family = RelLib.Family() + EditFamily.EditFamily(self.dbstate,self.uistate,[],family) def remove(self,obj): return diff --git a/src/TreeViews/_PersonTreeView.py b/src/TreeViews/_PersonTreeView.py index f699722ba..6b2396384 100644 --- a/src/TreeViews/_PersonTreeView.py +++ b/src/TreeViews/_PersonTreeView.py @@ -7,6 +7,8 @@ from Models import \ PersonTreeModel, PersonListModel, PersonFilterModel from NameDisplay import displayer +import Utils + display_given = displayer.display_given @@ -19,15 +21,14 @@ class PersonTreeView(gtk.TreeView): # Add the Name column cols = (\ - (_("Family Name"),300,self._family_name),\ + (_("Name"),300,self._family_name),\ (_("ID"),100,self._object_id),\ - (_("Given Name"),300,self._given_name),\ (_("Gender"),100,self._gender),\ (_("Birth Date"),200,self._birth_date),\ (_("Birth Place"),200,self._birth_place),\ (_("Death Date"),200,self._death_date),\ (_("Death Place"),200,self._death_place),\ - (_("Spouce"),200,self._spouce),\ + (_("Spouse"),200,self._spouce),\ (_("Last Change"),200,self._last_change),\ (_("Cause of Death"),300,self._death_cause)) @@ -71,30 +72,39 @@ class PersonTreeView(gtk.TreeView): cell.set_property('text', "") def _family_name(self, column, cell, model, iter, user_data=None): - (o,rowref) = model.get_value(iter, 0) - cell.set_property('text', str(rowref) + " " + o.get_primary_name().get_surname()) - - def _given_name(self, column, cell, model, iter, user_data=None): (o,rowref) = model.get_value(iter, 0) if len(rowref) > 1: - cell.set_property('text', "") + cell.set_property('text', displayer(o)) else: - cell.set_property('text', "") - + cell.set_property('text',o.primary_name.surname) def _gender(self, column, cell, model, iter, user_data=None): (o,rowref) = model.get_value(iter, 0) if len(rowref) > 1: - cell.set_property('text', "") + cell.set_property('text', Utils.gender[o.gender]) else: cell.set_property('text', "") def _birth_date(self, column, cell, model, iter, user_data=None): (o,rowref) = model.get_value(iter, 0) + cell_value = '' if len(rowref) > 1: - cell.set_property('text', "") - else: - cell.set_property('text', "") + b = o.get_birth_ref() + if b: + birth = self.db.get_event_from_handle(b.ref) + date_str = DateHandler.get_date(birth) + if date_str != "": + cell_value = cgi.escape(date_str) + else: + for er in o.get_event_ref_list(): + event = self.db.get_event_from_handle(er.ref) + etype = event.get_type()[0] + date_str = DateHandler.get_date(event) + if (etype in [Event.BAPTISM, Event.CHRISTEN] + and date_str != ""): + return + cell_value = "" + cgi.escape(date_str) + "" + cell.set_property('text', cell_value) def _birth_place(self, column, cell, model, iter, user_data=None): (o,rowref) = model.get_value(iter, 0) diff --git a/src/edit_person.glade b/src/edit_person.glade index 3708665eb..c8933ca5b 100644 --- a/src/edit_person.glade +++ b/src/edit_person.glade @@ -713,7 +713,8 @@ Unknown True - unlocked.png + 4 + gtk-dialog-authentication 0.5 0.5 0 diff --git a/src/gramps.glade b/src/gramps.glade index 51b814d41..fd4f07632 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -8645,7 +8645,7 @@ Very High 12 True 4 - 3 + 4 False 6 12 @@ -8707,27 +8707,6 @@ Very High - - - True - True - True - True - 0 - - True - * - False - - - 2 - 3 - 0 - 1 - - - - True @@ -8741,6 +8720,7 @@ Very High 0.5 0 0 + date PANGO_ELLIPSIZE_NONE -1 False @@ -8756,87 +8736,6 @@ Very High - - - True - False - 0 - - - - True - True - True - True - 0 - - True - * - False - - - 0 - True - True - - - - - - True - Invoke date editor - True - GTK_RELIEF_NONE - True - - - - True - 0.5 - 0.5 - 0 - 0 - - - - - 0 - False - False - - - - - 2 - 3 - 2 - 3 - fill - fill - - - - - - True - True - True - True - 0 - - True - * - False - - - 2 - 3 - 1 - 2 - - - - True @@ -8865,27 +8764,6 @@ Very High - - - True - True - True - True - 0 - - True - * - False - - - 2 - 3 - 3 - 4 - - - - True @@ -8965,6 +8843,147 @@ Very High fill + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 3 + 3 + 4 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 4 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 4 + 1 + 2 + + + + + + + True + Invoke date editor + True + GTK_RELIEF_NONE + True + + + + True + 0.5 + 0.5 + 0 + 0 + + + + + 3 + 4 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 3 + 2 + 3 + + + + + + + True + True + GTK_RELIEF_NONE + True + + + + True + gtk-open + 4 + 0.5 + 0.5 + 0 + 0 + + + + + 3 + 4 + 3 + 4 + fill + + + 0