6128: Fix bug to allow multiple styles for same report in a book

svn: r20572
This commit is contained in:
Nick Hall 2012-10-17 12:22:36 +00:00
parent 916f3d2fa1
commit 86cb61cd38

View File

@ -940,9 +940,8 @@ class BookReportSelector(ManagedWindow.ManagedWindow):
row = self.book_model.get_selected_row() row = self.book_model.get_selected_row()
item = self.book.get_item(row) item = self.book.get_item(row)
option_class = item.option_class option_class = item.option_class
item_dialog = BookItemDialog(self.dbstate, self.uistate, option_class, item_dialog = BookItemDialog(self.dbstate, self.uistate,
item.get_name(), item,
item.get_translated_name(),
self.track) self.track)
while True: while True:
@ -1110,13 +1109,15 @@ class BookItemDialog(ReportDialog):
in a way specific for this report. This is a book item dialog. in a way specific for this report. This is a book item dialog.
""" """
def __init__(self, dbstate, uistate, option_class, name, translated_name, def __init__(self, dbstate, uistate, item, track=[]):
track=[]):
self.category = CATEGORY_BOOK self.category = CATEGORY_BOOK
self.database = dbstate.db self.database = dbstate.db
self.option_class = option_class self.item = item
name = item.get_name()
translated_name = item.get_translated_name()
self.option_class = item.option_class
ReportDialog.__init__(self, dbstate, uistate, ReportDialog.__init__(self, dbstate, uistate,
option_class, name, translated_name, track) self.option_class, name, translated_name, track)
def on_ok_clicked(self, obj): def on_ok_clicked(self, obj):
"""The user is satisfied with the dialog choices. Parse all options """The user is satisfied with the dialog choices. Parse all options
@ -1125,7 +1126,7 @@ class BookItemDialog(ReportDialog):
# Preparation # Preparation
self.parse_style_frame() self.parse_style_frame()
self.parse_user_options() self.parse_user_options()
self.item.set_style_name(self.style_menu.get_value()[0])
self.options.handler.save_options() self.options.handler.save_options()
def setup_target_frame(self): def setup_target_frame(self):
@ -1196,37 +1197,6 @@ class BookReportDialog(DocReportDialog):
self.book = book self.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():
# Set up default style
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 = item.option_class.handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = item.option_class.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.RESPONSE_OK: if response == gtk.RESPONSE_OK:
@ -1255,15 +1225,16 @@ class BookReportDialog(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 = gui.user.User() user = gui.user.User()
self.rptlist = [] self.rptlist = []
for item in self.book.get_item_list(): for item in self.book.get_item_list():
style_sheet = create_style_sheet(item)
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)
self.rptlist.append(obj) self.rptlist.append((obj, style_sheet))
self.doc.open(self.target_path) self.doc.open(self.target_path)
def make_report(self): def make_report(self):
@ -1272,7 +1243,8 @@ class BookReportDialog(DocReportDialog):
self.doc.init() self.doc.init()
newpage = 0 newpage = 0
for item in self.rptlist: for item, 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
@ -1312,42 +1284,16 @@ def cl_report(database, name, category, options_str_dict):
else: else:
print _("Please specify a book name") print _("Please specify a book name")
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 = cli.user.User()
rptlist = []
for item in book.get_item_list(): for item in book.get_item_list():
# Set up default style style_sheet = create_style_sheet(item)
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 = item.option_class.handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = item.option_class.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.
opt_dict = item.option_class.options_dict opt_dict = item.option_class.options_dict
@ -1355,25 +1301,19 @@ def cl_report(database, name, category, options_str_dict):
for optname in opt_dict: for optname in opt_dict:
menu_option = menu.get_option_by_name(optname) menu_option = menu.get_option_by_name(optname)
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 = cli.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) 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 item, style_sheet in rptlist:
doc.set_style_sheet(style_sheet)
if newpage: if newpage:
doc.page_break() doc.page_break()
newpage = 1 newpage = 1
@ -1381,6 +1321,43 @@ def cl_report(database, name, category, options_str_dict):
item.write_report() item.write_report()
doc.close() doc.close()
def create_style_sheet(item):
"""
Create a style sheet for a book item.
"""
selected_style = StyleSheet()
# Set up default style
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 = item.option_class.handler.get_stylesheet_savefile()
style_list = StyleSheetList(style_file, default_style)
# Get the selected stylesheet
style_name = item.get_style_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
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Generic task function for book report # Generic task function for book report