Changes

Jump to: navigation, search

Report-writing tutorial

676 bytes added, 12:08, 12 September 2021
m
Typo in code variable name : "fist" instead of "first"
{{languages|Report-writing tutorial}}
{{stub}}
This tutorial covers the basics of writing a simple report using the Gramps report infrastructure. It covers the process of handling options, building a document and creating the report.
* The most common surname
As of {{man tip|From Gramps version 3.2, there is also a |A [[Simple Access API|simple access]] database [https://www.gramps-project.org/docs/ API] available, with accompanying [[Quick Views]], [[Gramplets]] and [[Addons development|Addons]].}}
==Overview==
A report can potentially be generated as a standalone report, as a Gramps Book item, and as a command line report. The registration determines which modes are enabled for a given report. The report class does not have to know anything about the mode. The options class is there to provide options interface for all available modes.
 
* [[Report-writing_tutorial#Registering_the_report]]
===report.py===
Paragraph and font styles are defined in the <tt>make_default_style()</tt> function of the options class. The paragraphs are grouped into a <tt>StyleSheet</tt>, which the <tt>make_default_style()</tt> function defines. For the example report (<tt>DbSummary</tt>), the paragraph styles are defined as below:
{{stub}}<!-- need to check code is correct for Gramps 5.1.x -->
compare to <code>gramps\plugins\textreport\summary.py</code> starting at [https://github.com/gramps-project/gramps/blob/master/gramps/plugins/textreport/summary.py#L297 line 297]
<pre>
def make_default_style(self, default_style):
# Options specific for this report
self.options_dict = {
'my_fist_optionmy_first_option' : 0,
'my_second_option' : '',
}
self.options_help = {
'my_fist_optionmy_first_option' : ("=num","Number of something",
[ "First value", "Second value" ],
True),
==Implementation==
===Defining the Report Options class===
 
In this example, no special options are required. This makes the options class very simple. All that is necessary is to define the default styles.
<pre>
** translated name (the one to display in menus)
** modes that should be enabled for the report (standalone, book item, command line)
* If the report requires an active person to run, then <code>require_active </code> should be set to <code>True</code>.
* Finally, both report class and options class should be passed to registration.
description = _("Produces a ..."),
version = '1.0',
gramps_target_version = '35.21',
status = STABLE,
fname = 'filename.py',
See an existing book report for more details.
 
== Manually installing your report ==
Install in the plugins directory of your Gramps user directory.
 
== Example output ==
Start Gramps and your tutorial report will be available from the reports menu as ....
 
Run the report and this is what the output looks like ....
==See also==
* [[Report_API|Report API]]
* [[Report_Generation|Report Generation]] (describing output format options)* [[Gramps_Data_Model|Gramps Data Model]]
[[Category:Addons]]
[[Category:Developers/General]]
[[Category:Developers/Tutorials]]
[[Category: Plugins]]
[[Category:Reports]]
3,060
edits

Navigation menu