5701: configure an existing "book" using saved-away values
svn: r19915
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# Copyright (C) 2003-2007 Donald N. Allingham
|
||||
# Copyright (C) 2007-2008 Brian G. Matherly
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
# Copyright (C) 2011 Paul Franklin
|
||||
# Copyright (C) 2011-2012 Paul Franklin
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -79,6 +79,8 @@ from gui.managedwindow import ManagedWindow, set_titles
|
||||
from gui.glade import Glade
|
||||
import gui.utils
|
||||
import gui.user
|
||||
from gui.plug import make_gui_option
|
||||
from types import ClassType
|
||||
|
||||
# Import from specific modules in ReportBase
|
||||
from gen.plug.report import CATEGORY_BOOK, book_categories
|
||||
@@ -446,7 +448,7 @@ class BookList(object):
|
||||
f = open(self.file, "w")
|
||||
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
f.write('<booklist>\n')
|
||||
for name in self.bookmap:
|
||||
for name in sorted(self.bookmap): # enable a diff of archived copies
|
||||
book = self.get_book(name)
|
||||
dbname = book.get_dbname()
|
||||
f.write('<book name="%s" database="%s">\n' % (name, dbname) )
|
||||
@@ -934,21 +936,26 @@ class BookReportSelector(ManagedWindow):
|
||||
"""
|
||||
store, the_iter = self.book_model.get_selected()
|
||||
if not the_iter:
|
||||
WarningDialog(_('No selected book item'),
|
||||
_('Please select a book item to configure.')
|
||||
)
|
||||
return
|
||||
data = self.book_model.get_data(the_iter, range(self.book_nr_cols))
|
||||
row = self.book_model.get_selected_row()
|
||||
item = self.book.get_item(row)
|
||||
option_class = item.option_class
|
||||
item_dialog = BookItemDialog(self.dbstate, self.uistate, option_class,
|
||||
item.get_name(),
|
||||
item.get_translated_name(),
|
||||
self.track)
|
||||
option_class.handler.set_default_stylesheet_name(item.get_style_name())
|
||||
item.is_from_saved_book = bool(self.book.get_name())
|
||||
item_dialog = BookItemDialog(self.dbstate, self.uistate,
|
||||
item, self.track)
|
||||
|
||||
while True:
|
||||
response = item_dialog.window.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
# dialog will be closed by connect, now continue work while
|
||||
# rest of dialog is unresponsive, release when finished
|
||||
style = option_class.handler.get_default_stylesheet_name()
|
||||
item.set_style_name(style)
|
||||
subject = _get_subject(option_class, self.db)
|
||||
self.book_model.model.set_value(the_iter, 2, subject)
|
||||
self.book.set_item(row, item)
|
||||
@@ -1043,6 +1050,9 @@ class BookReportSelector(ManagedWindow):
|
||||
if self.book.item_list:
|
||||
BookReportDialog(self.dbstate, self.uistate,
|
||||
self.book, BookOptions)
|
||||
else:
|
||||
WarningDialog(_('No items'), _('This book has no items.'))
|
||||
return
|
||||
self.close()
|
||||
|
||||
def on_save_clicked(self, obj):
|
||||
@@ -1087,7 +1097,7 @@ class BookReportSelector(ManagedWindow):
|
||||
if book:
|
||||
self.open_book(book)
|
||||
self.name_entry.set_text(book.get_name())
|
||||
self.book.name = book.get_name()
|
||||
self.book.set_name(book.get_name())
|
||||
|
||||
def on_edit_clicked(self, obj):
|
||||
"""
|
||||
@@ -1114,11 +1124,14 @@ class BookItemDialog(ReportDialog):
|
||||
in a way specific for this report. This is a book item dialog.
|
||||
"""
|
||||
|
||||
def __init__(self, dbstate, uistate, option_class, name, translated_name,
|
||||
track=[]):
|
||||
def __init__(self, dbstate, uistate, item, track=[]):
|
||||
option_class = item.option_class
|
||||
name = item.get_name()
|
||||
translated_name = item.get_translated_name()
|
||||
self.category = CATEGORY_BOOK
|
||||
self.database = dbstate.db
|
||||
self.option_class = option_class
|
||||
self.is_from_saved_book = item.is_from_saved_book
|
||||
ReportDialog.__init__(self, dbstate, uistate,
|
||||
option_class, name, translated_name, track)
|
||||
|
||||
@@ -1139,6 +1152,43 @@ class BookItemDialog(ReportDialog):
|
||||
def parse_target_frame(self):
|
||||
"""Target frame is not used."""
|
||||
return 1
|
||||
|
||||
def init_options(self, option_class):
|
||||
try:
|
||||
if (issubclass(option_class, object) or # New-style class
|
||||
isinstance(option_class, ClassType)): # Old-style class
|
||||
self.options = option_class(self.raw_name, self.db)
|
||||
except TypeError:
|
||||
self.options = option_class
|
||||
if not self.is_from_saved_book:
|
||||
self.options.load_previous_values()
|
||||
|
||||
def add_user_options(self):
|
||||
"""
|
||||
Generic method to add user options to the gui.
|
||||
"""
|
||||
if not hasattr(self.options, "menu"):
|
||||
return
|
||||
menu = self.options.menu
|
||||
options_dict = self.options.options_dict
|
||||
for category in menu.get_categories():
|
||||
for name in menu.get_option_names(category):
|
||||
option = menu.get_option(category, name)
|
||||
|
||||
# override option default with xml-saved value:
|
||||
if name in options_dict:
|
||||
option.set_value(options_dict[name])
|
||||
|
||||
widget, label = make_gui_option(option, self.dbstate,
|
||||
self.uistate, self.track,
|
||||
self.is_from_saved_book)
|
||||
if widget is not None:
|
||||
if label:
|
||||
self.add_frame_option(category,
|
||||
option.get_label(),
|
||||
widget)
|
||||
else:
|
||||
self.add_frame_option(category, "", widget)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -1194,26 +1244,30 @@ class BookReportDialog(DocReportDialog):
|
||||
def __init__(self, dbstate, uistate, book, options):
|
||||
self.format_menu = None
|
||||
self.options = options
|
||||
self.is_from_saved_book = False
|
||||
self.page_html_added = False
|
||||
self.book = book
|
||||
DocReportDialog.__init__(self, dbstate, uistate, options,
|
||||
'book', _("Book Report"))
|
||||
self.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 = item.option_class.handler.get_stylesheet_savefile()
|
||||
style_file = 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_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():
|
||||
@@ -1288,6 +1342,16 @@ class BookReportDialog(DocReportDialog):
|
||||
if self.open_with_app.get_active():
|
||||
gui.utils.open_file_with_default_application(self.target_path)
|
||||
|
||||
def init_options(self, option_class):
|
||||
try:
|
||||
if (issubclass(option_class, object) or # New-style class
|
||||
isinstance(option_class, ClassType)): # Old-style class
|
||||
self.options = option_class(self.raw_name, self.db)
|
||||
except TypeError:
|
||||
self.options = option_class
|
||||
if not self.is_from_saved_book:
|
||||
self.options.load_previous_values()
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Function to write books from command line
|
||||
@@ -1319,17 +1383,20 @@ def cl_report(database, name, category, options_str_dict):
|
||||
selected_style = StyleSheet()
|
||||
|
||||
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 = item.option_class.handler.get_stylesheet_savefile()
|
||||
style_file = 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_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():
|
||||
|
Reference in New Issue
Block a user