Rename CountAncestors to NumberOfAncestorsReport and convert it from a "view" to a "text" report.
svn: r10422
This commit is contained in:
parent
f64f6dd105
commit
e08a8cf205
@ -258,7 +258,6 @@ src/plugins/ChangeNames.py
|
|||||||
src/plugins/ChangeTypes.py
|
src/plugins/ChangeTypes.py
|
||||||
src/plugins/Check.py
|
src/plugins/Check.py
|
||||||
src/plugins/CmdRef.py
|
src/plugins/CmdRef.py
|
||||||
src/plugins/CountAncestors.py
|
|
||||||
src/plugins/CustomBookText.py
|
src/plugins/CustomBookText.py
|
||||||
src/plugins/DateParserDisplayTest.py
|
src/plugins/DateParserDisplayTest.py
|
||||||
src/plugins/DefaultGramplets.py
|
src/plugins/DefaultGramplets.py
|
||||||
@ -293,6 +292,7 @@ src/plugins/MarkerReport.py
|
|||||||
src/plugins/MediaManager.py
|
src/plugins/MediaManager.py
|
||||||
src/plugins/NarrativeWeb.py
|
src/plugins/NarrativeWeb.py
|
||||||
src/plugins/NotRelated.py
|
src/plugins/NotRelated.py
|
||||||
|
src/plugins/NumberOfAncestorsReport.py
|
||||||
src/plugins/OnThisDay.py
|
src/plugins/OnThisDay.py
|
||||||
src/plugins/OwnerEditor.py
|
src/plugins/OwnerEditor.py
|
||||||
src/plugins/PatchNames.py
|
src/plugins/PatchNames.py
|
||||||
|
@ -1,147 +0,0 @@
|
|||||||
#
|
|
||||||
# count_anc.py - Ancestor counting plugin for gramps
|
|
||||||
#
|
|
||||||
# Copyright (C) 2001 Jesper Zedlitz
|
|
||||||
# Copyright (C) 2004-2006 Donald Allingham
|
|
||||||
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
|
|
||||||
#
|
|
||||||
# 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$
|
|
||||||
|
|
||||||
"""Reports/View/Number of Ancestors"""
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# standard python modules
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
import os
|
|
||||||
from gettext import gettext as _
|
|
||||||
from math import pow
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# GNOME/GTK modules
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
from gtk import glade
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# GRAMPS modules
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
from PluginUtils import register_report
|
|
||||||
from ReportBase import CATEGORY_VIEW, MODE_GUI
|
|
||||||
import ManagedWindow
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
class CountAncestors(ManagedWindow.ManagedWindow):
|
|
||||||
|
|
||||||
def __init__(self, dbstate, uistate):
|
|
||||||
person = dbstate.get_active_person()
|
|
||||||
self.title = _('Ancestors of "%s"') \
|
|
||||||
% person.get_primary_name().get_name()
|
|
||||||
|
|
||||||
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
|
||||||
|
|
||||||
database = dbstate.db
|
|
||||||
text = ""
|
|
||||||
glade_file = "%s/summary.glade" % os.path.dirname(__file__)
|
|
||||||
topDialog = glade.XML(glade_file,"summary","gramps")
|
|
||||||
topDialog.signal_autoconnect({
|
|
||||||
"destroy_passed_object" : self.close,
|
|
||||||
})
|
|
||||||
thisgen = {}
|
|
||||||
all = {}
|
|
||||||
|
|
||||||
total_theoretical = 0
|
|
||||||
thisgen[person.get_handle()]=1
|
|
||||||
|
|
||||||
|
|
||||||
window = topDialog.get_widget("summary")
|
|
||||||
title = topDialog.get_widget("title")
|
|
||||||
self.set_window(window,title,self.title)
|
|
||||||
|
|
||||||
thisgensize = 1
|
|
||||||
gen = 0
|
|
||||||
while thisgensize > 0:
|
|
||||||
thisgensize = 0
|
|
||||||
if thisgen != {}:
|
|
||||||
thisgensize = len(thisgen.values())
|
|
||||||
gen += 1
|
|
||||||
theoretical = pow(2, ( gen - 1 ) )
|
|
||||||
total_theoretical += theoretical
|
|
||||||
percent = ( sum(thisgen.values()) / theoretical ) * 100
|
|
||||||
if thisgensize == 1 :
|
|
||||||
text += _("Generation %d has 1 individual. (%3.2f%%)\n") \
|
|
||||||
% (gen,percent)
|
|
||||||
else:
|
|
||||||
text += _("Generation %d has %d individuals. (%3.2f%%)\n")\
|
|
||||||
% (gen,thisgensize,percent)
|
|
||||||
temp = thisgen
|
|
||||||
thisgen = {}
|
|
||||||
for person_handle in temp.keys():
|
|
||||||
person = database.get_person_from_handle(person_handle)
|
|
||||||
family_handle = person.get_main_parents_family_handle()
|
|
||||||
if family_handle:
|
|
||||||
family = database.get_family_from_handle(family_handle)
|
|
||||||
father_handle = family.get_father_handle()
|
|
||||||
mother_handle = family.get_mother_handle()
|
|
||||||
if father_handle:
|
|
||||||
thisgen[father_handle] = thisgen.get(father_handle, 0) + temp[person_handle]
|
|
||||||
all[father_handle] = all.get(father_handle, 0) + temp[person_handle]
|
|
||||||
if mother_handle:
|
|
||||||
thisgen[mother_handle] = thisgen.get(mother_handle, 0) + temp[person_handle]
|
|
||||||
all[mother_handle] = all.get(mother_handle, 0) + temp[person_handle]
|
|
||||||
|
|
||||||
if( total_theoretical != 1 ):
|
|
||||||
percent = ( sum(all.values()) / (total_theoretical-1) ) * 100
|
|
||||||
else:
|
|
||||||
percent = 0
|
|
||||||
|
|
||||||
text += _("Total ancestors in generations 2 to %d is %d. (%3.2f%%)\n")\
|
|
||||||
% (gen, len(all.keys()) ,percent)
|
|
||||||
|
|
||||||
textwindow = topDialog.get_widget("textwindow")
|
|
||||||
textwindow.get_buffer().set_text(text)
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
def build_menu_names(self, obj):
|
|
||||||
return (self.title,None)
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
register_report(
|
|
||||||
name = 'count_ancestors',
|
|
||||||
category = CATEGORY_VIEW,
|
|
||||||
report_class = CountAncestors,
|
|
||||||
options_class = None,
|
|
||||||
modes = MODE_GUI,
|
|
||||||
translated_name = _("Number of Ancestors"),
|
|
||||||
status = _("Stable"),
|
|
||||||
description = _("Counts number of ancestors of selected person"),
|
|
||||||
author_name = "Brian G. Matherly",
|
|
||||||
author_email = "brian@gramps-project.org",
|
|
||||||
)
|
|
@ -18,7 +18,6 @@ pkgdata_PYTHON = \
|
|||||||
ChangeNames.py\
|
ChangeNames.py\
|
||||||
Check.py\
|
Check.py\
|
||||||
CmdRef.py\
|
CmdRef.py\
|
||||||
CountAncestors.py\
|
|
||||||
CustomBookText.py\
|
CustomBookText.py\
|
||||||
DateParserDisplayTest.py\
|
DateParserDisplayTest.py\
|
||||||
DefaultGramplets.py\
|
DefaultGramplets.py\
|
||||||
@ -53,6 +52,7 @@ pkgdata_PYTHON = \
|
|||||||
MediaManager.py\
|
MediaManager.py\
|
||||||
NarrativeWeb.py\
|
NarrativeWeb.py\
|
||||||
NotRelated.py\
|
NotRelated.py\
|
||||||
|
NumberOfAncestorsReport.py\
|
||||||
OnThisDay.py\
|
OnThisDay.py\
|
||||||
OwnerEditor.py\
|
OwnerEditor.py\
|
||||||
PatchNames.py\
|
PatchNames.py\
|
||||||
|
203
src/plugins/NumberOfAncestorsReport.py
Normal file
203
src/plugins/NumberOfAncestorsReport.py
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2001 Jesper Zedlitz
|
||||||
|
# Copyright (C) 2004-2006 Donald Allingham
|
||||||
|
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
|
||||||
|
# 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$
|
||||||
|
|
||||||
|
"""Reports/Text Reports /Number of Ancestors Report"""
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# standard python modules
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
from gettext import gettext as _
|
||||||
|
import math
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# GRAMPS modules
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
from PluginUtils import register_report, PersonOption
|
||||||
|
from ReportBase import Report, MenuReportOptions, ReportUtils, \
|
||||||
|
CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI
|
||||||
|
from BasicUtils import name_displayer
|
||||||
|
import BaseDoc
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# NumberOfAncestorsReport
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
class NumberOfAncestorsReport(Report):
|
||||||
|
"""
|
||||||
|
This report counts all the ancestors of the specified person.
|
||||||
|
"""
|
||||||
|
def __init__(self, database, options_class):
|
||||||
|
"""
|
||||||
|
Create the NumberOfAncestorsReport object that produces the report.
|
||||||
|
|
||||||
|
The arguments are:
|
||||||
|
|
||||||
|
database - the GRAMPS database instance
|
||||||
|
person - currently selected person
|
||||||
|
options_class - instance of the Options class for this report
|
||||||
|
"""
|
||||||
|
Report.__init__(self, database, options_class)
|
||||||
|
self.__db = database
|
||||||
|
pid = options_class.menu.get_option_by_name('pid').get_value()
|
||||||
|
self.__person = database.get_person_from_gramps_id(pid)
|
||||||
|
|
||||||
|
def write_report(self):
|
||||||
|
"""
|
||||||
|
The routine the actually creates the report. At this point, the document
|
||||||
|
is opened and ready for writing.
|
||||||
|
"""
|
||||||
|
thisgen = {}
|
||||||
|
all_people = {}
|
||||||
|
total_theoretical = 0
|
||||||
|
thisgen[self.__person.get_handle()]=1
|
||||||
|
|
||||||
|
self.doc.start_paragraph("NOA-Title")
|
||||||
|
name = name_displayer.display(self.__person)
|
||||||
|
title = _("Number of Ancestors for %s") % name
|
||||||
|
mark = BaseDoc.IndexMark(title, BaseDoc.INDEX_TYPE_TOC, 1)
|
||||||
|
self.doc.write_text(title, mark)
|
||||||
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
|
thisgensize = 1
|
||||||
|
gen = 0
|
||||||
|
while thisgensize > 0:
|
||||||
|
thisgensize = 0
|
||||||
|
if thisgen != {}:
|
||||||
|
thisgensize = len(thisgen.values())
|
||||||
|
gen += 1
|
||||||
|
theoretical = math.pow(2, ( gen - 1 ) )
|
||||||
|
total_theoretical += theoretical
|
||||||
|
percent = ( sum(thisgen.values()) / theoretical ) * 100
|
||||||
|
if thisgensize == 1 :
|
||||||
|
text = _("Generation %d has 1 individual. (%3.2f%%)") \
|
||||||
|
% (gen, percent)
|
||||||
|
else:
|
||||||
|
text = _("Generation %d has %d individuals. (%3.2f%%)")\
|
||||||
|
% (gen, thisgensize, percent)
|
||||||
|
|
||||||
|
self.doc.start_paragraph('NOA-Normal')
|
||||||
|
self.doc.write_text(text)
|
||||||
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
|
temp = thisgen
|
||||||
|
thisgen = {}
|
||||||
|
for person_handle in temp.keys():
|
||||||
|
person = self.__db.get_person_from_handle(person_handle)
|
||||||
|
family_handle = person.get_main_parents_family_handle()
|
||||||
|
if family_handle:
|
||||||
|
family = self.__db.get_family_from_handle(family_handle)
|
||||||
|
father_handle = family.get_father_handle()
|
||||||
|
mother_handle = family.get_mother_handle()
|
||||||
|
if father_handle:
|
||||||
|
thisgen[father_handle] = \
|
||||||
|
thisgen.get(father_handle, 0) + temp[person_handle]
|
||||||
|
all_people[father_handle] = \
|
||||||
|
all_people.get(father_handle, 0) + \
|
||||||
|
temp[person_handle]
|
||||||
|
if mother_handle:
|
||||||
|
thisgen[mother_handle] = \
|
||||||
|
thisgen.get(mother_handle, 0) + temp[person_handle]
|
||||||
|
all_people[mother_handle] = \
|
||||||
|
all_people.get(mother_handle, 0) + \
|
||||||
|
temp[person_handle]
|
||||||
|
|
||||||
|
if( total_theoretical != 1 ):
|
||||||
|
percent = ( sum(all_people.values()) / (total_theoretical-1) ) * 100
|
||||||
|
else:
|
||||||
|
percent = 0
|
||||||
|
|
||||||
|
text = _("Total ancestors in generations 2 to %d is %d. (%3.2f%%)") \
|
||||||
|
% (gen, len(all_people.keys()) ,percent)
|
||||||
|
|
||||||
|
self.doc.start_paragraph('NOA-Normal')
|
||||||
|
self.doc.write_text(text)
|
||||||
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# NumberOfAncestorsOptions
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
class NumberOfAncestorsOptions(MenuReportOptions):
|
||||||
|
"""
|
||||||
|
Defines options for the NumberOfAncestorsReport.
|
||||||
|
"""
|
||||||
|
def __init__(self, name, dbase):
|
||||||
|
MenuReportOptions.__init__(self, name, dbase)
|
||||||
|
|
||||||
|
def add_menu_options(self, menu):
|
||||||
|
"""
|
||||||
|
Add options to the menu for the kinship report.
|
||||||
|
"""
|
||||||
|
category_name = _("Report Options")
|
||||||
|
|
||||||
|
pid = PersonOption(_("Center Person"))
|
||||||
|
pid.set_help(_("The center person for the report"))
|
||||||
|
menu.add_option(category_name, "pid", pid)
|
||||||
|
|
||||||
|
def make_default_style(self, default_style):
|
||||||
|
"""Make the default output style for the Number of Ancestors Report."""
|
||||||
|
font = BaseDoc.FontStyle()
|
||||||
|
font.set_size(16)
|
||||||
|
font.set_type_face(BaseDoc.FONT_SANS_SERIF)
|
||||||
|
font.set_bold(1)
|
||||||
|
para = BaseDoc.ParagraphStyle()
|
||||||
|
para.set_header_level(1)
|
||||||
|
para.set_bottom_border(1)
|
||||||
|
para.set_bottom_margin(ReportUtils.pt2cm(8))
|
||||||
|
para.set_font(font)
|
||||||
|
para.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
||||||
|
para.set_description(_("The style used for the title of the page."))
|
||||||
|
default_style.add_paragraph_style("NOA-Title", para)
|
||||||
|
|
||||||
|
font = BaseDoc.FontStyle()
|
||||||
|
font.set_size(12)
|
||||||
|
para = BaseDoc.ParagraphStyle()
|
||||||
|
para.set_font(font)
|
||||||
|
para.set_description(_('The basic style used for the text display.'))
|
||||||
|
default_style.add_paragraph_style("NOA-Normal", para)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# register_report
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
register_report(
|
||||||
|
name = 'number_of_ancestors_report',
|
||||||
|
category = CATEGORY_TEXT,
|
||||||
|
report_class = NumberOfAncestorsReport,
|
||||||
|
options_class = NumberOfAncestorsOptions,
|
||||||
|
modes = MODE_GUI | MODE_BKI | MODE_CLI,
|
||||||
|
translated_name = _("Number of Ancestors Report"),
|
||||||
|
status = _("Stable"),
|
||||||
|
description = _("Counts number of ancestors of selected person"),
|
||||||
|
author_name = "Brian G. Matherly",
|
||||||
|
author_email = "brian@gramps-project.org"
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user