64
edits
Changes
From Gramps
→Options class: Options class is now based on MenuReportOptions. All code works.
===Options class===
====Using ReportOptions====<pre>class OptionsClassName(ReportOptions): def __init__(self,name,person_id=None): ReportOptions.__init__(self,name,person_id)</pre>* It should set new options that are specific for this report, by overriding Defining parameters of the <tt>set_new_options()</tt> method which defines <tt>options_dict</tt> and <tt>options_help</tt> dictionaries:<pre>def set_new_options(self): # Options specific for this report self.options_dict = { 'my_first_option' : 0, 'my_second_option' : '', } self.options_help = { 'my_first_option' : ("=num","Number of something", [ "First value", "Second value" ], True), 'my_second_option' : ("=str","Some necessary string for the report", "Whatever String You Wish"), }</pre>* It should also enable the "semi-common" options that are used in this report, by overriding the <tt>enable_options</tt> method which defines <tt>enable_dict</tt> dictionary. The semi-commons are the options which Gramps knows about, but which are not necessarily present in all reports:<pre>def enable_options(self): # Semi-common options that should be enabled for this report self.enable_dict = { 'filter' : 0, }</pre>All the common options are already taken care of by the core of Gramps.* For any new options set up in the options class, there must be defined UI widgets to provide means of changing these options through the dialogs. Also, there must be defined method <tt>parse_user_options</tt> to extract values of these options from the widgets and to set them into the class-variable dictionary <tt>options_dict</tt>:<pre>def add_user_options(self,dialog): option_menu = gtk.OptionMenu() self.the_menu = gtk.Menu()
</pre>
Object <precode>def add_menu_options(selfwhat_types</code> of class [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu._booleanlist.BooleanListOption BooleanListOption] is created that presents the user with a group of check boxes, menu)one is created for each call to [https: """ Add options to the //gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu for this report. """ category_name = _("Report Options") what_types = _booleanlist.BooleanListOption(_('Select From:')) what_types.add_button(_('People'), True) what_types.add_button(_('Families'), False) what_types]. Finally the object is added to the menu with [https://gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu._menu.add_button(_('Places'), False) what_typesMenu.add_button(_('Events'), False) add_option menu.add_option(category_name, "what_types", what_types)</pre>].
Then to access the selected values once the user runs the report, you make a call the menu object from within the report's <ttcode>__init__()</ttcode> functionmethod. For example, to access the "what_types" that are selected from the menu above you would add the following code:
<pre>
</pre>
In the example, the option <code>what_types_option</code> instance is retrieved by the [https://gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu._menu.Menu.get_option_by_name options_class.menu.get_option_by_name()] method. The string passed to the method must match the name you passed as the second argument to [https://gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu._menu.Menu.add_option menu.add_option()] when you created the menu. Then a list of the selected item titles is retrieved with [https://gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.menu._booleanlist.BooleanListOption.get_selected menu_optionwhat_types_option.get_selected()] and stored as a instance variable <ttcode>self.what_types</ttcode> for later use. The standard Gramps option for localizing the report has name "trans". Its value is passed to [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._reportbase.Report.set_locale <code>Report.set_locale()</code>] method that creates <code>self._()</code> method for the locale chosen by the report's user. It is then used by <code>write_report()</code> (see below).
====Defining user-adjustable paragraph styles ====
If the report uses the user-adjustable paragraph styles the default definitions for the styles must be defined here by overriding method [https://www.gramps-project.org/docs/gen/gen_plug.html#gramps.gen.plug.report._options.ReportOptions.make_default_style make_default_style()], to form a 'default' stylesheetstyle sheet:
<pre>