2006-10-31 23:06:38 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2001-2007 Donald N. Allingham
|
2006-10-31 23:06:38 +05:30
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2007-09-10 08:33:46 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2006-10-31 23:06:38 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2010-01-14 09:38:04 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2006-11-17 06:09:27 +05:30
|
|
|
|
2010-01-14 09:38:04 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from gen.display.name import displayer as name_displayer
|
2006-10-31 23:06:38 +05:30
|
|
|
import ListModel
|
|
|
|
import ManagedWindow
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
PARENT_TITLES = [(_('Father'), -1, 200), (_('Mother'), -1, 200), ('', -1, 0)]
|
|
|
|
FAMILY_TITLES = [(_('Spouse'), -1, 200), (_('Relationship'), -1, 200), ('', -1, 0)]
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
class Reorder(ManagedWindow.ManagedWindow):
|
|
|
|
|
|
|
|
def __init__(self, state, uistate, track, handle):
|
2009-05-15 01:45:59 +05:30
|
|
|
xml = Glade()
|
|
|
|
top = xml.toplevel
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.dbstate = state
|
2006-10-31 23:06:38 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
|
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.person = self.dbstate.db.get_person_from_handle(handle)
|
|
|
|
self.parent_list = self.person.get_parent_family_handle_list()
|
|
|
|
self.family_list = self.person.get_family_handle_list()
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
penable = len(self.parent_list) > 1
|
|
|
|
fenable = len(self.family_list) > 1
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.set_window(top, None, _("Reorder Relationships"))
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
self.ptree = xml.get_object('ptree')
|
2007-09-10 08:33:46 +05:30
|
|
|
self.pmodel = ListModel.ListModel(self.ptree, PARENT_TITLES)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
self.ftree = xml.get_object('ftree')
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fmodel = ListModel.ListModel(self.ftree, FAMILY_TITLES)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
xml.get_object('ok').connect('clicked', self.ok_clicked)
|
|
|
|
xml.get_object('cancel').connect('clicked', self.cancel_clicked)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
fup = xml.get_object('fup')
|
2007-09-10 08:33:46 +05:30
|
|
|
fup.connect('clicked', self.fup_clicked)
|
|
|
|
fup.set_sensitive(fenable)
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
fdown = xml.get_object('fdown')
|
2007-09-10 08:33:46 +05:30
|
|
|
fdown.connect('clicked', self.fdown_clicked)
|
|
|
|
fdown.set_sensitive(fenable)
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
pup = xml.get_object('pup')
|
2007-09-10 08:33:46 +05:30
|
|
|
pup.connect('clicked', self.pup_clicked)
|
|
|
|
pup.set_sensitive(penable)
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2009-05-06 20:14:22 +05:30
|
|
|
pdown = xml.get_object('pdown')
|
2007-09-10 08:33:46 +05:30
|
|
|
pdown.connect('clicked', self.pdown_clicked)
|
|
|
|
pdown.set_sensitive(penable)
|
2006-11-01 01:14:45 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fill_data()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.show()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def fill_data(self):
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fill_parents()
|
|
|
|
self.fill_family()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def fill_parents(self):
|
2007-09-10 08:33:46 +05:30
|
|
|
for handle in self.parent_list:
|
|
|
|
family = self.dbstate.db.get_family_from_handle(handle)
|
|
|
|
fhandle = family.get_father_handle()
|
|
|
|
mhandle = family.get_mother_handle()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
fname = ""
|
|
|
|
if fhandle:
|
|
|
|
father = self.dbstate.db.get_person_from_handle(fhandle)
|
|
|
|
if father:
|
|
|
|
fname = name_displayer.display(father)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
mname = ""
|
|
|
|
if mhandle:
|
|
|
|
mother = self.dbstate.db.get_person_from_handle(mhandle)
|
|
|
|
if mother:
|
|
|
|
mname = name_displayer.display(mother)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.pmodel.add([fname, mname, handle])
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def fill_family(self):
|
2007-09-10 08:33:46 +05:30
|
|
|
for handle in self.family_list:
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
family = self.dbstate.db.get_family_from_handle(handle)
|
|
|
|
fhandle = family.get_father_handle()
|
|
|
|
mhandle = family.get_mother_handle()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
name = ""
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
if fhandle and fhandle != self.person.handle:
|
|
|
|
spouse = self.dbstate.db.get_person_from_handle(fhandle)
|
|
|
|
if spouse:
|
|
|
|
name = name_displayer.display(spouse)
|
|
|
|
elif mhandle:
|
|
|
|
spouse = self.dbstate.db.get_person_from_handle(mhandle)
|
|
|
|
if spouse:
|
|
|
|
name = name_displayer.display(spouse)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
reltype = str(family.get_relationship())
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fmodel.add([name, reltype, handle])
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def cancel_clicked(self, obj):
|
2007-09-10 08:33:46 +05:30
|
|
|
self.close()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def ok_clicked(self, obj):
|
|
|
|
trans = self.dbstate.db.transaction_begin()
|
2007-09-10 08:33:46 +05:30
|
|
|
self.dbstate.db.commit_person(self.person, trans)
|
|
|
|
name = name_displayer.display(self.person)
|
|
|
|
msg = _("Reorder Relationships: %s") % name
|
2006-10-31 23:06:38 +05:30
|
|
|
self.dbstate.db.transaction_commit(trans, msg)
|
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
self.close()
|
2006-10-31 23:06:38 +05:30
|
|
|
|
2007-09-10 08:33:46 +05:30
|
|
|
def pup_clicked(self, obj):
|
2006-10-31 23:06:38 +05:30
|
|
|
"""Moves the current selection up one row"""
|
|
|
|
row = self.pmodel.get_selected_row()
|
|
|
|
if not row or row == -1:
|
|
|
|
return
|
2007-09-10 08:33:46 +05:30
|
|
|
store, the_iter = self.pmodel.get_selected()
|
|
|
|
data = self.pmodel.get_data(the_iter, xrange(3))
|
2006-10-31 23:06:38 +05:30
|
|
|
self.pmodel.remove(the_iter)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.pmodel.insert(row-1, data, None, 1)
|
2006-10-31 23:06:38 +05:30
|
|
|
handle = self.parent_list.pop(row)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.parent_list.insert(row-1, handle)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def pdown_clicked(self, obj):
|
|
|
|
row = self.pmodel.get_selected_row()
|
|
|
|
if row + 1 >= self.pmodel.count or row == -1:
|
|
|
|
return
|
2007-09-10 08:33:46 +05:30
|
|
|
store, the_iter = self.pmodel.get_selected()
|
|
|
|
data = self.pmodel.get_data(the_iter, xrange(3))
|
2006-10-31 23:06:38 +05:30
|
|
|
self.pmodel.remove(the_iter)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.pmodel.insert(row+1, data, None, 1)
|
2006-10-31 23:06:38 +05:30
|
|
|
handle = self.parent_list.pop(row)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.parent_list.insert(row+1, handle)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
def fup_clicked(self, obj):
|
|
|
|
row = self.fmodel.get_selected_row()
|
|
|
|
if not row or row == -1:
|
|
|
|
return
|
2007-09-10 08:33:46 +05:30
|
|
|
store, the_iter = self.fmodel.get_selected()
|
|
|
|
data = self.fmodel.get_data(the_iter, xrange(3))
|
2006-10-31 23:06:38 +05:30
|
|
|
self.fmodel.remove(the_iter)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fmodel.insert(row-1, data, None, 1)
|
2006-10-31 23:06:38 +05:30
|
|
|
handle = self.family_list.pop(row)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.family_list.insert(row-1, handle)
|
2006-10-31 23:06:38 +05:30
|
|
|
|
|
|
|
|
|
|
|
def fdown_clicked(self, obj):
|
|
|
|
row = self.fmodel.get_selected_row()
|
|
|
|
if row + 1 >= self.fmodel.count or row == -1:
|
|
|
|
return
|
2007-09-10 08:33:46 +05:30
|
|
|
store, the_iter = self.fmodel.get_selected()
|
|
|
|
data = self.fmodel.get_data(the_iter, xrange(3))
|
2006-10-31 23:06:38 +05:30
|
|
|
self.fmodel.remove(the_iter)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.fmodel.insert(row+1, data, None, 1)
|
2006-10-31 23:06:38 +05:30
|
|
|
handle = self.family_list.pop(row)
|
2007-09-10 08:33:46 +05:30
|
|
|
self.family_list.insert(row+1, handle)
|