Changes

Jump to: navigation, search

Report-writing tutorial

288 bytes removed, 03:40, 28 December 2012
m
Using ReportOptions: format
====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 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_fist_option' : 0, 'my_second_option' : '', } self.options_help = { 'my_fist_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 methods to extract values of these options from the widgets and to set them into the class-variable dictionary:
<pre>
def add_user_options(self,dialog): option_menu = gtk.OptionMenu() self.the_menu = gtk.Menu()
for item_index in range(10): item = _("Item numer %d") % item_index menuitem = gtk.MenuItem(item) menuitem.show() self.the_menu.append(menuitem)
option_menu.set_menu(self.the_menu) option_menu.set_history(self.options_dict['my_first_option'])
dialog.add_option(_('My first option'),option_menu)
self.the_string_entry = gtk.Entry() if self.options_dict['my_second_option']: self.the_string_entry.set_text(self.options_dict['my_second_option']) else: self.the_string_entry.set_text(_("Empty string")) self.the_string_entry.show() dialog.add_option(_('My second option'),self.the_string_entry)
def parse_user_options(self,dialog): self.options_dict['my_second_option'] = unicode(self.the_string_entry.get_text()) self.options_dict['my_first_option'] = self.the_menu.get_history()
</pre>
* Finally, the default definitions for the user-adjustable paragraph styles must be defined here, to form a 'default' stylesheet:
<pre>
def make_default_style(self, default_style): f = docgen.FontStyle() f.set_size(10) f.set_type_face(docgen.FONT_SANS_SERIF) p = docgen.ParagraphStyle() p.set_font(f) p.set_description(_("The style used for the person's name.")) default_style.add_style("ABC-Name",p)
</pre>

Navigation menu