- added an option to add page breaks after text items

- rewrite the updatePreviewText method using lxml
- the layout can now be modified with CSS (see .local/share/openlp/servicePrint.css)

bzr-revno: 1460
This commit is contained in:
Andreas Preikschat 2011-04-13 20:38:08 +02:00
commit e1b723270d
4 changed files with 175 additions and 38 deletions

View File

@ -116,7 +116,7 @@ class OpenLP(QtGui.QApplication):
self.processEvents() self.processEvents()
# start the main app window # start the main app window
self.mainWindow = MainWindow(screens, self.clipboard(), self.mainWindow = MainWindow(screens, self.clipboard(),
self.arguments()) self.arguments())
self.mainWindow.show() self.mainWindow.show()
if show_splash: if show_splash:
# now kill the splashscreen # now kill the splashscreen

View File

@ -452,7 +452,7 @@ def build_lyrics_css(item, webkitvers):
.lyricsshadow { .lyricsshadow {
%s %s
} }
""" """
theme = item.themedata theme = item.themedata
lyricstable = u'' lyricstable = u''
lyrics = u'' lyrics = u''
@ -460,8 +460,7 @@ def build_lyrics_css(item, webkitvers):
outline = u'' outline = u''
shadow = u'' shadow = u''
if theme and item.main: if theme and item.main:
lyricstable = u'left: %spx; top: %spx;' % \ lyricstable = u'left: %spx; top: %spx;' % (item.main.x(), item.main.y())
(item.main.x(), item.main.y())
lyrics = build_lyrics_format_css(theme, item.main.width(), lyrics = build_lyrics_format_css(theme, item.main.width(),
item.main.height()) item.main.height())
# For performance reasons we want to show as few DIV's as possible, # For performance reasons we want to show as few DIV's as possible,

View File

