2006-01-12 05:37:11 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import cPickle as pickle
|
2006-01-17 10:33:30 +05:30
|
|
|
import os
|
2006-01-12 05:37:11 +05:30
|
|
|
import sys
|
2006-01-13 06:15:22 +05:30
|
|
|
from gettext import gettext as _
|
2006-01-12 05:37:11 +05:30
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 2.4 provides a built in set. We want to use this, but need to handle
|
|
|
|
# older versions of python as well
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-02-06 10:33:44 +05:30
|
|
|
try:
|
|
|
|
set()
|
|
|
|
except:
|
|
|
|
from sets import Set as set
|
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# enable logging for error handling
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-01-12 05:37:11 +05:30
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".")
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import NameDisplay
|
|
|
|
import DisplayState
|
|
|
|
import Spell
|
|
|
|
import GrampsDisplay
|
|
|
|
import RelLib
|
|
|
|
import ReportUtils
|
2006-01-14 03:58:54 +05:30
|
|
|
import AutoComp
|
|
|
|
import GrampsWidgets
|
2006-01-12 05:37:11 +05:30
|
|
|
|
|
|
|
from DdTargets import DdTargets
|
|
|
|
from WindowUtils import GladeIf
|
2006-01-16 10:23:42 +05:30
|
|
|
from DisplayTabs import *
|
|
|
|
from GrampsWidgets import *
|
2006-01-20 16:00:35 +05:30
|
|
|
from ObjectSelector import PersonSelector,PersonFilterSpec
|
2006-01-12 05:37:11 +05:30
|
|
|
|
2006-01-16 10:23:42 +05:30
|
|
|
class ChildEmbedList(EmbeddedList):
|
2006-02-07 05:14:09 +05:30
|
|
|
"""
|
|
|
|
The child embed list is specific to the Edit Family dialog, so it
|
|
|
|
is contained here instead of in DisplayTabs.
|
|
|
|
"""
|
2006-01-13 06:15:22 +05:30
|
|
|
|
2006-01-19 04:03:27 +05:30
|
|
|
_HANDLE_COL = 10
|
2006-02-02 03:27:11 +05:30
|
|
|
_DND_TYPE = DdTargets.PERSON_LINK
|
2006-01-14 10:57:48 +05:30
|
|
|
|
2006-01-29 02:08:03 +05:30
|
|
|
_column_names = [
|
2006-01-13 06:15:22 +05:30
|
|
|
(_('#'),0) ,
|
|
|
|
(_('ID'),1) ,
|
|
|
|
(_('Name'),9),
|
|
|
|
(_('Gender'),3),
|
2006-01-19 04:03:27 +05:30
|
|
|
(_('Paternal'),12),
|
|
|
|
(_('Maternal'),13),
|
2006-01-13 06:15:22 +05:30
|
|
|
(_('Birth Date'),10),
|
|
|
|
(_('Death Date'),11),
|
|
|
|
(_('Birth Place'),6),
|
|
|
|
(_('Death Place'),7),
|
|
|
|
]
|
|
|
|
|
2006-01-14 10:57:48 +05:30
|
|
|
def __init__(self,dbstate,uistate,track,family):
|
2006-02-07 05:14:09 +05:30
|
|
|
"""
|
|
|
|
Create the object, storing the passed family value
|
|
|
|
"""
|
2006-01-13 06:15:22 +05:30
|
|
|
self.family = family
|
2006-01-16 10:23:42 +05:30
|
|
|
EmbeddedList.__init__(self, dbstate, uistate, track,
|
|
|
|
_('Children'), ChildModel)
|
2006-01-13 09:24:31 +05:30
|
|
|
|
2006-01-19 04:03:27 +05:30
|
|
|
def build_columns(self):
|
2006-02-07 05:14:09 +05:30
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2006-01-19 04:03:27 +05:30
|
|
|
for column in self.columns:
|
|
|
|
self.tree.remove_column(column)
|
|
|
|
self.columns = []
|
|
|
|
|
|
|
|
for pair in self.column_order():
|
|
|
|
if not pair[0]:
|
|
|
|
continue
|
2006-01-29 02:08:03 +05:30
|
|
|
name = self._column_names[pair[1]][0]
|
2006-01-19 04:03:27 +05:30
|
|
|
if pair[1] == 4 or pair[1] == 5:
|
2006-01-19 07:36:27 +05:30
|
|
|
render = TypeCellRenderer(Utils.child_relations)
|
|
|
|
column = gtk.TreeViewColumn(name, render, text=pair[1])
|
2006-01-19 04:03:27 +05:30
|
|
|
else:
|
|
|
|
render = gtk.CellRendererText()
|
2006-01-19 07:36:27 +05:30
|
|
|
column = gtk.TreeViewColumn(name, render, text=pair[1])
|
2006-01-19 04:03:27 +05:30
|
|
|
|
|
|
|
column.set_resizable(True)
|
|
|
|
column.set_min_width(40)
|
2006-01-29 02:08:03 +05:30
|
|
|
column.set_sort_column_id(self._column_names[pair[1]][1])
|
2006-01-19 04:03:27 +05:30
|
|
|
self.columns.append(column)
|
|
|
|
self.tree.append_column(column)
|
|
|
|
|
2006-01-15 10:19:13 +05:30
|
|
|
def get_icon_name(self):
|
2006-02-07 05:14:09 +05:30
|
|
|
return 'gramps-family'
|
2006-01-15 10:19:13 +05:30
|
|
|
|
2006-01-29 02:08:03 +05:30
|
|
|
def is_empty(self):
|
2006-02-07 05:14:09 +05:30
|
|
|
"""
|
|
|
|
The list is considered empty if the child list is empty.
|
|
|
|
"""
|
2006-01-29 02:08:03 +05:30
|
|
|
return len(self.family.get_child_handle_list()) == 0
|
|
|
|
|
2006-01-13 06:15:22 +05:30
|
|
|
def get_data(self):
|
2006-02-07 05:14:09 +05:30
|
|
|
"""
|
|
|
|
Normally, get_data returns a list. However, we return family
|
|
|
|
object here instead.
|
|
|
|
"""
|
2006-01-19 04:03:27 +05:30
|
|
|
return self.family
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
def column_order(self):
|
2006-01-19 04:03:27 +05:30
|
|
|
return [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(0,8),(0,9)]
|
2006-01-13 06:15:22 +05:30
|
|
|
|
2006-01-14 10:57:48 +05:30
|
|
|
def add_button_clicked(self,obj):
|
2006-01-20 16:00:35 +05:30
|
|
|
# we could workout the death years of the parents here and
|
|
|
|
# set a suitable filter_spec on the PersonSelector
|
|
|
|
# we might also be able to set a filter that only includes
|
|
|
|
# people that are not already listed as children in another
|
|
|
|
# family.
|
|
|
|
selector = PersonSelector(self.dbstate,self.uistate,self.track)
|
|
|
|
|
|
|
|
# this need the window handle of the main EditFamily window
|
|
|
|
# to make the PersonSelector transient to it. I am not sure
|
|
|
|
# want the best way is to get that handle from here.
|
|
|
|
#selector.set_transient_for(self.window)
|
|
|
|
|
|
|
|
# Connect this to the method used to add a new child.
|
|
|
|
#selector.connect('add-object',self.on_add_child)
|
|
|
|
|
2006-01-14 10:57:48 +05:30
|
|
|
|
|
|
|
def del_button_clicked(self,obj):
|
2006-01-14 23:32:07 +05:30
|
|
|
handle = self.get_selected()
|
|
|
|
if handle:
|
|
|
|
self.family.remove_child_handle(handle)
|
|
|
|
self.rebuild()
|
2006-01-14 10:57:48 +05:30
|
|
|
|
|
|
|
def edit_button_clicked(self,obj):
|
|
|
|
handle = self.get_selected()
|
|
|
|
if handle:
|
|
|
|
import EditPerson
|
|
|
|
person = self.dbstate.db.get_person_from_handle(handle)
|
|
|
|
EditPerson.EditPerson(self.dbstate,self.uistate,self.track,person)
|
|
|
|
|
2006-01-12 05:37:11 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-01-13 06:15:22 +05:30
|
|
|
# EditFamily
|
2006-01-12 05:37:11 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class EditFamily(DisplayState.ManagedWindow):
|
|
|
|
|
|
|
|
def __init__(self,dbstate,uistate,track,family):
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
|
|
|
self.family = family
|
|
|
|
|
|
|
|
DisplayState.ManagedWindow.__init__(self, uistate, track, family)
|
|
|
|
if self.already_exist:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.build_interface()
|
2006-02-07 05:14:09 +05:30
|
|
|
self.load_data()
|
2006-01-12 05:37:11 +05:30
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
self.mname = None
|
|
|
|
self.fname = None
|
2006-01-19 01:06:23 +05:30
|
|
|
|
|
|
|
self.signal_keys = []
|
|
|
|
self.signal_keys.append(self.dbstate.db.connect('person-update',
|
|
|
|
self.check_for_change))
|
|
|
|
self.signal_keys.append(self.dbstate.db.connect('person-delete',
|
|
|
|
self.check_for_change))
|
|
|
|
self.signal_keys.append(self.dbstate.db.connect('person-rebuild',
|
|
|
|
self.reload_people))
|
2006-01-14 03:58:54 +05:30
|
|
|
|
2006-01-12 05:37:11 +05:30
|
|
|
self.show()
|
|
|
|
|
2006-01-19 01:06:23 +05:30
|
|
|
def check_for_change(self,handles):
|
|
|
|
for node in handles:
|
|
|
|
if node in self.phandles:
|
|
|
|
self.reload_people()
|
|
|
|
break;
|
|
|
|
|
|
|
|
def reload_people(self):
|
|
|
|
fhandle = self.family.get_father_handle()
|
|
|
|
self.update_father(fhandle)
|
|
|
|
|
|
|
|
mhandle = self.family.get_mother_handle()
|
|
|
|
self.update_mother(mhandle)
|
|
|
|
self.child_list.rebuild()
|
|
|
|
|
2006-01-12 05:37:11 +05:30
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return ('Edit Family','Undefined Submenu')
|
|
|
|
|
|
|
|
def build_window_key(self,obj):
|
2006-02-07 05:14:09 +05:30
|
|
|
if self.family.handle:
|
|
|
|
return id(self.family.handle)
|
|
|
|
else:
|
|
|
|
return id(self)
|
2006-01-12 05:37:11 +05:30
|
|
|
|
|
|
|
def build_interface(self):
|
2006-01-16 10:23:42 +05:30
|
|
|
|
2006-01-17 10:33:30 +05:30
|
|
|
self.top = gtk.glade.XML(const.gladeFile,"marriageEditor","gramps")
|
2006-01-12 05:37:11 +05:30
|
|
|
self.gladeif = GladeIf(self.top)
|
|
|
|
self.window = self.top.get_widget("marriageEditor")
|
|
|
|
|
|
|
|
self.fbirth = self.top.get_widget('fbirth')
|
|
|
|
self.fdeath = self.top.get_widget('fdeath')
|
|
|
|
|
|
|
|
self.mbirth = self.top.get_widget('mbirth')
|
|
|
|
self.mdeath = self.top.get_widget('mdeath')
|
|
|
|
|
2006-01-13 06:15:22 +05:30
|
|
|
self.mbutton= self.top.get_widget('mbutton')
|
|
|
|
self.fbutton= self.top.get_widget('fbutton')
|
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
self.mbox = self.top.get_widget('mbox')
|
|
|
|
self.fbox = self.top.get_widget('fbox')
|
|
|
|
|
2006-01-12 05:37:11 +05:30
|
|
|
self.ok = self.top.get_widget('ok')
|
|
|
|
self.cancel = self.top.get_widget('cancel')
|
|
|
|
|
2006-01-13 06:15:22 +05:30
|
|
|
self.vbox = self.top.get_widget('vbox')
|
2006-01-14 03:58:54 +05:30
|
|
|
self.child_list = self.top.get_widget('child_list')
|
|
|
|
|
2006-02-06 10:33:44 +05:30
|
|
|
self.notebook = gtk.Notebook()
|
|
|
|
self.notebook.show()
|
|
|
|
self.vbox.pack_start(self.notebook,True)
|
|
|
|
|
|
|
|
self._setup_monitored_values()
|
2006-01-17 10:33:30 +05:30
|
|
|
|
2006-02-06 10:33:44 +05:30
|
|
|
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')
|
2006-02-07 05:14:09 +05:30
|
|
|
if self.family.get_gramps_id():
|
|
|
|
gid.set_text(self.family.get_gramps_id())
|
2006-02-06 10:33:44 +05:30
|
|
|
gid.connect('changed',
|
|
|
|
lambda x: self.family.set_gramps_id(x.get_text()))
|
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
rel_types = dict(Utils.family_relations)
|
|
|
|
|
|
|
|
mtype = self.family.get_relationship()
|
|
|
|
if mtype:
|
|
|
|
defval = mtype[0]
|
|
|
|
else:
|
|
|
|
defval = None
|
|
|
|
|
2006-02-06 10:33:44 +05:30
|
|
|
reltype = self.top.get_widget('marriage_type')
|
2006-01-14 03:58:54 +05:30
|
|
|
self.type_sel = AutoComp.StandardCustomSelector(
|
2006-02-06 10:33:44 +05:30
|
|
|
rel_types, reltype, RelLib.Family.CUSTOM, defval)
|
|
|
|
reltype.connect('changed',
|
|
|
|
lambda x: self.family.set_relationship(self.type_sel.get_values()))
|
2006-01-12 05:37:11 +05:30
|
|
|
|
|
|
|
def load_data(self):
|
2006-01-19 01:06:23 +05:30
|
|
|
fhandle = self.family.get_father_handle()
|
|
|
|
self.update_father(fhandle)
|
|
|
|
|
|
|
|
mhandle = self.family.get_mother_handle()
|
|
|
|
self.update_mother(mhandle)
|
|
|
|
|
|
|
|
self.phandles = [mhandle, fhandle] + self.family.get_child_handle_list()
|
|
|
|
self.phandles = [handle for handle in self.phandles if handle]
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
self.mbutton.connect('clicked',self.mother_clicked)
|
|
|
|
self.fbutton.connect('clicked',self.father_clicked)
|
2006-01-13 06:15:22 +05:30
|
|
|
|
2006-01-14 10:57:48 +05:30
|
|
|
self.child_list = ChildEmbedList(self.dbstate,self.uistate,
|
|
|
|
self.track, self.family)
|
2006-01-16 10:23:42 +05:30
|
|
|
self.event_list = EventEmbedList(self.dbstate,self.uistate,
|
|
|
|
self.track,self.family)
|
2006-01-24 09:43:21 +05:30
|
|
|
self.src_list = SourceEmbedList(self.dbstate,self.uistate,
|
|
|
|
self.track,self.family.source_list)
|
2006-01-14 10:57:48 +05:30
|
|
|
self.attr_list = AttrEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.family.get_attribute_list())
|
2006-01-16 10:23:42 +05:30
|
|
|
self.note_tab = NoteTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.family.get_note_object())
|
|
|
|
self.gallery_tab = GalleryTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.family.get_media_list())
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
self.notebook.insert_page(self.child_list)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.child_list,
|
|
|
|
self.child_list.get_tab_widget())
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
self.notebook.insert_page(self.event_list)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.event_list,
|
|
|
|
self.event_list.get_tab_widget())
|
2006-01-12 05:37:11 +05:30
|
|
|
|
2006-01-24 09:43:21 +05:30
|
|
|
self.notebook.insert_page(self.src_list)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.src_list,
|
|
|
|
self.src_list.get_tab_widget())
|
2006-01-24 09:43:21 +05:30
|
|
|
|
2006-01-13 09:24:31 +05:30
|
|
|
self.notebook.insert_page(self.attr_list)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.attr_list,
|
|
|
|
self.attr_list.get_tab_widget())
|
2006-01-13 09:24:31 +05:30
|
|
|
|
|
|
|
self.notebook.insert_page(self.note_tab)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.note_tab,
|
|
|
|
self.note_tab.get_tab_widget())
|
2006-01-13 09:24:31 +05:30
|
|
|
|
|
|
|
self.notebook.insert_page(self.gallery_tab)
|
2006-02-06 03:53:53 +05:30
|
|
|
self.notebook.set_tab_label(self.gallery_tab,
|
|
|
|
self.gallery_tab.get_tab_widget())
|
2006-01-13 09:24:31 +05:30
|
|
|
|
2006-01-17 10:33:30 +05:30
|
|
|
def privacy_toggled(self,obj):
|
|
|
|
for o in obj.get_children():
|
|
|
|
obj.remove(o)
|
|
|
|
img = gtk.Image()
|
|
|
|
if obj.get_active():
|
|
|
|
img.set_from_file(os.path.join(const.rootDir,"locked.png"))
|
2006-02-06 10:33:44 +05:30
|
|
|
self.family.set_privacy(True)
|
2006-01-17 10:33:30 +05:30
|
|
|
else:
|
|
|
|
img.set_from_file(os.path.join(const.rootDir,"unlocked.png"))
|
2006-02-06 10:33:44 +05:30
|
|
|
self.family.set_privacy(False)
|
2006-01-17 10:33:30 +05:30
|
|
|
img.show()
|
|
|
|
obj.add(img)
|
2006-01-13 06:15:22 +05:30
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
def update_father(self,handle):
|
2006-02-06 03:53:53 +05:30
|
|
|
self.load_parent(handle, self.fbox, self.fbirth,
|
|
|
|
self.fdeath, self.fbutton)
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
def update_mother(self,handle):
|
2006-02-06 03:53:53 +05:30
|
|
|
self.load_parent(handle, self.mbox, self.mbirth,
|
|
|
|
self.mdeath, self.mbutton)
|
2006-01-14 03:58:54 +05:30
|
|
|
|
2006-01-20 16:00:35 +05:30
|
|
|
def on_change_mother(self, selector_window, select_result):
|
2006-02-07 05:14:09 +05:30
|
|
|
print select_result
|
2006-01-20 16:00:35 +05:30
|
|
|
if select_result.is_person():
|
|
|
|
try:
|
2006-02-07 05:14:09 +05:30
|
|
|
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())
|
2006-01-20 16:00:35 +05:30
|
|
|
except:
|
2006-02-06 03:53:53 +05:30
|
|
|
log.warn(
|
|
|
|
"Failed to update mother: \n"
|
|
|
|
"gramps_id returned from selector was: %s\n"
|
|
|
|
"person returned from get_person_from_gramps_id: %s"
|
|
|
|
% (select_result.get_gramps_id(),
|
|
|
|
repr(self.dbstate.db.get_person_from_gramps_id(
|
|
|
|
select_result.get_gramps_id()))))
|
2006-01-20 16:00:35 +05:30
|
|
|
raise
|
|
|
|
else:
|
2006-02-06 03:53:53 +05:30
|
|
|
log.warn(
|
|
|
|
"Object selector returned a result of type = %s, it should "
|
|
|
|
"have been of type PERSON." % (str(select_result.get_object_type())))
|
2006-01-20 16:00:35 +05:30
|
|
|
|
|
|
|
selector_window.close()
|
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
def mother_clicked(self,obj):
|
|
|
|
handle = self.family.get_mother_handle()
|
|
|
|
if handle:
|
|
|
|
self.family.set_mother_handle(None)
|
|
|
|
self.update_mother(None)
|
|
|
|
else:
|
2006-01-20 16:00:35 +05:30
|
|
|
filter_spec = PersonFilterSpec()
|
|
|
|
filter_spec.set_gender(RelLib.Person.FEMALE)
|
|
|
|
|
|
|
|
child_birth_years = []
|
|
|
|
for person_handle in self.family.get_child_handle_list():
|
|
|
|
person = self.dbstate.db.get_person_from_handle(person_handle)
|
2006-02-06 03:53:53 +05:30
|
|
|
event_ref = person.get_birth_ref()
|
|
|
|
event_handle = event_ref.ref
|
2006-01-20 16:00:35 +05:30
|
|
|
if event_handle:
|
|
|
|
event = self.dbstate.db.get_event_from_handle(event_handle)
|
|
|
|
child_birth_years.append(event.get_date_object().get_year())
|
|
|
|
|
|
|
|
if len(child_birth_years) > 0:
|
|
|
|
filter_spec.set_birth_year(min(child_birth_years))
|
|
|
|
filter_spec.set_birth_criteria(PersonFilterSpec.BEFORE)
|
|
|
|
|
|
|
|
|
2006-02-06 03:53:53 +05:30
|
|
|
selector = PersonSelector(self.dbstate,self.uistate,
|
|
|
|
self.track,filter_spec=filter_spec)
|
2006-01-20 16:00:35 +05:30
|
|
|
selector.set_transient_for(self.window)
|
|
|
|
selector.connect('add-object',self.on_change_mother)
|
|
|
|
|
|
|
|
|
|
|
|
def on_change_father(self, selector_window, select_result):
|
|
|
|
if select_result.is_person():
|
|
|
|
try:
|
2006-02-07 05:14:09 +05:30
|
|
|
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())
|
2006-01-20 16:00:35 +05:30
|
|
|
except:
|
|
|
|
log.warn("Failed to update father: \n"
|
|
|
|
"gramps_id returned from selector was: %s\n"
|
|
|
|
"person returned from get_person_from_gramps_id: %s"
|
|
|
|
% (select_result.get_gramps_id(),
|
|
|
|
repr(self.dbstate.db.get_person_from_gramps_id(
|
|
|
|
select_result.get_gramps_id()))))
|
|
|
|
raise
|
|
|
|
else:
|
|
|
|
log.warn("Object selector returned a result of type = %s, it should "
|
|
|
|
"have been of type PERSON." % (str(select_result.get_object_type())))
|
|
|
|
|
|
|
|
selector_window.close()
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
def father_clicked(self,obj):
|
|
|
|
handle = self.family.get_father_handle()
|
|
|
|
if handle:
|
|
|
|
self.family.set_father_handle(None)
|
|
|
|
self.update_father(None)
|
|
|
|
else:
|
2006-01-20 16:00:35 +05:30
|
|
|
filter_spec = PersonFilterSpec()
|
|
|
|
filter_spec.set_gender(RelLib.Person.MALE)
|
|
|
|
|
|
|
|
child_birth_years = []
|
|
|
|
for person_handle in self.family.get_child_handle_list():
|
|
|
|
person = self.dbstate.db.get_person_from_handle(person_handle)
|
2006-02-06 03:53:53 +05:30
|
|
|
event_ref = person.get_birth_ref()
|
|
|
|
event_handle = event_ref.ref
|
2006-01-20 16:00:35 +05:30
|
|
|
if event_handle:
|
|
|
|
event = self.dbstate.db.get_event_from_handle(event_handle)
|
|
|
|
child_birth_years.append(event.get_date_object().get_year())
|
|
|
|
|
|
|
|
if len(child_birth_years) > 0:
|
|
|
|
filter_spec.set_birth_year(min(child_birth_years))
|
|
|
|
filter_spec.set_birth_criteria(PersonFilterSpec.BEFORE)
|
|
|
|
|
2006-02-06 03:53:53 +05:30
|
|
|
selector = PersonSelector(self.dbstate,self.uistate,
|
|
|
|
self.track,filter_spec=filter_spec)
|
2006-01-20 16:00:35 +05:30
|
|
|
selector.set_transient_for(self.window)
|
|
|
|
selector.connect('add-object',self.on_change_father)
|
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
def edit_person(self,obj,event,handle):
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
|
|
|
|
import EditPerson
|
|
|
|
person = self.dbstate.db.get_person_from_handle(handle)
|
2006-02-06 03:53:53 +05:30
|
|
|
EditPerson.EditPerson(self.dbstate, self.uistate,
|
|
|
|
self.track, person)
|
2006-01-13 06:15:22 +05:30
|
|
|
|
2006-01-14 03:58:54 +05:30
|
|
|
def load_parent(self,handle,box,birth_obj,death_obj,btn_obj):
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
is_used = handle != None
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
for i in box.get_children():
|
|
|
|
box.remove(i)
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
btn_obj.remove(btn_obj.get_children()[0])
|
|
|
|
|
|
|
|
if is_used:
|
2006-01-12 05:37:11 +05:30
|
|
|
db = self.dbstate.db
|
|
|
|
person = db.get_person_from_handle(handle)
|
|
|
|
name = "%s [%s]" % (NameDisplay.displayer.display(person),
|
|
|
|
person.gramps_id)
|
|
|
|
data = ReportUtils.get_birth_death_strings(db,person)
|
|
|
|
birth = data[0]
|
|
|
|
death = data[4]
|
2006-01-13 06:15:22 +05:30
|
|
|
|
|
|
|
del_image = gtk.Image()
|
|
|
|
del_image.show()
|
|
|
|
del_image.set_from_stock(gtk.STOCK_REMOVE,gtk.ICON_SIZE_BUTTON)
|
|
|
|
btn_obj.add(del_image)
|
2006-01-14 03:58:54 +05:30
|
|
|
|
|
|
|
box.pack_start(GrampsWidgets.LinkBox(
|
|
|
|
GrampsWidgets.BasicLabel(name),
|
|
|
|
GrampsWidgets.IconButton(self.edit_person,person.handle)
|
|
|
|
))
|
2006-01-12 05:37:11 +05:30
|
|
|
else:
|
|
|
|
name = ""
|
|
|
|
birth = ""
|
|
|
|
death = ""
|
|
|
|
|
2006-01-13 06:15:22 +05:30
|
|
|
add_image = gtk.Image()
|
|
|
|
add_image.show()
|
|
|
|
add_image.set_from_stock(gtk.STOCK_ADD,gtk.ICON_SIZE_BUTTON)
|
|
|
|
btn_obj.add(add_image)
|
|
|
|
|
2006-01-12 05:37:11 +05:30
|
|
|
birth_obj.set_text(birth)
|
|
|
|
death_obj.set_text(death)
|
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
def fix_parent_handles(self,orig_handle, new_handle, trans):
|
2006-02-06 10:33:44 +05:30
|
|
|
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)
|
|
|
|
|
2006-02-06 03:53:53 +05:30
|
|
|
def apply_changes(self,obj):
|
2006-02-07 05:14:09 +05:30
|
|
|
if self.family.handle:
|
|
|
|
original = self.dbstate.db.get_family_from_handle(self.family.handle)
|
|
|
|
else:
|
|
|
|
original = None
|
2006-02-06 03:53:53 +05:30
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
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()):
|
2006-02-06 10:33:44 +05:30
|
|
|
|
|
|
|
trans = self.dbstate.db.transaction_begin()
|
|
|
|
|
|
|
|
self.fix_parent_handles(original.get_father_handle(),
|
2006-02-07 05:14:09 +05:30
|
|
|
self.family.get_father_handle(),trans)
|
2006-02-06 10:33:44 +05:30
|
|
|
self.fix_parent_handles(original.get_mother_handle(),
|
2006-02-07 05:14:09 +05:30
|
|
|
self.family.get_mother_handle(),trans)
|
2006-02-06 10:33:44 +05:30
|
|
|
|
|
|
|
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)
|
2006-02-07 05:14:09 +05:30
|
|
|
print person.get_primary_name().get_name()
|
|
|
|
print person.get_parent_family_handle_list()
|
2006-02-06 10:33:44 +05:30
|
|
|
person.remove_parent_family_handle(self.family.handle)
|
2006-02-07 05:14:09 +05:30
|
|
|
print person.get_parent_family_handle_list()
|
2006-02-06 10:33:44 +05:30
|
|
|
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)
|
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
self.dbstate.db.commit_family(self.family,trans)
|
2006-02-06 10:33:44 +05:30
|
|
|
self.dbstate.db.transaction_commit(trans,_("Edit Family"))
|
2006-02-07 05:14:09 +05:30
|
|
|
self.close_window()
|
2006-02-06 03:53:53 +05:30
|
|
|
|
2006-02-07 05:14:09 +05:30
|
|
|
def close_window(self,*obj):
|
2006-01-19 01:06:23 +05:30
|
|
|
for key in self.signal_keys:
|
|
|
|
self.dbstate.db.disconnect(key)
|
2006-01-12 05:37:11 +05:30
|
|
|
self.close()
|