Move all quick views into plugins/quickview.
svn: r11635
This commit is contained in:
108
src/plugins/quickview/AgeOnDate.py
Normal file
108
src/plugins/quickview/AgeOnDate.py
Normal file
@@ -0,0 +1,108 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
# Copyright (C) 2009 Douglas S. Blank
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display references for any object
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_DATE
|
||||
import DateHandler
|
||||
import gen.lib
|
||||
import Config
|
||||
|
||||
def run(database, document, date):
|
||||
"""
|
||||
Display people probably alive and their ages on a particular date.
|
||||
"""
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
if not date.get_valid():
|
||||
sdoc.paragraph("Date is not a valid date.")
|
||||
return
|
||||
# display the title
|
||||
if date.get_day_valid():
|
||||
sdoc.title(_("People probably alive and their ages the %s") %
|
||||
DateHandler.displayer.display(date))
|
||||
else:
|
||||
sdoc.title(_("People probably alive and their ages on %s") %
|
||||
DateHandler.displayer.display(date))
|
||||
stab.columns(_("Person"), _("Age")) # Actual Date makes column unicode
|
||||
matches = 0
|
||||
for person in sdb.all_people():
|
||||
birth_date = None
|
||||
birth_str = ""
|
||||
birth_sort = 0
|
||||
birth_ref = gen.lib.Person.get_birth_ref(person)
|
||||
birth_date = get_event_date_from_ref(database, birth_ref)
|
||||
death_ref = gen.lib.Person.get_death_ref(person)
|
||||
death_date = get_event_date_from_ref(database, death_ref)
|
||||
if birth_date:
|
||||
if (birth_date.get_valid() and birth_date < date and
|
||||
birth_date.get_year() != 0 and
|
||||
((death_date is None) or (death_date > date))):
|
||||
diff_span = (date - birth_date)
|
||||
if ((death_date is not None) or
|
||||
(death_date is None and
|
||||
int(diff_span) <= Config.get(Config.MAX_AGE_PROB_ALIVE) * 365)):
|
||||
birth_str = str(diff_span)
|
||||
birth_sort = int(diff_span)
|
||||
if birth_str != "":
|
||||
stab.row(person, birth_str)
|
||||
stab.row_sort_val(1, diff_span)
|
||||
matches += 1
|
||||
sdoc.paragraph("\n%d matches.\n" % matches)
|
||||
stab.write(sdoc)
|
||||
sdoc.paragraph("")
|
||||
|
||||
def get_event_date_from_ref(database, ref):
|
||||
date = None
|
||||
if ref:
|
||||
handle = ref.get_reference_handle()
|
||||
if handle:
|
||||
event = database.get_event_from_handle(handle)
|
||||
if event:
|
||||
date = event.get_date_object()
|
||||
return date
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register the report
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'ageondate',
|
||||
category = CATEGORY_QR_DATE,
|
||||
run_func = run,
|
||||
translated_name = _("Age on Date"),
|
||||
status = _("Stable"),
|
||||
description= _("Display people and ages on a particular date"),
|
||||
author_name="Douglas Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
55
src/plugins/quickview/AttributeMatch.py
Normal file
55
src/plugins/quickview/AttributeMatch.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Douglas S. Blank
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
from ReportBase import CATEGORY_QR_MISC
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gen.plug import PluginManager
|
||||
|
||||
def run(database, document, attribute, value=None):
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
sdoc.title(_("People who have the '%s' Attribute") % attribute)
|
||||
sdoc.paragraph("")
|
||||
stab.columns(_("Person"), str(attribute))
|
||||
matches = 0
|
||||
for person_handle in database.get_person_handles(sort_handles=False):
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
matched = False
|
||||
for attr in person.attribute_list:
|
||||
if str(attr.type) == attribute:
|
||||
stab.row(person, str(attr.get_value()))
|
||||
matched = True
|
||||
if matched:
|
||||
matches += 1
|
||||
sdoc.paragraph(_("There are %d people with a matching attribute name.\n") % matches)
|
||||
stab.write(sdoc)
|
||||
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'attribute_match',
|
||||
category = CATEGORY_QR_MISC, # to run with attribute/value
|
||||
run_func = run,
|
||||
translated_name = _("Attribute Match"),
|
||||
status = _("Stable"),
|
||||
description= _("Display people with same attribute."),
|
||||
author_name="Douglas S. Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
239
src/plugins/quickview/FilterByName.py
Normal file
239
src/plugins/quickview/FilterByName.py
Normal file
@@ -0,0 +1,239 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display filtered data
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gen.plug import PluginManager
|
||||
from Utils import media_path_full
|
||||
from QuickReports import run_quick_report_by_name_direct
|
||||
from gen.lib import Person
|
||||
import DateHandler
|
||||
|
||||
import posixpath
|
||||
from gettext import gettext as _
|
||||
|
||||
# force translation
|
||||
[_('all people'), _('males'), _('females'), _('people with unknown gender'),
|
||||
_('people with incomplete names'), _('people with missing birth dates'),
|
||||
_('disconnected people'), _('all families'), _('unique surnames'),
|
||||
_('people with media'), _('media references'), _('unique media'),
|
||||
_('missing media'), _('media by size'), _('list of people')]
|
||||
|
||||
def run(database, document, filter_name, *args, **kwargs):
|
||||
"""
|
||||
Loops through the families that the person is a child in, and display
|
||||
the information about the other children.
|
||||
"""
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
# display the title
|
||||
sdoc.title(_("Filtering on %s") % _(filter_name)) # listed above
|
||||
sdoc.paragraph("")
|
||||
matches = 0
|
||||
if (filter_name == 'all people'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'males'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person.gender == Person.MALE:
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'females'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person.gender == Person.FEMALE:
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'people with unknown gender'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person.gender not in [Person.FEMALE, Person.MALE]:
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'people with incomplete names'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
if name.get_group_name() == "" or name.get_first_name() == "":
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'people with missing birth dates'):
|
||||
stab.columns(_("Person"), _("Type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
birth_ref = person.get_birth_ref()
|
||||
if birth_ref:
|
||||
birth = database.get_event_from_handle(birth_ref.ref)
|
||||
if not DateHandler.get_date(birth):
|
||||
stab.row(person, _("birth event but no date"))
|
||||
matches += 1
|
||||
else:
|
||||
stab.row(person, _("missing birth event"))
|
||||
matches += 1
|
||||
elif (filter_name == 'disconnected people'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
if ((not person.get_main_parents_family_handle()) and
|
||||
(not len(person.get_family_handle_list()))):
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
elif (filter_name == 'all families'):
|
||||
familyList = database.get_family_handles()
|
||||
stab.columns(_("Family"))
|
||||
for family_handle in familyList:
|
||||
family = database.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
stab.row(family)
|
||||
matches += 1
|
||||
elif (filter_name == 'unique surnames'):
|
||||
namelist = {}
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if person:
|
||||
names = [person.get_primary_name()] + person.get_alternate_names()
|
||||
surnames = list(set([name.get_group_name() for name in names]))
|
||||
for surname in surnames:
|
||||
namelist[surname] = namelist.get(surname, 0) + 1
|
||||
surnames = namelist.keys()
|
||||
surnames.sort()
|
||||
stab.columns(_("Surname"), _("Count"))
|
||||
for name in surnames:
|
||||
stab.row(name, namelist[name])
|
||||
matches += 1
|
||||
stab.set_callback("leftdouble",
|
||||
lambda name: run_quick_report_by_name_direct("samesurnames",
|
||||
database,
|
||||
document,
|
||||
name))
|
||||
elif (filter_name == 'people with media'):
|
||||
stab.columns(_("Person"), _("Media count"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if not person:
|
||||
continue
|
||||
length = len(person.get_media_list())
|
||||
if length > 0:
|
||||
stab.row(person, length)
|
||||
matches += 1
|
||||
elif (filter_name == 'media references'):
|
||||
stab.columns(_("Person"), _("Reference"))
|
||||
people = database.get_person_handles(sort_handles=False)
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
if not person:
|
||||
continue
|
||||
medialist = person.get_media_list()
|
||||
for item in medialist:
|
||||
stab.row(person, _("media"))
|
||||
matches += 1
|
||||
elif (filter_name == 'unique media'):
|
||||
stab.columns(_("Unique Media"))
|
||||
pobjects = database.get_media_object_handles()
|
||||
for photo_id in database.get_media_object_handles():
|
||||
photo = database.get_object_from_handle(photo_id)
|
||||
fullname = media_path_full(database, photo.get_path())
|
||||
stab.row(fullname)
|
||||
matches += 1
|
||||
elif (filter_name == 'missing media'):
|
||||
stab.columns(_("Missing Media"))
|
||||
pobjects = database.get_media_object_handles()
|
||||
for photo_id in database.get_media_object_handles():
|
||||
photo = database.get_object_from_handle(photo_id)
|
||||
fullname = media_path_full(database, photo.get_path())
|
||||
try:
|
||||
posixpath.getsize(fullname)
|
||||
except:
|
||||
stab.row(fullname)
|
||||
matches += 1
|
||||
elif (filter_name == 'media by size'):
|
||||
stab.columns(_("Media"), _("Size in bytes"))
|
||||
pobjects = database.get_media_object_handles()
|
||||
for photo_id in database.get_media_object_handles():
|
||||
photo = database.get_object_from_handle(photo_id)
|
||||
fullname = media_path_full(database, photo.get_path())
|
||||
try:
|
||||
bytes = posixpath.getsize(fullname)
|
||||
stab.row(fullname, bytes)
|
||||
matches += 1
|
||||
except:
|
||||
pass
|
||||
elif (filter_name == 'list of people'):
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
people = kwargs["handles"]
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
else:
|
||||
raise AttributeError, ("invalid filter name: '%s'" % filter_name)
|
||||
sdoc.paragraph(_("Filter matched %d records.") % matches)
|
||||
sdoc.paragraph("")
|
||||
if matches > 0:
|
||||
stab.write(sdoc)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'filterbyname',
|
||||
category = -1, # stand-alone
|
||||
run_func = run,
|
||||
translated_name = _("Filter"),
|
||||
status = _("Stable"),
|
||||
description= _("Display filtered data"),
|
||||
author_name="Douglas S. Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
32
src/plugins/quickview/Makefile.am
Normal file
32
src/plugins/quickview/Makefile.am
Normal file
@@ -0,0 +1,32 @@
|
||||
# This is the src/plugins/quickview level Makefile for Gramps
|
||||
# We could use GNU make's ':=' syntax for nice wildcard use,
|
||||
# but that is not necessarily portable.
|
||||
# If not using GNU make, then list all .py files individually
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/plugins/quickview
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
AgeOnDate.py \
|
||||
all_events.py \
|
||||
all_relations.py \
|
||||
AttributeMatch.py \
|
||||
FilterByName.py \
|
||||
lineage.py \
|
||||
OnThisDay.py \
|
||||
Query.py \
|
||||
References.py \
|
||||
Reporef.py \
|
||||
SameSurnames.py\
|
||||
siblings.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/plugins/quickview
|
||||
pkgpythondir = @pkgpythondir@/plugins/quickview
|
||||
|
||||
# Clean up all the byte-compiled files
|
||||
MOSTLYCLEANFILES = *pyc *pyo
|
||||
|
||||
GRAMPS_PY_MODPATH = "../../"
|
||||
|
||||
pycheck:
|
||||
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
|
||||
pychecker $(pkgdata_PYTHON));
|
150
src/plugins/quickview/OnThisDay.py
Normal file
150
src/plugins/quickview/OnThisDay.py
Normal file
@@ -0,0 +1,150 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display all events on a particular day.
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_EVENT
|
||||
import gen.lib
|
||||
|
||||
def get_ref(db, objclass, handle):
|
||||
"""
|
||||
Looks up object in database
|
||||
"""
|
||||
if objclass == 'Person':
|
||||
ref = db.get_person_from_handle(handle)
|
||||
elif objclass == 'Family':
|
||||
ref = db.get_family_from_handle(handle)
|
||||
elif objclass == 'Event':
|
||||
ref = db.get_event_from_handle(handle)
|
||||
elif objclass == 'Source':
|
||||
ref = db.get_source_from_handle(handle)
|
||||
elif objclass == 'Place':
|
||||
ref = db.get_place_from_handle(handle)
|
||||
elif objclass == 'Repository':
|
||||
ref = db.get_repository_from_handle(handle)
|
||||
else:
|
||||
ref = objclass
|
||||
return ref
|
||||
|
||||
def run(database, document, main_event):
|
||||
"""
|
||||
Displays events on a specific date of an event (or date)
|
||||
|
||||
Takes an Event or Date object
|
||||
"""
|
||||
if isinstance(main_event, gen.lib.Date):
|
||||
main_date = main_event
|
||||
else:
|
||||
main_date = main_event.get_date_object()
|
||||
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
stab.set_link_col(3)
|
||||
yeartab = SimpleTable(sdb)
|
||||
yeartab.set_link_col(3)
|
||||
histab = SimpleTable(sdb)
|
||||
histab.set_link_col(3)
|
||||
|
||||
# display the title
|
||||
sdoc.title(_("Events of %(date)s") %
|
||||
{"date": sdb.date_string(main_date)})
|
||||
sdoc.paragraph("")
|
||||
stab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
|
||||
yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
|
||||
histab.columns(_("Date"), _("Type"), _("Place"), _("Reference"))
|
||||
|
||||
for event_handle in database.get_event_handles():
|
||||
event = database.get_event_from_handle(event_handle)
|
||||
date = event.get_date_object()
|
||||
if date.get_year() == 0:
|
||||
continue
|
||||
if (date.get_year() == main_date.get_year() and
|
||||
date.get_month() == main_date.get_month() and
|
||||
date.get_day() == main_date.get_day()):
|
||||
for (objclass, handle) in database.find_backlink_handles(event_handle):
|
||||
ref = get_ref(database, objclass, handle)
|
||||
stab.row(date,
|
||||
sdb.event_type(event),
|
||||
sdb.event_place(event), ref)
|
||||
elif (date.get_month() == main_date.get_month() and
|
||||
date.get_day() == main_date.get_day() and
|
||||
date.get_month() != 0):
|
||||
for (objclass, handle) in database.find_backlink_handles(event_handle):
|
||||
ref = get_ref(database, objclass, handle)
|
||||
histab.row(date,
|
||||
sdb.event_type(event),
|
||||
sdb.event_place(event), ref)
|
||||
elif (date.get_year() == main_date.get_year()):
|
||||
for (objclass, handle) in database.find_backlink_handles(event_handle):
|
||||
ref = get_ref(database, objclass, handle)
|
||||
yeartab.row(date,
|
||||
sdb.event_type(event),
|
||||
sdb.event_place(event), ref)
|
||||
|
||||
if stab.get_row_count() > 0:
|
||||
sdoc.paragraph(_("Events on this exact date"))
|
||||
stab.write(sdoc)
|
||||
else:
|
||||
sdoc.paragraph(_("No events on this exact date"))
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
||||
if histab.get_row_count() > 0:
|
||||
sdoc.paragraph(_("Other events on this month/day in history"))
|
||||
histab.write(sdoc)
|
||||
else:
|
||||
sdoc.paragraph(_("No other events on this month/day in history"))
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
||||
if yeartab.get_row_count() > 0:
|
||||
sdoc.paragraph(_("Other events in %(year)d") %
|
||||
{"year":main_date.get_year()})
|
||||
yeartab.write(sdoc)
|
||||
else:
|
||||
sdoc.paragraph(_("No other events in %(year)d") %
|
||||
{"year":main_date.get_year()})
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register the report
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'onthisday',
|
||||
category = CATEGORY_QR_EVENT,
|
||||
run_func = run,
|
||||
translated_name = _("On This Day"),
|
||||
status = _("Stable"),
|
||||
description= _("Display events on a particular day"),
|
||||
author_name="Douglas Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
441
src/plugins/quickview/Query.py
Normal file
441
src/plugins/quickview/Query.py
Normal file
@@ -0,0 +1,441 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Run a query on the tables
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
import Utils
|
||||
from ReportBase import CATEGORY_QR_MISC
|
||||
import DateHandler
|
||||
import gen.lib
|
||||
import Config
|
||||
|
||||
def cleanup_column_name(column):
|
||||
""" Handle column aliases for CSV spreadsheet import and SQL """
|
||||
retval = column
|
||||
# Title case:
|
||||
if retval in ["Lastname",
|
||||
"Surname", _("Surname")]:
|
||||
return "surname"
|
||||
elif retval in ["Firstname",
|
||||
"Given name", _("Given name"),
|
||||
"Given", _("Given")]:
|
||||
return "firstname"
|
||||
elif retval in ["Callname",
|
||||
"Call name", _("Call name"),
|
||||
"Call", _("Call")]:
|
||||
return "callname"
|
||||
elif retval in ["Title", _("Title")]:
|
||||
return "title"
|
||||
elif retval in ["Prefix", _("Prefix")]:
|
||||
return "prefix"
|
||||
elif retval in ["Suffix", _("Suffix")]:
|
||||
return "suffix"
|
||||
elif retval in ["Gender", _("Gender")]:
|
||||
return "gender"
|
||||
elif retval in ["Source", _("Source")]:
|
||||
return "source"
|
||||
elif retval in ["Note", _("Note")]:
|
||||
return "note"
|
||||
elif retval in ["Birthplace",
|
||||
"Birth place", _("Birth place")]:
|
||||
return "birthplace"
|
||||
elif retval in ["Birthdate",
|
||||
"Birth date", _("Birth date")]:
|
||||
return "birthdate"
|
||||
elif retval in ["Birthsource",
|
||||
"Birth source", _("Birth source")]:
|
||||
return "birthsource"
|
||||
elif retval in ["Deathplace",
|
||||
"Death place", _("Death place")]:
|
||||
return "deathplace"
|
||||
elif retval in ["Deathdate",
|
||||
"Death date", _("Death date")]:
|
||||
return "deathdate"
|
||||
elif retval in ["Deathsource",
|
||||
"Death source", _("Death source")]:
|
||||
return "deathsource"
|
||||
elif retval in ["Deathcause",
|
||||
"Death cause", _("Death cause")]:
|
||||
return "deathcause"
|
||||
elif retval in ["Grampsid", "ID",
|
||||
"Gramps id", _("Gramps id")]:
|
||||
return "grampsid"
|
||||
elif retval in ["Person", _("Person")]:
|
||||
return "person"
|
||||
# ----------------------------------
|
||||
elif retval in ["Child", _("Child")]:
|
||||
return "child"
|
||||
elif retval in ["Source", _("Source")]:
|
||||
return "source"
|
||||
elif retval in ["Family", _("Family")]:
|
||||
return "family"
|
||||
# ----------------------------------
|
||||
elif retval in ["Mother", _("Mother"),
|
||||
"Wife", _("Wife"),
|
||||
"Parent2", _("Parent2")]:
|
||||
return "wife"
|
||||
elif retval in ["Father", _("Father"),
|
||||
"Husband", _("Husband"),
|
||||
"Parent1", _("Parent1")]:
|
||||
return "husband"
|
||||
elif retval in ["Marriage", _("Marriage")]:
|
||||
return "marriage"
|
||||
elif retval in ["Date", _("Date")]:
|
||||
return "date"
|
||||
elif retval in ["Place", _("Place")]:
|
||||
return "place"
|
||||
# lowercase
|
||||
elif retval in ["lastname", "last_name",
|
||||
"surname", _("surname")]:
|
||||
return "surname"
|
||||
elif retval in ["firstname", "first_name", "given_name",
|
||||
"given name", _("given name"),
|
||||
"given", _("given")]:
|
||||
return "firstname"
|
||||
elif retval in ["callname", "call_name",
|
||||
"call name",
|
||||
"call", _("call")]:
|
||||
return "callname"
|
||||
elif retval in ["title", _("title")]:
|
||||
return "title"
|
||||
elif retval in ["prefix", _("prefix")]:
|
||||
return "prefix"
|
||||
elif retval in ["suffix", _("suffix")]:
|
||||
return "suffix"
|
||||
elif retval in ["gender", _("gender")]:
|
||||
return "gender"
|
||||
elif retval in ["source", _("source")]:
|
||||
return "source"
|
||||
elif retval in ["note", _("note")]:
|
||||
return "note"
|
||||
elif retval in ["birthplace", "birth_place",
|
||||
"birth place", _("birth place")]:
|
||||
return "birthplace"
|
||||
elif retval in ["birthdate", "birth_date",
|
||||
"birth date", _("birth date")]:
|
||||
return "birthdate"
|
||||
elif retval in ["birthsource", "birth_source",
|
||||
"birth source", _("birth source")]:
|
||||
return "birthsource"
|
||||
elif retval in ["deathplace", "death_place",
|
||||
"death place", _("death place")]:
|
||||
return "deathplace"
|
||||
elif retval in ["deathdate", "death_date",
|
||||
"death date", _("death date")]:
|
||||
return "deathdate"
|
||||
elif retval in ["deathsource", "death_source",
|
||||
"death source", _("death source")]:
|
||||
return "deathsource"
|
||||
elif retval in ["deathcause", "death_cause",
|
||||
"death cause", _("death cause")]:
|
||||
return "deathcause"
|
||||
elif retval in ["grampsid", "id", "gramps_id",
|
||||
"gramps id", _("gramps id")]:
|
||||
return "grampsid"
|
||||
elif retval in ["person", _("person")]:
|
||||
return "person"
|
||||
# ----------------------------------
|
||||
elif retval in ["child", _("child")]:
|
||||
return "child"
|
||||
elif retval in ["source", _("source")]:
|
||||
return "source"
|
||||
elif retval in ["family", _("family")]:
|
||||
return "family"
|
||||
# ----------------------------------
|
||||
elif retval in ["mother", _("mother"),
|
||||
"wife", _("wife"),
|
||||
"parent2", _("parent2")]:
|
||||
return "wife"
|
||||
elif retval in ["father", _("father"),
|
||||
"husband", _("husband"),
|
||||
"parent1", _("parent1")]:
|
||||
return "husband"
|
||||
elif retval in ["marriage", _("marriage")]:
|
||||
return "marriage"
|
||||
elif retval in ["date", _("date")]:
|
||||
return "date"
|
||||
elif retval in ["place", _("place")]:
|
||||
return "place"
|
||||
#----------------------------------------------------
|
||||
return retval
|
||||
|
||||
|
||||
class DBI:
|
||||
def __init__(self, database, document):
|
||||
self.database = database
|
||||
self.document = document
|
||||
|
||||
def parse(self, query):
|
||||
# select col1, col2 from table where exp;
|
||||
# select * from table where exp;
|
||||
# delete from table where exp;
|
||||
self.query = query
|
||||
state = "START"
|
||||
data = None
|
||||
i = 0
|
||||
self.columns = []
|
||||
self.command = None
|
||||
self.where = None
|
||||
self.table = None
|
||||
while i < len(query):
|
||||
c = query[i]
|
||||
#print "STATE:", state, c
|
||||
if state == "START":
|
||||
if c in [' ', '\n', '\t']: # pre white space
|
||||
pass # skip it
|
||||
else:
|
||||
state = "COMMAND"
|
||||
data = c
|
||||
elif state == "COMMAND":
|
||||
if c in [' ', '\n', '\t']: # ending white space
|
||||
self.command = data.lower()
|
||||
data = ''
|
||||
state = "AFTER-COMMAND"
|
||||
else:
|
||||
data += c
|
||||
elif state == "AFTER-COMMAND":
|
||||
if c in [' ', '\n', '\t']: # pre white space
|
||||
pass
|
||||
else:
|
||||
state = "COL_OR_FROM"
|
||||
i -= 1
|
||||
elif state == "COL_OR_FROM":
|
||||
if c in [' ', '\n', '\t', ',']: # end white space or comma
|
||||
if data.upper() == "FROM":
|
||||
data = ''
|
||||
state = "PRE-GET-TABLE"
|
||||
else:
|
||||
self.columns.append(data.lower())
|
||||
data = ''
|
||||
state = "AFTER-COMMAND"
|
||||
else:
|
||||
data += c
|
||||
elif state == "PRE-GET-TABLE":
|
||||
if c in [' ', '\n', '\t']: # pre white space
|
||||
pass
|
||||
else:
|
||||
state = "GET-TABLE"
|
||||
i -= 1
|
||||
elif state == "GET-TABLE":
|
||||
if c in [' ', '\n', '\t', ';']: # end white space or colon
|
||||
self.table = data.lower()
|
||||
data = ''
|
||||
state = "PRE-GET-WHERE"
|
||||
else:
|
||||
data += c
|
||||
elif state == "PRE-GET-WHERE":
|
||||
if c in [' ', '\n', '\t']: # pre white space
|
||||
pass
|
||||
else:
|
||||
state = "GET-WHERE"
|
||||
i -= 1
|
||||
elif state == "GET-WHERE":
|
||||
if c in [' ', '\n', '\t']: # end white space
|
||||
if data.upper() != "WHERE":
|
||||
raise AttributeError("expecting WHERE got '%s'" % data)
|
||||
else:
|
||||
data = ''
|
||||
state = "GET-EXP"
|
||||
else:
|
||||
data += c
|
||||
elif state == "GET-EXP":
|
||||
self.where = query[i:]
|
||||
self.where = self.where.strip()
|
||||
if self.where.endswith(";"):
|
||||
self.where = self.where[:-1]
|
||||
i = len(query)
|
||||
else:
|
||||
raise AttributeError("unknown state: '%s'" % state)
|
||||
i += 1
|
||||
if self.table is None:
|
||||
raise AttributeError("malformed query: no table in '%s'\n" % self.query)
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
self.progress.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def eval(self):
|
||||
self.sdb = SimpleAccess(self.database)
|
||||
self.stab = SimpleTable(self.sdb)
|
||||
self.select = 0
|
||||
self.progress = Utils.ProgressMeter(_('Processing Query'))
|
||||
self.process_table()
|
||||
if self.select > 0:
|
||||
self.sdoc = SimpleDoc(self.document)
|
||||
self.sdoc.title(self.query)
|
||||
self.sdoc.paragraph("\n")
|
||||
self.sdoc.paragraph("%d rows processed.\n" % self.select)
|
||||
self.stab.write(self.sdoc)
|
||||
self.sdoc.paragraph("")
|
||||
return _("[%d rows processed]") % self.select
|
||||
|
||||
def get_columns(self, table):
|
||||
if table == "people":
|
||||
return ("name", "grampsid", "gender",
|
||||
"birth_date", "birth_place",
|
||||
"death_date", "death_place",
|
||||
"change", "marker", "private")
|
||||
elif table == "events":
|
||||
return ("grampsid", "type", "date",
|
||||
"description", "place",
|
||||
"change", "marker", "private")
|
||||
# families = grampsid, father, mother, relationship, date
|
||||
# sources =
|
||||
# places =
|
||||
# media =
|
||||
# repos =
|
||||
# notes =
|
||||
else:
|
||||
raise AttributeError("unknown table: '%s'" % table)
|
||||
|
||||
def process_table(self):
|
||||
for col_name in self.columns[:]: # copy
|
||||
if col_name == "*":
|
||||
self.columns.remove('*')
|
||||
self.columns.extend( self.get_columns(self.table))
|
||||
self.stab.columns(*map(lambda s: s.replace("_", "__"),
|
||||
self.columns))
|
||||
if self.table == "people":
|
||||
all_people = [person for person in self.sdb.all_people()]
|
||||
if len(all_people) > 100:
|
||||
self.progress.set_pass(_('Matching people...'), len(all_people)/50)
|
||||
count = 0
|
||||
for person in all_people:
|
||||
if len(all_people) > 100:
|
||||
if count % 50 == 0:
|
||||
self.progress.step()
|
||||
count += 1
|
||||
row = []
|
||||
sorts = []
|
||||
env = {_("Date"): gen.lib.date.Date} # env for py.eval
|
||||
for col_name in self.columns:
|
||||
col = cleanup_column_name(col_name)
|
||||
if col == "name":
|
||||
env[col_name] = str(person)
|
||||
row.append(person)
|
||||
elif col == "firstname":
|
||||
env[col_name] = person.get_primary_name().get_first_name()
|
||||
row.append(env[col_name])
|
||||
elif col == "surname":
|
||||
env[col_name] = person.get_primary_name().get_surname()
|
||||
row.append(env[col_name])
|
||||
elif col == "suffix":
|
||||
env[col_name] = person.get_primary_name().get_suffix()
|
||||
row.append(env[col_name])
|
||||
elif col == "title":
|
||||
env[col_name] = person.get_primary_name().get_title()
|
||||
row.append(env[col_name])
|
||||
elif col == "birthdate":
|
||||
env[col_name] = self.sdb.birth_date_obj(person)
|
||||
row.append(env[col_name])
|
||||
elif col == "deathdate":
|
||||
env[col_name] = self.sdb.death_date_obj(person)
|
||||
row.append(env[col_name])
|
||||
elif col == "gender":
|
||||
env[col_name] = self.sdb.gender(person)
|
||||
row.append(env[col_name])
|
||||
elif col == "birthplace":
|
||||
env[col_name] = self.sdb.birth_place(person)
|
||||
row.append(env[col_name])
|
||||
elif col == "deathplace":
|
||||
env[col_name] = self.sdb.death_place(person)
|
||||
row.append(env[col_name])
|
||||
elif col == "change":
|
||||
env[col_name] = person.get_change_display()
|
||||
row.append(env[col_name])
|
||||
elif col == "marker":
|
||||
env[col_name] = person.marker.string
|
||||
row.append(env[col_name])
|
||||
elif col == "private":
|
||||
env[col_name] = {True: "private", False: ""}[person.private]
|
||||
row.append(env[col_name])
|
||||
elif col == "grampsid":
|
||||
env[col_name] = person.gramps_id
|
||||
row.append(env[col_name])
|
||||
else:
|
||||
raise AttributeError("unknown column: '%s'" % col_name)
|
||||
#sorts.append((len(row)-1,sortval))
|
||||
# should we add it?:
|
||||
if self.where:
|
||||
try:
|
||||
result = eval(self.where, env)
|
||||
except:
|
||||
raise AttributeError("malformed where clause: '%s'" % self.where)
|
||||
result = False
|
||||
else:
|
||||
result = True
|
||||
if result:
|
||||
self.select += 1
|
||||
if self.command == "select":
|
||||
self.stab.row(*row)
|
||||
for (col, value) in sorts:
|
||||
self.stab.row_sort_val(col, value)
|
||||
elif self.command == "delete":
|
||||
self.database.active = person
|
||||
trans = self.database.transaction_begin()
|
||||
active_name = _("Delete Person (%s)") % self.sdb.name(person)
|
||||
gen.utils.delete_person_from_database(self.database, person, trans)
|
||||
# FIXME: delete familes, events, notes, resources, etc, if possible
|
||||
self.database.transaction_commit(trans, active_name)
|
||||
else:
|
||||
raise AttributeError("unknown command: '%s'", self.command)
|
||||
|
||||
def run(database, document, query):
|
||||
"""
|
||||
"""
|
||||
retval = ""
|
||||
dbi = DBI(database, document)
|
||||
try:
|
||||
q = dbi.parse(query)
|
||||
except AttributeError, msg:
|
||||
return msg
|
||||
try:
|
||||
retval = dbi.eval()
|
||||
except AttributeError, msg:
|
||||
# dialog?
|
||||
retval = msg
|
||||
dbi.close()
|
||||
return retval
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register the report
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'query',
|
||||
category = CATEGORY_QR_MISC,
|
||||
run_func = run,
|
||||
translated_name = _("Query"),
|
||||
status = _("Stable"),
|
||||
description= _("Display data that matches a query"),
|
||||
author_name="Douglas Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
||||
|
109
src/plugins/quickview/References.py
Normal file
109
src/plugins/quickview/References.py
Normal file
@@ -0,0 +1,109 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display references for any object
|
||||
"""
|
||||
from ReportBase import (CATEGORY_QR_SOURCE, CATEGORY_QR_PERSON,
|
||||
CATEGORY_QR_FAMILY, CATEGORY_QR_EVENT,
|
||||
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY)
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
|
||||
# mention so that will be translated for below
|
||||
[_('Person'), _('Family'), _('Event'), _('Source'),
|
||||
_('Place'), _('Repository')]
|
||||
|
||||
def get_ref(db, objclass, handle):
|
||||
"""
|
||||
Looks up object in database
|
||||
"""
|
||||
if objclass == 'Person':
|
||||
ref = db.get_person_from_handle(handle)
|
||||
elif objclass == 'Family':
|
||||
ref = db.get_family_from_handle(handle)
|
||||
elif objclass == 'Event':
|
||||
ref = db.get_event_from_handle(handle)
|
||||
elif objclass == 'Source':
|
||||
ref = db.get_source_from_handle(handle)
|
||||
elif objclass == 'Place':
|
||||
ref = db.get_place_from_handle(handle)
|
||||
elif objclass == 'Repository':
|
||||
ref = db.get_repository_from_handle(handle)
|
||||
else:
|
||||
ref = objclass
|
||||
return ref
|
||||
|
||||
def run(database, document, object, item, trans):
|
||||
"""
|
||||
Display back-references for this object.
|
||||
"""
|
||||
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
|
||||
# display the title
|
||||
sdoc.title(_("References for this %s") % trans)
|
||||
sdoc.paragraph("\n")
|
||||
stab.columns(_("Type"), _("Reference"))
|
||||
|
||||
for (objclass, handle) in database.find_backlink_handles(object.handle):
|
||||
ref = get_ref(database, objclass, handle)
|
||||
stab.row(_(objclass), ref) # translation are explicit (above)
|
||||
|
||||
if stab.get_row_count() > 0:
|
||||
stab.write(sdoc)
|
||||
else:
|
||||
sdoc.paragraph(_("No references for this %s") % trans)
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register the report
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
refitems = [(CATEGORY_QR_PERSON, 'person', _("Person")),
|
||||
(CATEGORY_QR_FAMILY,'family', _("Family")),
|
||||
(CATEGORY_QR_EVENT, 'event', _("Event")),
|
||||
(CATEGORY_QR_SOURCE, 'source', _("Source")),
|
||||
(CATEGORY_QR_PLACE, 'place', _("Place")),
|
||||
(CATEGORY_QR_REPOSITORY, 'repository', _("Repository")),
|
||||
]
|
||||
pmgr = PluginManager.get_instance()
|
||||
|
||||
for (category,item,trans) in refitems:
|
||||
pmgr.register_quick_report(
|
||||
name = item + 'refereneces',
|
||||
category = category,
|
||||
run_func = lambda db, doc, obj, item=item, trans=trans: \
|
||||
run(db, doc, obj, item, trans),
|
||||
translated_name = _("%s References") % trans,
|
||||
status = _("Stable"),
|
||||
description= _("Display references for a %s") % trans,
|
||||
author_name="Douglas Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
76
src/plugins/quickview/Reporef.py
Executable file
76
src/plugins/quickview/Reporef.py
Executable file
@@ -0,0 +1,76 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2006-2007 Alex Roitman
|
||||
# Copyright (C) 2007-2008 Jerome Rapinat
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display RepoRef for sources related to active repository
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_REPOSITORY
|
||||
import gen.lib
|
||||
|
||||
def run(database, document, repo):
|
||||
|
||||
sa = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
# First we find repository and add its text
|
||||
sdoc.title("%s\n" % repo.get_name())
|
||||
# Go over all the sources that refer to this repository
|
||||
repo_handle = repo.handle
|
||||
source_list = [item[1] for item in database.find_backlink_handles(repo_handle,['Source'])]
|
||||
|
||||
for source_handle in source_list :
|
||||
src = database.get_source_from_handle(source_handle)
|
||||
# Get the list of references from this source to our repo
|
||||
# (can be more than one, technically)
|
||||
for reporef in src.get_reporef_list():
|
||||
if reporef.ref == repo_handle:
|
||||
# Determine the text for this source
|
||||
mt = str(reporef.get_media_type())
|
||||
cn = reporef.get_call_number()
|
||||
sdoc.paragraph("%s, %s" % (mt, cn))
|
||||
sdoc.paragraph("%s\n" % src.get_title())
|
||||
else:
|
||||
continue
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'RepoRef',
|
||||
category = CATEGORY_QR_REPOSITORY,
|
||||
run_func = run,
|
||||
translated_name = _("RepoRef"),
|
||||
status = _("Beta"),
|
||||
description= _("Display RepoRef for sources related to active repository"),
|
||||
)
|
197
src/plugins/quickview/SameSurnames.py
Normal file
197
src/plugins/quickview/SameSurnames.py
Normal file
@@ -0,0 +1,197 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
# Copyright (C) 2009 Douglas S. Blank
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display a people who have a person's same surname or given name
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
import gen.lib
|
||||
from ReportBase import CATEGORY_QR_PERSON, CATEGORY_QR_MISC
|
||||
from Filters.Rules import Rule
|
||||
from Filters import GenericFilterFactory
|
||||
|
||||
class IncompleteSurname(Rule):
|
||||
"""People with incomplete surnames"""
|
||||
name = _('People with incomplete surnames')
|
||||
description = _("Matches people with lastname missing")
|
||||
category = _('General filters')
|
||||
def apply(self,db,person):
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
if name.get_group_name() == "":
|
||||
return True
|
||||
return False
|
||||
|
||||
class SameSurname(Rule):
|
||||
"""People with same surname"""
|
||||
labels = [_('Substring:')]
|
||||
name = _('People matching the <name>')
|
||||
description = _("Matches people with same lastname")
|
||||
category = _('General filters')
|
||||
def apply(self,db,person):
|
||||
src = self.list[0].upper()
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
if name.surname and name.surname.upper() == src.upper():
|
||||
return True
|
||||
return False
|
||||
|
||||
class SameGiven(Rule):
|
||||
"""People with same given name"""
|
||||
labels = [_('Substring:')]
|
||||
name = _('People matching the <given>')
|
||||
description = _("Matches people with same given name")
|
||||
category = _('General filters')
|
||||
def apply(self,db,person):
|
||||
src = self.list[0].upper()
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
if name.first_name:
|
||||
if " " in name.first_name.strip():
|
||||
for name in name.first_name.upper().strip().split():
|
||||
if name == src.upper():
|
||||
return True
|
||||
elif name.first_name.upper() == src.upper():
|
||||
return True
|
||||
return False
|
||||
|
||||
class IncompleteGiven(Rule):
|
||||
"""People with incomplete given names"""
|
||||
name = _('People with incomplete given names')
|
||||
description = _("Matches people with firstname missing")
|
||||
category = _('General filters')
|
||||
def apply(self,db,person):
|
||||
for name in [person.get_primary_name()] + person.get_alternate_names():
|
||||
if name.get_first_name() == "":
|
||||
return True
|
||||
return False
|
||||
|
||||
def run(database, document, person):
|
||||
"""
|
||||
Loops through the families that the person is a child in, and display
|
||||
the information about the other children.
|
||||
"""
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
if isinstance(person, gen.lib.Person):
|
||||
surname = sdb.surname(person)
|
||||
rsurname = person.get_primary_name().get_group_name()
|
||||
else:
|
||||
surname = person
|
||||
rsurname = person
|
||||
# display the title
|
||||
sdoc.title(_("People with the surname '%s'") % surname)
|
||||
sdoc.paragraph("")
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
filter = GenericFilterFactory('Person')()
|
||||
if rsurname != '':
|
||||
rule = SameSurname([rsurname])
|
||||
else:
|
||||
rule = IncompleteSurname([])
|
||||
filter.add_rule(rule)
|
||||
people = filter.apply(database,
|
||||
database.get_person_handles(sort_handles=False))
|
||||
matches = 0
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
sdoc.paragraph(_("There are %d people with a matching name, or alternate name.\n") % matches)
|
||||
stab.write(sdoc)
|
||||
|
||||
def run_given(database, document, person):
|
||||
"""
|
||||
Loops through the families that the person is a child in, and display
|
||||
the information about the other children.
|
||||
"""
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
if isinstance(person, gen.lib.Person):
|
||||
rgivenname = person.get_primary_name().get_first_name()
|
||||
else:
|
||||
rgivenname = person
|
||||
if " " in rgivenname.strip():
|
||||
rgivenname, second = rgivenname.strip().split(" ", 1)
|
||||
# display the title
|
||||
sdoc.title(_("People with the given name '%s'") % rgivenname)
|
||||
sdoc.paragraph("")
|
||||
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
|
||||
filter = GenericFilterFactory('Person')()
|
||||
if rgivenname != '':
|
||||
rule = SameGiven([rgivenname])
|
||||
else:
|
||||
rule = IncompleteGiven([])
|
||||
filter.add_rule(rule)
|
||||
people = filter.apply(database,
|
||||
database.get_person_handles(sort_handles=False))
|
||||
matches = 0
|
||||
for person_handle in people:
|
||||
person = database.get_person_from_handle(person_handle)
|
||||
stab.row(person, sdb.birth_date_obj(person),
|
||||
str(person.get_primary_name().get_type()))
|
||||
matches += 1
|
||||
sdoc.paragraph(_("There are %d people with a matching name, or alternate name.\n") % matches)
|
||||
stab.write(sdoc)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'samesurnames',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run,
|
||||
translated_name = _("Same Surnames"),
|
||||
status = _("Stable"),
|
||||
description= _("Display people with the same surname as a person."),
|
||||
author_name="Douglas S. Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'samegivens',
|
||||
category = CATEGORY_QR_PERSON, # to run with a person object
|
||||
run_func = run_given,
|
||||
translated_name = _("Same Given Names"),
|
||||
status = _("Stable"),
|
||||
description= _("Display people with the same given name as a person."),
|
||||
author_name="Douglas S. Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'samegivens_misc',
|
||||
category = CATEGORY_QR_MISC, # to run with a given name string
|
||||
run_func = run_given,
|
||||
translated_name = _("Same Given Names"),
|
||||
status = _("Stable"),
|
||||
description= _("Display people with the same given name as a person."),
|
||||
author_name="Douglas S. Blank",
|
||||
author_email="dblank@cs.brynmawr.edu"
|
||||
)
|
162
src/plugins/quickview/all_events.py
Normal file
162
src/plugins/quickview/all_events.py
Normal file
@@ -0,0 +1,162 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display a person's events, both personal and family
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, by_date, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY
|
||||
|
||||
def run(database, document, person):
|
||||
"""
|
||||
Loops through the person events and the family events of any family
|
||||
in which the person is a parent (to catch Marriage events), displaying
|
||||
the basic details of the event
|
||||
"""
|
||||
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
|
||||
# get the personal events
|
||||
event_list = sdb.events(person)
|
||||
|
||||
# get the events of each family in which the person is
|
||||
# a parent
|
||||
for family in sdb.parent_in(person):
|
||||
event_list += sdb.events(family)
|
||||
|
||||
# Sort the events by their date
|
||||
event_list.sort(by_date)
|
||||
|
||||
# display the results
|
||||
|
||||
sdoc.title(_("Sorted events of %s") % sdb.name(person))
|
||||
sdoc.paragraph("")
|
||||
|
||||
stab.columns(_("Event Type"), _("Event Date"), _("Event Place"))
|
||||
|
||||
for event in event_list:
|
||||
stab.row(event,
|
||||
sdb.event_date_obj(event),
|
||||
sdb.event_place(event))
|
||||
stab.write(sdoc)
|
||||
|
||||
def run_fam(database, document, family):
|
||||
"""
|
||||
Loops through the family events and the events of all parents, displaying
|
||||
the basic details of the event
|
||||
"""
|
||||
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
|
||||
# get the family events
|
||||
event_list = [(_('Family'), x) for x in sdb.events(family)]
|
||||
|
||||
# get the events of father and mother
|
||||
#fathername = sdb.first_name(sdb.father(family))
|
||||
event_list += [(sdb.father(family), x) for x in sdb.events(sdb.father(family))]
|
||||
#mothername = sdb.first_name(sdb.mother(family))
|
||||
event_list += [(sdb.mother(family), x) for x in sdb.events(sdb.mother(family))]
|
||||
|
||||
# children events
|
||||
event_list_children = []
|
||||
for child in sdb.children(family) :
|
||||
#name = sdb.first_name(child)
|
||||
event_list_children += [(child, x) for x in sdb.events(child)]
|
||||
|
||||
# Sort the events by their date
|
||||
event_list.sort(fam_sort)
|
||||
event_list_children.sort(fam_sort)
|
||||
|
||||
# display the results
|
||||
|
||||
sdoc.title(_("Sorted events of family\n %s - %s") %
|
||||
(sdb.name(sdb.father(family)),
|
||||
sdb.name(sdb.mother(family))))
|
||||
sdoc.paragraph("")
|
||||
|
||||
stab.columns(_("Family Member"), _("Event Type"),
|
||||
_("Event Date"), _("Event Place"))
|
||||
|
||||
for (person, event) in event_list:
|
||||
stab.row(person, sdb.event_type(event),
|
||||
sdb.event_date_obj(event),
|
||||
sdb.event_place(event))
|
||||
stab.write(sdoc)
|
||||
|
||||
stab = SimpleTable(sdb)
|
||||
sdoc.header1(_("Personal events of the children"))
|
||||
stab.columns(_("Family Member"), _("Event Type"),
|
||||
_("Event Date"), _("Event Place"))
|
||||
for (person, event) in event_list_children:
|
||||
stab.row(person, sdb.event_type(event),
|
||||
sdb.event_date_obj(event),
|
||||
sdb.event_place(event))
|
||||
stab.write(sdoc)
|
||||
|
||||
def fam_sort(event1, event2):
|
||||
"""
|
||||
Sort function that will compare two events by their dates.
|
||||
|
||||
@param event1: first event
|
||||
@type event1: L{Event}
|
||||
@param event2: second event
|
||||
@type event2: L{Event}
|
||||
@return: Returns -1 if event1 < event2, 0 if they are equal, and
|
||||
1 if they are the same.
|
||||
@rtype: int
|
||||
"""
|
||||
return by_date(event1[1],event2[1])
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'all_events',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run,
|
||||
translated_name = _("All Events"),
|
||||
status = _("Stable"),
|
||||
description= _("Display a person's events, both personal and family."),
|
||||
author_name="Donald N. Allingham",
|
||||
author_email="don@gramps-project.org"
|
||||
)
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'all_events_fam',
|
||||
category = CATEGORY_QR_FAMILY,
|
||||
run_func = run_fam,
|
||||
translated_name = _("All Events"),
|
||||
status = _("Stable"),
|
||||
description= _("Display the family and family members events."),
|
||||
author_name="B. Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
359
src/plugins/quickview/all_relations.py
Normal file
359
src/plugins/quickview/all_relations.py
Normal file
@@ -0,0 +1,359 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2007 B. Malengier
|
||||
# Copyright (C) 2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display a person's relations to the home person
|
||||
"""
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_PERSON
|
||||
|
||||
# define the formatting string once as a constant. Since this is reused
|
||||
|
||||
_FMT = "%-3d %s"
|
||||
_FMT_VOID = " %s"
|
||||
_FMT_DET1 = "%-3s %-15s"
|
||||
_FMT_DET2 = "%-30s %-15s\t%-10s %-2s"
|
||||
|
||||
|
||||
def run(database, document, person):
|
||||
"""
|
||||
Create the report class, and produce the quick report
|
||||
"""
|
||||
report = AllRelReport(database, document, person)
|
||||
report.run()
|
||||
|
||||
class AllRelReport():
|
||||
"""
|
||||
Obtains all relationships, displays the relations, and in details, the
|
||||
relation path
|
||||
"""
|
||||
def __init__(self, database, document, person):
|
||||
self.database = database
|
||||
self.person = person
|
||||
self.sdb = SimpleAccess(database)
|
||||
self.sdoc = SimpleDoc(document)
|
||||
|
||||
pmgr = PluginManager.get_instance()
|
||||
self.rel_class = pmgr.get_relationship_calculator()
|
||||
|
||||
self.msg_list = []
|
||||
|
||||
def run(self):
|
||||
#get home_person
|
||||
self.home_person = self.database.get_default_person()
|
||||
if not self.home_person :
|
||||
self.sdoc.paragraph(_("Home person not set."))
|
||||
return
|
||||
|
||||
self.print_title()
|
||||
|
||||
p2 = self.sdb.name(self.home_person)
|
||||
p1 = self.sdb.name(self.person)
|
||||
if self.person.handle == self.home_person.handle :
|
||||
self.sdoc.paragraph(_FMT_VOID % (
|
||||
_("%s and %s are the same person.") % ( p1, p2))
|
||||
)
|
||||
return
|
||||
|
||||
#check if not a family too:
|
||||
is_spouse = self.rel_class.is_spouse(self.database, self.home_person,
|
||||
self.person)
|
||||
if is_spouse:
|
||||
rel_string = is_spouse
|
||||
rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
|
||||
) % {'person' : p1, 'relationship' : rel_string,
|
||||
'active_person' : p2 }
|
||||
self.sdoc.paragraph(_FMT_VOID % (rstr))
|
||||
self.sdoc.paragraph("")
|
||||
|
||||
#obtain all relationships, assume home person has largest tree
|
||||
common, self.msg_list = self.rel_class.get_relationship_distance_new(
|
||||
self.database, self.person, self.home_person,
|
||||
all_families=True,
|
||||
all_dist=True,
|
||||
only_birth=False)
|
||||
#all relations
|
||||
if (not common or common[0][0]== -1 ) and not is_spouse:
|
||||
rstr = _("%(person)s and %(active_person)s are not "
|
||||
"directly related.") % {'person' : p2,
|
||||
'active_person' : p1 }
|
||||
self.sdoc.paragraph(_FMT_VOID % (rstr))
|
||||
self.sdoc.paragraph("")
|
||||
|
||||
#collapse common so parents of same fam in common are one line
|
||||
commonnew = self.rel_class.collapse_relations(common)
|
||||
self.print_details_header(commonnew, self.home_person, self.person,
|
||||
skip_list_text=None)
|
||||
self.print_details_path(commonnew, self.home_person, self.person)
|
||||
self.print_details_path(commonnew, self.home_person, self.person,
|
||||
first=False)
|
||||
|
||||
if not common or common[0][0]== -1 :
|
||||
self.remarks(self.msg_list)
|
||||
self.msg_list = []
|
||||
#check inlaw relation next
|
||||
else:
|
||||
#stop
|
||||
return
|
||||
|
||||
#we check the inlaw relationships if not partners.
|
||||
if is_spouse:
|
||||
return
|
||||
handles_done = [(self.person.handle, self.home_person.handle)]
|
||||
inlaws_pers = [self.person] + self.get_inlaws(self.person)
|
||||
inlaws_home = [self.home_person] + self.get_inlaws(self.home_person)
|
||||
#remove overlap:
|
||||
inlaws_home = [x for x in inlaws_home if x not in inlaws_pers]
|
||||
inlawwritten = False
|
||||
skiplist = []
|
||||
commonnew = []
|
||||
for inlawpers in inlaws_pers:
|
||||
for inlawhome in inlaws_home:
|
||||
if (inlawpers, inlawhome) in handles_done :
|
||||
continue
|
||||
else:
|
||||
handles_done.append((inlawpers, inlawhome))
|
||||
common, msg = \
|
||||
self.rel_class.get_relationship_distance_new(
|
||||
self.database, inlawpers, inlawhome,
|
||||
all_families=True,
|
||||
all_dist=True,
|
||||
only_birth=False)
|
||||
if msg:
|
||||
self.msg_list += msg
|
||||
if common and not common[0][0] == -1:
|
||||
if not inlawwritten:
|
||||
rstr = _("%(person)s and %(active_person)s have "
|
||||
"following in-law relations:"
|
||||
) % {'person' : p2,
|
||||
'active_person' : p1 }
|
||||
self.sdoc.paragraph(_FMT_VOID % (rstr))
|
||||
self.sdoc.paragraph("")
|
||||
inlawwritten = True
|
||||
else:
|
||||
continue
|
||||
inlawb = not inlawpers.handle == self.person.handle
|
||||
inlawa = not inlawhome.handle == self.home_person.handle
|
||||
commonnew.append((inlawa, inlawb, inlawhome, inlawpers,
|
||||
self.rel_class.collapse_relations(common)))
|
||||
skip=[]
|
||||
skip_text = []
|
||||
count = 1
|
||||
for inlawa, inlawb, inlawhome, inlawpers, commonrel in commonnew:
|
||||
count = self.print_details_header(commonrel,
|
||||
inlawhome, inlawpers,
|
||||
inlawa = inlawa, inlawb = inlawb,
|
||||
count=count,
|
||||
skip_list=skip, skip_list_text = skip_text)
|
||||
count = 1
|
||||
for inlawa, inlawb, inlawhome, inlawpers, commonrel in commonnew:
|
||||
self.print_details_path(commonrel, inlawhome, inlawpers,
|
||||
inlawa = inlawa, inlawb = inlawb,
|
||||
count = count, skip_list = skip)
|
||||
count = self.print_details_path(commonrel, inlawhome, inlawpers,
|
||||
inlawa = inlawa, inlawb = inlawb,
|
||||
count = count, skip_list = skip,
|
||||
first = False)
|
||||
self.remarks(self.msg_list, True)
|
||||
|
||||
def get_inlaws(self, person):
|
||||
inlaws = []
|
||||
family_handles = person.get_family_handle_list()
|
||||
for handle in family_handles:
|
||||
fam = self.database.get_family_from_handle(handle)
|
||||
if fam.father_handle and \
|
||||
not fam.father_handle == person.handle:
|
||||
inlaws.append(self.database.get_person_from_handle(
|
||||
fam.father_handle))
|
||||
elif fam.mother_handle and \
|
||||
not fam.mother_handle == person.handle:
|
||||
inlaws.append(self.database.get_person_from_handle(
|
||||
fam.mother_handle))
|
||||
return inlaws
|
||||
|
||||
|
||||
def print_title(self):
|
||||
""" print the title
|
||||
"""
|
||||
p2 = self.sdb.name(self.home_person)
|
||||
p1 = self.sdb.name(self.person)
|
||||
self.sdoc.title(_("Relationships of %s to %s") % (p1 ,p2))
|
||||
self.sdoc.paragraph("")
|
||||
|
||||
def print_details_header(self, relations, pers1, pers2,
|
||||
inlawa=False, inlawb=False, count=1,
|
||||
skip_list=[], skip_list_text = []):
|
||||
if not relations or relations[0][0] == -1:
|
||||
return count
|
||||
|
||||
sdoc = self.sdoc
|
||||
rel_class = self.rel_class
|
||||
for relation in relations:
|
||||
birth = self.rel_class.only_birth(relation[2])\
|
||||
and self.rel_class.only_birth(relation[4])
|
||||
distorig = len(relation[4])
|
||||
distother = len(relation[2])
|
||||
if distorig == distother == 1 and not inlawa \
|
||||
and not inlawb:
|
||||
rel_str = self.rel_class.get_sibling_relationship_string(
|
||||
self.rel_class.get_sibling_type(
|
||||
self.database, pers1, pers2),
|
||||
self.home_person.get_gender(),
|
||||
self.person.get_gender())
|
||||
else:
|
||||
rel_str = self.rel_class.get_single_relationship_string(
|
||||
distorig, distother,
|
||||
self.home_person.get_gender(),
|
||||
self.person.get_gender(),
|
||||
relation[4], relation[2],
|
||||
only_birth = birth,
|
||||
in_law_a = inlawa, in_law_b = inlawb)
|
||||
if not skip_list_text is None:
|
||||
if rel_str in skip_list_text:
|
||||
skip_list.append(count)
|
||||
else:
|
||||
skip_list_text.append(rel_str)
|
||||
sdoc.paragraph(_FMT % (count-len(skip_list), rel_str))
|
||||
else:
|
||||
sdoc.paragraph(_FMT % (count, rel_str))
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def print_details_path(self, relations, pers1, pers2,
|
||||
inlawa=False, inlawb=False,
|
||||
count = 1, skip_list = [], first=True):
|
||||
if not relations or relations[0][0] == -1:
|
||||
return count
|
||||
|
||||
sdoc = self.sdoc
|
||||
rel_class = self.rel_class
|
||||
p2 = self.sdb.name(self.home_person)
|
||||
p1 = self.sdb.name(self.person)
|
||||
pers = p2
|
||||
inlaw = inlawa
|
||||
if first:
|
||||
pers = p1
|
||||
inlaw = inlawb
|
||||
|
||||
if count == 1:
|
||||
sdoc.paragraph("")
|
||||
sdoc.header1(_("Detailed path from %(person)s to common ancestor"
|
||||
) % {'person':pers})
|
||||
sdoc.paragraph("")
|
||||
sdoc.header2(_FMT_DET1 % (_(' '), _('Name Common ancestor')))
|
||||
sdoc.header2(_FMT_DET2 % (' ', _('Parent'), _('Birth'), _('Family')))
|
||||
sdoc.paragraph("")
|
||||
for relation in relations:
|
||||
if count in skip_list:
|
||||
count += 1
|
||||
continue
|
||||
counter = str(count - len([x for x in range(count) if x+1 in skip_list]))
|
||||
name = _('Unknown')
|
||||
if relation[1]:
|
||||
name = self.sdb.name(self.database.get_person_from_handle(
|
||||
relation[1][0]))
|
||||
for handle in relation[1][1:]:
|
||||
name += ' ' + _('and') + ' ' + self.sdb.name(
|
||||
self.database.get_person_from_handle(handle))
|
||||
sdoc.paragraph(_FMT_DET1 % (counter, name))
|
||||
if inlaw:
|
||||
sdoc.paragraph(_FMT_DET2 % (' ', _('Partner'), ' ', ' '))
|
||||
if first:
|
||||
ind1 = 2
|
||||
ind2 = 3
|
||||
else:
|
||||
ind1 = 4
|
||||
ind2 = 5
|
||||
for rel,fam in zip(relation[ind1],relation[ind2]) :
|
||||
par_str = _('Unknown') #when sibling, parent is unknown
|
||||
if rel == rel_class.REL_MOTHER \
|
||||
or rel == rel_class.REL_MOTHER_NOTBIRTH:
|
||||
par_str = _('Mother')
|
||||
if rel == rel_class.REL_FATHER \
|
||||
or rel == rel_class.REL_FATHER_NOTBIRTH:
|
||||
par_str = _('Father')
|
||||
if (rel == rel_class.REL_FAM_BIRTH
|
||||
or rel == rel_class.REL_FAM_NONBIRTH
|
||||
or rel == rel_class.REL_FAM_BIRTH_MOTH_ONLY
|
||||
or rel == rel_class.REL_FAM_BIRTH_FATH_ONLY):
|
||||
par_str = _('Parents')
|
||||
birth_str = _('Yes')
|
||||
if (rel == rel_class.REL_MOTHER_NOTBIRTH
|
||||
or rel == rel_class.REL_FATHER_NOTBIRTH
|
||||
or rel == rel_class.REL_FAM_NONBIRTH):
|
||||
birth_str = _('No')
|
||||
elif (rel == rel_class.REL_FAM_BIRTH_FATH_ONLY
|
||||
or rel == rel_class.REL_FAM_BIRTH_MOTH_ONLY):
|
||||
birth_str = _('Partial')
|
||||
famstr = ''
|
||||
if isinstance(fam, list):
|
||||
famstr = str(fam[0]+1)
|
||||
for val in fam[1:] :
|
||||
famstr = famstr + ', ' + str(val+1)
|
||||
else:
|
||||
famstr = str(fam+1)
|
||||
sdoc.paragraph(_FMT_DET2 % (' ', par_str, birth_str, famstr))
|
||||
counter=''
|
||||
name = ''
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def remarks(self, msg_list, inlaw=False):
|
||||
if msg_list :
|
||||
sdoc = self.sdoc
|
||||
sdoc.paragraph("")
|
||||
if inlaw:
|
||||
sdoc.header1(_("Remarks with inlaw family"))
|
||||
else:
|
||||
sdoc.header1(_("Remarks"))
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph(_("The following problems were encountered:"))
|
||||
|
||||
for msg in msg_list :
|
||||
sdoc.paragraph(msg)
|
||||
sdoc.paragraph("")
|
||||
sdoc.paragraph("")
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'all_relations',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run,
|
||||
translated_name = _("Relation to Home Person"),
|
||||
status = _("Stable"),
|
||||
description= _("Display all relationships between person and home person."),
|
||||
author_name="B. Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
258
src/plugins/quickview/lineage.py
Normal file
258
src/plugins/quickview/lineage.py
Normal file
@@ -0,0 +1,258 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007 Jerome Rapinat, B. Malengier
|
||||
# Copyright (C) 2008 Brian G. Matherly
|
||||
#
|
||||
# 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$
|
||||
|
||||
"""
|
||||
Display a person's father or mother lineage
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
import gen.lib
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_PERSON
|
||||
|
||||
__FMT = "%-30s\t%-12s\t%-12s"
|
||||
__FMT_REM = " %s: %s"
|
||||
__MAX_GEN = 100
|
||||
|
||||
def run_father(database, document, person):
|
||||
""" Function writing the father lineage quick report
|
||||
"""
|
||||
sa = SimpleAccess(database)
|
||||
sd = SimpleDoc(document)
|
||||
|
||||
# display the results
|
||||
|
||||
sd.title(_("Father lineage for %s") % sa.name(person))
|
||||
sd.paragraph("")
|
||||
sd.paragraph(_(""
|
||||
"This report shows the father lineage, also called patronymic lineage"
|
||||
" or Y-line."
|
||||
" People in this lineage all share the same Y-chromosone."
|
||||
))
|
||||
sd.paragraph("")
|
||||
stab = SimpleTable(sa)
|
||||
stab.columns(_("Name Father"), _("Birth Date"), _("Death Date"), _("Remark"))
|
||||
make_details(gen.lib.Person.MALE, person, sa, sd, database, stab)
|
||||
stab.write(sd)
|
||||
sd.paragraph("")
|
||||
|
||||
if person.gender == gen.lib.Person.FEMALE :
|
||||
return
|
||||
|
||||
sd.header2((_("Direct line male descendants")))
|
||||
sd.paragraph("")
|
||||
|
||||
make_details_child(gen.lib.Person.MALE, person, sa, sd, database)
|
||||
|
||||
def run_mother(database, document, person):
|
||||
""" Function writing the mother lineage quick report
|
||||
"""
|
||||
sa = SimpleAccess(database)
|
||||
sd = SimpleDoc(document)
|
||||
|
||||
# display the results
|
||||
|
||||
sd.title(_("Mother lineage for %s") % sa.name(person))
|
||||
sd.paragraph("")
|
||||
sd.paragraph(_(""
|
||||
"This report shows the mother lineage, also called matronymic lineage "
|
||||
"or M-line."
|
||||
" People in this lineage all share the same RNA."
|
||||
))
|
||||
sd.paragraph("")
|
||||
|
||||
stab = SimpleTable(sa)
|
||||
stab.columns(_("Name Mother"), _("Birth"), _("Death Date"), _("Remark"))
|
||||
make_details(gen.lib.Person.FEMALE, person, sa, sd, database, stab)
|
||||
stab.write(sd)
|
||||
sd.paragraph("")
|
||||
|
||||
if person.gender == gen.lib.Person.MALE :
|
||||
return
|
||||
|
||||
sd.header2((_("Direct line female descendants")))
|
||||
sd.paragraph("")
|
||||
|
||||
make_details_child(gen.lib.Person.FEMALE, person, sa, sd, database)
|
||||
|
||||
def make_details(gender, person, sa, sd, database, stab) :
|
||||
""" Function writing one line of ancestry on the document in
|
||||
direct lineage
|
||||
"""
|
||||
# avoid infinite loop:
|
||||
personsprinted = 0
|
||||
|
||||
# loop as long as there are fathers/mothers
|
||||
rem_str = ""
|
||||
while person:
|
||||
person_handle = person.handle
|
||||
stab.row(person, sa.birth_date_obj(person),
|
||||
sa.death_date_obj(person), rem_str)
|
||||
#if rem_str:
|
||||
# sd.paragraph(__FMT_REM % (_("Remark"), rem_str))
|
||||
|
||||
personsprinted += 1
|
||||
if personsprinted > __MAX_GEN :
|
||||
sd.paragraph("")
|
||||
sd.paragraph(_("ERROR : Too many levels in the tree "
|
||||
"(perhaps a loop?)."))
|
||||
return
|
||||
|
||||
# obtain the first father/mother we find in the list
|
||||
parent_handle_list = person.get_parent_family_handle_list()
|
||||
person = None
|
||||
for parent in parent_handle_list:
|
||||
rem_str = ""
|
||||
family_id = parent_handle_list[0]
|
||||
family = database.get_family_from_handle(family_id)
|
||||
childrel = [(ref.get_mother_relation(),
|
||||
ref.get_father_relation()) for ref in
|
||||
family.get_child_ref_list()
|
||||
if ref.ref == person_handle]
|
||||
if gender == gen.lib.Person.MALE :
|
||||
person = database.get_person_from_handle(
|
||||
family.get_father_handle())
|
||||
refnr = 1
|
||||
else :
|
||||
person = database.get_person_from_handle(
|
||||
family.get_mother_handle())
|
||||
refnr = 0
|
||||
|
||||
#We do not allow for same sex marriages when going up
|
||||
# that would complicate the code
|
||||
#Also, we assume the birth relation is in the FIRST
|
||||
# family of the person, so we go up on non-birth
|
||||
if not childrel[0][refnr] == gen.lib.ChildRefType.BIRTH :
|
||||
rem_str = add_rem(rem_str, _("No birth relation with child"))
|
||||
if person and person.gender == gender :
|
||||
break
|
||||
elif person and person.gender == gen.lib.Person.UNKNOWN :
|
||||
rem_str = add_rem(rem_str, _("Unknown gender"))
|
||||
break
|
||||
else :
|
||||
person = None
|
||||
|
||||
def make_details_child(gender, person, sa, sd, database) :
|
||||
""" Function that prints the details of the children in the
|
||||
male/female lineage
|
||||
"""
|
||||
def make_child_line(child, prepend, generation) :
|
||||
""" Recursively called funcion to write one child line
|
||||
Person is the child, prepend is the string that preceeds it
|
||||
on print. As the recursion grows, prepend is increased
|
||||
Gen is the generation level
|
||||
"""
|
||||
if generation > __MAX_GEN :
|
||||
raise RuntimeError
|
||||
#we use some global var from make_details_child !
|
||||
rem_str = ""
|
||||
if child.gender == gen.lib.Person.UNKNOWN :
|
||||
rem_str = add_rem(rem_str, _("Unknown gender"))
|
||||
|
||||
if rem_str :
|
||||
rem_str = _("Remark")+": "+rem_str
|
||||
front = ""
|
||||
if prepend :
|
||||
front = prepend + "-"
|
||||
sd.paragraph(front + "%s (%s - %s) %s" % (sa.name(child),
|
||||
sa.birth_date(child),
|
||||
sa.death_date(child), rem_str))
|
||||
#obtain families in which child is a parent
|
||||
family_handles = child.get_family_handle_list()
|
||||
for fam_handle in family_handles :
|
||||
fam = database.get_family_from_handle(fam_handle)
|
||||
#what parent is the previous child? We are fancy and allow
|
||||
# for same sex marriage
|
||||
if fam.get_father_handle() == child.handle :
|
||||
childrelnr = 2
|
||||
elif fam.get_mother_handle() == child.handle :
|
||||
childrelnr = 1
|
||||
else :
|
||||
#something wrong with this family, continue with next
|
||||
continue
|
||||
childrel = [(ref.ref, ref.get_mother_relation(),
|
||||
ref.get_father_relation()) for ref in
|
||||
fam.get_child_ref_list()]
|
||||
for childdet in childrel:
|
||||
#relation with parent must be by birth
|
||||
if not childdet[childrelnr] == gen.lib.ChildRefType.BIRTH :
|
||||
continue
|
||||
|
||||
newchild = database.get_person_from_handle(childdet[0])
|
||||
# person must have the required gender
|
||||
if newchild and newchild.gender == gender :
|
||||
make_child_line(newchild, prepend + ' |', generation+1)
|
||||
|
||||
# loop over all children of gender and output, start with no prepend
|
||||
try :
|
||||
make_child_line(person, "", 0)
|
||||
except RuntimeError:
|
||||
sd.paragraph("")
|
||||
sd.paragraph(_("ERROR : Too many levels in the tree "
|
||||
"(perhaps a loop?)."))
|
||||
|
||||
def add_rem(remark, text):
|
||||
""" Allow for extension of remark, return new remark string
|
||||
"""
|
||||
if remark:
|
||||
return remark + ', ' + text
|
||||
else:
|
||||
return text
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'father_lineage',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run_father,
|
||||
translated_name = _("Father lineage"),
|
||||
status = _("Stable"),
|
||||
description= _("Display father lineage"),
|
||||
author_name="B. Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
||||
|
||||
pmgr.register_quick_report(
|
||||
name = 'mother_lineage',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run_mother,
|
||||
translated_name = _("Mother lineage"),
|
||||
status = _("Stable"),
|
||||
description= _("Display mother lineage"),
|
||||
author_name="B. Malengier",
|
||||
author_email="benny.malengier@gramps-project.org"
|
||||
)
|
||||
|
82
src/plugins/quickview/siblings.py
Normal file
82
src/plugins/quickview/siblings.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
"""
|
||||
Display a person's siblings in a report window
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gettext import gettext as _
|
||||
from gen.plug import PluginManager
|
||||
from ReportBase import CATEGORY_QR_PERSON
|
||||
|
||||
def run(database, document, person):
|
||||
"""
|
||||
Loops through the families that the person is a child in, and display
|
||||
the information about the other children.
|
||||
"""
|
||||
# setup the simple access functions
|
||||
sdb = SimpleAccess(database)
|
||||
sdoc = SimpleDoc(document)
|
||||
stab = SimpleTable(sdb)
|
||||
pmgr = PluginManager.get_instance()
|
||||
rel_class = pmgr.get_relationship_calculator()
|
||||
|
||||
# display the title
|
||||
sdoc.title(_("Siblings of %s") % sdb.name(person))
|
||||
sdoc.paragraph("")
|
||||
stab.columns(_("Sibling"), _("Gender"), _("Birth Date"), _("Type"))
|
||||
# grab our current id (self):
|
||||
gid = sdb.gid(person)
|
||||
# loop through each family in which the person is a child
|
||||
for family in sdb.child_in(person):
|
||||
# loop through each child in the family
|
||||
for child in sdb.children(family):
|
||||
# only display if this child is not the active person
|
||||
if sdb.gid(child) != gid:
|
||||
rel_str = rel_class.get_sibling_relationship_string(
|
||||
rel_class.get_sibling_type(database, person, child),
|
||||
person.get_gender(), child.get_gender())
|
||||
else:
|
||||
rel_str = _('self')
|
||||
# pass row the child object to make link:
|
||||
stab.row(child,
|
||||
sdb.gender(child),
|
||||
sdb.birth_date_obj(child),
|
||||
rel_str)
|
||||
stab.write(sdoc)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pmgr = PluginManager.get_instance()
|
||||
pmgr.register_quick_report(
|
||||
name = 'siblings',
|
||||
category = CATEGORY_QR_PERSON,
|
||||
run_func = run,
|
||||
translated_name = _("Siblings"),
|
||||
status = _("Stable"),
|
||||
description= _("Display a person's siblings."),
|
||||
author_name="Donald N. Allingham",
|
||||
author_email="don@gramps-project.org"
|
||||
)
|
Reference in New Issue
Block a user