Simplify using partials and lambdas

svn: r16703
This commit is contained in:
Gerald Britton 2011-02-23 14:53:00 +00:00
parent 449aa7a130
commit 8579483616

View File

@ -24,6 +24,13 @@
"""Reports/Text Reports/Family Group Report""" """Reports/Text Reports/Family Group Report"""
#------------------------------------------------------------------------
#
# Python Library
#
#------------------------------------------------------------------------
from functools import partial
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# GRAMPS # GRAMPS
@ -76,17 +83,19 @@ class FamilyGroup(Report):
else: else:
self.family_handle = None self.family_handle = None
self.recursive = menu.get_option_by_name('recursive').get_value() get_option_by_name = menu.get_option_by_name
self.missingInfo = menu.get_option_by_name('missinginfo').get_value() get_value = lambda name:get_option_by_name(name).get_value()
self.generations = menu.get_option_by_name('generations').get_value() self.recursive = get_value('recursive')
self.incParEvents = menu.get_option_by_name('incParEvents').get_value() self.missingInfo = get_value('missinginfo')
self.incParAddr = menu.get_option_by_name('incParAddr').get_value() self.generations = get_value('generations')
self.incParNotes = menu.get_option_by_name('incParNotes').get_value() self.incParEvents = get_value('incParEvents')
self.incParNames = menu.get_option_by_name('incParNames').get_value() self.incParAddr = get_value('incParAddr')
self.incParMar = menu.get_option_by_name('incParMar').get_value() self.incParNotes = get_value('incParNotes')
self.incRelDates = menu.get_option_by_name('incRelDates').get_value() self.incParNames = get_value('incParNames')
self.incChiMar = menu.get_option_by_name('incChiMar').get_value() self.incParMar = get_value('incParMar')
self.includeAttrs = menu.get_option_by_name('incattrs').get_value() self.incRelDates = get_value('incRelDates')
self.incChiMar = get_value('incChiMar')
self.includeAttrs = get_value('incattrs')
def dump_parent_event(self, name,event): def dump_parent_event(self, name,event):
place = "" place = ""
@ -606,73 +615,73 @@ class FamilyGroupOptions(MenuReportOptions):
def add_menu_options(self, menu): def add_menu_options(self, menu):
########################## ##########################
category_name = _("Report Options") add_option = partial(menu.add_option, _("Report Options"))
########################## ##########################
family_id = FamilyOption(_("Center Family")) family_id = FamilyOption(_("Center Family"))
family_id.set_help(_("The center family for the report")) family_id.set_help(_("The center family for the report"))
menu.add_option(category_name, "family_id", family_id) add_option("family_id", family_id)
recursive = BooleanOption(_('Recursive'),False) recursive = BooleanOption(_('Recursive'),False)
recursive.set_help(_("Create reports for all descendants " recursive.set_help(_("Create reports for all descendants "
"of this family.")) "of this family."))
menu.add_option(category_name,"recursive",recursive) add_option("recursive", recursive)
########################## ##########################
category_name = _("Include") add_option = partial(menu.add_option, _("Include"))
########################## ##########################
generations = BooleanOption(_("Generation numbers " generations = BooleanOption(_("Generation numbers "
"(recursive only)"),True) "(recursive only)"),True)
generations.set_help(_("Whether to include the generation on each " generations.set_help(_("Whether to include the generation on each "
"report (recursive only).")) "report (recursive only)."))
menu.add_option(category_name,"generations",generations) add_option("generations", generations)
incParEvents = BooleanOption(_("Parent Events"),False) incParEvents = BooleanOption(_("Parent Events"),False)
incParEvents.set_help(_("Whether to include events for parents.")) incParEvents.set_help(_("Whether to include events for parents."))
menu.add_option(category_name,"incParEvents",incParEvents) add_option("incParEvents", incParEvents)
incParAddr = BooleanOption(_("Parent Addresses"),False) incParAddr = BooleanOption(_("Parent Addresses"),False)
incParAddr.set_help(_("Whether to include addresses for parents.")) incParAddr.set_help(_("Whether to include addresses for parents."))
menu.add_option(category_name,"incParAddr",incParAddr) add_option("incParAddr", incParAddr)
incParNotes = BooleanOption(_("Parent Notes"),False) incParNotes = BooleanOption(_("Parent Notes"),False)
incParNotes.set_help(_("Whether to include notes for parents.")) incParNotes.set_help(_("Whether to include notes for parents."))
menu.add_option(category_name,"incParNotes",incParNotes) add_option("incParNotes", incParNotes)
incattrs = BooleanOption(_("Parent Attributes"),False) incattrs = BooleanOption(_("Parent Attributes"),False)
incattrs.set_help(_("Whether to include attributes.")) incattrs.set_help(_("Whether to include attributes."))
menu.add_option(category_name,"incattrs",incattrs) add_option("incattrs", incattrs)
incParNames = BooleanOption(_("Alternate Parent Names"),False) incParNames = BooleanOption(_("Alternate Parent Names"),False)
incParNames.set_help(_("Whether to include alternate " incParNames.set_help(_("Whether to include alternate "
"names for parents.")) "names for parents."))
menu.add_option(category_name,"incParNames",incParNames) add_option("incParNames", incParNames)
incParMar = BooleanOption(_("Parent Marriage"),False) incParMar = BooleanOption(_("Parent Marriage"),False)
incParMar.set_help(_("Whether to include marriage information " incParMar.set_help(_("Whether to include marriage information "
"for parents.")) "for parents."))
menu.add_option(category_name,"incParMar",incParMar) add_option("incParMar", incParMar)
incRelDates = BooleanOption(_("Dates of Relatives"),False) incRelDates = BooleanOption(_("Dates of Relatives"),False)
incRelDates.set_help(_("Whether to include dates for relatives " incRelDates.set_help(_("Whether to include dates for relatives "
"(father, mother, spouse).")) "(father, mother, spouse)."))
menu.add_option(category_name,"incRelDates",incRelDates) add_option("incRelDates", incRelDates)
incChiMar = BooleanOption(_("Children Marriages"),True) incChiMar = BooleanOption(_("Children Marriages"),True)
incChiMar.set_help(_("Whether to include marriage information " incChiMar.set_help(_("Whether to include marriage information "
"for children.")) "for children."))
menu.add_option(category_name,"incChiMar",incChiMar) add_option("incChiMar", incChiMar)
########################## ##########################
category_name = _("Missing Information") add_option = partial(menu.add_option, _("Missing Information"))
########################## ##########################
missinginfo = BooleanOption(_("Print fields for missing " missinginfo = BooleanOption(_("Print fields for missing "
"information"),True) "information"),True)
missinginfo.set_help(_("Whether to include fields for missing " missinginfo.set_help(_("Whether to include fields for missing "
"information.")) "information."))
menu.add_option(category_name,"missinginfo",missinginfo) add_option("missinginfo", missinginfo)
def make_default_style(self,default_style): def make_default_style(self,default_style):
"""Make default output style for the Family Group Report.""" """Make default output style for the Family Group Report."""