Remove get_report_filters() function. Let reports define the filter options themselves.

svn: r8315
This commit is contained in:
Brian Matherly 2007-03-25 20:35:33 +00:00
parent ec0623d67d
commit 7ee6b12070
12 changed files with 172 additions and 303 deletions

View File

@ -1,3 +1,18 @@
2007-03-25 Brian Matherly <brian@gramps-project.org>
*src/ReportBase/_ReportUtils.py
*src/ReportBase/_CommandLineReport.py
*src/ReportBase/_BareReportDialog.py
*src/plugins/IndivComplete.py
*src/plugins/NarrativeWeb.py
*src/plugins/TimeLine.py
*src/plugins/GraphViz.py
*src/plugins/EventCmp.py
*src/plugins/StatisticsChart.py
*src/PluginUtils/_Options.py
*src/PluginUtils/_Tool.py
Remove get_report_filters() function. Let reports define the filter options
themselves.
2007-03-24 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: add support for new directory type
* src/GrampsDb/_GrampsDbBase.py: use normal pickle encoding

View File

@ -381,16 +381,6 @@ class OptionHandler:
def save_common_options(self):
pass
def get_filter_number(self):
if self.default_options_dict.has_key('filter'):
return self.options_dict.get('filter',
self.default_options_dict['filter'])
else:
return None
def set_filter_number(self,val):
self.options_dict['filter'] = val
def get_person_id(self):
return self.person_id
@ -457,13 +447,7 @@ class Options:
Enables semi-common options for this module.
The semi-common option is the option which GRAMPS is aware of,
but not common enough to be present in all modules. Here's the list
of possible keys for semi-commons:
'filter' - Filter number, selected among filters
available for this module. If defined,
get_module_filters() method must be defined
which returns the list of available filters.
but not common enough to be present in all modules.
A self.enable_dict dictionary MUST be defined here, whose keys
are the valid semi-common keys above, and whose values are the
@ -508,11 +492,3 @@ class Options:
in the add_user_options() method above.
"""
pass
def get_filter_number(self):
"""
Return number of a filter to use.
This method MUST NOT be overridden by subclasses.
"""
return self.handler.get_filter_number()

View File

@ -173,7 +173,6 @@ class CommandLineTool:
self.options_help = {
'id' : ["=ID","Gramps ID of a central person."],
'filter' : ["=num","Filter number."],
}
if noopt:
@ -209,18 +208,6 @@ class CommandLineTool:
self.options_help['id'].append(id_list)
self.options_help['id'].append(False)
if self.options_dict.has_key('filter'):
filter_num = self.options_dict['filter']
self.filters = self.option_class.get_report_filters(self.person)
self.option_class.handler.set_filter_number(filter_num)
filt_list = [ filt.get_name() for filt in self.filters ]
cust_filt_list = [ filt2.get_name() for filt2 in
CustomFilters.get_filters() ]
filt_list.extend(cust_filt_list)
self.options_help['filter'].append(filt_list)
self.options_help['filter'].append(True)
def show_options(self):
if not self.show:
return

View File

@ -45,7 +45,6 @@ import BaseDoc
import Utils
import ManagedWindow
from Filters import FilterComboBox,Rules
from _StyleComboBox import StyleComboBox
from _StyleEditor import StyleListDisplay
@ -106,7 +105,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
#self.output_notebook = None
#self.notebook_page = 1
self.pagecount_menu = None
self.filter_combo = None
self.extra_menu = None
self.extra_textbox = None
self.pagebreak_checkbox = None
@ -120,10 +118,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
self.style_name = self.options.handler.get_default_stylesheet_name()
(self.max_gen,self.page_breaks) = \
self.options.handler.get_report_generations()
try:
self.local_filters = self.options.get_report_filters(self.person)
except AttributeError:
self.local_filters = []
window = gtk.Dialog('GRAMPS')
self.set_window(window,None,self.get_title())
@ -200,12 +194,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
created when needed. All subclasses should probably override
this function."""
return "basic_report.xml"
def get_report_filters(self):
"""Return the data used to fill out the 'filter' combo box in
the report options box. The return value is the list of
strings to be inserted into the pulldown."""
return []
def get_report_generations(self):
"""Return the default number of generations to start the
@ -398,7 +386,7 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
function relies on several report_xxx() customization
functions to determine which of the items should be present in
this box. *All* of these items are optional, although the
generations fields and the filter combo box are used in most
generations fields is used in most
(but not all) dialog boxes."""
(em_label, extra_map, preset, em_tip) = self.get_report_extra_menu_info()
@ -409,8 +397,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
max_rows = max_rows + 2
#if self.page_breaks:
# max_rows = max_rows + 1
if len(self.local_filters):
max_rows = max_rows + 1
if extra_map:
max_rows = max_rows + 1
@ -430,19 +416,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
table.set_border_width(6)
self.notebook.append_page(table,label)
row += 1
if len(self.local_filters):
self.filter_combo = FilterComboBox()
label = gtk.Label("%s:" % _("Filter"))
label.set_alignment(0.0,0.5)
table.attach(label, 1, 2, row, row+1, gtk.SHRINK|gtk.FILL,
gtk.SHRINK|gtk.FILL)
table.attach(self.filter_combo, 2, 3, row, row+1,
gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
self.filter_combo.set(self.local_filters)
self.filter_combo.set_active(self.options.handler.get_filter_number())
row += 1
# Set up the generations spin and page break checkbox
if self.max_gen:
@ -577,17 +550,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
if self.max_gen or self.pg_brk:
self.options.handler.set_report_generations(self.max_gen,self.pg_brk)
if self.filter_combo:
try:
self.filter = self.filter_combo.get_value()
active = max(0,self.filter_combo.get_active())
self.options.handler.set_filter_number(active)
except:
print "Error setting filter. Proceeding with 'Everyone'"
self.filter = Rules.Person.Everyone([])
else:
self.filter = None
if self.extra_menu:
self.report_menu = self.extra_menu.get_menu().get_active().get_data("d")
else:

View File

@ -75,7 +75,6 @@ class CommandLineReport:
'papero' : ["=num","Paper orientation number."],
'template' : ["=name","Template name (HTML only)."],
'id' : ["=ID","Gramps ID of a central person. MANDATORY"],
'filter' : ["=num","Filter number."],
'gen' : ["=num","Number of generations to follow."],
'pagebbg' : ["=0/1","Page break between generations."],
}
@ -115,18 +114,6 @@ class CommandLineReport:
self.options_help['id'].append(id_list)
self.options_help['id'].append(False)
if self.options_dict.has_key('filter'):
filter_num = self.options_dict['filter']
self.filters = self.option_class.get_report_filters(self.person)
self.option_class.handler.set_filter_number(filter_num)
filt_list = [ filt.get_name() for filt in self.filters ]
cust_filt_list = [ filt2.get_name() for filt2 in
CustomFilters.get_filters() ]
filt_list.extend(cust_filt_list)
self.options_help['filter'].append(filt_list)
self.options_help['filter'].append(True)
if self.options_dict.has_key('gen'):
max_gen = self.options_dict['gen']
page_breaks = self.options_dict['pagebbg']

