Fix style sheet bug in books

svn: r20527
This commit is contained in:
Nick Hall 2012-10-07 15:05:36 +00:00
parent 2658861b18
commit 88e6df595f
4 changed files with 73 additions and 92 deletions

View File

@ -57,7 +57,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)
ReportOptions, create_style_sheet)
from gramps.gen.plug.report._paper import paper_sizes
from gramps.gen.const import USER_HOME
from gramps.gen.dbstate import DbState
@ -666,44 +666,13 @@ def cl_book(database, name, book, options_str_dict):
if clr.show:
return
selected_style = StyleSheet()
# write report
doc = clr.format(None,
PaperStyle(clr.paper, clr.orien, clr.marginl,
clr.marginr, clr.margint, clr.marginb))
user = User()
rptlist = []
for item in book.get_item_list():
handler = item.option_class.handler
# Set up default style
handler.set_default_stylesheet_name(item.get_style_name())
default_style = StyleSheet()
make_default_style = item.option_class.make_default_style
make_default_style(default_style)
# Read all style sheets available for this item
style_file = handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = handler.get_default_stylesheet_name()
style_sheet = style_list.get_style_sheet(style_name)
for this_style_name in style_sheet.get_paragraph_style_names():
selected_style.add_paragraph_style(
this_style_name,
style_sheet.get_paragraph_style(this_style_name))
for this_style_name in style_sheet.get_draw_style_names():
selected_style.add_draw_style(
this_style_name,
style_sheet.get_draw_style(this_style_name))
for this_style_name in style_sheet.get_table_style_names():
selected_style.add_table_style(
this_style_name,
style_sheet.get_table_style(this_style_name))
for this_style_name in style_sheet.get_cell_style_names():
selected_style.add_cell_style(
this_style_name,
style_sheet.get_cell_style(this_style_name))
# The option values were loaded magically by the book parser.
# But they still need to be applied to the menu options.
@ -714,28 +683,23 @@ def cl_book(database, name, book, options_str_dict):
if menu_option:
menu_option.set_value(opt_dict[optname])
# write report
doc = clr.format(selected_style,
PaperStyle(clr.paper, clr.orien, clr.marginl,
clr.marginr, clr.margint, clr.marginb))
user = User()
rptlist = []
for item in book.get_item_list():
item.option_class.set_document(doc)
report_class = item.get_write_item()
obj = write_book_item(database,
report_class, item.option_class, user)
rptlist.append(obj)
style_sheet = create_style_sheet(item)
rptlist.append((obj, style_sheet))
doc.open(clr.option_class.get_output())
doc.init()
newpage = 0
for item in rptlist:
for rpt, style_sheet in rptlist:
doc.set_style_sheet(style_sheet)
if newpage:
doc.page_break()
newpage = 1
item.begin_report()
item.write_report()
rpt.begin_report()
rpt.write_report()
doc.close()
#------------------------------------------------------------------------

View File

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

View File

@ -61,6 +61,7 @@ except:
#-------------------------------------------------------------------------
from ...const import HOME_DIR
from ...utils.cast import get_type_converter_by_name, type_name
from ..docgen import StyleSheet, StyleSheetList
from .. import BasePluginManager
from . import book_categories
@ -440,3 +441,52 @@ class BookParser(handler.ContentHandler):
self.b.append_item(self.i)
elif tag == "book":
self.booklist.set_book(self.bname, self.b)
#-------------------------------------------------------------------------
#
# Functions
#
#-------------------------------------------------------------------------
def create_style_sheet(item):
"""
Create a style sheet for a book item.
"""
selected_style = StyleSheet()
handler = item.option_class.handler
# Set up default style
handler.set_default_stylesheet_name(item.get_style_name())
default_style = StyleSheet()
make_default_style = item.option_class.make_default_style
make_default_style(default_style)
# Read all style sheets available for this item
style_file = handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = handler.get_default_stylesheet_name()
style_sheet = style_list.get_style_sheet(style_name)
for this_style_name in style_sheet.get_paragraph_style_names():
selected_style.add_paragraph_style(
this_style_name,
style_sheet.get_paragraph_style(this_style_name))
for this_style_name in style_sheet.get_draw_style_names():
selected_style.add_draw_style(
this_style_name,
style_sheet.get_draw_style(this_style_name))
for this_style_name in style_sheet.get_table_style_names():
selected_style.add_table_style(
this_style_name,
style_sheet.get_table_style(this_style_name))
for this_style_name in style_sheet.get_cell_style_names():
selected_style.add_cell_style(
this_style_name,
style_sheet.get_cell_style(this_style_name))
return selected_style

