* src/Simple/_SimpleTable.py:

added callback for click/doubleclick manual override for rows
	added numeric sorting
	* src/QuickReports.py: added run_quick_report_by_name_direct
	that allows one quick report to run another
	* src/plugins/DefaultGramplets.py: made stats gramplet show 
	details when drilling down with double-click
	* src/plugins/SameSurnames.py: allow running by string rather than 
	person object
	* src/DataViews/GrampletView.py: added Filter type of link; fixed
	bug in drag and drop from earlier option infrastructure
	* src/plugins/FilterByName.py: quick report that runs a filter by
	name

2008-03-04  Douglas S. Blank  <dblank@cs.brynmawr.edu>


svn: r10188
This commit is contained in:
Doug Blank
2008-03-05 04:01:27 +00:00
parent bfa0ec0853
commit 2ef34cf90a
7 changed files with 355 additions and 40 deletions

View File

@@ -595,9 +595,12 @@ class StatsGramplet(Gramplet):
total_photos = total_photos + length
person = database.get_person_from_handle(person_handle)
name = person.get_primary_name()
if name.get_first_name() == "" or name.get_surname() == "":
incomp_names = incomp_names + 1
names = [person.get_primary_name()] + person.get_alternate_names()
for name in names:
if name.get_first_name() == "" or name.get_surname() == "":
incomp_names = incomp_names + 1
if name.get_surname() not in namelist:
namelist.append(name.get_surname())
if ((not person.get_main_parents_family_handle()) and
(not len(person.get_family_handle_list()))):
disconnected = disconnected + 1
@@ -614,39 +617,70 @@ class StatsGramplet(Gramplet):
males = males + 1
else:
unknowns += 1
if name.get_surname() not in namelist:
namelist.append(name.get_surname())
if cnt % 200 == 0:
yield True
cnt += 1
text = _("Individuals") + "\n"
text = text + "----------------------------\n"
text = text + "%s: %d\n" % (_("Number of individuals"),len(personList))
text = text + "%s: %d\n" % (_("Males"),males)
text = text + "%s: %d\n" % (_("Females"),females)
text = text + "%s: %d\n" % (_("Individuals with unknown gender"),unknowns)
text = text + "%s: %d\n" % (_("Individuals with incomplete names"),incomp_names)
text = text + "%s: %d\n" % (_("Individuals missing birth dates"),missing_bday)
text = text + "%s: %d\n" % (_("Disconnected individuals"),disconnected)
text = text + "\n%s\n" % _("Family Information")
text = text + "----------------------------\n"
text = text + "%s: %d\n" % (_("Number of families"),len(familyList))
text = text + "%s: %d\n" % (_("Unique surnames"),len(namelist))
text = text + "\n%s\n" % _("Media Objects")
text = text + "----------------------------\n"
text = text + "%s: %d\n" % (_("Individuals with media objects"),with_photos)
text = text + "%s: %d\n" % (_("Total number of media object references"),total_photos)
text = text + "%s: %d\n" % (_("Number of unique media objects"),pobjects)
text = text + "%s: %d %s\n" % (_("Total size of media objects"),bytes,\
_("bytes"))
if len(notfound) > 0:
text = text + "\n%s\n" % _("Missing Media Objects")
text = text + "----------------------------\n"
for p in notfound:
text = text + "%s\n" % p
self.set_text(text)
self.clear_text()
self.append_text(_("Individuals") + "\n")
self.append_text("----------------------------\n")
self.link(_("Number of individuals") + ":",
'Filter', 'all people')
self.append_text(" %s" % len(personList))
self.append_text("\n")
self.link("%s:" % _("Males"), 'Filter', 'males')
self.append_text(" %s" % males)
self.append_text("\n")
self.link("%s:" % _("Females"), 'Filter', 'females')
self.append_text(" %s" % females)
self.append_text("\n")
self.link("%s:" % _("Individuals with unknown gender"),
'Filter', 'people with unknown gender')
self.append_text(" %s" % unknowns)
self.append_text("\n")
self.link("%s:" % _("Individuals with incomplete names"),
'Filter', 'people with incomplete names')
self.append_text(" %s" % incomp_names)
self.append_text("\n")
self.link("%s:" % _("Individuals missing birth dates"),
'Filter', 'people with missing birth dates')
self.append_text(" %s" % missing_bday)
self.append_text("\n")
self.link("%s:" % _("Disconnected individuals"),
'Filter', 'disconnected people')
self.append_text(" %s" % disconnected)
self.append_text("\n")
self.append_text("\n%s\n" % _("Family Information"))
self.append_text("----------------------------\n")
self.link("%s:" % _("Number of families"),
'Filter', 'all families')
self.append_text(" %s" % len(familyList))
self.append_text("\n")
self.link("%s:" % _("Unique surnames"),
'Filter', 'unique surnames')
self.append_text(" %s" % len(namelist))
self.append_text("\n")
self.append_text("\n%s\n" % _("Media Objects"))
self.append_text("----------------------------\n")
self.link("%s:" % _("Individuals with media objects"),
'Filter', 'people with media')
self.append_text(" %s" % with_photos)
self.append_text("\n")
self.link("%s:" % _("Total number of media object references"),
'Filter', 'media references')
self.append_text(" %s" % total_photos)
self.append_text("\n")
self.link("%s:" % _("Number of unique media objects"),
'Filter', 'unique media')
self.append_text(" %s" % pobjects)
self.append_text("\n")
self.append_text("%s: %d %s\n" % (_("Total size of media objects"),
bytes,
_("bytes")))
self.link("%s:" % _("Missing Media Objects"),
'Filter', 'missing media')
self.append_text(" %s\n" % total_photos)
self.append_text("", scroll_to="begin")
class PythonGramplet(Gramplet):
def init(self):

210
src/plugins/FilterByName.py Normal file
View File

@@ -0,0 +1,210 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007 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 gettext import gettext as _
from PluginUtils import register_quick_report
from Utils import media_path_full
from QuickReports import run_quick_report_by_name_direct
from gen.lib import Person
import DateHandler
def run(database, document, filter_name):
"""
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, sdoc)
# display the title
sdoc.title(_("Filtering on %s") % filter_name)
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_surname() == "" 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:
name = person.get_primary_name()
if name:
surname = name.get_surname()
if surname:
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:
bytes = bytes + posixpath.getsize(fullname)
except:
stab.row(fullname)
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()
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
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"
)

View File

@@ -63,15 +63,19 @@ def run(database, document, person):
sdb = SimpleAccess(database)
sdoc = SimpleDoc(document)
stab = SimpleTable(sdb, sdoc)
if type(person) == str:
surname = person
rsurname = person
else:
surname = sdb.surname(person)
rsurname = person.get_primary_name().get_surname()
# display the title
sdoc.title(_("People with the surname '%s'") % sdb.surname(person))
sdoc.title(_("People with the surname '%s'") % surname)
sdoc.paragraph("")
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
# grab our current id (self):
gid = sdb.gid(person)
filter = GenericFilterFactory('Person')()
if person.get_primary_name().get_surname() != '':
rule = SameSurname([person.get_primary_name().get_surname()])
if rsurname != '':
rule = SameSurname([rsurname])
else:
rule = IncompleteSurname([])
filter.add_rule(rule)