View File

@ -2451,3 +2451,59 @@ def get_endnotes(sref_map,obj):
str = msg.getvalue()
msg.close()
return str
#-------------------------------------------------------------------------
#
# People Filters
#
#-------------------------------------------------------------------------
def get_person_filters(person,include_single=True):
"""
Returns a list of filters that are relevant for the given person
@param person: the person the filters should apply to.
@type person: L{RelLib.Person}
@param include_single: include a filter to include the single person
@type person: boolean
"""
from Filters import GenericFilter, Rules, CustomFilters
if person:
name = person.get_primary_name().get_name()
gramps_id = person.get_gramps_id()
else:
# Do this in case of command line options query (show=filter)
name = 'PERSON'
gramps_id = ''
if include_single == True:
filt_id = GenericFilter()
filt_id.set_name(name)
filt_id.add_rule(Rules.Person.HasIdOf([gramps_id]))
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id,1]))
df = GenericFilter()
df.set_name(_("Descendant Families of %s") % name)
df.add_rule(Rules.Person.IsDescendantFamilyOf([gramps_id,1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id,1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
if include_single == True:
the_filters = [filt_id,all,des,df,ans,com]
else:
the_filters = [all,des,df,ans,com]
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters

View File

@ -53,6 +53,7 @@ import Errors
import DateHandler
from QuestionDialog import WarningDialog
from PluginUtils import Tool, register_tool
from ReportBase import ReportUtils
from GrampsDisplay import help
import ManagedWindow
@ -138,7 +139,7 @@ class EventComparison(Tool.Tool,ManagedWindow.ManagedWindow):
the_filters.extend(CustomFilters.get_filters('Person'))
self.filter_menu = build_filter_menu(the_filters)
filter_num = self.options.handler.get_filter_number()
filter_num = self.options.handler.options_dict['filter']
self.filter_menu.set_active(filter_num)
self.filter_menu.show()
self.filters.set_menu(self.filter_menu)
@ -171,7 +172,7 @@ class EventComparison(Tool.Tool,ManagedWindow.ManagedWindow):
progress_bar.step()
progress_bar.close()
self.options.handler.set_filter_number(self.filters.get_history())
self.options.handler.options_dict['filter'] = self.filters.get_history()
# Save options
self.options.handler.save_options()
@ -428,10 +429,16 @@ class EventComparisonOptions(Tool.ToolOptions):
def __init__(self,name,person_id=None):
Tool.ToolOptions.__init__(self,name,person_id)
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'filter' : 0,
}
filters = ReportUtils.get_person_filters(None)
self.options_help = {
'filter' : ("=num","Filter number.",
[ filt.get_name() for filt in filters ],
True ),
}
#-------------------------------------------------------------------------

View File

@ -253,8 +253,8 @@ class GraphViz:
self.notesize = options['notesize']
self.note = options['note']
filter_num = options_class.get_filter_number()
filters = options_class.get_report_filters(person)
filter_num = options_class.handler.options_dict['filter']
filters = ReportUtils.get_person_filters(person,include_single=False)
self.filter = filters[filter_num]
the_buffer = self.get_report()
@ -591,6 +591,7 @@ class GraphVizOptions(ReportOptions):
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'filter' : 0,
'font' : "",
'fontsize' : 14,
'latin' : 1,
@ -614,8 +615,11 @@ class GraphVizOptions(ReportOptions):
'notesize' : 32,
'gvof' : 'ps',
}
filters = ReportUtils.get_person_filters(None,include_single=False)
self.options_help = {
'filter' : ("=num","Filter number.",
[ filt.get_name() for filt in filters ],
True ),
'font' : ("=str","Font to use in the report.",
[ "%s\t%s" % (item[0],item[1]) for item in _options.fonts ],
False),
@ -678,42 +682,6 @@ class GraphVizOptions(ReportOptions):
False),
}
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
}
def get_report_filters(self,person):
"""Set up the list of possible content filters."""
if person:
name = person.get_primary_name().get_name()
gramps_id = person.get_gramps_id()
else:
name = 'PERSON'
gramps_id = ''
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id,1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id,1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
the_filters = [all,des,ans,com]
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters
def make_doc_menu(self,dialog,active=None):
pass
@ -738,6 +706,16 @@ class GraphVizOptions(ReportOptions):
dialog.make_doc_menu = self.make_doc_menu
dialog.format_menu = GraphicsFormatComboBox()
dialog.format_menu.set(self.options_dict['gvof'])
filter_index = self.options_dict['filter']
filter_list = ReportUtils.get_person_filters(dialog.person,include_single=False)
self.filter_menu = gtk.combo_box_new_text()
for filter in filter_list:
self.filter_menu.append_text(filter.get_name())
if filter_index > len(filter_list):
filter_index = 0
self.filter_menu.set_active(filter_index)
dialog.add_option('Filter',self.filter_menu)
# Content options tab
msg = _("Include Birth, Marriage and Death dates")
@ -932,6 +910,7 @@ class GraphVizOptions(ReportOptions):
self.place_cause_cb.set_sensitive(self.includedates_cb.get_active())
def parse_user_options(self,dialog):
self.options_dict['filter'] = int(self.filter_menu.get_active())
self.options_dict['incdate'] = int(self.includedates_cb.get_active())
self.options_dict['url'] = int(self.includeurl_cb.get_active())
self.options_dict['margin'] = self.margin_sb.get_value()

