Open main menu

Gramps β

Changes

Учебник по написанию отчетов

966 bytes added, 11:09, 24 November 2025
The text before Overview section (and TOC) as well as the remaining section headings have been translated into Russian, some hyperlinks fixed
{{languages|Report-writing tutorial}}
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 goals of this report are to create a database summary reportВ результате выполнения упражнения будет написан отчет, содержащий общую информацию о базе данных. It will include the following information in the reportОн будет включать в себя:* The number of people in the database* The number of males and females* The number of unique surnames* The most common surname
* Количество людей в базе данных* Количество мужчин и женщин* Количество уникальных фамилий* Фамилия, которая встречается чаще всего {{man tip|From Начиная с Gramps version версии 3.2, there is alsoдоступны так же |A руководства [[Simple Access Using database API|simple accessпо использованию программного интерфейса]] database базы данных [https://www.gramps-project.org/docs/ gen/gen_db.html API] available, with accompanying а так же [[Quick Views|созданию отчётов быстрого просмотра]], [[Gramplets_development|Grampletsразработке грамплетов]] and и [[Addons development|Addonsдополнений]].}}
==Обзор==
;Options class : This is the code that provides means to obtain options necessary for the report using a variety of available mechanisms.
==Document interfaceИнтерфейс создания документа==
The [[Report Generation]] article provides an overview of the 'docgen' interfaces that are available for outputting documents.
==Определение классов==
===Класс Report class===
The user's report class should inherit from the Report class contained within the Report module. The constructor should take three arguments (besides class instance itself, usually denoted by 'self' name):
* Gramps database instance
The rest of the report class is pretty much up to the report writer. Depending on the goals and the scope of the report, there can be any amount of code involved. When the user generates the report in any mode, the class constructor will be run, and then the <tt>write_report()</tt> method will be called. So if you wrote that beautiful method listing something really important, make sure it is eventually called from within the <tt>write_report()</tt>. Otherwise nobody will see it unless looking at the code.
===Класс Options class===
* Options class should derive from [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._options.ReportOptions ReportOptions] class. Usually for a common report the <tt>MenuReportOptions</tt> class should be derived from. <tt>MenuReportOptions</tt> will abstract most of the lower-level widget handling below.
====Using Использование класса ReportOptions====
<pre>
class OptionsClassName(ReportOptions):
</pre>
====Using Использование класса MenuReportOptions====
The [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._options.MenuReportOptions MenuReportOptions] can be used in place of [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._options.ReportOptions ReportOptions] to present the user with a standard interface for running the report. Instead of parsing options, you generate a menu using one or more of the classes available in [https://www.gramps-project.org/docs/gen/gen_plug.html#module-gramps.gen.plug.menu._menu Menu]. All these are initialized in the [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug._options.MenuOptions.add_menu_options add_menu_options()] function (which is a required function when you inherit from [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._options.MenuReportOptions MenuReportOptions]). For example:
==Реализация==
===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.
So create now file '''report.py''' and copy there the above code.
===Defining the Report classОпределение класса отчета===
The actual implemention of the <tt>DbSummary</tt> report is rather simple. No additional work needs to be done to initialize the class, so the parent <tt>__init__</tt> routine is called.
Append the above code to the '''report.py''' file
===Registering the reportРегистрация отчета===
* Registration is set into a ''<name>.gpr.py'' file
* Registration should define internal name of the report (preferably, single string with non-special ascii characters, usable for report identification from the command line and in the options storage, as well as for forming sane filename for storing its own styles). It should also define the report's...
====Book ReportОтчет типа Книга ...====
To turn a report into one that will work as a book report, you may need to add the following:
See an existing book report for more details. DO NOT copy the above code into '''report.py''' file!
== Manually installing your report Ручная установка вашего отчета ==
Install in the plugins directory of your Gramps user directory. Go to ~/.local/share/gramps/gramps60/plugin directory (or similar for your version of Gramps) and create there RWT subdirectory. Then copy into RWT both '''report.py''' and '''report.gpr.py''' files.
== Example output Пример вывода отчета ==
Start Gramps and your tutorial report will be available from the reports menu as
[[File:Example_RWT_ID.jpg]]
==See alsoСмотрите также==
* [[Report_API|Report API]]
64
edits