View File

@ -58,7 +58,6 @@ from gi.repository import GObject
from ...listmodel import ListModel
from gramps.gen.errors import FilterError, ReportError
from ...pluginmanager import GuiPluginManager
from gramps.gen.plug.docgen import StyleSheet, StyleSheetList
from ...dialog import WarningDialog, ErrorDialog
from gramps.gen.plug.menu import PersonOption, FilterOption, FamilyOption
from ...managedwindow import ManagedWindow, set_titles
@ -69,7 +68,7 @@ from .. import make_gui_option
from types import ClassType
# Import from specific modules in ReportBase
from gramps.gen.plug.report import BookList, Book, BookItem
from gramps.gen.plug.report import BookList, Book, BookItem, create_style_sheet
from gramps.gen.plug.report import CATEGORY_BOOK, book_categories
from gramps.gen.plug.report._options import ReportOptions
from _reportdialog import ReportDialog
@ -861,40 +860,6 @@ class BookDialog(DocReportDialog):
'book', _("Book"))
self.options.options_dict['bookname'] = self.book.name
self.database = dbstate.db
self.selected_style = StyleSheet()
for item in self.book.get_item_list():
handler = item.option_class.handler
# Set up default style
handler.set_default_stylesheet_name(item.get_style_name())
default_style = StyleSheet()
make_default_style = item.option_class.make_default_style
make_default_style(default_style)
# Read all style sheets available for this item
style_file = handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = handler.get_default_stylesheet_name()
style_sheet = style_list.get_style_sheet(style_name)
for this_style_name in style_sheet.get_paragraph_style_names():
self.selected_style.add_paragraph_style(
this_style_name,style_sheet.get_paragraph_style(this_style_name))
for this_style_name in style_sheet.get_draw_style_names():
self.selected_style.add_draw_style(
this_style_name,style_sheet.get_draw_style(this_style_name))
for this_style_name in style_sheet.get_table_style_names():
self.selected_style.add_table_style(
this_style_name,style_sheet.get_table_style(this_style_name))
for this_style_name in style_sheet.get_cell_style_names():
self.selected_style.add_cell_style(
this_style_name,style_sheet.get_cell_style(this_style_name))
response = self.window.run()
if response == Gtk.ResponseType.OK:
@ -923,7 +888,7 @@ 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(self.selected_style, pstyle)
self.doc = self.format(None, pstyle)
user = User()
self.rptlist = []
for item in self.book.get_item_list():
@ -931,7 +896,8 @@ class BookDialog(DocReportDialog):
report_class = item.get_write_item()
obj = write_book_item(self.database, report_class,
item.option_class, user)
self.rptlist.append(obj)
style_sheet = create_style_sheet(item)
self.rptlist.append((obj, style_sheet))
self.doc.open(self.target_path)
def make_book(self):
@ -940,13 +906,14 @@ class BookDialog(DocReportDialog):
self.doc.init()
newpage = 0
for item in self.rptlist:
for rpt, style_sheet in self.rptlist:
self.doc.set_style_sheet(style_sheet)
if newpage:
self.doc.page_break()
newpage = 1
if item:
item.begin_report()
item.write_report()
if rpt:
rpt.begin_report()
rpt.write_report()
self.doc.close()
if self.open_with_app.get_active():