View File

@ -82,8 +82,8 @@ class IndivCompleteReport(Report):
self.use_srcs = options_class.handler.options_dict['cites']
filter_num = options_class.get_filter_number()
filters = options_class.get_report_filters(person)
filter_num = options_class.handler.options_dict['filter']
filters = ReportUtils.get_person_filters(person)
self.filter = filters[filter_num]
self.sref_map = {}
@ -562,60 +562,34 @@ class IndivCompleteOptions(ReportOptions):
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'filter' : 0,
'cites' : 1,
}
filters = ReportUtils.get_person_filters(None)
self.options_help = {
'filter' : ("=num","Filter number.",
[ filt.get_name() for filt in filters ],
True ),
'cites' : ("=0/1","Whether to cite sources.",
["Do not cite sources","Cite sources"],
True),
["Do not cite sources","Cite sources"],
True),
}
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
}
def get_report_filters(self,person):
"""Set up the list of possible content filters."""
if person:
name = _nd.display(person)
gramps_id = person.get_gramps_id()
else:
name = 'PERSON'
gramps_id = ''
filt_id = GenericFilter()
filt_id.set_name(name)
filt_id.add_rule(Rules.Person.HasIdOf([gramps_id]))
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id,1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id,1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
the_filters = [filt_id,all,des,ans,com]
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters
def add_user_options(self,dialog):
"""
Override the base class add_user_options task to add a menu that allows
the user to select the sort method.
"""
filter_index = self.options_dict['filter']
filter_list = ReportUtils.get_person_filters(dialog.person)
self.filter_menu = gtk.combo_box_new_text()
for filter in filter_list:
self.filter_menu.append_text(filter.get_name())
if filter_index > len(filter_list):
filter_index = 0
self.filter_menu.set_active(filter_index)
dialog.add_option('Filter',self.filter_menu)
self.use_srcs = gtk.CheckButton(_('Include Source Information'))
self.use_srcs.set_active(self.options_dict['cites'])
dialog.add_option('',self.use_srcs)
@ -624,7 +598,8 @@ class IndivCompleteOptions(ReportOptions):
"""
Parses the custom options that we have added.
"""
self.options_dict['cites'] = int(self.use_srcs.get_active ())
self.options_dict['filter'] = int(self.filter_menu.get_active())
self.options_dict['cites'] = int(self.use_srcs.get_active())
def make_default_style(self,default_style):
"""Make the default output style for the Individual Complete Report."""