@ -132,6 +132,8 @@ class Ui_PrintServiceDialog(object):
self.groupLayout = QtGui.QVBoxLayout() self.groupLayout = QtGui.QVBoxLayout()
self.slideTextCheckBox = QtGui.QCheckBox() self.slideTextCheckBox = QtGui.QCheckBox()
self.groupLayout.addWidget(self.slideTextCheckBox) self.groupLayout.addWidget(self.slideTextCheckBox)
self.pageBreakAfterText = QtGui.QCheckBox()
self.groupLayout.addWidget(self.pageBreakAfterText)
self.notesCheckBox = QtGui.QCheckBox() self.notesCheckBox = QtGui.QCheckBox()
self.groupLayout.addWidget(self.notesCheckBox) self.groupLayout.addWidget(self.notesCheckBox)
self.metaDataCheckBox = QtGui.QCheckBox() self.metaDataCheckBox = QtGui.QCheckBox()
@ -149,6 +151,8 @@ class Ui_PrintServiceDialog(object):
printServiceDialog.setWindowTitle(UiStrings.PrintServiceOrder) printServiceDialog.setWindowTitle(UiStrings.PrintServiceOrder)
self.slideTextCheckBox.setText(translate('OpenLP.PrintServiceForm', self.slideTextCheckBox.setText(translate('OpenLP.PrintServiceForm',
'Include slide text if available')) 'Include slide text if available'))
self.pageBreakAfterText.setText(translate('OpenLP.PrintServiceForm',
'Add page break before each text item.'))
self.notesCheckBox.setText(translate('OpenLP.PrintServiceForm', self.notesCheckBox.setText(translate('OpenLP.PrintServiceForm',
'Include service item notes')) 'Include service item notes'))
self.metaDataCheckBox.setText(translate('OpenLP.PrintServiceForm', self.metaDataCheckBox.setText(translate('OpenLP.PrintServiceForm',

View File

@ -24,12 +24,65 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import datetime import datetime
import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from lxml import html
from openlp.core.lib import translate from openlp.core.lib import translate, get_text_file_string
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize
from openlp.core.utils import AppLocation
DEFAULT_CSS = """/*
Edit this file to customize the service order print. Note, that not all CSS
properties are supported. See:
http://doc.trolltech.com/4.7/richtext-html-subset.html#css-properties
*/
.serviceTitle {
font-weight:600;
font-size:x-large;
color:black;
}
.itemTitle {
font-weight:600;
font-size:large;
color:black;
}
.itemText {
color:black;
}
.itemFooter {
font-size:8px;
color:black;
}
.itemNotesTitle {
font-weight:bold;
font-size:12px;
color:black;
}
.itemNotesText {
font-size:11px;
color:black;
}
.customNotesTitle {
font-weight:bold;
font-size:11px;
color:black;
}
.customNotesText {
font-size:11px;
color:black;
}
"""
class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
@ -50,6 +103,10 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
settings.beginGroup(u'advanced') settings.beginGroup(u'advanced')
self.slideTextCheckBox.setChecked(settings.value( self.slideTextCheckBox.setChecked(settings.value(
u'print slide text', QtCore.QVariant(False)).toBool()) u'print slide text', QtCore.QVariant(False)).toBool())
self.pageBreakAfterText.setChecked(settings.value(
u'add page break', QtCore.QVariant(False)).toBool())
if not self.slideTextCheckBox.isChecked():
self.pageBreakAfterText.setDisabled(True)
self.metaDataCheckBox.setChecked(settings.value( self.metaDataCheckBox.setChecked(settings.value(
u'print file meta data', QtCore.QVariant(False)).toBool()) u'print file meta data', QtCore.QVariant(False)).toBool())
self.notesCheckBox.setChecked(settings.value( self.notesCheckBox.setChecked(settings.value(
@ -76,6 +133,9 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
QtCore.SIGNAL(u'triggered()'), self.copyText) QtCore.SIGNAL(u'triggered()'), self.copyText)
QtCore.QObject.connect(self.htmlCopy, QtCore.QObject.connect(self.htmlCopy,
QtCore.SIGNAL(u'triggered()'), self.copyHtmlText) QtCore.SIGNAL(u'triggered()'), self.copyHtmlText)
QtCore.QObject.connect(self.slideTextCheckBox,
QtCore.SIGNAL(u'stateChanged(int)'),
self.onSlideTextCheckBoxChanged)
self.updatePreviewText() self.updatePreviewText()
def toggleOptions(self, checked): def toggleOptions(self, checked):
@ -93,59 +153,124 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
""" """
Creates the html text and updates the html of *self.document*. Creates the html text and updates the html of *self.document*.
""" """
text = u'' html_data = html.fromstring(
if self.titleLineEdit.text(): u'<title>%s</title>' % unicode(self.titleLineEdit.text()))
text += u'<h2>%s</h2>' % unicode(self.titleLineEdit.text()) css_path = os.path.join(
for item in self.serviceManager.serviceItems: AppLocation.get_data_path(), u'servicePrint.css')
if not os.path.isfile(css_path):
# Create default css file.
css_file = open(css_path, u'w')
css_file.write(DEFAULT_CSS)
css_file.close()
custom_css = get_text_file_string(css_path)
self._addChildToParent(
u'style', custom_css, html_data.head, u'type', u'text/css')
self._addChildToParent(u'body', parent=html_data)
self._addChildToParent(u'span', unicode(self.titleLineEdit.text()),
html_data.body, u'class', u'serviceTitle')
for index, item in enumerate(self.serviceManager.serviceItems):
item = item[u'service_item'] item = item[u'service_item']
div = self._addChildToParent(u'div', parent=html_data.body)
# Add the title of the service item. # Add the title of the service item.
text += u'<h3><img src="%s" /> %s</h3>' % (item.icon, item_title = self._addChildToParent(
item.get_display_title()) u'h2', parent=div, attribute=u'class', value=u'itemTitle')
# Add slide text of the service item. self._addChildToParent(
u'img', parent=item_title, attribute=u'src', value=item.icon)
self._fromstring(
u'<span> %s</span>' % item.get_display_title(), item_title)
if self.slideTextCheckBox.isChecked(): if self.slideTextCheckBox.isChecked():
# Add the text of the service item.
if item.is_text(): if item.is_text():
# Add the text of the service item. verse_def = None
verse = None
for slide in item.get_frames(): for slide in item.get_frames():
if not verse: if not verse_def or verse_def != slide[u'verseTag']:
text += u'<p>' + slide[u'html'] p = self._addChildToParent(u'p', parent=div,
verse = slide[u'verseTag'] attribute=u'class', value=u'itemText')
elif verse != slide[u'verseTag']:
text += u'<\p><p>' + slide[u'html']
verse = slide[u'verseTag']
else: else:
text += u'<br/>' + slide[u'html'] self._addChildToParent(u'br', parent=p)
text += u'</p>' self._fromstring(u'<span>%s</span>' % slide[u'html'], p)
verse_def = slide[u'verseTag']
# Break the page before the div element.
if index != 0 and self.pageBreakAfterText.isChecked():
div.set(u'style', u'page-break-before:always')
# Add the image names of the service item.
elif item.is_image(): elif item.is_image():
# Add the image names of the service item. ol = self._addChildToParent(u'ol', parent=div)
text += u'<ol>'
for slide in range(len(item.get_frames())): for slide in range(len(item.get_frames())):
text += u'<li><p>%s</p></li>' % \ self._addChildToParent(u'li', item.get_frame_title(slide), ol)
item.get_frame_title(slide) # add footer
text += u'</ol>'
if item.foot_text: if item.foot_text:
# add footer self._fromstring(
text += u'<p>%s</p>' % item.foot_text item.foot_text, div, u'class', u'itemFooter')
# Add service items' notes. # Add service items' notes.
if self.notesCheckBox.isChecked(): if self.notesCheckBox.isChecked():
if item.notes: if item.notes:
text += u'<p><strong>%s</strong></p>%s' % (translate( p = self._addChildToParent(u'p', parent=div)
'OpenLP.ServiceManager', 'Notes:'), self._addChildToParent(u'span', unicode(
item.notes.replace(u'\n', u'<br />')) translate('OpenLP.ServiceManager', 'Notes:')), p,
u'class', u'itemNotesTitle')
self._fromstring(u'<span> %s</span>' % item.notes.replace(
u'\n', u'<br />'), p, u'class', u'itemNotesText')
# Add play length of media files. # Add play length of media files.
if item.is_media() and self.metaDataCheckBox.isChecked(): if item.is_media() and self.metaDataCheckBox.isChecked():
tme = item.media_length tme = item.media_length
if item.end_time > 0: if item.end_time > 0:
tme = item.end_time - item.start_time tme = item.end_time - item.start_time
text += u'<p><strong>%s</strong> %s</p>' % (translate( title = self._fromstring(u'<p><strong>%s</strong> </p>' %
'OpenLP.ServiceManager', u'Playing time:'), translate('OpenLP.ServiceManager', 'Playing time:'), div)
unicode(datetime.timedelta(seconds=tme))) self._fromstring(u'<span>%s</span>' %
unicode(datetime.timedelta(seconds=tme)), title)
# Add the custom service notes:
if self.footerTextEdit.toPlainText(): if self.footerTextEdit.toPlainText():
text += u'<h4>%s</h4>%s' % (translate('OpenLP.ServiceManager', self._addChildToParent(u'span', translate('OpenLP.ServiceManager',
u'Custom Service Notes:'), self.footerTextEdit.toPlainText()) u'Custom Service Notes:'), div, u'class', u'customNotesTitle')
self.document.setHtml(text) self._addChildToParent(
u'span', u' %s' % self.footerTextEdit.toPlainText(), div,
u'class', u'customNotesText')
self.document.setHtml(html.tostring(html_data))
self.previewWidget.updatePreview() self.previewWidget.updatePreview()
def _addChildToParent(self, tag, text=None, parent=None, attribute=None,
value=None):
"""
Creates a html element. If ``text`` is given, the element's text will
set and if a ``parent`` is given, the element is appended.
``tag``
The html tag, e. g. ``u'span'``. Defaults to ``None``.
``text``
The text for the tag. Defaults to ``None``.
``parent``
The parent element. Defaults to ``None``.
``attribute``
An optional attribute, for instance ``u'class``.
``value``
The value for the given ``attribute``. It does not have a meaning,
if the attribute is left to its default.
"""
element = html.Element(tag)
if text is not None:
element.text = unicode(text)
if parent is not None:
parent.append(element)
if attribute is not None:
element.set(attribute, value if value is not None else u'')
return element
def _fromstring(self, string, parent, attribute=None, value=None):
"""
This is used to create a child html element from a string.
"""
element = html.fromstring(string)
if attribute is not None:
element.set(attribute, value if value is not None else u'')
parent.append(element)
return element
def paintRequested(self, printer): def paintRequested(self, printer):
""" """
Paint the preview of the *self.document*. Paint the preview of the *self.document*.
@ -232,6 +357,13 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
else: else:
self.copyTextButton.setText(UiStrings.CopyToText) self.copyTextButton.setText(UiStrings.CopyToText)
def onSlideTextCheckBoxChanged(self, state):
"""
Disable or enable the ``pageBreakAfterText`` checkbox as it should only
be enabled, when the ``slideTextCheckBox`` is enabled.
"""
self.pageBreakAfterText.setDisabled(state == QtCore.Qt.Unchecked)
def saveOptions(self): def saveOptions(self):
""" """
Save the settings and close the dialog. Save the settings and close the dialog.
@ -241,6 +373,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
settings.beginGroup(u'advanced') settings.beginGroup(u'advanced')
settings.setValue(u'print slide text', settings.setValue(u'print slide text',
QtCore.QVariant(self.slideTextCheckBox.isChecked())) QtCore.QVariant(self.slideTextCheckBox.isChecked()))
settings.setValue(u'add page break',
QtCore.QVariant(self.pageBreakAfterText.isChecked()))
settings.setValue(u'print file meta data', settings.setValue(u'print file meta data',
QtCore.QVariant(self.metaDataCheckBox.isChecked())) QtCore.QVariant(self.metaDataCheckBox.isChecked()))
settings.setValue(u'print notes', settings.setValue(u'print notes',