add "living people" option to Statistics Chart report
This commit is contained in:
parent
f0e89ef9d3
commit
52d414587f
@ -194,9 +194,11 @@ def run_living_people_option(report, menu, llocale=glocale):
|
|||||||
:param llocale: allow deferred translation of "[Living]"
|
:param llocale: allow deferred translation of "[Living]"
|
||||||
:type llocale: a :class:`.GrampsLocale` instance
|
:type llocale: a :class:`.GrampsLocale` instance
|
||||||
"""
|
"""
|
||||||
living_people = menu.get_option_by_name('living_people').get_value()
|
option = menu.get_option_by_name('living_people')
|
||||||
|
living_value = option.get_value()
|
||||||
years_past_death = menu.get_option_by_name('years_past_death').get_value()
|
years_past_death = menu.get_option_by_name('years_past_death').get_value()
|
||||||
if living_people != LivingProxyDb.MODE_INCLUDE_ALL:
|
if living_value != LivingProxyDb.MODE_INCLUDE_ALL:
|
||||||
report.database = LivingProxyDb(report.database, living_people,
|
report.database = LivingProxyDb(report.database, living_value,
|
||||||
years_after_death=years_past_death,
|
years_after_death=years_past_death,
|
||||||
llocale=llocale)
|
llocale=llocale)
|
||||||
|
return option
|
||||||
|
@ -730,31 +730,40 @@ class StatisticsChart(Report):
|
|||||||
database - the GRAMPS database instance
|
database - the GRAMPS database instance
|
||||||
options - instance of the Options class for this report
|
options - instance of the Options class for this report
|
||||||
user - a gen.user.User() instance
|
user - a gen.user.User() instance
|
||||||
|
incl_private - Whether to include private data
|
||||||
|
living_people - How to handle living people
|
||||||
|
years_past_death - Consider as living this many years after death
|
||||||
"""
|
"""
|
||||||
Report.__init__(self, database, options, user)
|
Report.__init__(self, database, options, user)
|
||||||
menu = options.menu
|
menu = options.menu
|
||||||
self._user = user
|
self._user = user
|
||||||
|
|
||||||
stdoptions.run_private_data_option(self, menu)
|
|
||||||
|
|
||||||
get_option_by_name = menu.get_option_by_name
|
|
||||||
get_value = lambda name: get_option_by_name(name).get_value()
|
|
||||||
|
|
||||||
lang = menu.get_option_by_name('trans').get_value()
|
lang = menu.get_option_by_name('trans').get_value()
|
||||||
rlocale = self.set_locale(lang)
|
rlocale = self.set_locale(lang)
|
||||||
# override default gettext, or English output will have "person|Title"
|
# override default gettext, or English output will have "person|Title"
|
||||||
self._ = rlocale.translation.sgettext
|
self._ = rlocale.translation.sgettext
|
||||||
|
|
||||||
self.filter_option = get_option_by_name('filter')
|
stdoptions.run_private_data_option(self, menu)
|
||||||
self.filter = self.filter_option.get_filter()
|
living_opt = stdoptions.run_living_people_option(self, menu, rlocale)
|
||||||
filter_name = self.filter.get_name(rlocale)
|
|
||||||
|
get_option_by_name = menu.get_option_by_name
|
||||||
|
get_value = lambda name: get_option_by_name(name).get_value()
|
||||||
|
|
||||||
|
filter_opt = get_option_by_name('filter')
|
||||||
|
self.filter = filter_opt.get_filter()
|
||||||
|
self.fil_name = self.filter.get_name(rlocale)
|
||||||
|
|
||||||
self.bar_items = get_value('bar_items')
|
self.bar_items = get_value('bar_items')
|
||||||
year_from = get_value('year_from')
|
year_from = get_value('year_from')
|
||||||
year_to = get_value('year_to')
|
year_to = get_value('year_to')
|
||||||
gender = get_value('gender')
|
gender = get_value('gender')
|
||||||
|
|
||||||
|
living_value = get_value('living_people')
|
||||||
|
for (value, description) in living_opt.get_items():
|
||||||
|
if value == living_value:
|
||||||
|
self.living_desc = '(%s)' % self._(description)
|
||||||
|
break
|
||||||
|
|
||||||
# title needs both data extraction method name + gender name
|
# title needs both data extraction method name + gender name
|
||||||
if gender == Person.MALE:
|
if gender == Person.MALE:
|
||||||
genders = self._("Men")
|
genders = self._("Men")
|
||||||
@ -780,7 +789,7 @@ class StatisticsChart(Report):
|
|||||||
# extract requested items from the database and count them
|
# extract requested items from the database and count them
|
||||||
self._user.begin_progress(_('Statistics Charts'),
|
self._user.begin_progress(_('Statistics Charts'),
|
||||||
_('Collecting data...'),
|
_('Collecting data...'),
|
||||||
database.get_number_of_people())
|
self.database.get_number_of_people())
|
||||||
tables = _Extract.collect_data(self.database, self.filter, menu,
|
tables = _Extract.collect_data(self.database, self.filter, menu,
|
||||||
gender, year_from, year_to,
|
gender, year_from, year_to,
|
||||||
get_value('no_years'),
|
get_value('no_years'),
|
||||||
@ -799,7 +808,7 @@ class StatisticsChart(Report):
|
|||||||
# document heading
|
# document heading
|
||||||
heading = "%(str1)s -- %(str2)s" % {'str1' : self._(table[0]),
|
heading = "%(str1)s -- %(str2)s" % {'str1' : self._(table[0]),
|
||||||
'str2' : span_string}
|
'str2' : span_string}
|
||||||
self.data.append((heading, filter_name, table[0], table[1], lookup))
|
self.data.append((heading, table[0], table[1], lookup))
|
||||||
self._user.step_progress()
|
self._user.step_progress()
|
||||||
self._user.end_progress()
|
self._user.end_progress()
|
||||||
|
|
||||||
@ -831,15 +840,15 @@ class StatisticsChart(Report):
|
|||||||
self.doc.draw_text('SC-title', '', 0, 0, mark) # put it in TOC
|
self.doc.draw_text('SC-title', '', 0, 0, mark) # put it in TOC
|
||||||
mark = None # crock, but we only want one of them
|
mark = None # crock, but we only want one of them
|
||||||
if len(data[3]) < self.bar_items:
|
if len(data[3]) < self.bar_items:
|
||||||
self.output_piechart(*data[:5])
|
self.output_piechart(*data[:4])
|
||||||
else:
|
else:
|
||||||
self.output_barchart(*data[:5])
|
self.output_barchart(*data[:4])
|
||||||
self.doc.end_page()
|
self.doc.end_page()
|
||||||
self._user.step_progress()
|
self._user.step_progress()
|
||||||
self._user.end_progress()
|
self._user.end_progress()
|
||||||
|
|
||||||
|
|
||||||
def output_piechart(self, title1, title2, typename, data, lookup):
|
def output_piechart(self, title1, typename, data, lookup):
|
||||||
|
|
||||||
# set layout variables
|
# set layout variables
|
||||||
middle_w = self.doc.get_usable_width() / 2
|
middle_w = self.doc.get_usable_width() / 2
|
||||||
@ -852,7 +861,9 @@ class StatisticsChart(Report):
|
|||||||
mark = IndexMark(title1, INDEX_TYPE_TOC, 2)
|
mark = IndexMark(title1, INDEX_TYPE_TOC, 2)
|
||||||
self.doc.center_text('SC-title', title1, middle_w, 0, mark)
|
self.doc.center_text('SC-title', title1, middle_w, 0, mark)
|
||||||
yoffset = ReportUtils.pt2cm(pstyle.get_font().get_size())
|
yoffset = ReportUtils.pt2cm(pstyle.get_font().get_size())
|
||||||
self.doc.center_text('SC-title', title2, middle_w, yoffset)
|
self.doc.center_text('SC-title', self.fil_name, middle_w, yoffset)
|
||||||
|
yoffset = 2 * ReportUtils.pt2cm(pstyle.get_font().get_size())
|
||||||
|
self.doc.center_text('SC-title', self.living_desc, middle_w, yoffset)
|
||||||
|
|
||||||
# collect data for output
|
# collect data for output
|
||||||
color = 0
|
color = 0
|
||||||
@ -880,7 +891,7 @@ class StatisticsChart(Report):
|
|||||||
draw_legend(self.doc, legendx, yoffset, chart_data, text, 'SC-legend')
|
draw_legend(self.doc, legendx, yoffset, chart_data, text, 'SC-legend')
|
||||||
|
|
||||||
|
|
||||||
def output_barchart(self, title1, title2, typename, data, lookup):
|
def output_barchart(self, title1, typename, data, lookup):
|
||||||
|
|
||||||
pt2cm = ReportUtils.pt2cm
|
pt2cm = ReportUtils.pt2cm
|
||||||
style_sheet = self.doc.get_style_sheet()
|
style_sheet = self.doc.get_style_sheet()
|
||||||
@ -907,8 +918,10 @@ class StatisticsChart(Report):
|
|||||||
mark = IndexMark(title1, INDEX_TYPE_TOC, 2)
|
mark = IndexMark(title1, INDEX_TYPE_TOC, 2)
|
||||||
self.doc.center_text('SC-title', title1, middle, 0, mark)
|
self.doc.center_text('SC-title', title1, middle, 0, mark)
|
||||||
yoffset = pt2cm(pstyle.get_font().get_size())
|
yoffset = pt2cm(pstyle.get_font().get_size())
|
||||||
self.doc.center_text('SC-title', title2, middle, yoffset)
|
self.doc.center_text('SC-title', self.fil_name, middle, yoffset)
|
||||||
yoffset = 2 * pt2cm(pstyle.get_font().get_size())
|
yoffset = 2 * pt2cm(pstyle.get_font().get_size())
|
||||||
|
self.doc.center_text('SC-title', self.living_desc, middle, yoffset)
|
||||||
|
yoffset = 3 * pt2cm(pstyle.get_font().get_size())
|
||||||
|
|
||||||
# header
|
# header
|
||||||
yoffset += (row_h + pad)
|
yoffset += (row_h + pad)
|
||||||
@ -975,6 +988,15 @@ class StatisticsChartOptions(MenuReportOptions):
|
|||||||
|
|
||||||
stdoptions.add_private_data_option(menu, category_name)
|
stdoptions.add_private_data_option(menu, category_name)
|
||||||
|
|
||||||
|
stdoptions.add_living_people_option(menu, category_name)
|
||||||
|
|
||||||
|
stdoptions.add_localization_option(menu, category_name)
|
||||||
|
|
||||||
|
################################
|
||||||
|
category_name = _("Report Details")
|
||||||
|
add_option = partial(menu.add_option, category_name)
|
||||||
|
################################
|
||||||
|
|
||||||
sortby = EnumeratedListOption(_('Sort chart items by'),
|
sortby = EnumeratedListOption(_('Sort chart items by'),
|
||||||
_options.SORT_VALUE)
|
_options.SORT_VALUE)
|
||||||
for item_idx in range(len(_options.opt_sorts)):
|
for item_idx in range(len(_options.opt_sorts)):
|
||||||
@ -1018,8 +1040,6 @@ class StatisticsChartOptions(MenuReportOptions):
|
|||||||
"used instead of a bar chart."))
|
"used instead of a bar chart."))
|
||||||
add_option("bar_items", bar_items)
|
add_option("bar_items", bar_items)
|
||||||
|
|
||||||
stdoptions.add_localization_option(menu, category_name)
|
|
||||||
|
|
||||||
# -------------------------------------------------
|
# -------------------------------------------------
|
||||||
# List of available charts on separate option tabs
|
# List of available charts on separate option tabs
|
||||||
idx = 0
|
idx = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user