* src/EditFamily.py: start apply operation, data saving

svn: r5890
This commit is contained in:
Don Allingham 2006-02-06 05:03:44 +00:00
parent 785631e35d
commit ec7a5f4658
2 changed files with 67 additions and 21 deletions

View File

@ -1,6 +1,6 @@
2006-02-05 Don Allingham <don@gramps-project.org> 2006-02-05 Don Allingham <don@gramps-project.org>
* src/AttrEdit.py: remove unused parameters * src/AttrEdit.py: remove unused parameters
* src/EditFamily.py: start apply operation * src/EditFamily.py: start apply operation, data saving
* src/DisplayModels.py: handle places correctly * src/DisplayModels.py: handle places correctly
* src/DisplayTabs.py: Add LocationTab * src/DisplayTabs.py: Add LocationTab
* src/EditPlace.py: update to use DisplayTabs * src/EditPlace.py: update to use DisplayTabs

View File

@ -30,6 +30,11 @@ import os
import sys import sys
from gettext import gettext as _ from gettext import gettext as _
try:
set()
except:
from sets import Set as set
import logging import logging
log = logging.getLogger(".") log = logging.getLogger(".")
@ -216,9 +221,6 @@ class EditFamily(DisplayState.ManagedWindow):
self.mbirth = self.top.get_widget('mbirth') self.mbirth = self.top.get_widget('mbirth')
self.mdeath = self.top.get_widget('mdeath') self.mdeath = self.top.get_widget('mdeath')
self.gid = self.top.get_widget('gid')
self.reltype= self.top.get_widget('marriage_type')
self.mbutton= self.top.get_widget('mbutton') self.mbutton= self.top.get_widget('mbutton')
self.fbutton= self.top.get_widget('fbutton') self.fbutton= self.top.get_widget('fbutton')
@ -231,7 +233,24 @@ class EditFamily(DisplayState.ManagedWindow):
self.vbox = self.top.get_widget('vbox') self.vbox = self.top.get_widget('vbox')
self.child_list = self.top.get_widget('child_list') self.child_list = self.top.get_widget('child_list')
self.private= self.top.get_widget('private') self.notebook = gtk.Notebook()
self.notebook.show()
self.vbox.pack_start(self.notebook,True)
self._setup_monitored_values()
self.cancel.connect('clicked', self.close_window)
self.ok.connect('clicked', self.apply_changes)
def _setup_monitored_values(self):
private= self.top.get_widget('private')
private.set_active(self.family.get_privacy())
private.connect('toggled', self.privacy_toggled)
gid = self.top.get_widget('gid')
gid.set_text(self.family.get_gramps_id())
gid.connect('changed',
lambda x: self.family.set_gramps_id(x.get_text()))
rel_types = dict(Utils.family_relations) rel_types = dict(Utils.family_relations)
@ -241,15 +260,11 @@ class EditFamily(DisplayState.ManagedWindow):
else: else:
defval = None defval = None
reltype = self.top.get_widget('marriage_type')
self.type_sel = AutoComp.StandardCustomSelector( self.type_sel = AutoComp.StandardCustomSelector(
rel_types, self.reltype, RelLib.Family.CUSTOM, defval) rel_types, reltype, RelLib.Family.CUSTOM, defval)
reltype.connect('changed',
self.notebook = gtk.Notebook() lambda x: self.family.set_relationship(self.type_sel.get_values()))
self.notebook.show()
self.vbox.pack_start(self.notebook,True)
self.cancel.connect('clicked', self.close_window)
self.ok.connect('clicked', self.apply_changes)
def load_data(self): def load_data(self):
fhandle = self.family.get_father_handle() fhandle = self.family.get_father_handle()
@ -301,18 +316,16 @@ class EditFamily(DisplayState.ManagedWindow):
self.notebook.set_tab_label(self.gallery_tab, self.notebook.set_tab_label(self.gallery_tab,
self.gallery_tab.get_tab_widget()) self.gallery_tab.get_tab_widget())
self.gid.set_text(self.family.get_gramps_id())
self.private.connect('toggled',self.privacy_toggled)
self.private.set_active(self.family.get_privacy())
def privacy_toggled(self,obj): def privacy_toggled(self,obj):
for o in obj.get_children(): for o in obj.get_children():
obj.remove(o) obj.remove(o)
img = gtk.Image() img = gtk.Image()
if obj.get_active(): if obj.get_active():
img.set_from_file(os.path.join(const.rootDir,"locked.png")) img.set_from_file(os.path.join(const.rootDir,"locked.png"))
self.family.set_privacy(True)
else: else:
img.set_from_file(os.path.join(const.rootDir,"unlocked.png")) img.set_from_file(os.path.join(const.rootDir,"unlocked.png"))
self.family.set_privacy(False)
img.show() img.show()
obj.add(img) obj.add(img)
@ -470,13 +483,46 @@ class EditFamily(DisplayState.ManagedWindow):
birth_obj.set_text(birth) birth_obj.set_text(birth)
death_obj.set_text(death) death_obj.set_text(death)
def fix_parent_handles(self,orig_handle, new_handle):
if orig_handle != new_handle:
if orig_handle:
person = self.dbstate.db.get_person_from_handle(orig_handle)
person.family_list.remove(self.family.handle)
self.dbstate.db.commit_person(person,trans)
if new_handle:
person = self.dbstate.db.get_person_from_handle(orig_handle)
if self.family.handle not in self.person.family_list:
person.family_list.append(self.family.handle)
self.dbstate.db.commit_person(person,trans)
def apply_changes(self,obj): def apply_changes(self,obj):
original = self.dbstate.db.get_family_from_handle(self.family.handle) original = self.dbstate.db.get_family_from_handle(self.family.handle)
print original.get_father_handle(), self.family.get_father_handle() if cmp(original.serialize(),self.family.serialize()):
print original.get_mother_handle(), self.family.get_mother_handle()
print original.get_child_handle_list(), self.family.get_child_handle_list() trans = self.dbstate.db.transaction_begin()
print "Apply Changes"
self.fix_parent_handles(original.get_father_handle(),
self.family.get_father_handle())
self.fix_parent_handles(original.get_mother_handle(),
self.family.get_mother_handle())
orig_set = set(original.get_child_handle_list())
new_set = set(self.family.get_child_handle_list())
# 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)
person.remove_parent_family_handle(self.family.handle)
self.dbstate.db.commit_person(person,trans)
# add the family from children which have been removed
for handle in new_set.difference(orig_set):
person = self.dbstate.db.get_person_from_handle(handle)
#person.remove_parent_family_handle(self.family.handle)
#self.dbstate.db.commit_person(person,trans)
self.dbstate.db.transaction_commit(trans,_("Edit Family"))
def close_window(self,obj): def close_window(self,obj):
for key in self.signal_keys: for key in self.signal_keys: