Fix style sheet bug in books
svn: r20527
This commit is contained in:
parent
2658861b18
commit
88e6df595f
@ -57,7 +57,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)
|
ReportOptions, create_style_sheet)
|
||||||
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
|
||||||
@ -666,44 +666,13 @@ def cl_book(database, name, book, options_str_dict):
|
|||||||
if clr.show:
|
if clr.show:
|
||||||
return
|
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():
|
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.
|
# The option values were loaded magically by the book parser.
|
||||||
# But they still need to be applied to the menu options.
|
# 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:
|
if menu_option:
|
||||||
menu_option.set_value(opt_dict[optname])
|
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)
|
item.option_class.set_document(doc)
|
||||||
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)
|
||||||
rptlist.append(obj)
|
style_sheet = create_style_sheet(item)
|
||||||
|
rptlist.append((obj, style_sheet))
|
||||||
|
|
||||||
doc.open(clr.option_class.get_output())
|
doc.open(clr.option_class.get_output())
|
||||||
doc.init()
|
doc.init()
|
||||||
newpage = 0
|
newpage = 0
|
||||||
for item in rptlist:
|
for rpt, style_sheet in rptlist:
|
||||||
|
doc.set_style_sheet(style_sheet)
|
||||||
if newpage:
|
if newpage:
|
||||||
doc.page_break()
|
doc.page_break()
|
||||||
newpage = 1
|
newpage = 1
|
||||||
item.begin_report()
|
rpt.begin_report()
|
||||||
item.write_report()
|
rpt.write_report()
|
||||||
doc.close()
|
doc.close()
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
@ -34,4 +34,4 @@ from _bibliography import Bibliography, Citation
|
|||||||
|
|
||||||
from _options import MenuReportOptions, ReportOptions
|
from _options import MenuReportOptions, ReportOptions
|
||||||
|
|
||||||
from _book import BookList, Book, BookItem
|
from _book import BookList, Book, BookItem, create_style_sheet
|
||||||
|
@ -61,6 +61,7 @@ except:
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from ...const import HOME_DIR
|
from ...const import HOME_DIR
|
||||||
from ...utils.cast import get_type_converter_by_name, type_name
|
from ...utils.cast import get_type_converter_by_name, type_name
|
||||||
|
from ..docgen import StyleSheet, StyleSheetList
|
||||||
from .. import BasePluginManager
|
from .. import BasePluginManager
|
||||||
from . import book_categories
|
from . import book_categories
|
||||||
|
|
||||||
@ -440,3 +441,52 @@ class BookParser(handler.ContentHandler):
|
|||||||
self.b.append_item(self.i)
|
self.b.append_item(self.i)
|
||||||
elif tag == "book":
|
elif tag == "book":
|
||||||
self.booklist.set_book(self.bname, self.b)
|
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
|
||||||
|
@ -58,7 +58,6 @@ from gi.repository import GObject
|
|||||||
from ...listmodel import ListModel
|
from ...listmodel import ListModel
|
||||||
from gramps.gen.errors import FilterError, ReportError
|
from gramps.gen.errors import FilterError, ReportError
|
||||||
from ...pluginmanager import GuiPluginManager
|
from ...pluginmanager import GuiPluginManager
|
||||||
from gramps.gen.plug.docgen import StyleSheet, StyleSheetList
|
|
||||||
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 ...managedwindow import ManagedWindow, set_titles
|
from ...managedwindow import ManagedWindow, set_titles
|
||||||
@ -69,7 +68,7 @@ from .. import make_gui_option
|
|||||||
from types import ClassType
|
from types import ClassType
|
||||||
|
|
||||||
# Import from specific modules in ReportBase
|
# 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 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
|
||||||
@ -861,40 +860,6 @@ class BookDialog(DocReportDialog):
|
|||||||
'book', _("Book"))
|
'book', _("Book"))
|
||||||
self.options.options_dict['bookname'] = self.book.name
|
self.options.options_dict['bookname'] = self.book.name
|
||||||
self.database = dbstate.db
|
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()
|
response = self.window.run()
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
@ -923,7 +888,7 @@ 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()
|
pstyle = self.paper_frame.get_paper_style()
|
||||||
self.doc = self.format(self.selected_style, pstyle)
|
self.doc = self.format(None, pstyle)
|
||||||
user = User()
|
user = User()
|
||||||
self.rptlist = []
|
self.rptlist = []
|
||||||
for item in self.book.get_item_list():
|
for item in self.book.get_item_list():
|
||||||
@ -931,7 +896,8 @@ class BookDialog(DocReportDialog):
|
|||||||
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)
|
||||||
self.rptlist.append(obj)
|
style_sheet = create_style_sheet(item)
|
||||||
|
self.rptlist.append((obj, style_sheet))
|
||||||
self.doc.open(self.target_path)
|
self.doc.open(self.target_path)
|
||||||
|
|
||||||
def make_book(self):
|
def make_book(self):
|
||||||
@ -940,13 +906,14 @@ class BookDialog(DocReportDialog):
|
|||||||
|
|
||||||
self.doc.init()
|
self.doc.init()
|
||||||
newpage = 0
|
newpage = 0
|
||||||
for item in self.rptlist:
|
for rpt, style_sheet 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 item:
|
if rpt:
|
||||||
item.begin_report()
|
rpt.begin_report()
|
||||||
item.write_report()
|
rpt.write_report()
|
||||||
self.doc.close()
|
self.doc.close()
|
||||||
|
|
||||||
if self.open_with_app.get_active():
|
if self.open_with_app.get_active():
|
||||||
|
Loading…
Reference in New Issue
Block a user