From c861968fd3c48448d73fa730346c7223c492ea1e Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 7 Mar 2013 22:54:58 +0000 Subject: [PATCH] 6128: Reverse bug fix keeping code refactor svn: r21576 --- gramps/cli/plug/__init__.py | 20 ++++++------------ gramps/gen/plug/report/__init__.py | 2 +- gramps/gen/plug/report/_book.py | 8 ++------ gramps/gui/plug/report/_bookdialog.py | 29 +++++++++++---------------- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/gramps/cli/plug/__init__.py b/gramps/cli/plug/__init__.py index d7f695175..7588c9b04 100644 --- a/gramps/cli/plug/__init__.py +++ b/gramps/cli/plug/__init__.py @@ -60,7 +60,7 @@ from gramps.gen.display.name import displayer as name_displayer from gramps.gen.errors import ReportError, FilterError from gramps.gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, CATEGORY_GRAPHVIZ, CATEGORY_CODE, - ReportOptions, create_style_sheet) + ReportOptions, append_styles) from gramps.gen.plug.report._paper import paper_sizes from gramps.gen.const import USER_HOME from gramps.gen.dbstate import DbState @@ -727,7 +727,7 @@ def cl_book(database, name, book, options_str_dict): clr.marginr, clr.margint, clr.marginb)) user = User() rptlist = [] - global_style = None + selected_style = StyleSheet() for item in book.get_item_list(): # The option values were loaded magically by the book parser. @@ -743,27 +743,19 @@ def cl_book(database, name, book, options_str_dict): report_class = item.get_write_item() obj = write_book_item(database, report_class, item.option_class, user) - style_sheet = create_style_sheet(item) - rptlist.append((obj, style_sheet)) - if ( item.name == 'table_of_contents' or - item.name == 'alphabetical_index' ): # ugly hack: FIXME - if global_style is None: - global_style = style_sheet - else: - global_style = create_style_sheet(item, global_style) + append_styles(selected_style, item) + rptlist.append(obj) + doc.set_style_sheet(selected_style) doc.open(clr.option_class.get_output()) doc.init() newpage = 0 - for rpt, style_sheet in rptlist: - doc.set_style_sheet(style_sheet) + for rpt in rptlist: if newpage: doc.page_break() newpage = 1 rpt.begin_report() rpt.write_report() - if global_style: - doc.set_style_sheet(global_style) doc.close() #------------------------------------------------------------------------ diff --git a/gramps/gen/plug/report/__init__.py b/gramps/gen/plug/report/__init__.py index 77ae44e70..d845287aa 100644 --- a/gramps/gen/plug/report/__init__.py +++ b/gramps/gen/plug/report/__init__.py @@ -34,4 +34,4 @@ from ._bibliography import Bibliography, Citation from ._options import MenuReportOptions, ReportOptions, DocOptions -from ._book import BookList, Book, BookItem, create_style_sheet +from ._book import BookList, Book, BookItem, append_styles diff --git a/gramps/gen/plug/report/_book.py b/gramps/gen/plug/report/_book.py index bbc798e00..47d4ba38c 100644 --- a/gramps/gen/plug/report/_book.py +++ b/gramps/gen/plug/report/_book.py @@ -449,12 +449,10 @@ class BookParser(handler.ContentHandler): # Functions # #------------------------------------------------------------------------- -def create_style_sheet(item, previous_style=None): +def append_styles(selected_style, item): """ - Create a style sheet for a book item, appending any previous_style. + Append the styles for a book item to the stylesheet. """ - selected_style = StyleSheet(previous_style) - handler = item.option_class.handler # Set up default style @@ -490,5 +488,3 @@ def create_style_sheet(item, previous_style=None): selected_style.add_cell_style( this_style_name, style_sheet.get_cell_style(this_style_name)) - - return selected_style diff --git a/gramps/gui/plug/report/_bookdialog.py b/gramps/gui/plug/report/_bookdialog.py index 388cf435c..0b34db5e8 100644 --- a/gramps/gui/plug/report/_bookdialog.py +++ b/gramps/gui/plug/report/_bookdialog.py @@ -65,6 +65,7 @@ from gramps.gen.constfunc import cuni from ...pluginmanager import GuiPluginManager from ...dialog import WarningDialog, ErrorDialog from gramps.gen.plug.menu import PersonOption, FilterOption, FamilyOption +from gramps.gen.plug.docgen import StyleSheet from ...managedwindow import ManagedWindow, set_titles from ...glade import Glade from ...utils import is_right_click, open_file_with_default_application @@ -72,7 +73,7 @@ from ...user import User from .. import make_gui_option # Import from specific modules in ReportBase -from gramps.gen.plug.report import BookList, Book, BookItem, create_style_sheet +from gramps.gen.plug.report import BookList, Book, BookItem, append_styles from gramps.gen.plug.report import CATEGORY_BOOK, book_categories from gramps.gen.plug.report._options import ReportOptions from ._reportdialog import ReportDialog @@ -889,25 +890,22 @@ class BookDialog(DocReportDialog): def make_document(self): """Create a document of the type requested by the user.""" - pstyle = self.paper_frame.get_paper_style() - self.doc = self.format(None, pstyle) user = User() self.rptlist = [] - self.global_style = None + selected_style = StyleSheet() + + pstyle = self.paper_frame.get_paper_style() + self.doc = self.format(None, pstyle) + for item in self.book.get_item_list(): item.option_class.set_document(self.doc) report_class = item.get_write_item() obj = write_book_item(self.database, report_class, item.option_class, user) - style_sheet = create_style_sheet(item) - self.rptlist.append((obj, style_sheet)) - if ( item.name == 'table_of_contents' or - item.name == 'alphabetical_index' ): # ugly hack: FIXME - if self.global_style is None: - self.global_style = style_sheet - else: - self.global_style = create_style_sheet(item, - self.global_style) + self.rptlist.append(obj) + append_styles(selected_style, item) + + self.doc.set_style_sheet(selected_style) self.doc.open(self.target_path) def make_book(self): @@ -916,16 +914,13 @@ class BookDialog(DocReportDialog): self.doc.init() newpage = 0 - for rpt, style_sheet in self.rptlist: - self.doc.set_style_sheet(style_sheet) + for rpt in self.rptlist: if newpage: self.doc.page_break() newpage = 1 if rpt: rpt.begin_report() rpt.write_report() - if self.global_style: - self.doc.set_style_sheet(self.global_style) self.doc.close() if self.open_with_app.get_active():