From feb36c5ce4b57a29ae305a87f322395b253666ac Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Wed, 17 Apr 2013 20:49:14 +0000 Subject: [PATCH] refactor: move name_format into stdoptions.py svn: r22008 --- gramps/gen/plug/report/stdoptions.py | 21 ++++++++++++++-- gramps/plugins/drawreport/calendarreport.py | 17 +++++++------ gramps/plugins/textreport/ancestorreport.py | 13 ++-------- gramps/plugins/textreport/birthdayreport.py | 9 ++----- gramps/plugins/textreport/descendreport.py | 11 ++------- .../plugins/textreport/detancestralreport.py | 12 ++-------- .../plugins/textreport/detdescendantreport.py | 10 +------- gramps/plugins/textreport/endoflinereport.py | 21 ++++++---------- gramps/plugins/textreport/familygroup.py | 24 +++++++------------ gramps/plugins/textreport/indivcomplete.py | 21 ++++++---------- gramps/plugins/textreport/kinshipreport.py | 14 +++-------- .../textreport/numberofancestorsreport.py | 15 ++++-------- 12 files changed, 66 insertions(+), 122 deletions(-) diff --git a/gramps/gen/plug/report/stdoptions.py b/gramps/gen/plug/report/stdoptions.py index a84d9e5b8..9bf12d3a5 100644 --- a/gramps/gen/plug/report/stdoptions.py +++ b/gramps/gen/plug/report/stdoptions.py @@ -1,7 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright 2013 John Ralls +# Copyright (C) 2013 John Ralls +# Copyright (C) 2013 Paul Franklin # # 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 @@ -22,14 +23,17 @@ """ Commonly used report options. Call the function, don't copy the code! """ + #------------------------------------------------------------------------- # # gramps modules # #------------------------------------------------------------------------- -from gramps.gen.plug.menu import EnumeratedListOption from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +from gramps.gen.display.name import displayer as global_name_display +from gramps.gen.plug.menu import EnumeratedListOption + #------------------------------------------------------------------------- # # StandardReportOptions @@ -49,3 +53,16 @@ def add_localization_option(menu, category): trans.add_item(languages[language], language) trans.set_help(_("The translation to be used for the report.")) menu.add_option(category, "trans", trans) + +def add_name_format_option(menu, category): + """ + Insert an option for changing the report's name format to a + report-specific format instead of the user's Edit=>Preferences choice + """ + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + format_list = global_name_display.get_name_format() + for number, name, format_string, whether_active in format_list: + name_format.add_item(number, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category, "name_format", name_format) diff --git a/gramps/plugins/drawreport/calendarreport.py b/gramps/plugins/drawreport/calendarreport.py index 8ffdc9a34..231c68189 100644 --- a/gramps/plugins/drawreport/calendarreport.py +++ b/gramps/plugins/drawreport/calendarreport.py @@ -50,6 +50,7 @@ from gramps.gen.plug.menu import (BooleanOption, StringOption, NumberOption, from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions from gramps.gen.utils.alive import probably_alive from gramps.gen.datehandler import displayer as _dd, long_days from gramps.gen.lib import Date, EventRoleType, EventType, Name, NameType, Person, Surname @@ -412,7 +413,12 @@ class CalendarOptions(MenuReportOptions): def add_menu_options(self, menu): """ Add the options for the graphical calendar """ - add_option = partial(menu.add_option, _("Report Options")) + + ########################## + category_name = _("Report Options") + add_option = partial(menu.add_option, category_name) + ########################## + year = NumberOption(_("Year of calendar"), time.localtime()[0], 1000, 3000) year.set_help(_("Year of calendar")) @@ -430,14 +436,7 @@ class CalendarOptions(MenuReportOptions): self.__update_filters() - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = _nd.get_name_format() - name_format = EnumeratedListOption(_("Name format"), fmt_list[0][0]) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - add_option("name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) country = EnumeratedListOption(_("Country for holidays"), 0) holiday_table = libholiday.HolidayTable() diff --git a/gramps/plugins/textreport/ancestorreport.py b/gramps/plugins/textreport/ancestorreport.py index fe9bdf3ea..33db9da3b 100644 --- a/gramps/plugins/textreport/ancestorreport.py +++ b/gramps/plugins/textreport/ancestorreport.py @@ -43,8 +43,7 @@ _ = glocale.translation.gettext from gramps.gen.display.name import displayer as global_name_display from gramps.gen.errors import ReportError from gramps.gen.lib import ChildRefType -from gramps.gen.plug.menu import (BooleanOption, NumberOption, PersonOption, - EnumeratedListOption) +from gramps.gen.plug.menu import (BooleanOption, NumberOption, PersonOption) from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) @@ -272,15 +271,7 @@ class AncestorOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) maxgen = NumberOption(_("Generations"), 10, 1, 100) maxgen.set_help(_("The number of generations to include in the report")) diff --git a/gramps/plugins/textreport/birthdayreport.py b/gramps/plugins/textreport/birthdayreport.py index b64d8965a..8bfe121e2 100644 --- a/gramps/plugins/textreport/birthdayreport.py +++ b/gramps/plugins/textreport/birthdayreport.py @@ -52,6 +52,7 @@ from gramps.gen.plug.menu import (BooleanOption, StringOption, NumberOption, from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions from gramps.gen.utils.alive import probably_alive from gramps.gen.datehandler import displayer as _dd, long_days @@ -384,13 +385,7 @@ class BirthdayOptions(MenuReportOptions): self.__update_filters() - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) country = EnumeratedListOption(_("Country for holidays"), 0) holiday_table = libholiday.HolidayTable() diff --git a/gramps/plugins/textreport/descendreport.py b/gramps/plugins/textreport/descendreport.py index 0895b7480..1b3d13fca 100644 --- a/gramps/plugins/textreport/descendreport.py +++ b/gramps/plugins/textreport/descendreport.py @@ -52,6 +52,7 @@ from gramps.gen.errors import ReportError from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions from gramps.gen.datehandler import get_date from gramps.gen.sort import Sort from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, @@ -394,15 +395,7 @@ class DescendantOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) numbering = EnumeratedListOption(_("Numbering system"), "Simple") numbering.set_items([ diff --git a/gramps/plugins/textreport/detancestralreport.py b/gramps/plugins/textreport/detancestralreport.py index 87fd1f129..7b5da7e4f 100644 --- a/gramps/plugins/textreport/detancestralreport.py +++ b/gramps/plugins/textreport/detancestralreport.py @@ -49,7 +49,7 @@ from gramps.gen.lib import EventType, FamilyRelType, Person, NoteType from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, FONT_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from gramps.gen.plug.menu import BooleanOption, NumberOption, PersonOption, EnumeratedListOption +from gramps.gen.plug.menu import BooleanOption, NumberOption, PersonOption from gramps.gen.plug.report import ( Report, Bibliography ) from gramps.gen.plug.report import endnotes from gramps.gen.plug.report import utils as ReportUtils @@ -720,15 +720,7 @@ class DetAncestorOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) addopt("pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - addopt("name_format", name_format) + stdoptions.add_name_format_option(menu, category) gen = NumberOption(_("Generations"),10,1,100) gen.set_help(_("The number of generations to include in the report")) diff --git a/gramps/plugins/textreport/detdescendantreport.py b/gramps/plugins/textreport/detdescendantreport.py index e89b60f90..e935e0086 100644 --- a/gramps/plugins/textreport/detdescendantreport.py +++ b/gramps/plugins/textreport/detdescendantreport.py @@ -886,15 +886,7 @@ class DetDescendantOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) add_option("pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - add_option("name_format", name_format) + stdoptions.add_name_format_option(menu, category) numbering = EnumeratedListOption(_("Numbering system"), "Henry") numbering.set_items([ diff --git a/gramps/plugins/textreport/endoflinereport.py b/gramps/plugins/textreport/endoflinereport.py index 78e0c5ed9..0d5ae779a 100644 --- a/gramps/plugins/textreport/endoflinereport.py +++ b/gramps/plugins/textreport/endoflinereport.py @@ -39,13 +39,15 @@ _ = glocale.translation.gettext #------------------------------------------------------------------------ from gramps.gen.display.name import displayer as global_name_display from gramps.gen.errors import ReportError -from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, - TableCellStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, - PARA_ALIGN_CENTER) -from gramps.gen.plug.menu import (PersonOption, EnumeratedListOption) +from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, + TableStyle, TableCellStyle, + FONT_SANS_SERIF, INDEX_TYPE_TOC, + PARA_ALIGN_CENTER) +from gramps.gen.plug.menu import PersonOption from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions from gramps.gen.datehandler import get_date #------------------------------------------------------------------------ @@ -255,16 +257,7 @@ class EndOfLineOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) - + stdoptions.add_name_format_option(menu, category_name) def make_default_style(self, default_style): """Make the default output style for the End of Line Report.""" diff --git a/gramps/plugins/textreport/familygroup.py b/gramps/plugins/textreport/familygroup.py index 13b15210b..5eebbb354 100644 --- a/gramps/plugins/textreport/familygroup.py +++ b/gramps/plugins/textreport/familygroup.py @@ -38,13 +38,15 @@ from functools import partial # #------------------------------------------------------------------------ from gramps.gen.lib import EventRoleType, EventType, NoteType, Person -from gramps.gen.plug.menu import (BooleanOption, FamilyOption, EnumeratedListOption) +from gramps.gen.plug.menu import (BooleanOption, FamilyOption) from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions -from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, - TableCellStyle, FONT_SANS_SERIF, FONT_SERIF, - INDEX_TYPE_TOC, PARA_ALIGN_CENTER) +from gramps.gen.plug.report import stdoptions +from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, + TableStyle, TableCellStyle, + FONT_SANS_SERIF, FONT_SERIF, + INDEX_TYPE_TOC, PARA_ALIGN_CENTER) from gramps.gen.datehandler import get_date from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext @@ -625,23 +627,15 @@ class FamilyGroupOptions(MenuReportOptions): def add_menu_options(self, menu): ########################## - add_option = partial(menu.add_option, _("Report Options")) + category_name = _("Report Options") + add_option = partial(menu.add_option, category_name) ########################## family_id = FamilyOption(_("Center Family")) family_id.set_help(_("The center family for the report")) add_option("family_id", family_id) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - add_option("name_format", name_format) - + stdoptions.add_name_format_option(menu, category_name) recursive = BooleanOption(_('Recursive'),False) recursive.set_help(_("Create reports for all descendants " diff --git a/gramps/plugins/textreport/indivcomplete.py b/gramps/plugins/textreport/indivcomplete.py index 5d57b551b..eea5f1a95 100644 --- a/gramps/plugins/textreport/indivcomplete.py +++ b/gramps/plugins/textreport/indivcomplete.py @@ -43,17 +43,19 @@ from collections import defaultdict # #------------------------------------------------------------------------ from gramps.gen.lib import EventRoleType, EventType, Person, NoteType -from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, - TableCellStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, - PARA_ALIGN_CENTER) +from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, + TableStyle, TableCellStyle, + FONT_SANS_SERIF, INDEX_TYPE_TOC, + PARA_ALIGN_CENTER) from gramps.gen.datehandler import get_date from gramps.gen.plug.menu import (BooleanOption, FilterOption, PersonOption, - BooleanListOption, EnumeratedListOption) + BooleanListOption) from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions from gramps.gen.plug.report import Bibliography from gramps.gen.plug.report import endnotes as Endnotes +from gramps.gen.plug.report import stdoptions from gramps.gen.display.name import displayer as global_name_display from gramps.gen.utils.file import media_path_full @@ -691,16 +693,7 @@ class IndivCompleteOptions(MenuReportOptions): menu.add_option(category_name, "pid", self.__pid) self.__pid.connect('value-changed', self.__update_filters) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) - + stdoptions.add_name_format_option(menu, category_name) self.__update_filters() diff --git a/gramps/plugins/textreport/kinshipreport.py b/gramps/plugins/textreport/kinshipreport.py index c794639f9..4d9259952 100644 --- a/gramps/plugins/textreport/kinshipreport.py +++ b/gramps/plugins/textreport/kinshipreport.py @@ -44,11 +44,11 @@ from gramps.gen.errors import ReportError from gramps.gen.relationship import get_relationship_calculator from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from gramps.gen.plug.menu import (NumberOption, BooleanOption, PersonOption, - EnumeratedListOption) +from gramps.gen.plug.menu import (NumberOption, BooleanOption, PersonOption) from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions from gramps.gen.datehandler import get_date from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback @@ -342,15 +342,7 @@ class KinshipOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) maxdescend = NumberOption(_("Max Descendant Generations"), 2, 1, 20) maxdescend.set_help(_("The maximum number of descendant generations")) diff --git a/gramps/plugins/textreport/numberofancestorsreport.py b/gramps/plugins/textreport/numberofancestorsreport.py index b71242afd..453ad616a 100644 --- a/gramps/plugins/textreport/numberofancestorsreport.py +++ b/gramps/plugins/textreport/numberofancestorsreport.py @@ -44,13 +44,14 @@ import math #------------------------------------------------------------------------ from gramps.gen.display.name import displayer as global_name_display from gramps.gen.errors import ReportError -from gramps.gen.plug.menu import PersonOption, EnumeratedListOption +from gramps.gen.plug.menu import PersonOption from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, PARA_ALIGN_CENTER, INDEX_TYPE_TOC) from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions +from gramps.gen.plug.report import stdoptions #------------------------------------------------------------------------ # @@ -187,7 +188,7 @@ class NumberOfAncestorsOptions(MenuReportOptions): def add_menu_options(self, menu): """ - Add options to the menu for the kinship report. + Add options to the menu for the Number of Ancestors report. """ category_name = _("Report Options") @@ -195,15 +196,7 @@ class NumberOfAncestorsOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = global_name_display.get_name_format() - name_format = EnumeratedListOption(_("Name format"), 0) - name_format.add_item(0, _("Default")) - for num, name, fmt_str, act in fmt_list: - name_format.add_item(num, name) - name_format.set_help(_("Select the format to display names")) - menu.add_option(category_name, "name_format", name_format) + stdoptions.add_name_format_option(menu, category_name) def make_default_style(self, default_style): """Make the default output style for the Number of Ancestors Report."""