Refactoring the report system. Decouple MenuOptions from the code that displays them. (Book Report is broken and needs to be fixed.)

svn: r9875
This commit is contained in:
Brian Matherly
2008-01-18 05:39:50 +00:00
parent ae1912f431
commit 07e1529f27
31 changed files with 1568 additions and 1004 deletions

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Donald N. Allingham
# Copyright (C) 2008 Brian 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
@@ -37,11 +38,12 @@ import time
#------------------------------------------------------------------------
from PluginUtils import Tool, register_tool, PluginWindows, \
MenuToolOptions, BooleanOption, PersonFilterOption, StringOption, \
NumberOption
NumberOption, PersonOption
import gen.lib
import Config
from BasicUtils import name_displayer
import Errors
from ReportBase import ReportUtils
#------------------------------------------------------------------------
#
@@ -52,12 +54,21 @@ class CalcEstDateOptions(MenuToolOptions):
""" Calculate Estimated Date options """
def add_menu_options(self, menu, dbstate):
self.__db = dbstate.get_database()
""" Adds the options """
category_name = _("Options")
filter = PersonFilterOption(_("Filter"), dbstate, 0, False)
filter.set_help(_("Select filter to restrict people"))
menu.add_option(category_name,"filter", filter)
self.__pid = PersonOption(_("Filter Person"))
self.__pid.set_help(_("The center person for the filter"))
menu.add_option(category_name, "pid", self.__pid)
self.__pid.connect('value-changed', self.__update_filters)
self.__filter = PersonFilterOption(_("Filter"), 0)
self.__filter.set_help(_("Select filter to restrict people"))
self.__update_filters()
menu.add_option(category_name, "filter", self.__filter)
self.__filter.connect('value-changed', self.__filter_changed)
source_text = StringOption(_("Source text"),
_("Calculated Date Estimates"))
@@ -105,6 +116,28 @@ class CalcEstDateOptions(MenuToolOptions):
0, 200)
num.set_help(_("Average years between two generations"))
menu.add_option(category_name, "AVG_GENERATION_GAP", num)
def __update_filters(self):
"""
Update the filter list based on the selected person
"""
gid = self.__pid.get_value()
person = self.__db.get_person_from_gramps_id(gid)
filter_list = ReportUtils.get_person_filters(person, False)
self.__filter.set_filters(filter_list)
def __filter_changed(self):
"""
Handle filter change. If the filter is not specific to a person,
disable the person option
"""
filter_value = self.__filter.get_value()
if filter_value in [1, 2, 3, 4]:
# Filters 0, 2, 3, 4 and 5 rely on the center person
self.__pid.set_available(True)
else:
# The rest don't
self.__pid.set_available(False)
class CalcToolManagedWindow(PluginWindows.ToolManagedWindowBatch):