Implement new "User()" class for reports to indicate progress and prompt the user. This allows the removal of from "gui.utils import ProgressMeter" from reports so that they don't depend on gui.

svn: r18378
This commit is contained in:
Brian Matherly 2011-10-29 05:02:33 +00:00
parent d2f31ae81b
commit 0b8ea1202d
40 changed files with 706 additions and 276 deletions

View File

@ -29,8 +29,12 @@ src/cli/arghandler.py
src/cli/argparser.py
src/cli/clidbman.py
src/cli/grampscli.py
src/cli/user.py
src/cli/plug/__init__.py
# gen
src/gen/user.py
# gen db API
src/gen/db/base.py
src/gen/db/exceptions.py
@ -90,6 +94,7 @@ src/gui/filtereditor.py
src/gui/grampsbar.py
src/gui/grampsgui.py
src/gui/makefilter.py
src/gui/user.py
src/gui/utils.py
src/gui/viewmanager.py

View File

@ -114,7 +114,7 @@ class GenericFilter(object):
def find_from_handle(self, db, handle):
return db.get_person_from_handle(handle)
def check_func(self, db, id_list, task, progress=None, tupleind=None):
def check_func(self, db, id_list, task, cb_progress=None, tupleind=None):
final_list = []
if id_list is None:
@ -122,8 +122,8 @@ class GenericFilter(object):
for handle, data in cursor:
person = self.make_obj()
person.unserialize(data)
if progress:
progress.step()
if cb_progress:
cb_progress()
if task(db, person) != self.invert:
final_list.append(handle)
else:
@ -133,13 +133,13 @@ class GenericFilter(object):
else:
handle = data[tupleind]
person = self.find_from_handle(db, handle)
if progress:
progress.step()
if cb_progress:
cb_progress()
if task(db, person) != self.invert:
final_list.append(data)
return final_list
def check_and(self, db, id_list, progress=None, tupleind=None):
def check_and(self, db, id_list, cb_progress=None, tupleind=None):
final_list = []
flist = self.flist
@ -148,8 +148,8 @@ class GenericFilter(object):
for handle, data in cursor:
person = self.make_obj()
person.unserialize(data)
if progress:
progress.step()
if cb_progress:
cb_progress()
val = all(rule.apply(db, person) for rule in flist)
if val != self.invert:
final_list.append(handle)
@ -160,23 +160,23 @@ class GenericFilter(object):
else:
handle = data[tupleind]
person = self.find_from_handle(db, handle)
if progress:
progress.step()
if cb_progress:
cb_progress()
val = all(rule.apply(db, person) for rule in flist if person)
if val != self.invert:
final_list.append(data)
return final_list
def check_or(self, db, id_list, progress=None, tupleind=None):
return self.check_func(db, id_list, self.or_test, progress,
def check_or(self, db, id_list, cb_progress=None, tupleind=None):
return self.check_func(db, id_list, self.or_test, cb_progress,
tupleind)
def check_one(self, db, id_list, progress=None, tupleind=None):
return self.check_func(db, id_list, self.one_test, progress,
def check_one(self, db, id_list, cb_progress=None, tupleind=None):
return self.check_func(db, id_list, self.one_test, cb_progress,
tupleind)
def check_xor(self, db, id_list, progress=None, tupleind=None):
return self.check_func(db, id_list, self.xor_test, progress,
def check_xor(self, db, id_list, cb_progress=None, tupleind=None):
return self.check_func(db, id_list, self.xor_test, cb_progress,
tupleind)
def xor_test(self, db, person):
@ -207,16 +207,15 @@ class GenericFilter(object):
def check(self, db, handle):
return self.get_check_func()(db, [handle])
# progress is optional. If present it must be an instance of
# gui.utils.ProgressMeter
def apply(self, db, id_list=None, progress=None, tupleind=None):
def apply(self, db, id_list=None, cb_progress=None, tupleind=None):
"""
Apply the filter using db.
If id_list given, the handles in id_list are used. If not given
a database cursor will be used over all entries.
If progress given, it will be used to indicate progress of the
Filtering
cb_progress is optional. If present it must be a function that takes no
parameters. If cb_progress given, it will be called occasionally to
indicate progress of the filtering.
If tupleind is given, id_list is supposed to consist of a list of
tuples, with the handle being index tupleind. So
@ -230,7 +229,7 @@ class GenericFilter(object):
m = self.get_check_func()
for rule in self.flist:
rule.requestprepare(db)
res = m(db, id_list, progress, tupleind)
res = m(db, id_list, cb_progress, tupleind)
for rule in self.flist:
rule.requestreset()
return res

View File

@ -13,7 +13,8 @@ pkgdata_PYTHON = \
arghandler.py \
argparser.py \
clidbman.py \
grampscli.py
grampscli.py \
user.py
pkgpyexecdir = @pkgpyexecdir@/cli
pkgpythondir = @pkgpythondir@/cli

View File

@ -62,6 +62,7 @@ from gen.plug.report._paper import paper_sizes
import const
import DbState
from cli.grampscli import CLIManager
import cli.user
#------------------------------------------------------------------------
#
@ -559,7 +560,7 @@ def cl_report(database, name, category, report_class, options_class,
if clr.css_filename is not None and \
hasattr(clr.option_class.handler.doc, 'set_css_filename'):
clr.option_class.handler.doc.set_css_filename(clr.css_filename)
MyReport = report_class(database, clr.option_class)
MyReport = report_class(database, clr.option_class, cli.user.User())
MyReport.doc.init()
MyReport.begin_report()
MyReport.write_report()

142
src/cli/user.py Normal file
View File

@ -0,0 +1,142 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 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:$
#
"""
The User class provides basic interaction with the user.
"""
#------------------------------------------------------------------------
#
# Python Modules
#
#------------------------------------------------------------------------
import sys
#------------------------------------------------------------------------
#
# Gramps Modules
#
#------------------------------------------------------------------------
import gen.user
#------------------------------------------------------------------------
#
# Private Constants
#
#------------------------------------------------------------------------
_SPINNER = ['|', '/', '-', '\\']
#-------------------------------------------------------------------------
#
# User class
#
#-------------------------------------------------------------------------
class User(gen.user.User):
"""
This class provides a means to interact with the user via CLI.
It implements the interface in gen.user.User()
"""
def __init__(self):
self.steps = 0;
self.current_step = 0;
def begin_progress(self, title, message, steps):
"""
Start showing a progress indicator to the user.
@param title: the title of the progress meter
@type title: str
@param message: the message associated with the progress meter
@type message: str
@param steps: the total number of steps for the progress meter. a value
of 0 indicates that the ending is unknown and the meter should just
show activity.
@type steps: int
@returns: none
"""
print message
self.steps = steps
self.current_step = 0;
if self.steps == 0:
sys.stdout.write(_SPINNER[self.current_step])
else:
sys.stdout.write("00%")
def step_progress(self):
"""
Advance the progress meter.
"""
self.current_step += 1
if self.steps == 0:
self.current_step %= 4
sys.stdout.write("\r %s " % _SPINNER[self.current_step])
else:
percent = int((float(self.current_step) / self.steps) * 100)
sys.stdout.write("\r%02d%%" % percent)
def end_progress(self):
"""
Start showing a progress indicator to the user.
"""
if self.steps != 0:
sys.stdout.write("\r100%")
sys.stdout.write("\n")
def prompt(self, title, question):
"""
Ask the user a question. The answer must be "yes" or "no". The user will
be forced to answer the question before proceeding.
@param title: the title of the question
@type title: str
@param question: the question
@type question: str
@returns: the user's answer to the question
@rtype: bool
"""
return False
def warn(self, title, warning):
"""
Warn the user. The user will be forced to acknowledge the warning before
proceeding.
@param title: the title of the warning
@type title: str
@param warning: the warning
@type warning: str
@returns: none
"""
pass
def notify_error(self, title, error):
"""
Notify the user of an error. The user will be forced to acknowledge the
error before proceeding.
@param title: the title of the error
@type title: str
@param error: the error message
@type error: str
@returns: none
"""
pass

View File

@ -17,7 +17,8 @@ pkgdatadir = $(datadir)/@PACKAGE@/gen
pkgdata_PYTHON = \
__init__.py \
ggettext.py \
updatecallback.py
updatecallback.py \
user.py
pkgpyexecdir = @pkgpyexecdir@/gen
pkgpythondir = @pkgpythondir@/gen

View File

@ -35,7 +35,7 @@ class Report(object):
sub-classed to create a functional report generator.
"""
def __init__(self, database, options_class):
def __init__(self, database, options_class, user):
self.database = database
self.options_class = options_class

104
src/gen/user.py Normal file
View File

@ -0,0 +1,104 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 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:$
#
"""
The User class provides basic interaction with the user.
"""
#-------------------------------------------------------------------------
#
# User class
#
#-------------------------------------------------------------------------
class User():
"""
This class provides a means to interact with the user in an abstract way.
This class should be overridden by each respective user interface to provide
the appropriate interaction (eg. dialogs for GTK, promts for CLI).
"""
def begin_progress(self, title, message, steps):
"""
Start showing a progress indicator to the user.
@param title: the title of the progress meter
@type title: str
@param message: the message associated with the progress meter
@type message: str
@param steps: the total number of steps for the progress meter. a value
of 0 indicates that the ending is unknown and the meter should just
show activity.
@type steps: int
@returns: none
"""
pass
def step_progress(self):
"""
Advance the progress meter.
"""
pass
def end_progress(self):
"""
Start showing a progress indicator to the user.
"""
pass
def prompt(self, title, question):
"""
Ask the user a question. The answer must be "yes" or "no". The user will
be forced to answer the question before proceeding.
@param title: the title of the question
@type title: str
@param question: the question
@type question: str
@returns: the user's answer to the question
@rtype: bool
"""
return False
def warn(self, title, warning):
"""
Warn the user. The user will be forced to acknowledge the warning before
proceeding.
@param title: the title of the warning
@type title: str
@param warning: the warning
@type warning: str
@returns: none
"""
pass
def notify_error(self, title, error):
"""
Notify the user of an error. The user will be forced to acknowledge the
error before proceeding.
@param title: the title of the error
@type title: str
@param error: the error message
@type error: str
@returns: none
"""
pass

View File

@ -27,6 +27,7 @@ pkgdata_PYTHON = \
navigator.py \
makefilter.py \
pluginmanager.py \
user.py \
utils.py \
viewmanager.py

View File

@ -53,6 +53,7 @@ import config
import Errors
from gui.utils import ProgressMeter, open_file_with_default_application
from gui.plug import add_gui_options
from gui.user import User
from QuestionDialog import ErrorDialog, OptionDialog
from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK,
CATEGORY_CODE, CATEGORY_WEB, CATEGORY_GRAPHVIZ,
@ -675,7 +676,8 @@ def report(dbstate, uistate, person, report_class, options_class,
if response == gtk.RESPONSE_OK:
dialog.close()
try:
MyReport = report_class(dialog.db, dialog.options)
user = User()
MyReport = report_class(dialog.db, dialog.options, user)
def do_report():
MyReport.doc.init()

121
src/gui/user.py Normal file
View File

@ -0,0 +1,121 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2010 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:$
#
"""
The User class provides basic interaction with the user.
"""
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import gen.user
from gui.utils import ProgressMeter
#-------------------------------------------------------------------------
#
# User class
#
#-------------------------------------------------------------------------
class User(gen.user.User):
"""
This class provides a means to interact with the user via GTK.
It implements the interface in gen.user.User()
"""
def __init__(self):
self.progress = None
def begin_progress(self, title, message, steps):
"""
Start showing a progress indicator to the user.
@param title: the title of the progress meter
@type title: str
@param message: the message associated with the progress meter
@type message: str
@param steps: the total number of steps for the progress meter. a value
of 0 indicates that the ending is unknown and the meter should just
show activity.
@type steps: int
@returns: none
"""
self.progress = ProgressMeter(title)
if steps > 0:
self.progress.set_pass(message, steps, ProgressMeter.MODE_FRACTION)
else:
self.progress.set_pass(message, mode=ProgressMeter.MODE_ACTIVITY)
def step_progress(self):
"""
Advance the progress meter.
"""
if self.progress:
self.progress.step()
def end_progress(self):
"""
Start showing a progress indicator to the user.
"""
if self.progress:
self.progress.close()
self.progress = None
def prompt(self, title, question):
"""
Ask the user a question. The answer must be "yes" or "no". The user will
be forced to answer the question before proceeding.
@param title: the title of the question
@type title: str
@param question: the question
@type question: str
@returns: the user's answer to the question
@rtype: bool
"""
return False
def warn(self, title, warning):
"""
Warn the user. The user will be forced to acknowledge the warning before
proceeding.
@param title: the title of the warning
@type title: str
@param warning: the warning
@type warning: str
@returns: none
"""
pass
def notify_error(self, title, error):
"""
Notify the user of an error. The user will be forced to acknowledge the
error before proceeding.
@param title: the title of the error
@type title: str
@param error: the error message
@type error: str
@returns: none
"""
pass

View File

@ -523,7 +523,7 @@ class TreeBaseModel(gtk.GenericTreeModel):
total_steps=self.__total, interval=self.__total//10)
pmon.add_op(status_filter)
handle_list = dfilter.apply(self.db, handle_list,
progress=status_filter)
cb_progress=status_filter.heartbeat)
status_filter.end()
status.heartbeat()

View File

@ -78,6 +78,7 @@ from gen.plug.menu import PersonOption, FilterOption, FamilyOption
import ManagedWindow
from glade import Glade
from gui.utils import open_file_with_default_application
import gui.user
# Import from specific modules in ReportBase
from gen.plug.report import CATEGORY_BOOK, book_categories
@ -85,6 +86,7 @@ from gui.plug.report._reportdialog import ReportDialog
from gui.plug.report._docreportdialog import DocReportDialog
from gen.plug.report._options import ReportOptions
from cli.plug import CommandLineReport
import cli.user
from gen.display.name import displayer as _nd
@ -1252,13 +1254,13 @@ class BookReportDialog(DocReportDialog):
"""Create a document of the type requested by the user."""
pstyle = self.paper_frame.get_paper_style()
self.doc = self.format(self.selected_style, pstyle)
user = gui.user.User()
self.rptlist = []
for item in self.book.get_item_list():
item.option_class.set_document(self.doc)
report_class = item.get_write_item()
obj = write_book_item(self.database,
report_class, item.option_class)
obj = write_book_item(self.database, report_class,
item.option_class, user)
self.rptlist.append(obj)
self.doc.open(self.target_path)
@ -1357,6 +1359,7 @@ def cl_report(database, name, category, options_str_dict):
doc = clr.format(selected_style,
PaperStyle(clr.paper, clr.orien, clr.marginl,
clr.marginr, clr.margint, clr.marginb))
user = cli.user.User()
rptlist = []
for item in book.get_item_list():
item.option_class.set_document(doc)
@ -1381,11 +1384,11 @@ def cl_report(database, name, category, options_str_dict):
# Generic task function for book report
#
#------------------------------------------------------------------------
def write_book_item(database, report_class, options_class):
"""Write the Timeline Graph using options set.
def write_book_item(database, report_class, options, user):
"""Write the report using options set.
All user dialog has already been handled and the output file opened."""
try:
return report_class(database, options_class)
return report_class(database, options, user)
except Errors.ReportError, msg:
(m1, m2) = msg.messages()
ErrorDialog(m1, m2)

View File

@ -431,10 +431,10 @@ class RecordsGramplet(Gramplet):
#------------------------------------------------------------------------
class RecordsReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
menu = options.menu
self.filter_option = menu.get_option_by_name('filter')
self.filter = self.filter_option.get_filter()

View File

@ -61,8 +61,6 @@ from gen.plug.report import MenuReportOptions
from gen.display.name import displayer as name_displayer
from gui.utils import ProgressMeter
PT2CM = ReportUtils.pt2cm
#cm2pt = ReportUtils.cm2pt
@ -646,7 +644,7 @@ class GUIConnect():
#------------------------------------------------------------------------
class AncestorTree(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create AncestorTree object that produces the report.
@ -654,13 +652,14 @@ class AncestorTree(Report):
database - the GRAMPS database instance
person - currently selected person
options_class - instance of the Options class for this report
options - instance of the Options class for this report
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.options_class = options_class
self.options = options
self.database = database
self._user = user
#The canvas that we will put our report on and print off of
self.canvas = Canvas(self.doc)
@ -687,15 +686,15 @@ class AncestorTree(Report):
database = self.database
self.connect = GUIConnect()
self.connect.set__opts(self.options_class.menu)
self.connect.set__opts(self.options.menu)
#Set up the canvas that we will print on.
style_sheet = self.doc.get_style_sheet()
font_normal = style_sheet.get_paragraph_style("AC2-Normal").get_font()
self.doc.report_opts = ReportOptions(self.doc, font_normal, 'AC2-line')
self.progress = ProgressMeter(_('Ancestor Tree'))
self.progress.set_pass(_('Making the Tree...'), 4)
self._user.begin_progress(_('Ancestor Tree'),
_('Making the Tree...'), 4)
#make the tree onto the canvas
inlc_marr = self.connect.get_val("inc_marr")
@ -706,7 +705,7 @@ class AncestorTree(Report):
tree.start(self.connect.get_val('pid'))
tree = None
self.progress.step()
self._user.step_progress()
#Title
title = self.connect.title_class(self.doc)
@ -724,7 +723,7 @@ class AncestorTree(Report):
self.max_generations = report.get_generations() #already know
report = None
self.progress.step()
self._user.step_progress()
#Note?
if self.connect.get_val("inc_note"):
@ -769,7 +768,7 @@ class AncestorTree(Report):
if prnnum:
page_num_box = PageNumberBox(self.doc, 'AC2-box')
self.progress.step()
self._user.step_progress()
#####################
#ok, everyone is now ready to print on the canvas. Paginate?
self.canvas.paginate(colsperpage, one_page)
@ -779,7 +778,9 @@ class AncestorTree(Report):
#lets finally make some pages!!!
#####################
pages = self.canvas.page_count(incblank)
self.progress.set_pass(_('Printing the Tree...'), pages)
self._user.end_progress()
self._user.begin_progress( _('Ancestor Tree'),
_('Printing the Tree...'), pages)
for page in self.canvas.page_iter_gen(incblank):
@ -796,10 +797,10 @@ class AncestorTree(Report):
#Print the individual people and lines
page.display()
self.progress.step()
self._user.step_progress()
self.doc.end_page()
self.progress.close()
self._user.end_progress()
def scale_styles(self, scale):

View File

@ -45,7 +45,6 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
from gen.plug.docgen.fontscale import string_trim
from gen.plug.menu import (BooleanOption, StringOption, NumberOption,
EnumeratedListOption, FilterOption, PersonOption)
from gui.utils import ProgressMeter
from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions
@ -74,9 +73,10 @@ class Calendar(Report):
"""
Create the Calendar object that produces the report.
"""
def __init__(self, database, options_class):
Report.__init__(self, database, options_class)
menu = options_class.menu
def __init__(self, database, options, user):
Report.__init__(self, database, options, user)
menu = options.menu
self._user = user
get_value = lambda name: menu.get_option_by_name(name).get_value()
self.year = get_value('year')
@ -154,7 +154,6 @@ class Calendar(Report):
def write_report(self):
""" The short method that runs through each month and creates a page. """
# initialize the dict to fill:
self.progress = ProgressMeter(_('Calendar Report'))
self.calendar = {}
# get the information, first from holidays:
@ -164,11 +163,12 @@ class Calendar(Report):
# get data from database:
self.collect_data()
# generate the report:
self.progress.set_pass(_('Formatting months...'), 12)
self._user.begin_progress( _('Calendar Report'),
_('Formatting months...'), 12)
for month in range(1, 13):
self.progress.step()
self._user.step_progress()
self.print_page(month)
self.progress.close()
self._user.end_progress()
def print_page(self, month):
"""
@ -261,13 +261,18 @@ class Calendar(Report):
"""
db = self.database
people = db.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'), db.get_number_of_people())
people = self.filter.apply(self.database, people, self.progress)
self._user.begin_progress(_('Calendar Report'),
_('Applying Filter...'),
db.get_number_of_people())
people = self.filter.apply(self.database, people,
self._user.step_progress)
rel_calc = Relationship.get_relationship_calculator()
self._user.end_progress()
self.progress.set_pass(_('Reading database...'), len(people))
self._user.begin_progress(_('Calendar Report'),
_('Reading database...'), len(people))
for person_handle in people:
self.progress.step()
self._user.step_progress()
person = db.get_person_from_handle(person_handle)
birth_ref = person.get_birth_ref()
birth_date = None
@ -381,6 +386,7 @@ class Calendar(Report):
prob_alive_date)
if ((self.alive and alive1 and alive2) or not self.alive):
self.add_day_item(text, month, day)
self._user.end_progress()
#------------------------------------------------------------------------
#

View File

@ -1255,17 +1255,18 @@ class GuiConnect():
#------------------------------------------------------------------------
class DescendTree(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create DescendTree object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.options_class = options_class
self.options = options
self.database = database
#The canvas that we will put our report on and print off of
@ -1279,7 +1280,7 @@ class DescendTree(Report):
database = self.database
self.Connect = GuiConnect()
self.Connect.set__opts(self.options_class.menu, self.options_class.name)
self.Connect.set__opts(self.options.menu, self.options.name)
style_sheet = self.doc.get_style_sheet()
font_normal = style_sheet.get_paragraph_style("CG2-Normal").get_font()

View File

@ -135,15 +135,15 @@ def draw_wedge(doc, style, centerx, centery, radius, start_angle,
#------------------------------------------------------------------------
class FanChart(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the FanChart 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
options - instance of the Options class for this report
user - a gen.user.User instance
This report needs the following parameters (class variables)
that come in the options class.
@ -154,7 +154,7 @@ class FanChart(Report):
radial - Print radial texts roundabout or as upright as possible.
"""
menu = options_class.menu
menu = options.menu
self.max_generations = menu.get_option_by_name('maxgen').get_value()
self.circle = menu.get_option_by_name('circle').get_value()
self.background = menu.get_option_by_name('background').get_value()
@ -177,7 +177,7 @@ class FanChart(Report):
self.calendar = 0
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.height = 0
self.map = [None] * 2**self.max_generations

View File

@ -54,7 +54,6 @@ from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions
import DateHandler
from gui.utils import ProgressMeter
#------------------------------------------------------------------------
#
@ -614,7 +613,7 @@ class Extract(object):
def collect_data(self, db, filter_func, menu, genders,
year_from, year_to, no_years):
year_from, year_to, no_years, cb_progress):
"""goes through the database and collects the selected personal
data persons fitting the filter and birth year criteria. The
arguments are:
@ -625,6 +624,7 @@ class Extract(object):
year_from - use only persons who've born this year of after
year_to - use only persons who've born this year or before
no_years - use also people without known birth year
cb_progress - callback to indicate progress
Returns an array of tuple of:
- Extraction method title
@ -643,8 +643,8 @@ class Extract(object):
data.append((ext[name][1], {}, ext[name][2], ext[name][3]))
# go through the people and collect data
for person_handle in filter_func.apply(db, db.iter_person_handles()):
for person_handle in filter_func.apply(db, db.iter_person_handles(), cb_progress):
cb_progress()
person = db.get_person_from_handle(person_handle)
# check whether person has suitable gender
if person.gender != genders and genders != Person.UNKNOWN:
@ -687,7 +687,7 @@ _Extract = Extract()
#------------------------------------------------------------------------
class StatisticsChart(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the Statistics object that produces the report.
Uses the Extractor class to extract the data from the database.
@ -696,12 +696,13 @@ class StatisticsChart(Report):
database - the GRAMPS database instance
person - currently selected person
options_class - instance of the Options class for this report
options - instance of the Options class for this report
To see what the options are, check the options help in the options class.
"""
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
menu = options.menu
self._user = user
get_option_by_name = menu.get_option_by_name
get_value = lambda name: get_option_by_name(name).get_value()
@ -727,16 +728,17 @@ class StatisticsChart(Report):
'year_from': year_from,
'year_to': year_to
}
self.progress = ProgressMeter(_('Statistics Charts'))
# extract requested items from the database and count them
self.progress.set_pass(_('Collecting data...'), 1)
self._user.begin_progress(_('Statistics Charts'),
_('Collecting data...'), 0)
tables = _Extract.collect_data(database, self.filter, menu,
gender, year_from, year_to,
get_value('no_years'))
self.progress.step()
get_value('no_years'), self._user.step_progress)
self._user.end_progress()
self.progress.set_pass(_('Sorting data...'), len(tables))
self._user.begin_progress(_('Statistics Charts'),
_('Sorting data...'), len(tables))
self.data = []
sortby = get_value('sortby')
reverse = get_value('reverse')
@ -750,7 +752,8 @@ class StatisticsChart(Report):
else:
heading = _("Persons born %(year_from)04d-%(year_to)04d: %(chart_title)s") % mapping
self.data.append((heading, table[0], table[1], lookup))
self.progress.step()
self._user.step_progress()
self._user.end_progress()
#DEBUG
#print heading
#print table[1]
@ -779,7 +782,8 @@ class StatisticsChart(Report):
def write_report(self):
"output the selected statistics..."
self.progress.set_pass(_('Saving charts...'), len(self.data))
self._user.begin_progress(_('Statistics Charts'),
_('Saving charts...'), len(self.data))
for data in self.data:
self.doc.start_page()
if len(data[2]) < self.bar_items:
@ -787,8 +791,8 @@ class StatisticsChart(Report):
else:
self.output_barchart(*data[:4])
self.doc.end_page()
self.progress.step()
self.progress.close()
self._user.step_progress()
self._user.end_progress()
def output_piechart(self, title, typename, data, lookup):

