Add StyleOption class for reports and use it in WebCal.
svn: r10651
This commit is contained in:
parent
39c8d63029
commit
5181e073e9
@ -316,16 +316,18 @@ class GuiBooleanOption(gtk.CheckButton):
|
||||
# GuiEnumeratedListOption class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class GuiEnumeratedListOption(gtk.EventBox):
|
||||
class GuiEnumeratedListOption(gtk.HBox):
|
||||
"""
|
||||
This class displays an option that provides a finite number of values.
|
||||
Each possible value is assigned a value and a description.
|
||||
"""
|
||||
def __init__(self, option, dbstate, uistate, track, tooltip):
|
||||
gtk.EventBox.__init__(self)
|
||||
gtk.HBox.__init__(self)
|
||||
evtBox = gtk.EventBox()
|
||||
self.__option = option
|
||||
self.__combo = gtk.combo_box_new_text()
|
||||
self.add(self.__combo)
|
||||
evtBox.add(self.__combo)
|
||||
self.pack_start(evtBox, True, True)
|
||||
|
||||
self.__update_options()
|
||||
|
||||
@ -1043,7 +1045,8 @@ class GuiSurnameColourOption(gtk.HBox):
|
||||
#-------------------------------------------------------------------------
|
||||
class GuiDestinationOption(gtk.HBox):
|
||||
"""
|
||||
This class displays an option that is a simple one-line string.
|
||||
This class displays an option that allows the user to select a
|
||||
DestinationOption.
|
||||
"""
|
||||
def __init__(self, option, dbstate, uistate, track, tooltip):
|
||||
"""
|
||||
@ -1131,6 +1134,44 @@ class GuiDestinationOption(gtk.HBox):
|
||||
|
||||
self.__entry.set_text( self.__option.get_value() )
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GuiStyleOption class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class GuiStyleOption(GuiEnumeratedListOption):
|
||||
"""
|
||||
This class displays a StyleOption.
|
||||
"""
|
||||
def __init__(self, option, dbstate, uistate, track, tooltip):
|
||||
"""
|
||||
@param option: The option to display.
|
||||
@type option: MenuOption.StyleOption
|
||||
@return: nothing
|
||||
"""
|
||||
GuiEnumeratedListOption.__init__(self, option, dbstate, uistate, track, tooltip)
|
||||
self.__option = option
|
||||
|
||||
self.__button = gtk.Button("%s..." % _("Style Editor"))
|
||||
self.__button.connect('clicked', self.__on_style_edit_clicked)
|
||||
|
||||
self.pack_end(self.__button, False, False)
|
||||
|
||||
def __on_style_edit_clicked(self, *obj):
|
||||
"""The user has clicked on the 'Edit Styles' button. Create a
|
||||
style sheet editor object and let them play. When they are
|
||||
done, update the displayed styles."""
|
||||
import BaseDoc
|
||||
from ReportBase._StyleEditor import StyleListDisplay
|
||||
style_list = BaseDoc.StyleSheetList(self.__option.get_style_file(),
|
||||
self.__option.get_default_style())
|
||||
StyleListDisplay(style_list, None, None)
|
||||
|
||||
new_items = []
|
||||
for style_name in style_list.get_style_names():
|
||||
new_items.append( (style_name, style_name) )
|
||||
self.__option.set_items(new_items)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GuiMenuOptions class
|
||||
@ -1257,6 +1298,8 @@ def make_gui_option(option, tooltips, dbstate, uistate, track):
|
||||
widget = GuiStringOption(option, dbstate,
|
||||
uistate, track,
|
||||
tooltips)
|
||||
elif isinstance(option, _MenuOptions.StyleOption):
|
||||
widget = GuiStyleOption(option, dbstate, uistate, track, tooltips)
|
||||
elif isinstance(option, _MenuOptions.EnumeratedListOption):
|
||||
widget = GuiEnumeratedListOption(option, dbstate,
|
||||
uistate, track,
|
||||
|
@ -604,6 +604,55 @@ class DestinationOption(StringOption):
|
||||
"""
|
||||
return self.__extension
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# StyleOption class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class StyleOption(EnumeratedListOption):
|
||||
"""
|
||||
This class describes an option that allows the use to select a style sheet.
|
||||
"""
|
||||
|
||||
def __init__(self, label, default_style, module_name):
|
||||
"""
|
||||
@param label: A friendly label to be applied to this option.
|
||||
Example: "Style"
|
||||
@type label: string
|
||||
@param default_style: A BaseDoc.StyleSheet instance which provides the
|
||||
default styles.
|
||||
@type default_style: BaseDoc.StyleSheet
|
||||
@param module_name: The name of the module the style sheets belong to.
|
||||
Example: "web_cal"
|
||||
@type module_name: string
|
||||
@return: nothing
|
||||
"""
|
||||
import BaseDoc
|
||||
EnumeratedListOption.__init__(self, label, "default")
|
||||
|
||||
self.__default_style = default_style
|
||||
self.__default_style.set_name("default")
|
||||
self.__style_file = "%s_style.xml" % module_name
|
||||
style_list = BaseDoc.StyleSheetList(self.__style_file,
|
||||
self.__default_style)
|
||||
for style_name in style_list.get_style_names():
|
||||
self.add_item(style_name, style_name)
|
||||
|
||||
def get_default_style(self):
|
||||
""" Get the default style """
|
||||
return self.__default_style
|
||||
|
||||
def get_style_file(self):
|
||||
""" Get the name of the style file """
|
||||
return self.__style_file
|
||||
|
||||
def get_style(self):
|
||||
""" Get the selected style """
|
||||
import BaseDoc
|
||||
style_list = BaseDoc.StyleSheetList(self.__style_file,
|
||||
self.__default_style)
|
||||
return style_list.get_style_sheet(self.get_value())
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Menu class
|
||||
|
@ -32,7 +32,7 @@ from _MenuOptions import (NumberOption, BooleanOption, TextOption,
|
||||
EnumeratedListOption, FilterOption, StringOption,
|
||||
ColourOption, PersonOption, PersonListOption,
|
||||
SurnameColourOption, FamilyOption, DestinationOption,
|
||||
NoteOption, MediaOption)
|
||||
NoteOption, MediaOption, StyleOption)
|
||||
from _GuiOptions import GuiMenuOptions, make_gui_option
|
||||
from _PluginMgr import (register_export, register_import, register_tool,
|
||||
register_report, register_relcalc, relationship_class,
|
||||
|
@ -130,6 +130,7 @@ class StyleListDisplay:
|
||||
def on_ok_clicked(self, obj):
|
||||
"""Called with the OK button is clicked; Calls the callback task,
|
||||
then saves the stylesheet."""
|
||||
if self.callback is not None:
|
||||
self.callback()
|
||||
try:
|
||||
self.sheetlist.save()
|
||||
|
@ -71,7 +71,7 @@ from PluginUtils import register_report
|
||||
from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_WEB,
|
||||
MODE_GUI)
|
||||
from PluginUtils import FilterOption, EnumeratedListOption, PersonOption, \
|
||||
BooleanOption, NumberOption, StringOption, DestinationOption
|
||||
BooleanOption, NumberOption, StringOption, DestinationOption, StyleOption
|
||||
import Utils
|
||||
import GrampsLocale
|
||||
from QuestionDialog import ErrorDialog
|
||||
@ -201,6 +201,8 @@ class WebCalReport(Report):
|
||||
menu.get_option_by_name('note_nov').get_value(),
|
||||
menu.get_option_by_name('note_dec').get_value()]
|
||||
|
||||
self.__style = menu.get_option_by_name("style").get_style()
|
||||
|
||||
def get_short_name(self, person, maiden_name = None):
|
||||
""" Return person's name, unless maiden_name given, unless married_name listed. """
|
||||
# Get all of a person's names:
|
||||
@ -269,17 +271,6 @@ class WebCalReport(Report):
|
||||
# use user defined font families
|
||||
font_family = [self.SanSerif_fonts,self.Serif_fonts]
|
||||
|
||||
default_style = BaseDoc.StyleSheet()
|
||||
self.options.make_default_style(default_style)
|
||||
|
||||
# Read all style sheets available for this item
|
||||
style_file = self.options.handler.get_stylesheet_savefile()
|
||||
self.style_list = BaseDoc.StyleSheetList(style_file,default_style)
|
||||
|
||||
# Get the selected stylesheet
|
||||
style_name = self.options.handler.get_default_stylesheet_name()
|
||||
self.selected_style = self.style_list.get_style_sheet(style_name)
|
||||
default_style = BaseDoc.StyleSheet(self.selected_style)
|
||||
#
|
||||
# NAVIGATION BLOCK
|
||||
#
|
||||
@ -298,7 +289,7 @@ class WebCalReport(Report):
|
||||
# HEADER / BODY BACKGROUND
|
||||
#
|
||||
of.write('h1 {')
|
||||
style = default_style.get_paragraph_style("WC-Title")
|
||||
style = self.__style.get_paragraph_style("WC-Title")
|
||||
font = style.get_font()
|
||||
italic = font_style[font.get_italic()]
|
||||
bold = font_weight[font.get_bold()]
|
||||
@ -314,7 +305,7 @@ class WebCalReport(Report):
|
||||
# CALENDAR TABLE
|
||||
#
|
||||
of.write('.calendar { ')
|
||||
style = default_style.get_paragraph_style("WC-Table")
|
||||
style = self.__style.get_paragraph_style("WC-Table")
|
||||
font = style.get_font()
|
||||
italic = font_style[font.get_italic()]
|
||||
bold = font_weight[font.get_bold()]
|
||||
@ -329,7 +320,7 @@ class WebCalReport(Report):
|
||||
#
|
||||
# MONTH NAME
|
||||
#
|
||||
style = default_style.get_paragraph_style("WC-Month")
|
||||
style = self.__style.get_paragraph_style("WC-Month")
|
||||
of.write('.cal_month { border-bottom-width: 0;\n')
|
||||
font = style.get_font()
|
||||
italic = font_style[font.get_italic()]
|
||||
@ -360,7 +351,7 @@ class WebCalReport(Report):
|
||||
#
|
||||
# CALENDAR ENTRY TEXT
|
||||
#
|
||||
style = default_style.get_paragraph_style("WC-Text")
|
||||
style = self.__style.get_paragraph_style("WC-Text")
|
||||
of.write('.cal_text { vertical-align:bottom;\n')
|
||||
font = style.get_font()
|
||||
italic = font_style[font.get_italic()]
|
||||
@ -377,7 +368,7 @@ class WebCalReport(Report):
|
||||
#
|
||||
# CALENDAR NOTE TEXT
|
||||
#
|
||||
style = default_style.get_paragraph_style("WC-Note")
|
||||
style = self.__style.get_paragraph_style("WC-Note")
|
||||
font = style.get_font()
|
||||
italic = font_style[font.get_italic()]
|
||||
bold = font_weight[font.get_bold()]
|
||||
@ -727,6 +718,12 @@ class WebCalOptions(MenuReportOptions):
|
||||
encoding.set_help( _("The encoding to be used for the web files"))
|
||||
menu.add_option(category_name, "encoding", encoding)
|
||||
|
||||
default_style = BaseDoc.StyleSheet()
|
||||
self.__make_default_style(default_style)
|
||||
style = StyleOption("Style", default_style, "WebCal")
|
||||
style.set_help( _("The style to be used for the web files"))
|
||||
menu.add_option(category_name, "style", style)
|
||||
|
||||
def __add_content_options(self, menu):
|
||||
"""
|
||||
Options on the "Content Options" tab.
|
||||
@ -891,7 +888,7 @@ class WebCalOptions(MenuReportOptions):
|
||||
# The rest don't
|
||||
self.__pid.set_available(False)
|
||||
|
||||
def make_default_style(self, default_style):
|
||||
def __make_default_style(self, default_style):
|
||||
"""Make the default output style for the Web Calendar
|
||||
There are 5 named styles for this report.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user