View File

@ -2098,8 +2098,8 @@ class WebReport(Report):
self.start_person = person
self.options = options
filter_num = options.get_filter_number()
filters = options.get_report_filters(person)
filter_num = options.handler.options_dict['NWEBfilter']
filters = ReportUtils.get_person_filters(person,include_single=False)
self.filter = filters[filter_num]
self.target_path = options.handler.options_dict['NWEBod']
@ -2416,6 +2416,7 @@ class WebReportOptions(ReportOptions):
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'NWEBfilter' : 0,
'NWEBarchive' : 0,
'NWEBgraph' : 1,
'NWEBgraphgens' : 4,
@ -2443,46 +2444,6 @@ class WebReportOptions(ReportOptions):
self.options_help = {
}
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
}
def get_report_filters(self,person):
"""Set up the list of possible content filters."""
if person:
name = person.get_primary_name().get_name()
gramps_id = person.get_gramps_id()
else:
name = 'PERSON'
gramps_id = ''
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id,1]))
df = GenericFilter()
df.set_name(_("Descendant Families of %s") % name)
df.add_rule(Rules.Person.IsDescendantFamilyOf([gramps_id,1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id,1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
the_filters = [all,des,df,ans,com]
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters
def add_user_options(self,dialog):
priv_msg = _("Do not include records marked private")
restrict_msg = _("Restrict information on living people")
@ -2493,6 +2454,17 @@ class WebReportOptions(ReportOptions):
gallery_msg = _("Include images and media objects")
download_msg = _("Include download page")
graph_msg = _("Include ancestor graph")
filter_index = self.options_dict['NWEBfilter']
filter_list = ReportUtils.get_person_filters(dialog.person,
include_single=False)
self.filter_menu = gtk.combo_box_new_text()
for filter in filter_list:
self.filter_menu.append_text(filter.get_name())
if filter_index > len(filter_list):
filter_index = 0
self.filter_menu.set_active(filter_index)
dialog.add_option('Filter',self.filter_menu)
self.no_private = gtk.CheckButton(priv_msg)
self.no_private.set_active(not self.options_dict['NWEBincpriv'])
@ -2647,6 +2619,7 @@ class WebReportOptions(ReportOptions):
"""Parse the privacy options frame of the dialog. Save the
user selected choices for later use."""
self.options_dict['NWEBfilter'] = int(self.filter_menu.get_active())
self.options_dict['NWEBrestrictinfo'] = int(self.restrict_living.get_active())
self.options_dict['NWEBrestrictyears'] = int(self.restrict_years.get_text())
self.options_dict['NWEBincpriv'] = int(not self.no_private.get_active())

View File

@ -478,8 +478,8 @@ class StatisticsChart(Report):
"""
Report.__init__(self,database,person,options_class)
filter_num = options_class.get_filter_number()
filters = options_class.get_report_filters(person)
filter_num = options_class.handler.options_dict['filter']
filters = ReportUtils.get_person_filters(person,False)
filterfun = filters[filter_num]
options = options_class.handler.options_dict
@ -760,6 +760,7 @@ class StatisticsChartOptions(ReportOptions):
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'filter' : 0,
'gender' : Person.UNKNOWN,
'sortby' : _options.SORT_VALUE,
'reverse' : 0,
@ -772,6 +773,7 @@ class StatisticsChartOptions(ReportOptions):
self.options_dict[key] = 0
self.options_dict['data_gender'] = 1
filters = ReportUtils.get_person_filters(None,False)
self.options_help = {
'gender' : ("=num", "Genders included",
["%d\t%s" % (item[0], item[1]) for item in _options.genders],
@ -796,14 +798,6 @@ class StatisticsChartOptions(ReportOptions):
["Leave chart with this data out", "Include chart with this data"],
True)
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
}
def make_default_style(self, default_style):
"""Make the default output style for the Statistics report."""
f = BaseDoc.FontStyle()
@ -824,43 +818,21 @@ class StatisticsChartOptions(ReportOptions):
p.set_description(_("The style used for the title of the page."))
default_style.add_style("SC-Title",p)
def get_report_filters(self, person):
"""Set up the list of possible content filters."""
if person:
name = person.get_primary_name().get_name()
gramps_id = person.get_gramps_id()
else:
name = 'PERSON'
gramps_id = ''
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id, 1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id, 1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
the_filters = [all, des, ans, com]
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters
def add_user_options(self, dialog):
"""
Override the base class add_user_options task to add
report specific options
"""
filter_index = self.options_dict['filter']
filter_list = ReportUtils.get_person_filters(dialog.person,False)
self.filter_menu = gtk.combo_box_new_text()
for filter in filter_list:
self.filter_menu.append_text(filter.get_name())
if filter_index > len(filter_list):
filter_index = 0
self.filter_menu.set_active(filter_index)
dialog.add_option('Filter',self.filter_menu)
# how to sort the data
self.sort_menu = gtk.combo_box_new_text()
for item_idx in range(len(_options.sorts)):
@ -950,6 +922,7 @@ class StatisticsChartOptions(ReportOptions):
"""
Parses the custom options that we have added.
"""
self.options_dict['filter'] = int(self.filter_menu.get_active())
self.options_dict['sortby'] = _options.sorts[self.sort_menu.get_active()][0]
self.options_dict['reverse'] = int(self.reverse.get_active())
self.options_dict['year_to'] = int(self.to_box.get_value_as_int())

View File

@ -84,8 +84,8 @@ class TimeLine(Report):
Report.__init__(self,database,person,options_class)
filter_num = options_class.get_filter_number()
filters = options_class.get_report_filters(person)
filter_num = options_class.handler.options_dict['filter']
filters = ReportUtils.get_person_filters(person,False)
self.filter = filters[filter_num]
name = NameDisplay.displayer.display_formal(person)
@ -360,21 +360,20 @@ class TimeLineOptions(ReportOptions):
def set_new_options(self):
# Options specific for this report
self.options_dict = {
'filter' : 0,
'sortby' : 0,
}
filters = ReportUtils.get_person_filters(None,False)
self.options_help = {
'filter' : ("=num","Filter number.",
[ filt.get_name() for filt in filters ],
True ),
'sortby' : ("=num","Number of a sorting function",
[item[0] for item in
self.get_sort_functions(Sort.Sort(None))],
True),
}
def enable_options(self):
# Semi-common options that should be enabled for this report
self.enable_dict = {
'filter' : 0,
}
def make_default_style(self,default_style):
"""Make the default output style for the Timeline report."""
f = BaseDoc.FontStyle()
@ -402,36 +401,6 @@ class TimeLineOptions(ReportOptions):
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_description(_("The style used for the title of the page."))
default_style.add_style("TLG-Title",p)
def get_report_filters(self,person):
"""Set up the list of possible content filters."""
if person:
name = person.get_primary_name().get_name()
gramps_id = person.get_gramps_id()
else:
name = 'PERSON'
gramps_id = ''
all = GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(Rules.Person.Everyone([]))
des = GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(Rules.Person.IsDescendantOf([gramps_id,1]))
ans = GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(Rules.Person.IsAncestorOf([gramps_id,1]))
com = GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(Rules.Person.HasCommonAncestorWith([gramps_id]))
the_filters = [all,des,ans,com]
from Filters import CustomFilters
the_filters.extend(CustomFilters.get_filters('Person'))
return the_filters
def get_sort_functions(self,sort):
return [
@ -444,6 +413,15 @@ class TimeLineOptions(ReportOptions):
Override the base class add_user_options task to add a menu that allows
the user to select the sort method.
"""
filter_index = self.options_dict['filter']
filter_list = ReportUtils.get_person_filters(dialog.person,False)
self.filter_menu = gtk.combo_box_new_text()
for filter in filter_list:
self.filter_menu.append_text(filter.get_name())
if filter_index > len(filter_list):
filter_index = 0
self.filter_menu.set_active(filter_index)
dialog.add_option('Filter',self.filter_menu)
self.sort_menu = gtk.combo_box_new_text()
@ -459,6 +437,7 @@ class TimeLineOptions(ReportOptions):
"""
Parses the custom options that we have added.
"""
self.options_dict['filter'] = int(self.filter_menu.get_active())
self.options_dict['sortby'] = self.sort_menu.get_active()
#------------------------------------------------------------------------