View File

@ -48,7 +48,6 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
import Sort
from QuestionDialog import ErrorDialog
from gen.display.name import displayer as name_displayer
from gui.utils import ProgressMeter
import config
from gen.utils import get_birth_or_fallback, get_death_or_fallback
@ -77,15 +76,15 @@ def _get_sort_functions(sort):
#------------------------------------------------------------------------
class TimeLine(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the Timeline 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
options - instance of the Options class for this report
user - instance of gen.user.User()
This report needs the following parameters (class variables)
that come in the options class.
@ -95,9 +94,9 @@ class TimeLine(Report):
returning the list of filters.
sortby - Sorting method to be used.
"""
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
self._user = user
menu = options.menu
self.filter = menu.get_option_by_name('filter').get_filter()
self.title = _("Timeline Graph for %s") % self.filter.get_name()
@ -109,8 +108,6 @@ class TimeLine(Report):
self.calendar = 0
def write_report(self):
self.progress = ProgressMeter(_('Timeline'))
(low, high) = self.find_year_range()
if low == high:
@ -142,14 +139,17 @@ class TimeLine(Report):
length = len(self.plist)
self.progress.set_pass(_('Sorting dates...'), 1)
self._user.begin_progress(_('Timeline'), _('Sorting dates...'), 1)
self.plist.sort(key=self.sort_func)
self.progress.set_pass(_('Calculating timeline...'), len(self.plist))
self._user.end_progress()
self._user.begin_progress(_('Timeline'),
_('Calculating timeline...'), len(self.plist))
self.calendar = config.get('preferences.calendar-format-report')
for p_id in self.plist:
self.progress.step()
self._user.step_progress()
p = self.database.get_person_from_handle(p_id)
birth = get_birth_or_fallback(self.database, p)
if birth:
@ -203,7 +203,7 @@ class TimeLine(Report):
else:
index += 1;
current += 1
self.progress.close()
self._user.end_progress()
self.build_grid(low, high,start,stop)
self.doc.end_page()

View File

@ -284,17 +284,17 @@ class FamilyLinesOptions(MenuReportOptions):
#
#------------------------------------------------------------------------
class FamilyLinesReport(Report):
def __init__(self, database, options):
def __init__(self, database, options, user):
"""
Create FamilyLinesReport object that eventually produces the report.
The arguments are:
database - the GRAMPS database instance
person - currently selected person
options - instance of the FamilyLinesOptions class for this report
user - a gen.user.User() instance
"""
Report.__init__(self, database, options)
Report.__init__(self, database, options, user)
# initialize several convenient variables
self._db = database

View File

@ -67,11 +67,11 @@ class HourGlassReport(Report):
"""
An hourglass report displays ancestors and descendants of a center person.
"""
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create HourGlass object that produces the report.
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
# Would be nice to get rid of these 2 hard-coded arrays of colours
# and instead allow the user to pick-and-choose whatever colour they
@ -93,7 +93,7 @@ class HourGlassReport(Report):
self.__db = database
self.__used_people = []
menu = options_class.menu
menu = options.menu
self.max_descend = menu.get_option_by_name('maxdescend').get_value()
self.max_ascend = menu.get_option_by_name('maxascend').get_value()
pid = menu.get_option_by_name('pid').get_value()

View File

@ -80,15 +80,15 @@ _ARROWS = [ { 'name' : _("Descendants <- Ancestors"), 'value' : 'd' },
#------------------------------------------------------------------------
class RelGraphReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create ComprehensiveAncestorsReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -114,12 +114,12 @@ class RelGraphReport(Report):
dashed - Whether to use dashed lines for non-birth relationships
use_roundedcorners - Whether to use rounded corners for females
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.database = database
menu = options_class.menu
get_option_by_name = options_class.menu.get_option_by_name
menu = options.menu
get_option_by_name = options.menu.get_option_by_name
get_value = lambda name: get_option_by_name(name).get_value()
self.includeid = get_value('incid')

View File

@ -73,15 +73,15 @@ class AncestorReport(Report):
"""
Ancestor Report class
"""
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the AncestorReport object that produces the Ahnentafel report.
The arguments are:
database - the GRAMPS database instance
person - currently selected person
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -91,11 +91,11 @@ class AncestorReport(Report):
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.map = {}
menu = options_class.menu
menu = options.menu
self.max_generations = menu.get_option_by_name('maxgen').get_value()
self.pgbrk = menu.get_option_by_name('pagebbg').get_value()
self.opt_namebrk = menu.get_option_by_name('namebrk').get_value()

View File

@ -46,7 +46,6 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
PARA_ALIGN_LEFT, PARA_ALIGN_CENTER)
from gen.plug.menu import (BooleanOption, StringOption, NumberOption,
EnumeratedListOption, FilterOption, PersonOption)
from gui.utils import ProgressMeter
from gen.plug.report import Report
from gen.plug.report import utils as ReportUtils
from gen.plug.report import MenuReportOptions
@ -65,10 +64,11 @@ class CalendarReport(Report):
"""
Create the Calendar object that produces the report.
"""
def __init__(self, database, options_class):
Report.__init__(self, database, options_class)
menu = options_class.menu
mgobn = lambda name:options_class.menu.get_option_by_name(name).get_value()
def __init__(self, database, options, user):
Report.__init__(self, database, options, user)
self._user = user
menu = options.menu
mgobn = lambda name:options.menu.get_option_by_name(name).get_value()
self.titletext = mgobn('titletext')
self.relationships = mgobn('relationships')
@ -144,7 +144,6 @@ class CalendarReport(Report):
def write_report(self):
""" The short method that runs through each month and creates a page. """
# initialize the dict to fill:
self.progress = ProgressMeter(_('Birthday and Anniversary Report'))
self.calendar = {}
# get the information, first from holidays:
if self.country != 0:
@ -172,11 +171,12 @@ class CalendarReport(Report):
self.doc.start_paragraph('BIR-Text3style')
self.doc.write_text(_("Relationships shown are to %s") % _nd.display_name(name))
self.doc.end_paragraph()
self.progress.set_pass(_('Formatting months...'), 12)
self._user.begin_progress(_('Birthday and Anniversary Report'),
_('Formatting months...'), 12)
for month in range(1, 13):
self.progress.step()
self._user.step_progress()
self.print_page(month)
self.progress.close()
self._user.end_progress()
def print_page(self, month):
""" Prints a month as a page """
@ -209,14 +209,19 @@ class CalendarReport(Report):
and text.
"""
people = self.database.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'),
self.database.get_number_of_people())
people = self.filter.apply(self.database, people, self.progress)
self._user.begin_progress(_('Birthday and Anniversary Report'),
_('Applying Filter...'),
self.database.get_number_of_people())
people = self.filter.apply(self.database, people,
self._user.step_progress)
self._user.end_progress()
rel_calc = Relationship.get_relationship_calculator()
self.progress.set_pass(_('Reading database...'), len(people))
self._user.begin_progress(_('Birthday and Anniversary Report'),
_('Reading database...'), len(people))
for person_handle in people:
self.progress.step()
self._user.step_progress()
person = self.database.get_person_from_handle(person_handle)
birth_ref = person.get_birth_ref()
birth_date = None
@ -331,6 +336,7 @@ class CalendarReport(Report):
prob_alive_date)
if (self.alive and alive1 and alive2) or not self.alive:
self.add_day_item(text, month, day)
self._user.end_progress()
#------------------------------------------------------------------------
#

