gramps/src/plugins/tool/RelCalc.py

258 lines
9.6 KiB
Python
Raw Normal View History

2002-10-20 19:55:16 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
* src/TreeViews/_PersonTreeView.py: Use name_displayer. * src/ReportBase/_ReportUtils.py: Use name_displayer. * src/ReportBase/_CommandLineReport.py: Use name_displayer. * src/ReportBase/_BareReportDialog.py: Use name_displayer. * src/PluginUtils/_Tool.py: Use name_displayer. * src/plugins/TimeLine.py: Use name_displayer. * src/plugins/RelCalc.py: Use name_displayer. * src/plugins/ReadGrdb.py: Use name_displayer. * src/plugins/NarrativeWeb.py: Use name_displayer. * src/plugins/IndivComplete.py: Use name_displayer. * src/plugins/GraphViz.py: Use name_displayer. * src/plugins/FindDupes.py: Use name_displayer. * src/plugins/FamilyGroup.py: Use name_displayer. * src/plugins/DetDescendantReport.py: Use name_displayer. * src/plugins/DetAncestralReport.py: Use name_displayer. * src/plugins/DesGraph.py: Use name_displayer. * src/plugins/DescendReport.py: Use name_displayer. * src/plugins/DescendChart.py: Use name_displayer. * src/plugins/Check.py: Use name_displayer. * src/plugins/Ancestors.py: Use name_displayer. * src/plugins/AncestorReport.py: Use name_displayer. * src/plugins/AncestorChart2.py: Use name_displayer. * src/ObjectSelector/_PersonTreeFrame.py: Use name_displayer. * src/ObjectSelector/_PersonFrame.py: Use name_displayer. * src/Merge/_MergePerson.py: Use name_displayer. * src/GrampsDbUtils/_WriteGedcom.py: Use name_displayer. * src/GrampsDbUtils/_ReadXML.py: Use name_displayer. * src/GrampsDbUtils/_GedcomParse.py: Use name_displayer. * src/FilterEditor/_ShowResults.py: Use name_displayer. * src/FilterEditor/_EditRule.py: Use name_displayer. * src/Editors/_EditPrimary.py: Use name_displayer. * src/Editors/_EditPersonRef.py: Use name_displayer. * src/Editors/_EditPerson.py: Use name_displayer. * src/Editors/_EditName.py: Use name_displayer. * src/Editors/_EditLdsOrd.py: Use name_displayer. * src/Editors/_EditFamily.py: Use name_displayer. * src/DisplayTabs/_PersonRefModel.py: Use name_displayer. * src/DisplayTabs/_NameModel.py: Use name_displayer. * src/DisplayTabs/_ChildModel.py: Use name_displayer. * src/DisplayTabs/_BackRefModel.py: Use name_displayer. * src/DisplayModels/_PeopleModel.py: Use name_displayer. * src/DisplayModels/_FamilyModel.py: Use name_displayer. * src/DataViews/_PersonView.py: Use name_displayer. * src/DataViews/_RelationView.py: Use name_displayer. * src/DataViews/_PedigreeView.py: Use name_displayer. * src/Utils.py: Use name_displayer. * src/SubstKeywords.py: Use name_displayer. * src/Sort.py: Use name_displayer. * src/Reorder.py: Use name_displayer. * src/PageView.py (BookMarkView.add_bookmark): Use name_displayer. * src/Navigation.py: Use name_displayer. * src/DisplayState.py: Use name_displayer. * src/GrampsCfg.py: Use name_displayer. * src/Bookmarks.py (Bookmarks.make_label): Use name_displayer. * src/GrampsDb/Makefile.am (pkgdata_PYTHON): Ship new files. * src/Makefile.am (gdir_PYTHON): Ship ProgressDialog.py svn: r8680
2007-06-28 11:11:40 +05:30
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Gary Burton
2002-10-20 19:55:16 +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.
#
# 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$
"""Tools/Utilities/Relationship Calculator"""
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# GNOME libraries
#
#-------------------------------------------------------------------------
import gtk
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gen.display.name import displayer as name_displayer
import ManagedWindow
from gui.views.treemodels import PeopleBaseModel, PersonTreeModel
from libpersonview import BasePersonView
import Relationship
from QuestionDialog import ErrorDialog
from PluginUtils import Tool
from glade import Glade
2005-12-07 01:24:16 +05:30
#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
column_names = BasePersonView.COLUMN_NAMES
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
class RelCalc(Tool.Tool, ManagedWindow.ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None):
2005-12-07 01:24:16 +05:30
"""
Relationship calculator class.
"""
Tool.Tool.__init__(self, dbstate, options_class, name)
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
#set the columns to see
for data in BasePersonView.CONFIGSETTINGS:
if data[0] == 'columns.order':
colord = data[1]
elif data[0] == 'columns.visible':
colvis = data[1]
elif data[0] == 'columns.sizecol':
colsize = data[1]
self.colord = []
for col, size in zip(colord, colsize):
if col in colvis:
self.colord.append((1, col, size))
else:
self.colord.append((0, col, size))
self.dbstate = dbstate
self.relationship = Relationship.get_relationship_calculator()
self.relationship.connect_db_signals(dbstate)
2002-10-20 19:55:16 +05:30
self.glade = Glade()
self.person = self.db.get_person_from_handle(
uistate.get_active('Person'))
name = ''
if self.person:
name = name_displayer.display(self.person)
self.title = _('Relationship calculator: %(person_name)s'
) % {'person_name' : name}
window = self.glade.toplevel
self.titlelabel = self.glade.get_object('title')
self.set_window(window, self.titlelabel,
_('Relationship to %(person_name)s'
) % {'person_name' : name },
self.title)
2002-10-20 19:55:16 +05:30
self.tree = self.glade.get_object("peopleList")
self.text = self.glade.get_object("text1")
self.textbuffer = gtk.TextBuffer()
self.text.set_buffer(self.textbuffer)
2005-12-07 01:24:16 +05:30
self.model = PersonTreeModel(self.db)
2005-12-07 01:24:16 +05:30
self.tree.set_model(self.model)
self.tree.connect('key-press-event', self._key_press)
self.selection = self.tree.get_selection()
self.selection.set_mode(gtk.SELECTION_SINGLE)
#keep reference of column so garbage collection works
self.columns = []
for pair in self.colord:
2005-12-07 01:24:16 +05:30
if not pair[0]:
continue
2005-12-07 01:24:16 +05:30
name = column_names[pair[1]]
column = gtk.TreeViewColumn(name, gtk.CellRendererText(),
markup=pair[1])
2005-12-07 01:24:16 +05:30
column.set_resizable(True)
column.set_min_width(60)
column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
self.tree.append_column(column)
#keep reference of column so garbage collection works
self.columns.append(column)
2005-12-07 01:24:16 +05:30
self.sel = self.tree.get_selection()
self.changedkey = self.sel.connect('changed',self.on_apply_clicked)
self.closebtn = self.glade.get_object("button5")
self.closebtn.connect('clicked', self.close)
2002-10-20 19:55:16 +05:30
if not self.person:
self.window.hide()
ErrorDialog(_('Active person has not been set'),
_('You must select an active person for this '
'tool to work properly.'))
self.close()
return
self.show()
def close(self, *obj):
""" Close relcalc tool. Remove non-gtk connections so garbage
collection can do its magic.
"""
self.relationship.disconnect_db_signals(self.dbstate)
self.sel.disconnect(self.changedkey)
ManagedWindow.ManagedWindow.close(self, *obj)
def build_menu_names(self, obj):
return (_("Relationship Calculator tool"),None)
def on_apply_clicked(self, obj):
model, node = self.tree.get_selection().get_selected()
if not node:
2002-10-20 19:55:16 +05:30
return
handle = model.get_value(node, PeopleBaseModel.COLUMN_INT_ID)
other_person = self.db.get_person_from_handle(handle)
if other_person is None :
self.textbuffer.set_text("")
return
#now determine the relation, and print it out
rel_strings, common_an = self.relationship.get_all_relationships(
self.db, self.person, other_person)
p1 = name_displayer.display(self.person)
p2 = name_displayer.display(other_person)
text = []
if other_person is None:
pass
2005-12-07 01:24:16 +05:30
elif self.person.handle == other_person.handle:
rstr = _("%(person)s and %(active_person)s are the same person.")) % {
'person' : p1, 'active_person' : p2 }
text.append((rstr, ""))
elif len(rel_strings) == 0:
2003-04-30 05:54:32 +05:30
rstr = _("%(person)s and %(active_person)s are not related.") % {
'person' : p2, 'active_person' : p1 }
text.append((rstr, ""))
2002-10-20 19:55:16 +05:30
for rel_string, common in zip(rel_strings, common_an):
rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
) % {'person' : p2, 'relationship' : rel_string,
'active_person' : p1 }
length = len(common)
if length == 1:
person = self.db.get_person_from_handle(common[0])
if common[0] in [other_person.handle, self.person.handle]:
commontext = ''
else :
name = name_displayer.display(person)
commontext = " " + _("Their common ancestor is %s.") % name
elif length == 2:
p1c = self.db.get_person_from_handle(common[0])
p2c = self.db.get_person_from_handle(common[1])
p1str = name_displayer.display(p1c)
p2str = name_displayer.display(p2c)
2010-02-25 22:49:12 +05:30
commontext = " " + _("Their common ancestors are %(ancestor1)s and %(ancestor2)s.")
% { 'ancestor1' : p1str, 'ancestor2' : p2str }
elif length > 2:
index = 0
commontext = " " + _("Their common ancestors are: ")
for person_handle in common:
person = self.db.get_person_from_handle(person_handle)
if index:
commontext += ", "
commontext += name_displayer.display(person)
index += 1
commontext += "."
else:
commontext = ""
text.append((rstr, commontext))
textval = ""
for val in text:
textval += "%s %s\n" % (val[0], val[1])
self.textbuffer.set_text(textval)
2002-10-20 19:55:16 +05:30
def _key_press(self, obj, event):
if not event.state or event.state in (gtk.gdk.MOD2_MASK, ):
if event.keyval in (gtk.keysyms.Return, gtk.keysyms.KP_Enter):
store, paths = self.selection.get_selected_rows()
if paths and len(paths[0]) == 1 :
if self.tree.row_expanded(paths[0]):
self.tree.collapse_row(paths[0])
else:
self.tree.expand_row(paths[0], 0)
return True
return False
2005-12-07 01:24:16 +05:30
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class RelCalcOptions(Tool.ToolOptions):
"""
Defines options and provides handling interface.
"""
def __init__(self, name,person_id=None):
Tool.ToolOptions.__init__(self, name,person_id)