Changes to the service print html/css

serviceprint.css can now be deleted and has been replaced by service-print.css. There have been changes to the css/html which will be documented on the wiki

bzr-revno: 1486
This commit is contained in:
Jonathan Corwin 2011-04-25 17:22:16 +01:00
commit 5887033238
1 changed files with 113 additions and 100 deletions

View File

@ -46,41 +46,58 @@ http://doc.trolltech.com/4.7/richtext-html-subset.html#css-properties
color:black; color:black;
} }
.item {
color:black;
}
.itemTitle { .itemTitle {
font-weight:600; font-weight:600;
font-size:large; font-size:large;
color:black;
} }
.itemText { .itemText {}
color:black;
}
.itemFooter { .itemFooter {
font-size:8px; font-size:8px;
color:black;
} }
.itemNotes {}
.itemNotesTitle { .itemNotesTitle {
font-weight:bold; font-weight:bold;
font-size:12px; font-size:12px;
color:black;
} }
.itemNotesText { .itemNotesText {
font-size:11px; font-size:11px;
color:black; }
.media {}
.mediaTitle {
font-weight:bold;
font-size:11px;
}
.mediaText {}
.imageList {}
.customNotes {
margin-top: 10px;
} }
.customNotesTitle { .customNotesTitle {
font-weight:bold; font-weight:bold;
font-size:11px; font-size:11px;
color:black;
} }
.customNotesText { .customNotesText {
font-size:11px; font-size:11px;
color:black; }
.newPage {
page-break-before:always;
} }
""" """
@ -153,86 +170,90 @@ 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*.
""" """
html_data = html.fromstring( html_data = self._addElement(u'html')
u'<title>%s</title>' % unicode(self.titleLineEdit.text())) self._addElement(u'head', parent=html_data)
self._addElement(u'title', unicode(self.titleLineEdit.text()),
html_data.head)
css_path = os.path.join( css_path = os.path.join(
AppLocation.get_data_path(), u'servicePrint.css') AppLocation.get_data_path(), u'service_print.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) custom_css = get_text_file_string(css_path)
self._addChildToParent( if not custom_css:
u'style', custom_css, html_data.head, u'type', u'text/css') custom_css = DEFAULT_CSS
self._addChildToParent(u'body', parent=html_data) self._addElement(u'style', custom_css, html_data.head,
self._addChildToParent(u'span', unicode(self.titleLineEdit.text()), attribute=(u'type', u'text/css'))
html_data.body, u'class', u'serviceTitle') self._addElement(u'body', parent=html_data)
self._addElement(u'h1', unicode(self.titleLineEdit.text()),
html_data.body, classId=u'serviceTitle')
for index, item in enumerate(self.serviceManager.serviceItems): for index, item in enumerate(self.serviceManager.serviceItems):
item = item[u'service_item'] self._addPreviewItem(html_data.body, item[u'service_item'], index)
div = self._addChildToParent(u'div', parent=html_data.body) # Add the custom service notes:
if self.footerTextEdit.toPlainText():
div = self._addElement(u'div', parent=html_data.body,
classId=u'customNotes')
self._addElement(u'span', translate('OpenLP.ServiceManager',
u'Custom Service Notes: '), div, classId=u'customNotesTitle')
self._addElement(u'span', self.footerTextEdit.toPlainText(), div,
classId=u'customNotesText')
self.document.setHtml(html.tostring(html_data))
self.previewWidget.updatePreview()
def _addPreviewItem(self, body, item, index):
div = self._addElement(u'div', classId=u'item', parent=body)
# Add the title of the service item. # Add the title of the service item.
item_title = self._addChildToParent( item_title = self._addElement(u'h2', parent=div, classId=u'itemTitle')
u'h2', parent=div, attribute=u'class', value=u'itemTitle') self._addElement(u'img', parent=item_title,
self._addChildToParent( attribute=(u'src', item.icon))
u'img', parent=item_title, attribute=u'src', value=item.icon) self._addElement(u'span', u'&nbsp;' + item.get_display_title(),
self._fromstring( item_title)
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. # Add the text of the service item.
if item.is_text(): if item.is_text():
verse_def = None verse_def = None
for slide in item.get_frames(): for slide in item.get_frames():
if not verse_def or verse_def != slide[u'verseTag']: if not verse_def or verse_def != slide[u'verseTag']:
p = self._addChildToParent(u'p', parent=div, p = self._addElement(u'div', parent=div,
attribute=u'class', value=u'itemText') classId=u'itemText')
else: else:
self._addChildToParent(u'br', parent=p) self._addElement(u'br', parent=p)
self._fromstring(u'<span>%s</span>' % slide[u'html'], p) self._addElement(u'p', slide[u'html'], p)
verse_def = slide[u'verseTag'] verse_def = slide[u'verseTag']
# Break the page before the div element. # Break the page before the div element.
if index != 0 and self.pageBreakAfterText.isChecked(): if index != 0 and self.pageBreakAfterText.isChecked():
div.set(u'style', u'page-break-before:always') div.set(u'class', u'item newPage')
# Add the image names of the service item. # Add the image names of the service item.
elif item.is_image(): elif item.is_image():
ol = self._addChildToParent(u'ol', parent=div) ol = self._addElement(u'ol', parent=div, classId=u'imageList')
for slide in range(len(item.get_frames())): for slide in range(len(item.get_frames())):
self._addChildToParent(u'li', item.get_frame_title(slide), ol) self._addElement(u'li', item.get_frame_title(slide), ol)
# add footer # add footer
if item.foot_text: foot_text = item.foot_text
self._fromstring( foot_text = foot_text.partition(u'<br>')[2]
item.foot_text, div, u'class', u'itemFooter') if foot_text:
foot = self._addElement(u'div', foot_text, parent=div,
classId=u'itemFooter')
# Add service items' notes. # Add service items' notes.
if self.notesCheckBox.isChecked(): if self.notesCheckBox.isChecked():
if item.notes: if item.notes:
p = self._addChildToParent(u'p', parent=div) p = self._addElement(u'div', classId=u'itemNotes', parent=div)
self._addChildToParent(u'span', unicode( self._addElement(u'span',
translate('OpenLP.ServiceManager', 'Notes:')), p, translate('OpenLP.ServiceManager', 'Notes: '), p,
u'class', u'itemNotesTitle') classId=u'itemNotesTitle')
self._fromstring(u'<span> %s</span>' % item.notes.replace( notes = self._addElement(u'span',
u'\n', u'<br />'), p, u'class', u'itemNotesText') item.notes.replace(u'\n', u'<br />'), p,
classId=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
title = self._fromstring(u'<p><strong>%s</strong> </p>' % title = self._addElement(u'div', classId=u'media', parent=div)
translate('OpenLP.ServiceManager', 'Playing time:'), div) self._addElement(u'span', translate('OpenLP.ServiceManager',
self._fromstring(u'<span>%s</span>' % 'Playing time: '), title, classId=u'mediaTitle')
unicode(datetime.timedelta(seconds=tme)), title) self._addElement(u'span', unicode(datetime.timedelta(seconds=tme)),
# Add the custom service notes: title, classId=u'mediaText')
if self.footerTextEdit.toPlainText():
div = self._addChildToParent(u'div', parent=html_data.body)
self._addChildToParent(u'span', translate('OpenLP.ServiceManager',
u'Custom Service Notes:'), div, u'class', u'customNotesTitle')
self._addChildToParent(
u'span', u' %s' % self.footerTextEdit.toPlainText(), div,
u'class', u'customNotesText')
self.document.setHtml(html.tostring(html_data))
self.previewWidget.updatePreview()
def _addChildToParent(self, tag, text=None, parent=None, attribute=None, def _addElement(self, tag, text=None, parent=None, classId=None,
value=None): attribute=None):
""" """
Creates a html element. If ``text`` is given, the element's text will Creates a html element. If ``text`` is given, the element's text will
set and if a ``parent`` is given, the element is appended. set and if a ``parent`` is given, the element is appended.
@ -246,30 +267,22 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
``parent`` ``parent``
The parent element. Defaults to ``None``. The parent element. Defaults to ``None``.
``attribute`` ``classId``
An optional attribute, for instance ``u'class``. Value for the class attribute
``value`` ``attribute``
The value for the given ``attribute``. It does not have a meaning, Tuple name/value pair to add as an optional attribute
if the attribute is left to its default.
""" """
element = html.Element(tag)
if text is not None: if text is not None:
element.text = unicode(text) element = html.fragment_fromstring(unicode(text), create_parent=tag)
else:
element = html.Element(tag)
if parent is not None: if parent is not None:
parent.append(element) parent.append(element)
if classId is not None:
element.set(u'class', classId)
if attribute is not None: if attribute is not None:
element.set(attribute, value if value is not None else u'') element.set(attribute[0], attribute[1])
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 return element
def paintRequested(self, printer): def paintRequested(self, printer):