diff --git a/ChangeLog b/ChangeLog index 6a9b06fb7..7c2fb841c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2008-01-05 Brian Matherly + * src/ReportBase/_ReportDialog.py: + * src/ReportBase/_BareReportDialog.py: + * src/ReportBase/_ReportOptions.py: + * src/plugins/KinshipReport.py: + * src/plugins/DetDescendantReport.py: + * src/plugins/DescendReport.py: + * src/plugins/IndivComplete.py: + * src/plugins/CalculateEstimatedDates.py: + * src/plugins/BookReport.py: + * src/plugins/TimeLine.py: + * src/plugins/GVFamilyLines.py: + * src/plugins/Calendar.py: + * src/plugins/AncestorReport.py: + * src/plugins/MarkerReport.py: + * src/plugins/DescendChart.py: + * src/plugins/EndOfLineReport.py: + * src/plugins/DetAncestralReport.py: + * src/plugins/SimpleBookTitle.py: + * src/plugins/CustomBookText.py: + * src/plugins/FamilyGroup.py: + * src/plugins/GVRelGraph.py: + * src/plugins/GVHourGlass.py: + * src/plugins/StatisticsChart.py: + * src/plugins/FanChart.py: + * src/PluginUtils/_PluginWindows.py: + * src/PluginUtils/__init__.py: + * src/PluginUtils/_MenuOptions.py: + More refactoring in the report system. More reports use MenuOptions now. + BareReportDialog no longer has "center person". + 2008-01-05 Raphael Ackermann 2008-01-05 Brian Matherly * src/DataViews/PedigreeView.py: diff --git a/src/PluginUtils/_MenuOptions.py b/src/PluginUtils/_MenuOptions.py index bfa6eb4da..b252ff7d1 100644 --- a/src/PluginUtils/_MenuOptions.py +++ b/src/PluginUtils/_MenuOptions.py @@ -549,91 +549,65 @@ class EnumeratedListOption(Option): #------------------------------------------------------------------------- # -# FilterListOption class +# PersonFilterOption class # #------------------------------------------------------------------------- -class FilterListOption(Option): +class PersonFilterOption(Option): """ - This class describes an option that provides a finite list of filters. - Each possible value is assigned a type of set of filters to use. + This class describes an option that provides a list of person filters. + Each possible value represents one of the possible filters. """ - def __init__(self,label,value=0): + def __init__(self,label, dbstate, value=0, include_single=True): """ @param label: A friendly label to be applied to this option. Example: "Filter" @type label: string + @param dbstate: A DbState instance + @type dbstate: DbState + @param value: A default value for the option. + Example: 1 + @type label: int + @param include_single: Whether a filter should be included for a + single person. + @type include_single: bool @return: nothing """ + from ReportBase import ReportUtils Option.__init__(self,label,value) - self.__items = [] - self.__filters = [] - - def add_item(self,value): + self.__dbstate = dbstate + self.__include_single = include_single + self.__person = self.__dbstate.get_active_person() + self.__filters = ReportUtils.get_person_filters(self.__person, + self.__include_single) + if self.get_value() > len(self.__filters): + self.set_value(0) + + def get_center_person(self): + return self.__person + + def get_filter(self): """ - Add an item to the list of possible values. - - @param value: A name of a set of filters. - Example: "person" - @type value: string - @return: nothing + Return the filter object. """ - self.__items.append(value) - - def get_items(self): - """ - Get all the possible values for this option. - - @return: an array of tuples containing (value,description) pairs. - """ - return self.__items - - def add_filter(self, filter): - """ - Add a filter set to the list. - - @param filter: A filter object. - Example: - @type value: Filter - @return: nothing - """ - self.__filters.append(filter) - - def get_filters(self): - """ - Get all of the filter objects. - - @type value: Filter - @return: an array of filter objects - """ - return self.__filters - - def clear_filters(self): - """ - Clear all of the filter objects. - - """ - self.__filters = [] + return self.__filters[self.get_value()] def make_gui_obj(self, gtk, dialog): """ - Add an FilterListOption to the dialog. + Add an PersonFilterOption to the dialog. """ - from ReportBase import ReportUtils self.dialog = dialog self.combo = gtk.combo_box_new_text() + self.combo.connect('changed',self.__on_value_changed) self.gobj = gtk.HBox() - for filter in self.get_items(): - if filter in ["person"]: - filter_list = ReportUtils.get_person_filters(dialog.person, - include_single=True) - for filter in filter_list: - self.combo.append_text(filter.get_name()) - self.add_filter(filter) - self.combo.set_active(self.get_value()) self.change_button = gtk.Button("%s..." % _('C_hange') ) self.change_button.connect('clicked',self.on_change_clicked) self.gobj.pack_start(self.combo, False) self.gobj.pack_start(self.change_button, False) + + self.update_gui_obj() + + def __on_value_changed(self, obj): + self.set_value( int(self.combo.get_active()) ) def on_change_clicked(self, *obj): from Selectors import selector_factory @@ -643,39 +617,28 @@ class FilterListOption(Option): self.dialog.track) new_person = sel_person.run() if new_person: - self.dialog.person = new_person + self.__person = new_person self.update_gui_obj() - def get_center_person(self): - return self.dialog.person - - def get_filter(self): - """ - Return the filter object. - """ - return self.get_filters()[int(self.combo.get_active())] - def update_gui_obj(self): # update the gui object with new filter info from ReportBase import ReportUtils - for i in range(len(self.get_filters())): - self.combo.remove_text(0) - self.clear_filters() - for filter in self.get_items(): - if filter in ["person"]: - filter_list = ReportUtils.get_person_filters(self.dialog.person, - include_single=True) - for filter in filter_list: - self.combo.append_text(filter.get_name()) - self.add_filter(filter) + self.combo.get_model().clear() + self.__filters = ReportUtils.get_person_filters(self.__person, + self.__include_single) + for filter in self.__filters: + self.combo.append_text(filter.get_name()) + + if self.get_value() >= len(self.__filters): + # Set the value to zero if it is not valid. + self.set_value(0) self.combo.set_active(self.get_value()) def parse(self): """ Parse the object and return. """ - self.__value = int(self.combo.get_active()) - return self.__value + return self.get_value() #------------------------------------------------------------------------- # diff --git a/src/PluginUtils/_PluginWindows.py b/src/PluginUtils/_PluginWindows.py index 24d18c46c..f9ccd7387 100644 --- a/src/PluginUtils/_PluginWindows.py +++ b/src/PluginUtils/_PluginWindows.py @@ -217,7 +217,6 @@ class ToolManagedWindowBase(ManagedWindow.ManagedWindow): # Build the list of widgets that are used to extend the Options # frame and to create other frames self.add_user_options() - self.setup_center_person() self.notebook = gtk.Notebook() self.notebook.set_border_width(6) @@ -365,11 +364,6 @@ class ToolManagedWindowBase(ManagedWindow.ManagedWindow): label = gtk.Label('%s' % title) label.set_use_markup(True) self.window.vbox.pack_start(label, True, True, self.border_pad) - - def setup_center_person(self): - """Set up center person labels and change button. - Should be overwritten by standalone report dialogs. """ - pass def add_frame_option(self,frame_name,label_text,widget,tooltip=None): """Similar to add_option this method takes a frame_name, a diff --git a/src/PluginUtils/__init__.py b/src/PluginUtils/__init__.py index f2b5e5959..52515aa74 100644 --- a/src/PluginUtils/__init__.py +++ b/src/PluginUtils/__init__.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2001-2006 Donald N. Allingham +# Copyright (C) 2008 Brian Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +30,7 @@ # of the list. from _MenuOptions import MenuOptions, \ NumberOption, FloatOption, BooleanOption, TextOption, \ - EnumeratedListOption, FilterListOption, StringOption, ColourButtonOption, \ + EnumeratedListOption, PersonFilterOption, StringOption, ColourButtonOption, \ PersonOption, PersonListOption, SurnameColourOption from _PluginMgr import \ register_export, register_import, \ diff --git a/src/ReportBase/_BareReportDialog.py b/src/ReportBase/_BareReportDialog.py index 1b4c2bd62..a1010e326 100644 --- a/src/ReportBase/_BareReportDialog.py +++ b/src/ReportBase/_BareReportDialog.py @@ -146,7 +146,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow): self.add_user_options() self.setup_main_options() - self.setup_center_person() self.setup_target_frame() self.setup_format_frame() self.setup_style_frame() @@ -297,27 +296,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow): self.tbl.attach(label, 0, 4, self.col, self.col+1, gtk.FILL|gtk.EXPAND) self.col += 1 - def setup_center_person(self): - """Set up center person labels and change button. - Should be overwritten by standalone report dialogs. """ - - center_label = gtk.Label("%s" % _("Center Person")) - center_label.set_use_markup(True) - center_label.set_alignment(0.0,0.5) - self.tbl.set_border_width(12) - self.tbl.attach(center_label,0,4,self.col,self.col+1) - self.col += 1 - - name = name_displayer.display(self.person) - self.person_label = gtk.Label( "%s" % name ) - self.person_label.set_alignment(0.0,0.5) - self.tbl.attach(self.person_label,2,3,self.col,self.col+1) - - change_button = gtk.Button("%s..." % _('C_hange') ) - change_button.connect('clicked',self.on_center_person_change_clicked) - self.tbl.attach(change_button,3,4,self.col,self.col+1,gtk.SHRINK) - self.col += 1 - def setup_style_frame(self): """Set up the style frame of the dialog. This function relies on other routines create the default style for this report, @@ -493,18 +471,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow): StyleListDisplay(self.style_sheet_list,self.build_style_menu, self.window) - def on_center_person_change_clicked(self,*obj): - from Selectors import selector_factory - SelectPerson = selector_factory('Person') - sel_person = SelectPerson(self.dbstate,self.uistate,self.track) - new_person = sel_person.run() - if new_person: - self.new_person = new_person - new_name = name_displayer.display(new_person) - if new_name: - self.person_label.set_text( "%s" % new_name ) - self.person_label.set_use_markup(True) - #------------------------------------------------------------------------ # # Functions related to creating the actual report document. diff --git a/src/ReportBase/_ReportDialog.py b/src/ReportBase/_ReportDialog.py index 99a50a132..d805ad5f0 100644 --- a/src/ReportBase/_ReportDialog.py +++ b/src/ReportBase/_ReportDialog.py @@ -88,9 +88,6 @@ class ReportDialog(BareReportDialog): def init_interface(self): BareReportDialog.init_interface(self) - def setup_center_person(self): - pass - def get_title(self): """The window title for this dialog""" name = self.report_name diff --git a/src/ReportBase/_ReportOptions.py b/src/ReportBase/_ReportOptions.py index 5ccaaa757..3bdd5a8f7 100644 --- a/src/ReportBase/_ReportOptions.py +++ b/src/ReportBase/_ReportOptions.py @@ -670,5 +670,11 @@ class MenuReportOptions(MenuOptions,ReportOptions): active_person = None ReportOptions.__init__(self,name,active_person) MenuOptions.__init__(self,dbstate) - + + def load_previous_values(self): + ReportOptions.load_previous_values(self) + # Pass the loaded values to the menu options so they will be displayed properly. + for optname in self.options_dict: + menu_option = self.menu.get_option_by_name(optname) + menu_option.set_value(self.options_dict[optname]) diff --git a/src/plugins/AncestorReport.py b/src/plugins/AncestorReport.py index 612a0e6fe..f0d300497 100644 --- a/src/plugins/AncestorReport.py +++ b/src/plugins/AncestorReport.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +37,8 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from PluginUtils import register_report, NumberOption, BooleanOption +from PluginUtils import register_report, NumberOption, \ + BooleanOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc @@ -79,6 +80,8 @@ class AncestorReport(Report): self.max_generations = options_class.handler.options_dict['maxgen'] self.pgbrk = options_class.handler.options_dict['pagebbg'] self.opt_namebrk = options_class.handler.options_dict['namebrk'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) def apply_filter(self,person_handle,index,generation=1): """ @@ -142,12 +145,12 @@ class AncestorReport(Report): # Call apply_filter to build the self.map array of people in the database that # match the ancestry. - self.apply_filter(self.start_person.get_handle(),1) + self.apply_filter(self.center_person.get_handle(),1) # Write the title line. Set in INDEX marker so that this section will be # identified as a major category if this is included in a Book report. - name = name_displayer.display_formal(self.start_person) + name = name_displayer.display_formal(self.center_person) title = _("Ahnentafel Report for %s") % name mark = BaseDoc.IndexMark(title, BaseDoc.INDEX_TYPE_TOC,1 ) self.doc.start_paragraph("AHN-Title") @@ -226,6 +229,16 @@ class AncestorOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the ancestor report. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") maxgen = NumberOption(_("Generations"),10,1,15) diff --git a/src/plugins/BookReport.py b/src/plugins/BookReport.py index ac95efd2f..a8e170a6e 100644 --- a/src/plugins/BookReport.py +++ b/src/plugins/BookReport.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2003-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -71,6 +71,7 @@ import Errors import BaseDoc from QuestionDialog import WarningDialog, ErrorDialog from PluginUtils import bkitems_list, register_report, Plugins +from PluginUtils import PersonOption, PersonFilterOption import ManagedWindow # Import from specific modules in ReportBase @@ -82,6 +83,35 @@ from ReportBase._DocReportDialog import DocReportDialog from ReportBase._CommandLineReport import CommandLineReport from ReportBase._ReportOptions import ReportOptions +#------------------------------------------------------------------------ +# +# Private Functions +# +#------------------------------------------------------------------------ +def _get_subject(options,db): + """ + Attempts to determine the subject of a set of options. The subject would + likely be a person (using a PersonOption) or a filter (using a + PersonFilterOption) + + options: The ReportOptions class + db: the database for which it corresponds + """ + if not hasattr(options,"menu"): + return _("Not Applicable") + menu = options.menu + option_names = menu.get_all_option_names() + for name in option_names: + option = menu.get_option_by_name(name) + if isinstance(option,PersonOption): + from BasicUtils import name_displayer as _nd + gid = option.get_value() + person = db.get_person_from_gramps_id(gid) + return _nd.display(person) + elif isinstance(option,PersonFilterOption): + return option.get_filter().get_name() + return _("Not Applicable") + #------------------------------------------------------------------------ # # Book Item class @@ -92,14 +122,14 @@ class BookItem: Interface into the book item -- a smallest element of the book. """ - def __init__(self,name=None): + def __init__(self,dbstate,name=None): """ Creates a new empty BookItem. name: if not None then the book item is retreived from the book item registry using name for lookup """ - + self.dbstate = dbstate if name: self.get_registered_item(name) else: @@ -137,7 +167,7 @@ class BookItem: self.category = item[1] self.write_item = item[2] self.name = item[4] - self.option_class = item[3](self.name) + self.option_class = item[3](self.name,self.dbstate) self.option_class.load_previous_values() def get_name(self): @@ -309,14 +339,14 @@ class BookList: BookList is loaded from a specified XML file if it exists. """ - def __init__(self,filename): + def __init__(self,filename,dbstate): """ Creates a new BookList from the books that may be defined in the specified file. file: XML file that contains book items definitions """ - + self.dbstate = dbstate self.bookmap = {} self.file = os.path.join(const.HOME_DIR,filename) self.parse() @@ -402,7 +432,7 @@ class BookList: """ try: p = make_parser() - p.setContentHandler(BookParser(self)) + p.setContentHandler(BookParser(self,self.dbstate)) the_file = open(self.file) p.parse(the_file) the_file.close() @@ -420,13 +450,14 @@ class BookParser(handler.ContentHandler): SAX parsing class for the Books XML file. """ - def __init__(self,booklist): + def __init__(self,booklist,dbstate): """ Creates a BookParser class that populates the passed booklist. booklist: BookList to be loaded from the file. """ handler.ContentHandler.__init__(self) + self.dbstate = dbstate self.booklist = booklist self.b = None self.i = None @@ -449,7 +480,7 @@ class BookParser(handler.ContentHandler): self.dbname = attrs['database'] self.b.set_dbname(self.dbname) elif tag == "item": - self.i = BookItem(attrs['name']) + self.i = BookItem(self.dbstate,attrs['name']) self.o = {} elif tag == "option": self.an_o_name = attrs['name'] @@ -587,7 +618,7 @@ class BookOptions(ReportOptions): } self.options_help = { 'bookname' : ("=name","Name of the book. MANDATORY", - BookList('books.xml').get_book_names(), + BookList('books.xml',None).get_book_names(), False), } @@ -655,7 +686,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow): av_titles = [(_('Name'),0,150),(_('Type'),1,50),('',-1,0)] bk_titles = [(_('Item name'),-1,150),(_('Type'),-1,50),('',-1,0), - (_('Center person'),-1,50)] + (_('Subject'),-1,50)] self.av_ncols = len(av_titles) self.bk_ncols = len(bk_titles) @@ -718,22 +749,15 @@ class BookReportSelector(ManagedWindow.ManagedWindow): self.bk_model.clear() for saved_item in book.get_item_list(): name = saved_item.get_name() - item = BookItem(name) + item = BookItem(self.dbstate,name) item.option_class = saved_item.option_class - person_id = item.option_class.handler.get_person_id() - if not same_db or not person_id: - person_id = self.person.get_gramps_id() - item.option_class.handler.set_person_id(person_id) item.set_style_name(saved_item.get_style_name()) self.book.append_item(item) data = [ item.get_translated_name(), item.get_category(), item.get_name() ] - if data[2] in ('simple_book_title','custom_text'): - data[2]=(_("Not Applicable")) - else: - pname = self.db.get_person_from_gramps_id(person_id) - data[2]=(pname.get_primary_name().get_regular_name()) + + data[2] = _get_subject(item.option_class,self.db) self.bk_model.add(data) def on_add_clicked(self,obj): @@ -746,16 +770,9 @@ class BookReportSelector(ManagedWindow.ManagedWindow): if not the_iter: return data = self.av_model.get_data(the_iter,range(self.av_ncols)) - item = BookItem(data[2]) - if data[2] in ('simple_book_title','custom_text'): - data[2]=(_("Not Applicable")) - else: - data[2]=(self.person.get_primary_name().get_regular_name()) + item = BookItem(self.dbstate,data[2]) + data[2] = _get_subject(item.option_class,self.db) self.bk_model.add(data) - person_id = item.option_class.handler.get_person_id() - if not person_id: - person_id = self.person.get_gramps_id() - item.option_class.handler.set_person_id(person_id) self.book.append_item(item) def on_remove_clicked(self,obj): @@ -820,10 +837,9 @@ class BookReportSelector(ManagedWindow.ManagedWindow): item.get_translated_name(), self.track) response = item_dialog.window.run() - if (response == RESPONSE_OK) and (item_dialog.person) \ - and (data[1] != _("Title")): - self.bk_model.model.set_value(the_iter,2, - item_dialog.person.get_primary_name().get_regular_name()) + if response == RESPONSE_OK: + subject = _get_subject(option_class,self.db) + self.bk_model.model.set_value(the_iter,2,subject) self.book.set_item(row,item) item_dialog.close() @@ -914,7 +930,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow): """ Save the current book in the xml booklist file. """ - self.book_list = BookList(self.file) + self.book_list = BookList(self.file,dbstate) name = unicode(self.name_entry.get_text()) self.book.set_name(name) self.book.set_dbname(self.db.get_save_path()) @@ -925,7 +941,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow): """ Run the BookListDisplay dialog to present the choice of books to open. """ - self.book_list = BookList(self.file) + self.book_list = BookList(self.file,self.dbstate) booklistdisplay = BookListDisplay(self.book_list,1,0) booklistdisplay.top.destroy() book = booklistdisplay.selection @@ -937,7 +953,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow): """ Run the BookListDisplay dialog to present the choice of books to delete. """ - self.book_list = BookList(self.file) + self.book_list = BookList(self.file,self.dbstate) booklistdisplay = BookListDisplay(self.book_list,0,1) booklistdisplay.top.destroy() @@ -958,10 +974,7 @@ class BookItemDialog(BareReportDialog): self.database = dbstate.db self.option_class = option_class - self.person = self.database.get_person_from_gramps_id( - self.option_class.handler.get_person_id()) - self.new_person = None - BareReportDialog.__init__(self,dbstate,uistate,self.person, + BareReportDialog.__init__(self,dbstate,uistate,None, option_class,name,translated_name,track) def on_ok_clicked(self, obj): @@ -972,10 +985,6 @@ class BookItemDialog(BareReportDialog): self.parse_style_frame() self.parse_user_options() - if self.new_person: - self.person = self.new_person - - self.option_class.handler.set_person_id(self.person.get_gramps_id()) self.options.handler.save_options() #------------------------------------------------------------------------ @@ -1108,7 +1117,7 @@ def cl_report(database,name,category,options_str_dict): if clr.show: return - book_list = BookList('books.xml') + book_list = BookList('books.xml',None) book_name = clr.options_dict['bookname'] book = book_list.get_book(book_name) selected_style = BaseDoc.StyleSheet() diff --git a/src/plugins/CalculateEstimatedDates.py b/src/plugins/CalculateEstimatedDates.py index b376bb314..59948d22e 100644 --- a/src/plugins/CalculateEstimatedDates.py +++ b/src/plugins/CalculateEstimatedDates.py @@ -36,7 +36,7 @@ import time # #------------------------------------------------------------------------ from PluginUtils import Tool, register_tool, PluginWindows, \ - MenuToolOptions, BooleanOption, FilterListOption, StringOption, \ + MenuToolOptions, BooleanOption, PersonFilterOption, StringOption, \ NumberOption import gen.lib import Config @@ -55,8 +55,7 @@ class CalcEstDateOptions(MenuToolOptions): """ Adds the options """ category_name = _("Options") - filter = FilterListOption(_("Filter"), 3) - filter.add_item("person") + filter = PersonFilterOption(_("Filter"), dbstate, 3) filter.set_help(_("Select filter to restrict people")) menu.add_option(category_name,"filter", filter) diff --git a/src/plugins/Calendar.py b/src/plugins/Calendar.py index 3547bf259..ecd1f604d 100644 --- a/src/plugins/Calendar.py +++ b/src/plugins/Calendar.py @@ -45,7 +45,7 @@ from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_DRAW, CATEGORY_TEXT, \ MODE_GUI, MODE_BKI, MODE_CLI from PluginUtils import NumberOption, BooleanOption, StringOption, \ - FilterListOption, EnumeratedListOption + PersonFilterOption, EnumeratedListOption import GrampsLocale import gen.lib from Utils import probably_alive, ProgressMeter @@ -480,8 +480,7 @@ class CalendarOptions(MenuReportOptions): year.set_help(_("Year of calendar")) menu.add_option(category_name,"year", year) - filter = FilterListOption(_("Filter")) - filter.add_item("person") + filter = PersonFilterOption(_("Filter"),dbstate,0,False) filter.set_help(_("Select filter to restrict people that appear on calendar")) menu.add_option(category_name,"filter", filter) diff --git a/src/plugins/CustomBookText.py b/src/plugins/CustomBookText.py index 98ec8889d..50245bb74 100644 --- a/src/plugins/CustomBookText.py +++ b/src/plugins/CustomBookText.py @@ -41,8 +41,8 @@ import gtk # gramps modules # #------------------------------------------------------------------------ -from PluginUtils import register_report -from ReportBase import Report, ReportOptions, CATEGORY_TEXT, MODE_BKI +from PluginUtils import register_report, TextOption +from ReportBase import Report, MenuReportOptions, CATEGORY_TEXT, MODE_BKI import BaseDoc #------------------------------------------------------------------------ @@ -77,105 +77,52 @@ class CustomText(Report): def write_report(self): self.doc.start_paragraph('CBT-Initial') - self.doc.write_text(self.top_text) + for line in self.top_text: + self.doc.write_text(line) + self.doc.write_text("\n") self.doc.end_paragraph() self.doc.start_paragraph('CBT-Middle') - self.doc.write_text(self.middle_text) + for line in self.middle_text: + self.doc.write_text(line) + self.doc.write_text("\n") self.doc.end_paragraph() self.doc.start_paragraph('CBT-Final') - self.doc.write_text(self.bottom_text) + for line in self.bottom_text: + self.doc.write_text(line) + self.doc.write_text("\n") self.doc.end_paragraph() #------------------------------------------------------------------------ # -# +# CustomTextOptions # #------------------------------------------------------------------------ -class CustomTextOptions(ReportOptions): +class CustomTextOptions(MenuReportOptions): """ Defines options and provides handling interface. """ - - def __init__(self,name,person_id=None): - ReportOptions.__init__(self,name,person_id) - - # Options specific for this report - self.options_dict = { - 'top' : '', - 'mid' : '', - 'bot' : '', - } - self.options_help = { - 'top' : ("=str","Initial Text", - "Whatever String You Wish"), - 'mid' : ("=str","Middle Text", - "Whatever String You Wish"), - 'bot' : ("=str","Final Text", - "Whatever String You Wish"), - } + + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) - def do_nothing(self): - pass - - def add_user_options(self,dialog): - dialog.setup_center_person = self.do_nothing #Disable center person - dialog.notebook = gtk.Notebook() - dialog.notebook.set_border_width(6) - dialog.window.vbox.add(dialog.notebook) - - top_sw = gtk.ScrolledWindow() - middle_sw = gtk.ScrolledWindow() - bottom_sw = gtk.ScrolledWindow() - - top_sw.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - middle_sw.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - bottom_sw.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - - self.top_text_view = gtk.TextView() - self.top_text_view.get_buffer().set_text(self.options_dict['top']) - self.middle_text_view = gtk.TextView() - self.middle_text_view.get_buffer().set_text(self.options_dict['mid']) - self.bottom_text_view = gtk.TextView() - self.bottom_text_view.get_buffer().set_text(self.options_dict['bot']) - - top_sw.add_with_viewport(self.top_text_view) - middle_sw.add_with_viewport(self.middle_text_view) - bottom_sw.add_with_viewport(self.bottom_text_view) - - dialog.add_frame_option(_('Initial Text'),"",top_sw) - dialog.add_frame_option(_('Middle Text'),"",middle_sw) - dialog.add_frame_option(_('Final Text'),"",bottom_sw) - - def parse_user_options(self,dialog): - """ - Parses the custom options that we have added. - """ - self.options_dict['top'] = unicode( - self.top_text_view.get_buffer().get_text( - self.top_text_view.get_buffer().get_start_iter(), - self.top_text_view.get_buffer().get_end_iter(), - False - ) - ).replace('\n',' ') - - self.options_dict['mid'] = unicode( - self.middle_text_view.get_buffer().get_text( - self.middle_text_view.get_buffer().get_start_iter(), - self.middle_text_view.get_buffer().get_end_iter(), - False - ) - ).replace('\n',' ') - - self.options_dict['bot'] = unicode( - self.bottom_text_view.get_buffer().get_text( - self.bottom_text_view.get_buffer().get_start_iter(), - self.bottom_text_view.get_buffer().get_end_iter(), - False - ) - ).replace('\n',' ') + def add_menu_options(self,menu,dbstate): + + category_name = _("Text") + + top = TextOption(_("Initial Text"), [""] ) + top.set_help(_("Text to display at the top.")) + menu.add_option(category_name,"top",top) + + mid = TextOption(_("Middle Text"), [""] ) + mid.set_help(_("Text to display in the middle")) + menu.add_option(category_name,"mid",mid) + + bot = TextOption(_("Final Text"), [""] ) + bot.set_help(_("Text to display last.")) + menu.add_option(category_name,"bot",bot) def make_default_style(self,default_style): """Make the default output style for the Custom Text report.""" diff --git a/src/plugins/DescendChart.py b/src/plugins/DescendChart.py index ea6f7fa94..d0ea99249 100644 --- a/src/plugins/DescendChart.py +++ b/src/plugins/DescendChart.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,8 @@ # #------------------------------------------------------------------------ from BasicUtils import name_displayer -from PluginUtils import register_report, NumberOption, BooleanOption, TextOption +from PluginUtils import register_report, NumberOption, BooleanOption, \ + TextOption, PersonOption from ReportBase import Report, MenuReportOptions, \ ReportUtils, CATEGORY_DRAW, MODE_GUI, MODE_BKI, MODE_CLI from SubstKeywords import SubstKeywords @@ -124,8 +125,10 @@ class DescendChart(Report): self.max_generations = options_class.handler.options_dict['maxgen'] self.force_fit = options_class.handler.options_dict['singlep'] self.incblank = options_class.handler.options_dict['incblank'] + pid = options_class.handler.options_dict['pid'] + center_person = database.get_person_from_gramps_id(pid) - name = name_displayer.display_formal(person) + name = name_displayer.display_formal(center_person) self.title = _("Descendant Chart for %s") % name self.map = {} @@ -139,7 +142,7 @@ class DescendChart(Report): self.genchart = GenChart(32) - self.apply_filter(self.start_person.get_handle(),0,0) + self.apply_filter(center_person.get_handle(),0,0) self.calc() @@ -400,7 +403,17 @@ class DescendChartOptions(MenuReportOptions): def __init__(self,name,dbstate=None): MenuReportOptions.__init__(self,name,dbstate) - def add_menu_options(self,menu): + def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the descendant report. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") max_gen = NumberOption(_("Generations"),10,1,50) diff --git a/src/plugins/DescendReport.py b/src/plugins/DescendReport.py index 12873e5ab..b43efdadf 100644 --- a/src/plugins/DescendReport.py +++ b/src/plugins/DescendReport.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -from PluginUtils import register_report, NumberOption +from PluginUtils import register_report, NumberOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc @@ -83,6 +83,8 @@ class DescendantReport(Report): Report.__init__(self,database,person,options_class) self.max_generations = options_class.handler.options_dict['gen'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) sort = Sort.Sort(self.database) self.by_birthdate = sort.by_birthdate @@ -148,12 +150,12 @@ class DescendantReport(Report): def write_report(self): self.doc.start_paragraph("DR-Title") - name = name_displayer.display(self.start_person) + name = name_displayer.display(self.center_person) title = _("Descendants of %s") % name mark = BaseDoc.IndexMark(title,BaseDoc.INDEX_TYPE_TOC,1) self.doc.write_text(title,mark) self.doc.end_paragraph() - self.dump(1,self.start_person) + self.dump(1,self.center_person) def dump(self,level,person): @@ -199,6 +201,13 @@ class DescendantOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") gen = NumberOption(_("Generations"),10,1,15) diff --git a/src/plugins/DetAncestralReport.py b/src/plugins/DetAncestralReport.py index f873eec3b..6152708bb 100644 --- a/src/plugins/DetAncestralReport.py +++ b/src/plugins/DetAncestralReport.py @@ -3,7 +3,7 @@ # # Copyright (C) 2000-2002 Bruce J. DeGrasse # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,20 +31,14 @@ #------------------------------------------------------------------------ from gettext import gettext as _ -#------------------------------------------------------------------------ -# -# Gnome/GTK modules -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # GRAMPS modules # #------------------------------------------------------------------------ import gen.lib -from PluginUtils import register_report, NumberOption, BooleanOption +from PluginUtils import register_report, NumberOption, \ + BooleanOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI from ReportBase import Bibliography, Endnotes @@ -92,6 +86,7 @@ class DetAncestorReport(Report): dupPerson - Whether to omit duplicate ancestors (e.g. when distant cousins mary). childRef - Whether to add descendant references in child list. addImages - Whether to include images. + pid - The Gramps ID of the center person for the report. """ Report.__init__(self,database,person,options_class) @@ -114,6 +109,8 @@ class DetAncestorReport(Report): self.includeAddr = options_class.handler.options_dict['incaddresses'] self.includeSources= options_class.handler.options_dict['incsources'] self.includeAttrs = options_class.handler.options_dict['incattrs'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) self.gen_handles = {} self.prev_gen_handles= {} @@ -143,9 +140,9 @@ class DetAncestorReport(Report): self.apply_filter(family.get_mother_handle(),(index*2)+1) def write_report(self): - self.apply_filter(self.start_person.get_handle(),1) + self.apply_filter(self.center_person.get_handle(),1) - name = _nd.display_name(self.start_person.get_primary_name()) + name = _nd.display_name(self.center_person.get_primary_name()) self.doc.start_paragraph("DAR-Title") title = _("Ancestral Report for %s") % name mark = BaseDoc.IndexMark(title,BaseDoc.INDEX_TYPE_TOC,1) @@ -663,6 +660,13 @@ class DetAncestorOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") gen = NumberOption(_("Generations"),10,1,100) diff --git a/src/plugins/DetDescendantReport.py b/src/plugins/DetDescendantReport.py index 02b4c6991..c3b92ef1c 100644 --- a/src/plugins/DetDescendantReport.py +++ b/src/plugins/DetDescendantReport.py @@ -3,7 +3,7 @@ # # Copyright (C) 2000-2002 Bruce J. DeGrasse # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007 Robert Cawley # # This program is free software; you can redistribute it and/or modify @@ -32,20 +32,14 @@ #------------------------------------------------------------------------ from gettext import gettext as _ -#------------------------------------------------------------------------ -# -# Gnome/GTK modules -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # GRAMPS modules # #------------------------------------------------------------------------ import gen.lib -from PluginUtils import register_report, NumberOption, BooleanOption +from PluginUtils import register_report, NumberOption, \ + BooleanOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI from ReportBase import Bibliography, Endnotes @@ -95,6 +89,7 @@ class DetDescendantReport(Report): dupPerson - Whether to omit duplicate ancestors (e.g. when distant cousins mary). childRef - Whether to add descendant references in child list. addImages - Whether to include images. + pid - The Gramps ID of the center person for the report. """ Report.__init__(self,database,person,options_class) @@ -118,6 +113,8 @@ class DetDescendantReport(Report): self.includeSources= options_class.handler.options_dict['incsources'] self.includeMates = options_class.handler.options_dict['incmates'] self.includeAttrs = options_class.handler.options_dict['incattrs'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) self.gen_handles = {} self.prev_gen_handles= {} @@ -158,15 +155,15 @@ class DetDescendantReport(Report): index += 1 def write_report(self): - self.apply_filter(self.start_person.get_handle(),1,"1") + self.apply_filter(self.center_person.get_handle(),1,"1") - name = _nd.display_name(self.start_person.get_primary_name()) + name = _nd.display_name(self.center_person.get_primary_name()) spouseName = "" nspouses = 0 - for family_handle in self.start_person.get_family_handle_list(): + for family_handle in self.center_person.get_family_handle_list(): family = self.database.get_family_from_handle(family_handle) - if self.start_person.get_gender() == gen.lib.Person.MALE: + if self.center_person.get_gender() == gen.lib.Person.MALE: spouse_handle = family.get_mother_handle() else: spouse_handle = family.get_father_handle() @@ -626,6 +623,16 @@ class DetDescendantOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the detailed descendant report. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") gen = NumberOption(_("Generations"),10,1,100) diff --git a/src/plugins/EndOfLineReport.py b/src/plugins/EndOfLineReport.py index 3bc015749..dc9c039a1 100644 --- a/src/plugins/EndOfLineReport.py +++ b/src/plugins/EndOfLineReport.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from PluginUtils import register_report +from PluginUtils import register_report, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc @@ -64,7 +64,8 @@ class EndOfLineReport(Report): """ Report.__init__(self,database,person,options_class) - self.person = person + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) # eol_map is a map whose: # keys are the generations of the people @@ -81,7 +82,7 @@ class EndOfLineReport(Report): # # eol_map is populated by get_eol() which calls itself recursively. self.eol_map = {} - self.get_eol(self.person,1,[]) + self.get_eol(self.center_person,1,[]) def get_eol(self,person,gen,pedigree): name = name_displayer.display(person) @@ -123,7 +124,7 @@ class EndOfLineReport(Report): The routine the actually creates the report. At this point, the document is opened and ready for writing. """ - pname = name_displayer.display(self.person) + pname = name_displayer.display(self.center_person) self.doc.start_paragraph("EOL-Title") title = _("End of Line Report for %s") % pname @@ -221,7 +222,15 @@ class EndOfLineOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): - pass + """ + Add options to the menu for the End of Line report. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) def make_default_style(self,default_style): """Make the default output style for the End of Line Report.""" diff --git a/src/plugins/FamilyGroup.py b/src/plugins/FamilyGroup.py index 2409a1569..7a73ef22f 100644 --- a/src/plugins/FamilyGroup.py +++ b/src/plugins/FamilyGroup.py @@ -596,8 +596,13 @@ class FamilyGroupOptions(MenuReportOptions): category_name = _("Report Options") ########################## - families = self.get_families(dbstate.get_database(), - dbstate.get_active_person()) + if dbstate: + db = dbstate.get_database() + person = dbstate.get_active_person() + else: + db = None + person = None + families = self.get_families(db, person) family_id = EnumeratedListOption(_("Spouse"), "") for item in families: diff --git a/src/plugins/FanChart.py b/src/plugins/FanChart.py index 4a16d0e7b..35eedf208 100644 --- a/src/plugins/FanChart.py +++ b/src/plugins/FanChart.py @@ -1,8 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2006 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2003-2006 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,8 +35,8 @@ from gettext import gettext as _ #------------------------------------------------------------------------ import BaseDoc from PluginUtils import register_report -from PluginUtils import NumberOption, EnumeratedListOption -from ReportBase import Report, ReportUtils,MenuReportOptions,CATEGORY_DRAW, \ +from PluginUtils import NumberOption, EnumeratedListOption, PersonOption +from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_DRAW, \ MODE_GUI, MODE_BKI, MODE_CLI from SubstKeywords import SubstKeywords @@ -87,6 +87,8 @@ class FanChart(Report): self.circle = options_class.handler.options_dict['circle'] self.background = options_class.handler.options_dict['background'] self.radial = options_class.handler.options_dict['radial'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) self.background_style = [] self.text_style = [] @@ -143,8 +145,8 @@ class FanChart(Report): self.doc.start_page() - self.apply_filter(self.start_person.get_handle(),1) - n = self.start_person.get_primary_name().get_regular_name() + self.apply_filter(self.center_person.get_handle(),1) + n = self.center_person.get_primary_name().get_regular_name() if self.circle == FULL_CIRCLE: max_angle = 360.0 @@ -321,6 +323,16 @@ class FanChartOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the fan chart. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") max_gen = NumberOption(_("Generations"),5,1,self.MAX_GENERATIONS) diff --git a/src/plugins/GVFamilyLines.py b/src/plugins/GVFamilyLines.py index be4507a2b..eb2336579 100644 --- a/src/plugins/GVFamilyLines.py +++ b/src/plugins/GVFamilyLines.py @@ -64,10 +64,10 @@ import DateHandler import GrampsWidgets import ManagedWindow from PluginUtils import register_report -from ReportBase import Report, ReportUtils, ReportOptions, CATEGORY_CODE, MODE_GUI, MODE_CLI +from ReportBase import Report, ReportUtils, CATEGORY_CODE, MODE_GUI, MODE_CLI from ReportBase import Report, MenuReportOptions, MODE_GUI, MODE_CLI, CATEGORY_GRAPHVIZ from ReportBase._ReportDialog import ReportDialog -from PluginUtils import register_report, FilterListOption, EnumeratedListOption, BooleanOption, NumberOption, ColourButtonOption, PersonListOption, SurnameColourOption +from PluginUtils import register_report, EnumeratedListOption, BooleanOption, NumberOption, ColourButtonOption, PersonListOption, SurnameColourOption from QuestionDialog import ErrorDialog, WarningDialog from BasicUtils import name_displayer as _nd from DateHandler import displayer as _dd diff --git a/src/plugins/GVHourGlass.py b/src/plugins/GVHourGlass.py index a1a929e9d..16242d961 100644 --- a/src/plugins/GVHourGlass.py +++ b/src/plugins/GVHourGlass.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ Generate an hourglass graph using the GraphViz generator. # GRAMPS modules # #------------------------------------------------------------------------ -from PluginUtils import register_report, NumberOption +from PluginUtils import register_report, NumberOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, \ MODE_GUI, MODE_CLI, CATEGORY_GRAPHVIZ from BasicUtils import name_displayer @@ -46,15 +46,16 @@ class HourGlassReport(Report): Creates HourGlass object that produces the report. """ Report.__init__(self,database,person,options_class) - self.person = person self.db = database self.max_descend = options_class.handler.options_dict['maxdescend'] self.max_ascend = options_class.handler.options_dict['maxascend'] + pid = options_class.handler.options_dict['pid'] + self.center_person = database.get_person_from_gramps_id(pid) def write_report(self): - self.add_person(self.person) - self.traverse_up(self.person,1) - self.traverse_down(self.person,1) + self.add_person(self.center_person) + self.traverse_up(self.center_person,1) + self.traverse_down(self.center_person,1) def traverse_down(self,person,gen): """ @@ -153,6 +154,13 @@ class HourGlassOptions(MenuReportOptions): MenuReportOptions.__init__(self,name,dbstate) def add_menu_options(self,menu,dbstate): + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) + category_name = _("Report Options") max_gen = NumberOption(_('Max Descendant Generations'),10,1,15) diff --git a/src/plugins/GVRelGraph.py b/src/plugins/GVRelGraph.py index 6c4a140e0..2ebe17ef0 100644 --- a/src/plugins/GVRelGraph.py +++ b/src/plugins/GVRelGraph.py @@ -34,7 +34,7 @@ Create a relationship graph using Graphviz # GRAMPS modules # #------------------------------------------------------------------------ -from PluginUtils import register_report, FilterListOption, \ +from PluginUtils import register_report, PersonFilterOption, \ EnumeratedListOption, BooleanOption from ReportBase import Report, MenuReportOptions, \ MODE_GUI, MODE_CLI, CATEGORY_GRAPHVIZ @@ -135,9 +135,7 @@ class RelGraphReport(Report): self.arrowtailstyle = 'none' filter_option = options_class.menu.get_option_by_name('filter') - filter_index = int(filter_option.get_value()) - filters = filter_option.get_filters() - self.filter = filters[filter_index] + self.filter = filter_option.get_filter() def write_report(self): self.person_handles = self.filter.apply(self.database, @@ -418,8 +416,7 @@ class RelGraphOptions(MenuReportOptions): category_name = _("Report Options") ################################ - filter = FilterListOption(_("Filter")) - filter.add_item("person") + filter = PersonFilterOption(_("Filter"),dbstate,0,False) filter.set_help(_("Select the filter to be applied to the report")) menu.add_option(category_name,"filter", filter) diff --git a/src/plugins/IndivComplete.py b/src/plugins/IndivComplete.py index 63ce2c419..92ecc7c1c 100644 --- a/src/plugins/IndivComplete.py +++ b/src/plugins/IndivComplete.py @@ -1,8 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,13 +29,6 @@ import os from gettext import gettext as _ -#------------------------------------------------------------------------ -# -# Gnome/GTK modules -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # GRAMPS modules @@ -47,8 +40,8 @@ import Utils import BaseDoc from Filters import GenericFilter, Rules import DateHandler -from PluginUtils import register_report -from ReportBase import Report, ReportUtils, ReportOptions, \ +from PluginUtils import register_report, PersonFilterOption, BooleanOption +from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI from ReportBase import Bibliography, Endnotes from BasicUtils import name_displayer as _nd @@ -84,9 +77,8 @@ class IndivCompleteReport(Report): self.use_srcs = options_class.handler.options_dict['cites'] - filter_num = options_class.handler.options_dict['filter'] - filters = ReportUtils.get_person_filters(person) - self.filter = filters[filter_num] + filter_option = options_class.menu.get_option_by_name('filter') + self.filter = filter_option.get_filter() self.bibli = None def write_fact(self,event_ref): @@ -529,61 +521,31 @@ class IndivCompleteReport(Report): self.write_note() if self.use_srcs: Endnotes.write_endnotes(self.bibli,self.database,self.doc) - + #------------------------------------------------------------------------ # -# +# IndivCompleteOptions # #------------------------------------------------------------------------ -class IndivCompleteOptions(ReportOptions): - +class IndivCompleteOptions(MenuReportOptions): """ Defines options and provides handling interface. """ - - def __init__(self,name,person_id=None): - ReportOptions.__init__(self,name,person_id) - - # Options specific for this report - self.options_dict = { - 'filter' : 0, - 'cites' : 1, - } - filters = ReportUtils.get_person_filters(None) - self.options_help = { - 'filter' : ("=num","Filter number.", - [ filt.get_name() for filt in filters ], - True ), - 'cites' : ("=0/1","Whether to cite sources.", - ["Do not cite sources","Cite sources"], - True), - } - - def add_user_options(self,dialog): - """ - Override the base class add_user_options task to add a menu that allows - the user to select the sort method. - """ - filter_index = self.options_dict['filter'] - filter_list = ReportUtils.get_person_filters(dialog.person) - self.filter_menu = gtk.combo_box_new_text() - for filter in filter_list: - self.filter_menu.append_text(filter.get_name()) - if filter_index > len(filter_list): - filter_index = 0 - self.filter_menu.set_active(filter_index) - dialog.add_option('Filter',self.filter_menu) - - self.use_srcs = gtk.CheckButton(_('Include Source Information')) - self.use_srcs.set_active(self.options_dict['cites']) - dialog.add_option('',self.use_srcs) - - def parse_user_options(self,dialog): - """ - Parses the custom options that we have added. - """ - self.options_dict['filter'] = int(self.filter_menu.get_active()) - self.options_dict['cites'] = int(self.use_srcs.get_active()) + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) + + def add_menu_options(self,menu,dbstate): + ################################ + category_name = _("Report Options") + ################################ + + filter = PersonFilterOption(_("Filter"),dbstate,0,True) + filter.set_help(_("Select the filter to be applied to the report")) + menu.add_option(category_name,"filter", filter) + + cites = BooleanOption(_("Include Source Information"), True) + cites.set_help(_("Whether to cite sources.")) + menu.add_option(category_name,"cites", cites) def make_default_style(self,default_style): """Make the default output style for the Individual Complete Report.""" diff --git a/src/plugins/KinshipReport.py b/src/plugins/KinshipReport.py index 8a39f642a..e7265c575 100644 --- a/src/plugins/KinshipReport.py +++ b/src/plugins/KinshipReport.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,20 +30,14 @@ from gettext import gettext as _ from string import capitalize -#------------------------------------------------------------------------ -# -# GTK modules -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # gramps modules # #------------------------------------------------------------------------ -from PluginUtils import register_report, relationship_class -from ReportBase import Report, ReportUtils, ReportOptions, \ +from PluginUtils import register_report, relationship_class, NumberOption, \ + BooleanOption, PersonOption +from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc from BasicUtils import name_displayer @@ -74,6 +68,7 @@ class KinshipReport(Report): incspouses - Whether to include spouses. inccousins - Whether to include cousins. incaunts - Whether to include aunts/uncles/nephews/nieces. + pid - The Gramps ID of the center person for the report. """ Report.__init__(self,database,person,options_class) @@ -82,8 +77,9 @@ class KinshipReport(Report): self.incSpouses = options_class.handler.options_dict['incspouses'] self.incCousins = options_class.handler.options_dict['inccousins'] self.incAunts = options_class.handler.options_dict['incaunts'] - - self.person = person + pid = options_class.handler.options_dict['pid'] + self.person = database.get_person_from_gramps_id(pid) + self.db = database self.relCalc = relationship_class() self.kinship_map = {} @@ -113,7 +109,7 @@ class KinshipReport(Report): # Collect all ancestors/aunts/uncles/nephews/cousins of the person self.traverse_up(self.person.get_handle(),1,0) - # Write Ancestors + # Write Kin for Ga in self.kinship_map.keys(): for Gb in self.kinship_map[Ga]: # To understand these calculations, see: @@ -321,72 +317,47 @@ class KinshipReport(Report): # KinshipOptions # #------------------------------------------------------------------------ -class KinshipOptions(ReportOptions): +class KinshipOptions(MenuReportOptions): + """ Defines options and provides handling interface. """ - def __init__(self,name,person_id=None): - ReportOptions.__init__(self,name,person_id) - - self.options_dict = { - 'maxdescend' : 2, - 'maxascend' : 2, - 'incspouses' : 1, - 'inccousins' : 1, - 'incsiblings' : 1, - 'incaunts' : 1, - } - self.options_help = { - 'maxdescend' : ("=int","Max Descendants", - "The number of generations of descendants to " \ - "include in the report", - True), - 'maxascend' : ("=int","Max Ancestors", - "The number of generations of ancestors to " \ - "include in the report", - True), - 'incspouses' : ("=0/1","Whether to include spouses", - ["Do not include spouses","Include spouses"], - True), - 'inccousins' : ("=0/1","Whether to include cousins", - ["Do not include cousins","Include cousins"], - True), - 'incaunts' : ("=0/1", - "Whether to include aunts/uncles/nephews/nieces", - ["Do not include aunts","Include aunts"], - True), - } + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) - def add_user_options(self,dialog): - self.maxdescend = gtk.SpinButton(gtk.Adjustment(1,1,20,1)) - self.maxdescend.set_value(self.options_dict['maxdescend']) + def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the kinship report. + """ + id = "" + if dbstate: + id = dbstate.get_active_person().get_gramps_id() + pid = PersonOption(_("Center Person"),id,dbstate) + pid.set_help(_("The center person for the report")) + menu.add_option("","pid",pid) - self.maxascend = gtk.SpinButton(gtk.Adjustment(1,1,20,1)) - self.maxascend.set_value(self.options_dict['maxascend']) + category_name = _("Report Options") - self.incspouses = gtk.CheckButton(_("Include spouses")) - self.incspouses.set_active(self.options_dict['incspouses']) + maxdescend = NumberOption(_("Max Descendant Generations"),2,1,20) + maxdescend.set_help(_("The maximum number of descendant generations")) + menu.add_option(category_name,"maxdescend",maxdescend) - self.inccousins = gtk.CheckButton(_("Include cousins")) - self.inccousins.set_active(self.options_dict['inccousins']) + maxascend = NumberOption(_("Max Ancestor Generations"),2,1,20) + maxascend.set_help(_("The maximum number of ancestor generations")) + menu.add_option(category_name,"maxascend",maxascend) - self.incaunts = gtk.CheckButton( - _("Include aunts/uncles/nephews/nieces")) - self.incaunts.set_active(self.options_dict['incaunts']) - - dialog.add_option (_('Max Descendant Generations'), self.maxdescend) - dialog.add_option (_('Max Ancestor Generations'), self.maxascend) - dialog.add_option ('', self.incspouses) - dialog.add_option ('', self.inccousins) - dialog.add_option ('', self.incaunts) - - def parse_user_options(self,dialog): - self.options_dict['maxdescend'] = self.maxdescend.get_value_as_int() - self.options_dict['maxascend'] = self.maxascend.get_value_as_int() - self.options_dict['incspouses'] = int(self.incspouses.get_active ()) - self.options_dict['inccousins'] = int(self.inccousins.get_active()) - self.options_dict['incaunts'] = int(self.incaunts.get_active()) + incspouses = BooleanOption(_("Include spouses"),True) + incspouses.set_help(_("Whether to include spouses")) + menu.add_option(category_name,"incspouses",incspouses) + + inccousins = BooleanOption(_("Include cousins"),True) + inccousins.set_help(_("Whether to include cousins")) + menu.add_option(category_name,"inccousins",inccousins) + + incaunts = BooleanOption(_("Include aunts/uncles/nephews/nieces"),True) + incaunts.set_help(_("Whether to include aunts/uncles/nephews/nieces")) + menu.add_option(category_name,"incaunts",incaunts) def make_default_style(self,default_style): """Make the default output style for the Kinship Report.""" diff --git a/src/plugins/MarkerReport.py b/src/plugins/MarkerReport.py index b34e42a03..d5209569a 100644 --- a/src/plugins/MarkerReport.py +++ b/src/plugins/MarkerReport.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,31 +28,21 @@ # #------------------------------------------------------------------------ from gettext import gettext as _ -import copy #------------------------------------------------------------------------ # # GRAMPS modules # #------------------------------------------------------------------------ -from PluginUtils import register_report -from ReportBase import Report, ReportUtils, ReportOptions, \ +from PluginUtils import register_report, EnumeratedListOption +from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc -import Sort -import AutoComp from gen.lib import MarkerType, FamilyRelType from Filters import GenericFilter, GenericFilterFactory, Rules from BasicUtils import name_displayer import DateHandler -#------------------------------------------------------------------------ -# -# GTK/GNOME modules -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # MarkerReport @@ -73,18 +63,20 @@ class MarkerReport(Report): This report needs the following parameters (class variables) that come in the options class. - marker - The marker each object must match to be included, - an English string for normal data, otherwise custom - language string. - marker_str - Same as marker but now always localized. + marker - The marker each object must match to be included. """ Report.__init__(self,database,person,options_class) - self.marker = options_class.markerval - self.marker_str = options_class.marker_str + self.marker = options_class.handler.options_dict['marker'] def write_report(self): + markerstr = self.marker + # Use localized name if this is not a custom marker + if MarkerType._E2IMAP.has_key(self.marker): + mtype = MarkerType._E2IMAP[self.marker] + markerstr = MarkerType._I2SMAP[mtype] + self.doc.start_paragraph("MR-Title") - title = _("Marker Report for %s Items") % self.marker_str + title = _("Marker Report for %s Items") % markerstr mark = BaseDoc.IndexMark(title,BaseDoc.INDEX_TYPE_TOC,1) self.doc.write_text(title,mark) self.doc.end_paragraph() @@ -427,70 +419,32 @@ class MarkerReport(Report): #------------------------------------------------------------------------ # -# +# MarkerOptions # #------------------------------------------------------------------------ -class MarkerOptions(ReportOptions): +class MarkerOptions(MenuReportOptions): - """ - Defines options and provides handling interface. - """ - - def __init__(self,name,person_id=None): - ReportOptions.__init__(self,name,person_id) - - # Options specific for this report - self.options_dict = { - 'marker' : "", - } - self.options_help = { - 'marker' : ("=str","Marker", - "The marker each item must match to be included", - True), - } + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) - def add_user_options(self,dialog): + def add_menu_options(self,menu,dbstate): """ - Override the base class add_user_options task to add generations option + Add options to the menu for the marker report. """ - self.marker_menu = gtk.ComboBoxEntry() - int_to_string_map = copy.deepcopy(MarkerType._I2SMAP) - #remove the None - del int_to_string_map[MarkerType.NONE] - #add custom markers - self.max_non_custom = max(int_to_string_map.keys()) - nextint = self.max_non_custom+1 - custommarkers = dialog.db.get_marker_types() - for item in custommarkers: - int_to_string_map[nextint] = item - nextint += 1 - - marker_index = 0 - for int, str in int_to_string_map.items() : - if self.options_dict['marker'] == str : - marker_index = int - break - self.sel = AutoComp.StandardCustomSelector(int_to_string_map, - self.marker_menu, - MarkerType._CUSTOM, - marker_index) + category_name = _("Report Options") - dialog.add_option(_('Marker'),self.marker_menu) - - def parse_user_options(self,dialog): - """ - Parses the custom options that we have added. Set the value in the - options dictionary. - """ - self.options_dict['marker'] = self.sel.get_values()[1] - - int, str = self.sel.get_values() - self.marker_str = str - #marker filter needs untranslated english string, skip custom entry - if int is not MarkerType.CUSTOM and int <= self.max_non_custom: - self.markerval = MarkerType._I2EMAP[int] - else: - self.markerval = str + marker = EnumeratedListOption(_('Marker'),0) + # Add built-in marker types + for mtype in MarkerType._I2SMAP: + if mtype != MarkerType.NONE and mtype != MarkerType.CUSTOM: + # Use translated name for built-in marker types + marker.add_item(MarkerType._I2EMAP[mtype], + MarkerType._I2SMAP[mtype] ) + # Add custom marker types + for m in dbstate.get_database().get_marker_types(): + marker.add_item( m, m ) + marker.set_help( _("The marker to use for the report")) + menu.add_option(category_name,"marker",marker) def make_default_style(self,default_style): """Make the default output style for the Marker Report.""" diff --git a/src/plugins/SimpleBookTitle.py b/src/plugins/SimpleBookTitle.py index 952477427..f5a17f5b1 100644 --- a/src/plugins/SimpleBookTitle.py +++ b/src/plugins/SimpleBookTitle.py @@ -144,12 +144,8 @@ class SimpleBookTitleOptions(ReportOptions): "0 (to fit the page)."], False), } - - def do_nothing(self): - pass def add_user_options(self,dialog): - dialog.setup_center_person = self.do_nothing #Disable center person dialog.notebook = gtk.Notebook() dialog.notebook.set_border_width(6) dialog.window.vbox.add(dialog.notebook) diff --git a/src/plugins/StatisticsChart.py b/src/plugins/StatisticsChart.py index d33916f19..dabdde762 100644 --- a/src/plugins/StatisticsChart.py +++ b/src/plugins/StatisticsChart.py @@ -1,8 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2006 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2003-2006 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,13 +37,6 @@ Statistics Chart report import time from TransUtils import sgettext as _ -#------------------------------------------------------------------------ -# -# GNOME/gtk -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # GRAMPS modules @@ -55,7 +48,9 @@ from gen.lib import Person, FamilyRelType, EventType # gender and report type names import BaseDoc from PluginUtils import register_report -from ReportBase import Report, ReportUtils, ReportOptions, \ +from PluginUtils import BooleanOption, PersonFilterOption, EnumeratedListOption, \ + NumberOption +from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_DRAW, MODE_GUI, MODE_BKI, MODE_CLI from Filters import GenericFilter, Rules import DateHandler @@ -479,9 +474,8 @@ class StatisticsChart(Report): """ Report.__init__(self,database,person,options_class) - filter_num = options_class.handler.options_dict['filter'] - filters = ReportUtils.get_person_filters(person,False) - filterfun = filters[filter_num] + self.filter_option = options_class.menu.get_option_by_name('filter') + self.filter = self.filter_option.get_filter() options = options_class.handler.options_dict self.bar_items = options['bar_items'] @@ -507,7 +501,7 @@ class StatisticsChart(Report): # extract requested items from the database and count them self.progress.set_pass(_('Collecting data...'), 1) - tables = _Extract.collect_data(database, filterfun, options, + tables = _Extract.collect_data(database, self.filter, options, gender, year_from, year_to, options['no_years']) self.progress.step() @@ -660,55 +654,87 @@ class StatisticsChart(Report): #------------------------------------------------------------------------ # -# Statistics report options +# StatisticsChartOptions # #------------------------------------------------------------------------ -class StatisticsChartOptions(ReportOptions): - """ - Defines options and provides their handling interface. - """ - def __init__(self,name, person_id=None): - ReportOptions.__init__(self, name, person_id) +class StatisticsChartOptions(MenuReportOptions): - # Options specific for this report - self.options_dict = { - 'filter' : 0, - 'gender' : Person.UNKNOWN, - 'sortby' : _options.SORT_VALUE, - 'reverse' : 0, - 'year_from' : 1700, - 'year_to' : time.localtime()[0], - 'no_years' : 0, - 'bar_items' : 8 - } - for key in _Extract.extractors: - self.options_dict[key] = 0 - self.options_dict['data_gender'] = 1 + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) + + def add_menu_options(self,menu,dbstate): + """ + Add options to the menu for the statistics report. + """ + category_name = _("Report Options") + + filter = PersonFilterOption(_("Filter"),dbstate,0,False) + filter.set_help(_("Determines what people are included in the report")) + menu.add_option(category_name,"filter", filter) + + sortby = EnumeratedListOption(_('Sort chart items by'), + _options.SORT_VALUE ) + for item_idx in range(len(_options.sorts)): + item = _options.sorts[item_idx] + sortby.add_item(item_idx,item[2]) + sortby.set_help( _("Select how the statistical data is sorted.")) + menu.add_option(category_name,"sortby",sortby) - filters = ReportUtils.get_person_filters(None,False) - self.options_help = { - 'gender' : ("=num", "Genders included", - ["%d\t%s" % (item[0], item[1]) for item in _options.genders], - False), - 'sortby' : ("=num", "Sort chart items by", - ["%d\t%s" % (item[0], item[1]) for item in _options.sorts], - False), - 'reverse' : ("=0/1", "Whether to sort in reverse order", - ["Do not sort in reverse", "Sort in reverse"], - True), - 'year_from' : ("=num", "Birth year from which to include people", - "Earlier than 'year_to' value"), - 'year_to' : ("=num", "Birth year until which to include people", - "Smaller than %d" % self.options_dict['year_to']), - 'no_years' : ("=0/1", "Whether to include people without known birth years", - ["Do not include", "Include"], True), - 'bar_items' : ("=num", "Use barchart instead of piechart with this many or more items", - "Number of items with which piecharts still look good...") - } + reverse = BooleanOption(_("Sort in reverse order"), False) + reverse.set_help(_("Check to reverse the sorting order.")) + menu.add_option(category_name,"reverse", reverse) + + this_year = time.localtime()[0] + year_from = NumberOption(_("People Born Before"), + 1700, 1, this_year) + year_from.set_help(_("Birth year from which to include people")) + menu.add_option(category_name,"year_from", year_from) + + year_to = NumberOption(_("People Born After"), + this_year, 1, this_year) + year_to.set_help(_("Birth year until which to include people")) + menu.add_option(category_name,"year_to", year_to) + + no_years = BooleanOption(_("Include people without known birth years"), + False) + no_years.set_help(_("Whether to include people without " + "known birth years")) + menu.add_option(category_name,"no_years", no_years) + + gender = EnumeratedListOption(_('Genders included'), + Person.UNKNOWN ) + for item_idx in range(len(_options.genders)): + item = _options.genders[item_idx] + gender.add_item(item[0],item[2]) + gender.set_help( _("Select which genders are included into " + "statistics.")) + menu.add_option(category_name,"gender",gender) + + bar_items = NumberOption(_("Max. items for a pie"), 8, 0, 20) + bar_items.set_help(_("With fewer items pie chart and legend will be " + "used instead of a bar chart.")) + menu.add_option(category_name,"bar_items", bar_items) + + # ------------------------------------------------- + # List of available charts on separate option tabs + idx = 0 + half = (len(_Extract.extractors))/2 + self.charts = {} for key in _Extract.extractors: - self.options_help[key] = ("=0/1", _Extract.extractors[key][0], - ["Leave chart with this data out", "Include chart with this data"], - True) + if idx < half: + category_name = _("Charts 1") + else: + category_name = _("Charts 2") + + opt = BooleanOption(_Extract.extractors[key][1], False) + opt.set_help(_("Include charts with indicated dat")) + menu.add_option(category_name,key, opt) + idx += 1 + + # Enable a couple of charts by default + menu.get_option_by_name("data_gender").set_value(True) + menu.get_option_by_name("data_ccount").set_value(True) + menu.get_option_by_name("data_bmonth").set_value(True) def make_default_style(self, default_style): """Make the default output style for the Statistics report.""" @@ -819,121 +845,6 @@ class StatisticsChartOptions(ReportOptions): g.set_line_width(0) default_style.add_draw_style("SC-legend",g) - def add_user_options(self, dialog): - """ - Override the base class add_user_options task to add - report specific options - """ - filter_index = self.options_dict['filter'] - filter_list = ReportUtils.get_person_filters(dialog.person,False) - self.filter_menu = gtk.combo_box_new_text() - for filter in filter_list: - self.filter_menu.append_text(filter.get_name()) - if filter_index > len(filter_list): - filter_index = 0 - self.filter_menu.set_active(filter_index) - dialog.add_option(_('Filter'),self.filter_menu) - - # how to sort the data - self.sort_menu = gtk.combo_box_new_text() - for item_idx in range(len(_options.sorts)): - item = _options.sorts[item_idx] - self.sort_menu.append_text(item[2]) - if item[0] == self.options_dict['sortby']: - self.sort_menu.set_active(item_idx) - tip = _("Select how the statistical data is sorted.") - dialog.add_option(_("Sort chart items by"), self.sort_menu, tip) - - # sorting order - tip = _("Check to reverse the sorting order.") - self.reverse = gtk.CheckButton(_("Sort in reverse order")) - self.reverse.set_active(self.options_dict['reverse']) - dialog.add_option(None, self.reverse, tip) - self.reverse.show() - - # year range - from_adj = gtk.Adjustment(value=self.options_dict['year_from'], - lower=1, upper=time.localtime()[0], - step_incr=1, page_incr=100) - self.from_box = gtk.SpinButton(adjustment=from_adj, digits=0) - to_adj = gtk.Adjustment(value=self.options_dict['year_to'], - lower=1, upper=time.localtime()[0], - step_incr=1, page_incr=100) - self.to_box = gtk.SpinButton(adjustment=to_adj, digits=0) - - box = gtk.HBox() - box.add(self.from_box) - box.add(gtk.Label("-")) - box.add(self.to_box) - tip = _("Select year range within which people need to be born to be selected for statistics.") - dialog.add_option(_('People born between'), box, tip) - box.show_all() - - # include people without known birth year? - tip = _("Check this if you want people who have no known birth date or year to be accounted also in the statistics.") - self.no_years = gtk.CheckButton(_("Include people without known birth years")) - self.no_years.set_active(self.options_dict['no_years']) - dialog.add_option(None, self.no_years, tip) - self.no_years.show() - - # gender selection - self.gender_menu = gtk.combo_box_new_text() - for item_idx in range(len(_options.genders)): - item = _options.genders[item_idx] - self.gender_menu.append_text(item[2]) - if item[0] == self.options_dict['gender']: - self.gender_menu.set_active(item_idx) - tip = _("Select which genders are included into statistics.") - dialog.add_option(_("Genders included"), self.gender_menu, tip) - - # max. pie item selection - tip = _("With fewer items pie chart and legend will be used instead of a bar chart.") - pie_adj = gtk.Adjustment(value=self.options_dict['bar_items'], - lower=0, upper=20, step_incr=1) - self.bar_items = gtk.SpinButton(adjustment=pie_adj, digits=0) - dialog.add_option(_("Max. items for a pie"), self.bar_items, tip) - - # ------------------------------------------------- - # List of available charts on a separate option tab - idx = 0 - half = (len(_Extract.extractors)+1)/2 - hbox = gtk.HBox() - vbox = gtk.VBox() - self.charts = {} - for key in _Extract.extractors: - check = gtk.CheckButton(_Extract.extractors[key][1]) - check.set_active(self.options_dict[key]) - self.charts[key] = check - vbox.add(check) - idx += 1 - if idx == half: - hbox.add(vbox) - vbox = gtk.VBox() - hbox.add(vbox) - tip = _("Mark checkboxes to add charts with indicated data") - dialog.add_frame_option(_("Charts"), "", hbox, tip) - hbox.show_all() - - # Note about children - label = gtk.Label(_("Note that both biological and adopted children are taken into account.")) - dialog.add_frame_option(_("Charts"), "", label) - - - def parse_user_options(self, dialog): - """ - Parses the custom options that we have added. - """ - self.options_dict['filter'] = int(self.filter_menu.get_active()) - self.options_dict['sortby'] = _options.sorts[self.sort_menu.get_active()][0] - self.options_dict['reverse'] = int(self.reverse.get_active()) - self.options_dict['year_to'] = int(self.to_box.get_value_as_int()) - self.options_dict['year_from'] = int(self.from_box.get_value_as_int()) - self.options_dict['no_years'] = int(self.no_years.get_active()) - self.options_dict['gender'] = _options.genders[self.gender_menu.get_active()][0] - self.options_dict['bar_items'] = int(self.bar_items.get_value_as_int()) - for key in _Extract.extractors: - self.options_dict[key] = int(self.charts[key].get_active()) - #------------------------------------------------------------------------ # # Register report/options @@ -949,6 +860,7 @@ register_report( status = (_("Stable")), author_name="Eero Tamminen", author_email="", - description= _("Generates statistical bar and pie charts of the people in the database."), + description= _("Generates statistical bar and pie charts of the people " + "in the database."), require_active=False, ) diff --git a/src/plugins/TimeLine.py b/src/plugins/TimeLine.py index 0491705a9..3f053d77f 100644 --- a/src/plugins/TimeLine.py +++ b/src/plugins/TimeLine.py @@ -1,8 +1,8 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2003-2007 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly +# Copyright (C) 2003-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,20 +32,14 @@ Timeline report #------------------------------------------------------------------------ from TransUtils import sgettext as _ -#------------------------------------------------------------------------ -# -# GNOME/gtk -# -#------------------------------------------------------------------------ -import gtk - #------------------------------------------------------------------------ # # GRAMPS modules # #------------------------------------------------------------------------ from PluginUtils import register_report -from ReportBase import Report, ReportUtils, ReportOptions, \ +from PluginUtils import PersonFilterOption, EnumeratedListOption +from ReportBase import Report, ReportUtils, MenuReportOptions, \ CATEGORY_DRAW, MODE_GUI, MODE_BKI, MODE_CLI pt2cm = ReportUtils.pt2cm import BaseDoc @@ -54,6 +48,17 @@ import Sort from QuestionDialog import ErrorDialog from BasicUtils import name_displayer +#------------------------------------------------------------------------ +# +# Private Functions +# +#------------------------------------------------------------------------ +def _get_sort_functions(sort): + return [ + (_("Birth Date"),sort.by_birthdate), + (_("Name"),sort.by_last_name), +] + #------------------------------------------------------------------------ # # TimeLine @@ -77,23 +82,19 @@ class TimeLine(Report): filter - Filter to be applied to the people of the database. The option class carries its number, and the function returning the list of filters. - sort_func - function used to sort entries, that returns -1/0/1 - when given two personal handles (like cmp). - The option class carries its number, and the function - returning the list of sort functions. + sortby - Sorting method to be used. """ Report.__init__(self,database,person,options_class) filter_num = options_class.handler.options_dict['filter'] - filters = ReportUtils.get_person_filters(person,False) - self.filter = filters[filter_num] + self.filter_option = options_class.menu.get_option_by_name('filter') + self.filter = self.filter_option.get_filter() - name = name_displayer.display_formal(person) - self.title = _("Timeline Graph for %s") % name + self.title = _("Timeline Graph for %s") % self.filter.get_name() sort_func_num = options_class.handler.options_dict['sortby'] - sort_functions = options_class.get_sort_functions(Sort.Sort(database)) + sort_functions = _get_sort_functions(Sort.Sort(database)) self.sort_func = sort_functions[sort_func_num][1] def write_report(self): @@ -289,34 +290,30 @@ class TimeLine(Report): #------------------------------------------------------------------------ # -# +# TimeLineOptions # #------------------------------------------------------------------------ -class TimeLineOptions(ReportOptions): - - """ - Defines options and provides handling interface. - """ - - def __init__(self,name,person_id=None): - ReportOptions.__init__(self,name,person_id) - - # Options specific for this report - self.options_dict = { - 'filter' : 0, - 'sortby' : 0, - } - filters = ReportUtils.get_person_filters(None,False) - self.options_help = { - 'filter' : ("=num","Filter number.", - [ filt.get_name() for filt in filters ], - True ), - 'sortby' : ("=num","Number of a sorting function", - [item[0] for item in - self.get_sort_functions(Sort.Sort(None))], - True), - } +class TimeLineOptions(MenuReportOptions): + def __init__(self,name,dbstate=None): + MenuReportOptions.__init__(self,name,dbstate) + + def add_menu_options(self,menu,dbstate): + category_name = _("Report Options") + + filter = PersonFilterOption(_("Filter"),dbstate,0,False) + filter.set_help(_("Determine what people will be included in " + "the report")) + menu.add_option(category_name,"filter", filter) + + sortby = EnumeratedListOption(_('Sort by'), 0 ) + idx = 0 + for item in _get_sort_functions(Sort.Sort(dbstate.get_database())): + sortby.add_item(idx,item[0]) + idx += 1 + sortby.set_help( _("Sorting method to use")) + menu.add_option(category_name,"sortby",sortby) + def make_default_style(self,default_style): """Make the default output style for the Timeline report.""" # Paragraph Styles @@ -405,44 +402,6 @@ class TimeLineOptions(ReportOptions): g.set_line_width(0) default_style.add_draw_style("TLG-label",g) - def get_sort_functions(self,sort): - return [ - (_("Birth Date"),sort.by_birthdate), - (_("Name"),sort.by_last_name), - ] - - def add_user_options(self,dialog): - """ - Override the base class add_user_options task to add a menu that allows - the user to select the sort method. - """ - filter_index = self.options_dict['filter'] - filter_list = ReportUtils.get_person_filters(dialog.person,False) - self.filter_menu = gtk.combo_box_new_text() - for filter in filter_list: - self.filter_menu.append_text(filter.get_name()) - if filter_index > len(filter_list): - filter_index = 0 - self.filter_menu.set_active(filter_index) - dialog.add_option(_('Filter'),self.filter_menu) - - self.sort_menu = gtk.combo_box_new_text() - - sort_functions = self.get_sort_functions(Sort.Sort(dialog.db)) - for item in sort_functions: - self.sort_menu.append_text(item[0]) - - self.sort_menu.set_active(self.options_dict['sortby']) - - dialog.add_option(_('Sort by'),self.sort_menu) - - def parse_user_options(self,dialog): - """ - Parses the custom options that we have added. - """ - self.options_dict['filter'] = int(self.filter_menu.get_active()) - self.options_dict['sortby'] = self.sort_menu.get_active() - #------------------------------------------------------------------------ # #