View File

@ -55,15 +55,15 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle, FONT_SANS_SERIF,
#------------------------------------------------------------------------
class CustomText(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create CustomText 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -72,9 +72,9 @@ class CustomText(Report):
mid - Text in the middle.
bot - Text on the bottom.
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
menu = options.menu
self.top_text = menu.get_option_by_name('top').get_value()
self.middle_text = menu.get_option_by_name('mid').get_value()
self.bottom_text = menu.get_option_by_name('bot').get_value()

View File

@ -306,14 +306,15 @@ class RecurseDown():
#------------------------------------------------------------------------
class DescendantReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the DescendantReport object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -323,9 +324,9 @@ class DescendantReport(Report):
dups - Whether to include duplicate descendant trees
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
menu = options.menu
self.max_generations = menu.get_option_by_name('gen').get_value()
pid = menu.get_option_by_name('pid').get_value()
self.center_person = database.get_person_from_gramps_id(pid)

View File

@ -73,15 +73,15 @@ EMPTY_ENTRY = "_____________"
#------------------------------------------------------------------------
class DetAncestorReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the DetAncestorReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -104,11 +104,11 @@ class DetAncestorReport(Report):
pid - The Gramps ID of the center person for the report.
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.map = {}
menu = options_class.menu
menu = options.menu
get_option_by_name = menu.get_option_by_name
get_value = lambda name: get_option_by_name(name).get_value()

View File

@ -78,15 +78,15 @@ HENRY = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#------------------------------------------------------------------------
class DetDescendantReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the DetDescendantReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -118,11 +118,11 @@ class DetDescendantReport(Report):
name_format - Preferred format to display names
incmateref - Whether to print mate information or reference
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.map = {}
menu = options_class.menu
menu = options.menu
get_option_by_name = menu.get_option_by_name
get_value = lambda name: get_option_by_name(name).get_value()
self.max_generations = get_value('gen')

View File

@ -54,23 +54,23 @@ import DateHandler
#------------------------------------------------------------------------
class EndOfLineReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the EndOfLineReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
menu = options.menu
pid = menu.get_option_by_name('pid').get_value()
self.center_person = database.get_person_from_gramps_id(pid)
if (self.center_person == None) :

View File

@ -56,15 +56,15 @@ from gen.display.name import displayer as global_name_display
#------------------------------------------------------------------------
class FamilyGroup(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the DetAncestorReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -73,8 +73,8 @@ class FamilyGroup(Report):
includeAttrs - Whether to include attributes
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
menu = options.menu
self.family_handle = None

View File

@ -143,14 +143,15 @@ for event_group, type_list in GROUP_DICT.iteritems():
#------------------------------------------------------------------------
class IndivCompleteReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the IndivCompleteReport object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -165,9 +166,9 @@ class IndivCompleteReport(Report):
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
menu = options.menu
self.use_pagebreak = menu.get_option_by_name('pageben').get_value()
self.use_srcs = menu.get_option_by_name('cites').get_value()
self.use_srcs_notes = menu.get_option_by_name('incsrcnotes').get_value()
@ -176,7 +177,7 @@ class IndivCompleteReport(Report):
self.use_images = menu.get_option_by_name('images').get_value()
filter_option = options_class.menu.get_option_by_name('filter')
filter_option = options.menu.get_option_by_name('filter')
self.filter = filter_option.get_filter()
self.bibli = None

View File

@ -58,14 +58,15 @@ from gen.utils import get_birth_or_fallback, get_death_or_fallback
#------------------------------------------------------------------------
class KinshipReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the KinshipReport object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -78,9 +79,9 @@ class KinshipReport(Report):
pid - The Gramps ID of the center person for the report.
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
menu = options.menu
self.max_descend = menu.get_option_by_name('maxdescend').get_value()
self.max_ascend = menu.get_option_by_name('maxascend').get_value()
self.inc_spouses = menu.get_option_by_name('incspouses').get_value()

View File

@ -61,20 +61,22 @@ class NumberOfAncestorsReport(Report):
"""
This report counts all the ancestors of the specified person.
"""
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
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
options - instance of the Options class for this report
user - a gen.user.User() instance
Menu options:
name_format - Preferred format to display names
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.__db = database
pid = options_class.menu.get_option_by_name('pid').get_value()
pid = options.menu.get_option_by_name('pid').get_value()
self.__person = database.get_person_from_gramps_id(pid)
if (self.__person == None) :
raise ReportError(_("Person %s is not in the Database") % pid )
@ -82,7 +84,7 @@ class NumberOfAncestorsReport(Report):
# Copy the global NameDisplay so that we don't change application
# defaults.
self._name_display = copy.deepcopy(global_name_display)
name_format = options_class.menu.get_option_by_name("name_format").get_value()
name_format = options.menu.get_option_by_name("name_format").get_value()
if name_format != 0:
self._name_display.set_default_format(name_format)

View File

@ -47,20 +47,20 @@ from gen.proxy import PrivateProxyDb
import DateHandler
import Sort
from gen.display.name import displayer as _nd
from gui.utils import ProgressMeter
class PlaceReport(Report):
"""
Place Report class
"""
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the PlaceReport object produces the Place report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - instance of a gen.user.User class
This report needs the following parameters (class variables)
that come in the options class.
@ -71,9 +71,10 @@ class PlaceReport(Report):
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
self._user = user
menu = options.menu
places = menu.get_option_by_name('places').get_value()
self.center = menu.get_option_by_name('center').get_value()
self.incpriv = menu.get_option_by_name('incpriv').get_value()
@ -104,9 +105,6 @@ class PlaceReport(Report):
is opened and ready for writing.
"""
# Create progress meter bar
self.progress = ProgressMeter(_("Place Report"), '')
# Write the title line. Set in INDEX marker so that this section will be
# identified as a major category if this is included in a Book report.
@ -117,15 +115,16 @@ class PlaceReport(Report):
self.doc.end_paragraph()
self.__write_all_places()
# Close the progress meter
self.progress.close()
def __write_all_places(self):
"""
This procedure writes out each of the selected places.
"""
place_nbr = 1
self.progress.set_pass(_("Generating report"), len(self.place_handles))
self._user.begin_progress(_("Place Report"),
_("Generating report"),
len(self.place_handles))
for handle in self.place_handles:
self.__write_place(handle, place_nbr)
if self.center == "Event":
@ -136,7 +135,9 @@ class PlaceReport(Report):
raise AttributeError("no such center: '%s'" % self.center)
place_nbr += 1
# increment progress bar
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def __write_place(self, handle, place_nbr):
"""

View File

@ -48,14 +48,15 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle,
#------------------------------------------------------------------------
class SimpleBookTitle(Report):
""" This report class generates a title page for a book. """
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create SimpleBookTitle object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
@ -66,9 +67,9 @@ class SimpleBookTitle(Report):
imgsize - Size for the image.
footer - Footer string.
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
menu = options_class.menu
menu = options.menu
self.title_string = menu.get_option_by_name('title').get_value()
self.image_size = menu.get_option_by_name('imgsize').get_value()
self.subtitle_string = menu.get_option_by_name('subtitle').get_value()

View File

@ -58,17 +58,18 @@ class SummaryReport(Report):
"""
This report produces a summary of the objects in the database.
"""
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the SummaryReport object that produces the report.
The arguments are:
database - the GRAMPS database instance
options_class - instance of the Options class for this report
options - instance of the Options class for this report
user - a gen.user.User() instance
"""
Report.__init__(self, database, options_class)
Report.__init__(self, database, options, user)
self.__db = database
def write_report(self):

View File

@ -57,23 +57,23 @@ import DateHandler
#------------------------------------------------------------------------
class TagReport(Report):
def __init__(self, database, options_class):
def __init__(self, database, options, user):
"""
Create the TagReport 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
options - instance of the Options class for this report
user - a gen.user.User() instance
This report needs the following parameters (class variables)
that come in the options class.
tag - The tag each object must match to be included.
"""
Report.__init__(self, database, options_class)
menu = options_class.menu
Report.__init__(self, database, options, user)
menu = options.menu
self.tag = menu.get_option_by_name('tag').get_value()
if not self.tag:
raise ReportError(_('Tag Report'),

View File

@ -89,7 +89,6 @@ from gen.plug.report import MenuReportOptions
import Utils
import constfunc
from gui.utils import ProgressMeter
import ThumbNails
import ImgManip
import gen.mime
@ -3443,7 +3442,6 @@ class EventPage(BasePage):
@param: title -- is the title of the web pages
@param: event_handle -- the event handle for the database
@param: progressmeter -- progress meter bar
"""
db = report.database
@ -4310,7 +4308,7 @@ class MediaListPage(BasePage):
return hyper
class ThumbnailPreviewPage(BasePage):
def __init__(self, report, title, ticker):
def __init__(self, report, title, cb_progress):
BasePage.__init__(self, report, title)
db = report.database
@ -4438,7 +4436,7 @@ class ThumbnailPreviewPage(BasePage):
index += 1
# increase progress meter...
ticker.step()
cb_progress()
# add body id element
body.attr = 'id ="ThumbnailPreview"'
@ -6244,7 +6242,7 @@ class AddressBookPage(BasePage):
class NavWebReport(Report):
def __init__(self, database, options):
def __init__(self, database, options, user):
"""
Create WebReport object that produces the report.
@ -6252,8 +6250,10 @@ class NavWebReport(Report):
database - the GRAMPS database instance
options - instance of the Options class for this report
user - instance of a gen.user.User()
"""
Report.__init__(self, database, options)
Report.__init__(self, database, options, user)
self._user = user
menu = options.menu
self.link_prefix_up = True
self.options = {}
@ -6419,8 +6419,6 @@ class NavWebReport(Report):
str(value))
return
self.progress = ProgressMeter(_("Narrated Web Site Report"), '')
# Build the person list
ind_list = self.build_person_list()
@ -6488,7 +6486,6 @@ class NavWebReport(Report):
if len(_WRONGMEDIAPATH) > 10:
error += '\n ...'
WarningDialog(_("Missing media objects:"), error)
self.progress.close()
def build_person_list(self):
"""
@ -6498,8 +6495,13 @@ class NavWebReport(Report):
# gets the person list and applies the requested filter
self.person_handles = {}
ind_list = self.database.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people())
ind_list = self.filter.apply(self.database, ind_list, self.progress)
self._user.begin_progress(_("Narrated Web Site Report"),
_('Applying Filter...'),
self.database.get_number_of_people())
ind_list = self.filter.apply(self.database, ind_list,
self._user.step_progress)
self._user.end_progress()
for handle in ind_list:
self.person_handles[handle] = True
return ind_list
@ -6577,27 +6579,27 @@ class NavWebReport(Report):
"""
creates IndividualListPage, IndividualPage, and gendex page
"""
self.progress.set_pass(_('Creating individual pages'), len(ind_list) + 1)
self.progress.step() # otherwise the progress indicator sits at 100%
# for a short while from the last step we did,
# which was to apply the privacy filter
self._user.begin_progress(_("Narrated Web Site Report"),
_('Creating individual pages'),
len(ind_list) + 1)
IndividualListPage(self, self.title, ind_list)
for person_handle in ind_list:
self.progress.step()
self._user.step_progress()
person = self.database.get_person_from_handle(person_handle)
IndividualPage(self, self.title, person, ind_list, place_list, source_list, place_lat_long)
self._user.end_progress()
if self.inc_gendex:
self.progress.set_pass(_('Creating GENDEX file'), len(ind_list))
self._user.beign_progress(_("Narrated Web Site Report"),
_('Creating GENDEX file'), len(ind_list))
fp_gendex = self.create_file("gendex", ext=".txt")
for person_handle in ind_list:
self.progress.step()
self._user.step_progress()
person = self.database.get_person_from_handle(person_handle)
self.write_gendex(fp_gendex, person)
self.close_file(fp_gendex)
self._user.end_progress()
def write_gendex(self, fp, person):
"""
@ -6631,7 +6633,8 @@ class NavWebReport(Report):
local_list = sort_people(self.database, ind_list)
self.progress.set_pass(_("Creating surname pages"), len(local_list))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating surname pages"), len(local_list))
SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_NAME,
self.surname_fname)
@ -6641,20 +6644,23 @@ class NavWebReport(Report):
for (surname, handle_list) in local_list:
SurnamePage(self, self.title, surname, handle_list)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def source_pages(self, source_list):
"""
creates SourceListPage and SourcePage
"""
self.progress.set_pass(_("Creating source pages"), len(source_list))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating source pages"), len(source_list))
SourceListPage(self, self.title, source_list.keys())
for key in source_list:
SourcePage(self, self.title, key, source_list)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def family_pages(self, ppl_handle_list, place_list, place_lat_long):
"""
@ -6662,8 +6668,9 @@ class NavWebReport(Report):
"""
db = self.database
# set ProgressMeter for Families/ Relationship pages...
self.progress.set_pass(_("Creating family pages..."), len(db.get_family_handles() ))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating family pages..."),
len(db.get_family_handles() ))
displayed = set()
FamilyListPage(self, self.title, ppl_handle_list, displayed)
@ -6678,20 +6685,23 @@ class NavWebReport(Report):
if family:
FamilyPage(self, self.title, person, family, place_list, ppl_handle_list, place_lat_long)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def place_pages(self, place_list, source_list):
"""
creates PlaceListPage and PlacePage
"""
self.progress.set_pass(_("Creating place pages"), len(place_list))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating place pages"), len(place_list))
PlaceListPage(self, self.title, place_list)
for place in place_list:
PlacePage(self, self.title, place, source_list, place_list)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def event_pages(self, ind_list):
"""
@ -6702,23 +6712,26 @@ class NavWebReport(Report):
# set up progress bar for event pages; using ind list
event_handle_list, event_types = build_event_data(db, ind_list)
self.progress.set_pass(_("Creating event pages"), len(event_handle_list))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating event pages"),
len(event_handle_list))
# send all data to the events list page
EventListPage(self, self.title, event_types, event_handle_list, ind_list)
for event_handle in event_handle_list:
# create individual event pages
EventPage(self, self.title, event_handle, ind_list)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def gallery_pages(self, source_list):
"""
creates MediaListPage and MediaPage
"""
self.progress.set_pass(_("Creating media pages"), len(self.photo_list))
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating media pages"),
len(self.photo_list))
MediaListPage(self, self.title)
@ -6734,9 +6747,10 @@ class NavWebReport(Report):
# Notice. Here self.photo_list[photo_handle] is used not self.photo_list
MediaPage(self, self.title, photo_handle, source_list, self.photo_list[photo_handle],
(prev, next, index, total))
self.progress.step()
self._user.step_progress()
prev = photo_handle
index += 1
self._user.end_progress()
def thumbnail_preview_page(self):
"""
@ -6744,9 +6758,11 @@ class NavWebReport(Report):
"""
db = self.database
self.progress.set_pass(_("Creating thumbnail preview page..."), len(self.photo_list))
ThumbnailPreviewPage(self, self.title, self.progress)
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating thumbnail preview page..."),
len(self.photo_list))
ThumbnailPreviewPage(self, self.title, self._user.step_progress)
self._user.end_progress()
def base_pages(self):
"""
@ -6782,8 +6798,10 @@ class NavWebReport(Report):
# set progress bar pass for Repositories
repository_size = len(repos_dict)
self.progress.set_pass(_('Creating repository pages'), repository_size)
self._user.begin_progress(_("Narrated Web Site Report"),
_('Creating repository pages'),
repository_size)
# RepositoryListPage Class
RepositoryListPage(self, self.title, repos_dict, keys)
@ -6791,7 +6809,8 @@ class NavWebReport(Report):
(repo, handle) = repos_dict[key]
RepositoryPage(self, self.title, repository, handle, source_list)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def addressbook_pages(self, ind_list):
"""
@ -6827,17 +6846,21 @@ class NavWebReport(Report):
AddressBookListPage(self, self.title, url_addr_res)
# begin Address Book pages
addr_size = len(url_addr_res)
self.progress.set_pass(_("Creating address book pages ..."), addr_size)
addr_size = len(url_addr_res)
self._user.begin_progress(_("Narrated Web Site Report"),
_("Creating address book pages ..."),
addr_size)
for (sort_name, person_handle, add, res, url) in url_addr_res:
AddressBookPage(self, self.title, person_handle, add, res, url)
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def build_subdirs(self, subdir, fname, up = False):
"""
If subdir is given, then two extra levels of subdirectory are inserted
between 'subdir' and the filename. The reason is to prevent directories with
too many entries.
between 'subdir' and the filename. The reason is to prevent directories
with too many entries.
For example, this may return "8/1/aec934857df74d36618"

