This commit is contained in:
Andreas Preikschat 2011-04-07 10:45:49 +02:00
commit db616bfe1a
2 changed files with 98 additions and 33 deletions

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',
'break'))
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

@ -26,6 +26,7 @@
import datetime import datetime
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
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
@ -50,6 +51,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'enable 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 +81,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,58 +101,102 @@ 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()) style = html.Element(u'style')
for item in self.serviceManager.serviceItems: style.set(u'type', u'text/css')
file = open(u'/home/andreas/styles.css', u'r')
style.text = u' '.join(file.readlines())
file.close()
html_data.head.append(style)
html_data.append(html.Element(u'body'))
service_title = html.Element(u'span')
service_title.set(u'class', u'serviceTitle')
service_title.text = unicode(self.titleLineEdit.text())
html_data.body.append(service_title)
for index, item in enumerate(self.serviceManager.serviceItems):
item = item[u'service_item'] item = item[u'service_item']
div = html.Element(u'div')
# 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 = html.Element(u'h2')
item.get_display_title()) item_title.set(u'class', u'itemTitle')
# Add slide text of the service item. icon = html.Element(u'img')
icon.set(u'src', item.icon)
item_title.append(icon)
item_title.append(html.fromstring(
u'<span> %s</span>' % item.get_display_title()))
div.append(item_title)
if self.slideTextCheckBox.isChecked(): if self.slideTextCheckBox.isChecked():
if item.is_text():
# Add the text of the service item. # Add the text of the service item.
verse = None if item.is_text():
verse_def = 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 = html.Element(u'p')
verse = slide[u'verseTag'] p.set(u'class', u'itemText')
elif verse != slide[u'verseTag']: div.append(p)
text += u'<\p><p>' + slide[u'html']
verse = slide[u'verseTag']
else: else:
text += u'<br/>' + slide[u'html'] p.append(html.Element(u'br'))
text += u'</p>' p.append(html.fromstring(
elif item.is_image(): u'<span>%s</span>' % slide[u'html']))
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. # Add the image names of the service item.
text += u'<ol>' elif item.is_image():
ol = html.Element(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>' % \ li = html.Element(u'li')
item.get_frame_title(slide) li.text = item.get_frame_title(slide)
text += u'</ol>' ol.append(li)
if item.foot_text: div.append(ol)
# add footer # add footer
text += u'<p>%s</p>' % item.foot_text if item.foot_text:
p = html.fromstring(item.foot_text)
p.set(u'class', u'itemFooter')
div.append(p)
# 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 = html.Element(u'p')
'OpenLP.ServiceManager', 'Notes:'), title = html.Element(u'span')
title.set(u'class', u'itemNotesTitle')
title.text = unicode(
translate('OpenLP.ServiceManager', 'Notes:'))
p.append(title)
text = html.fromstring(u'<span> %s</span>' %
item.notes.replace(u'\n', u'<br />')) item.notes.replace(u'\n', u'<br />'))
text.set(u'class', u'itemNotesText')
p.append(text)
div.append(p)
# 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( p = html.fromstring(u'<p><strong>%s</strong> </p>' %
'OpenLP.ServiceManager', u'Playing time:'), translate('OpenLP.ServiceManager', 'Playing time:'))
unicode(datetime.timedelta(seconds=tme))) p.append(html.fromstring(u'<span>%s</span>' %
unicode(datetime.timedelta(seconds=tme))))
div.append(p)
html_data.body.append(div)
# Add the custom service notes:
if self.footerTextEdit.toPlainText(): if self.footerTextEdit.toPlainText():
text += u'<h4>%s</h4>%s' % (translate('OpenLP.ServiceManager', title = html.Element(u'span')
u'Custom Service Notes:'), self.footerTextEdit.toPlainText()) title.set(u'class', u'customNotesTitle')
self.document.setHtml(text) title.text = unicode(
translate('OpenLP.ServiceManager', u'Custom Service Notes:'))
div.append(title)
text = html.Element(u'span')
text.set(u'class', u'customNotesText')
text.text = u' %s' % self.footerTextEdit.toPlainText()
div.append(text)
self.document.setHtml(html.tostring(html_data))
self.previewWidget.updatePreview() self.previewWidget.updatePreview()
test = open(u'/home/andreas/test.html', u'w')
test.write(html.tostring(html_data))
test.close()
def paintRequested(self, printer): def paintRequested(self, printer):
""" """
@ -232,6 +284,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 +300,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'enable 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',