6128: Reverse bug fix keeping code refactor

svn: r21577
This commit is contained in:
Nick Hall 2013-03-07 22:55:23 +00:00
parent 5a64a968ff
commit a5b4759f40
4 changed files with 21 additions and 38 deletions

View File

@ -60,7 +60,7 @@ from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.errors import ReportError, FilterError from gramps.gen.errors import ReportError, FilterError
from gramps.gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, from gramps.gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK,
CATEGORY_GRAPHVIZ, CATEGORY_CODE, CATEGORY_GRAPHVIZ, CATEGORY_CODE,
ReportOptions, create_style_sheet) ReportOptions, append_styles)
from gramps.gen.plug.report._paper import paper_sizes from gramps.gen.plug.report._paper import paper_sizes
from gramps.gen.const import USER_HOME from gramps.gen.const import USER_HOME
from gramps.gen.dbstate import DbState 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)) clr.marginr, clr.margint, clr.marginb))
user = User() user = User()
rptlist = [] rptlist = []
global_style = None selected_style = StyleSheet()
for item in book.get_item_list(): for item in book.get_item_list():
# The option values were loaded magically by the book parser. # 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() report_class = item.get_write_item()
obj = write_book_item(database, obj = write_book_item(database,
report_class, item.option_class, user) report_class, item.option_class, user)
style_sheet = create_style_sheet(item) append_styles(selected_style, item)
rptlist.append((obj, style_sheet)) rptlist.append(obj)
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)
doc.set_style_sheet(selected_style)
doc.open(clr.option_class.get_output()) doc.open(clr.option_class.get_output())
doc.init() doc.init()
newpage = 0 newpage = 0
for rpt, style_sheet in rptlist: for rpt in rptlist:
doc.set_style_sheet(style_sheet)
if newpage: if newpage:
doc.page_break() doc.page_break()
newpage = 1 newpage = 1
rpt.begin_report() rpt.begin_report()
rpt.write_report() rpt.write_report()
if global_style:
doc.set_style_sheet(global_style)
doc.close() doc.close()
#------------------------------------------------------------------------ #------------------------------------------------------------------------

View File

@ -34,4 +34,4 @@ from ._bibliography import Bibliography, Citation
from ._options import MenuReportOptions, ReportOptions, DocOptions from ._options import MenuReportOptions, ReportOptions, DocOptions
from ._book import BookList, Book, BookItem, create_style_sheet from ._book import BookList, Book, BookItem, append_styles

View File

@ -449,12 +449,10 @@ class BookParser(handler.ContentHandler):
# Functions # 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 handler = item.option_class.handler
# Set up default style # Set up default style
@ -490,5 +488,3 @@ def create_style_sheet(item, previous_style=None):
selected_style.add_cell_style( selected_style.add_cell_style(
this_style_name, this_style_name,
style_sheet.get_cell_style(this_style_name)) style_sheet.get_cell_style(this_style_name))
return selected_style

View File

@ -65,6 +65,7 @@ from gramps.gen.constfunc import cuni
from ...pluginmanager import GuiPluginManager from ...pluginmanager import GuiPluginManager
from ...dialog import WarningDialog, ErrorDialog from ...dialog import WarningDialog, ErrorDialog
from gramps.gen.plug.menu import PersonOption, FilterOption, FamilyOption from gramps.gen.plug.menu import PersonOption, FilterOption, FamilyOption
from gramps.gen.plug.docgen import StyleSheet
from ...managedwindow import ManagedWindow, set_titles from ...managedwindow import ManagedWindow, set_titles
from ...glade import Glade from ...glade import Glade
from ...utils import is_right_click, open_file_with_default_application from ...utils import is_right_click, open_file_with_default_application
@ -72,7 +73,7 @@ from ...user import User
from .. import make_gui_option from .. import make_gui_option
# Import from specific modules in ReportBase # 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 import CATEGORY_BOOK, book_categories
from gramps.gen.plug.report._options import ReportOptions from gramps.gen.plug.report._options import ReportOptions
from ._reportdialog import ReportDialog from ._reportdialog import ReportDialog
@ -889,25 +890,22 @@ class BookDialog(DocReportDialog):
def make_document(self): def make_document(self):
"""Create a document of the type requested by the user.""" """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() user = User()
self.rptlist = [] 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(): for item in self.book.get_item_list():
item.option_class.set_document(self.doc) item.option_class.set_document(self.doc)
report_class = item.get_write_item() report_class = item.get_write_item()
obj = write_book_item(self.database, report_class, obj = write_book_item(self.database, report_class,
item.option_class, user) item.option_class, user)
style_sheet = create_style_sheet(item) self.rptlist.append(obj)
self.rptlist.append((obj, style_sheet)) append_styles(selected_style, item)
if ( item.name == 'table_of_contents' or
item.name == 'alphabetical_index' ): # ugly hack: FIXME self.doc.set_style_sheet(selected_style)
if self.global_style is None:
self.global_style = style_sheet
else:
self.global_style = create_style_sheet(item,
self.global_style)
self.doc.open(self.target_path) self.doc.open(self.target_path)
def make_book(self): def make_book(self):
@ -916,16 +914,13 @@ class BookDialog(DocReportDialog):
self.doc.init() self.doc.init()
newpage = 0 newpage = 0
for rpt, style_sheet in self.rptlist: for rpt in self.rptlist:
self.doc.set_style_sheet(style_sheet)
if newpage: if newpage:
self.doc.page_break() self.doc.page_break()
newpage = 1 newpage = 1
if rpt: if rpt:
rpt.begin_report() rpt.begin_report()
rpt.write_report() rpt.write_report()
if self.global_style:
self.doc.set_style_sheet(self.global_style)
self.doc.close() self.doc.close()
if self.open_with_app.get_active(): if self.open_with_app.get_active():