View File

@ -61,7 +61,6 @@ from gen.plug.menu import BooleanOption, NumberOption, StringOption, \
import GrampsLocale
from QuestionDialog import WarningDialog
from Utils import probably_alive, xml_lang, get_researcher
from gui.utils import ProgressMeter
from DateHandler import displayer as _dd
from gen.display.name import displayer as _nd
@ -99,9 +98,10 @@ class WebCalReport(Report):
"""
Create WebCalReport object that produces the report.
"""
def __init__(self, database, options):
Report.__init__(self, database, options)
def __init__(self, database, options, user):
Report.__init__(self, database, options, user)
mgobn = lambda name:options.menu.get_option_by_name(name).get_value()
self._user = user
# class to do conversion of styled notes to html markup
self._backend = HtmlBackend()
@ -293,7 +293,9 @@ class WebCalReport(Report):
def __get_holidays(self, year):
# _('translation')
self.progress.set_pass((_('Calculating Holidays for year %04d') % year), 365)
self._user.begin_progress(_("Web Calendar Report"),
(_('Calculating Holidays for year %04d') % year),
365)
""" Get the holidays for the specified country and year """
holiday_table = libholiday.HolidayTable()
@ -304,9 +306,8 @@ class WebCalReport(Report):
holiday_names = holiday_table.get_holidays(month, day)
for holiday_name in holiday_names:
self.add_day_item(holiday_name, year, month, day, 'Holiday')
# increment progress bar
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def copy_calendar_files(self):
"""
@ -803,8 +804,8 @@ class WebCalReport(Report):
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
# generate progress pass for "WebCal"
self.progress.set_pass(_('Formatting months ...'), 12)
self._user.begin_progress(_("Web Calendar Report"),
_('Formatting months ...'), 12)
for month in range(1, 13):
cal_fname = _dd.long_months[month]
@ -854,8 +855,8 @@ class WebCalReport(Report):
# and close the file
self.XHTMLWriter(webcal, of)
# increase progress bar
self.progress.step()
self._user.step_progress()
self._user.end_progress()
def year_glance(self, year):
"""
@ -866,7 +867,8 @@ class WebCalReport(Report):
nr_up = 1 # Number of directory levels up to get to root
# generate progress pass for "Year At A Glance"
self.progress.set_pass(_('Creating Year At A Glance calendar'), 12)
self._user.begin_progress(_("Web Calendar Report"),
_('Creating Year At A Glance calendar'), 12)
of = self.create_file('fullyearlinked', str(year))
@ -903,7 +905,7 @@ class WebCalReport(Report):
content += monthly_calendar
# increase progress bar
self.progress.step()
self._user.step_progress()
# create blank line for stylesheets
# write footer section
@ -913,6 +915,7 @@ class WebCalReport(Report):
# send calendar page to web output
# and close the file
self.XHTMLWriter(yearglance, of)
self._user.end_progress()
def one_day(self, event_date, fname_date, day_list):
"""
@ -1045,12 +1048,16 @@ class WebCalReport(Report):
db = self.database
people = db.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'), db.get_number_of_people())
people = self.filter.apply(db, people, self.progress)
self._user.begin_progress(_("Web Calendar Report"),
_('Applying Filter...'),
db.get_number_of_people())
people = self.filter.apply(db, people, self._user.step_progress)
self._user.end_progress()
self.progress.set_pass(_("Reading database..."), len(people))
self._user.begin_progress(_("Web Calendar Report"),
_("Reading database..."), len(people))
for person in imap(db.get_person_from_handle, people):
self.progress.step()
self._user.step_progress()
family_list = person.get_family_handle_list()
birth_ref = person.get_birth_ref()
@ -1148,7 +1155,8 @@ class WebCalReport(Report):
'person' : short_name}
self.add_day_item(text, year, month, day, 'Anniversary')
self._user.end_progress()
def write_footer(self, nr_up):
"""
Writes the footer section of the pages
@ -1200,10 +1208,6 @@ class WebCalReport(Report):
"""
The short method that runs through each month and creates a page.
"""
# Create progress meter bar
self.progress = ProgressMeter(_("Web Calendar Report"), '')
# get data from database for birthdays/ anniversaries
self.collect_data(self.start_year)
@ -1251,9 +1255,6 @@ class WebCalReport(Report):
if self.fullyear:
self.year_glance(cal_year)
# Close the progress meter
self.progress.close()
# ---------------------------------------------------------------------------------------
# WebCalOptions; Creates the Menu
#----------------------------------------------------------------------------------------