forked from openlp/openlp
extended helper methods
This commit is contained in:
parent
004bbc8865
commit
7d2719288a
@ -163,20 +163,19 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
|
|||||||
css_file.write(DEFAULT_CSS)
|
css_file.write(DEFAULT_CSS)
|
||||||
css_file.close()
|
css_file.close()
|
||||||
custom_css = get_text_file_string(css_path)
|
custom_css = get_text_file_string(css_path)
|
||||||
style = self._addChildToParent(u'style', custom_css, html_data.head)
|
self._addChildToParent(
|
||||||
style.set(u'type', u'text/css')
|
u'style', custom_css, html_data.head, u'type', u'text/css')
|
||||||
self._addChildToParent(u'body', parent=html_data)
|
self._addChildToParent(u'body', parent=html_data)
|
||||||
service_title = self._addChildToParent(
|
self._addChildToParent(u'span', unicode(self.titleLineEdit.text()),
|
||||||
u'span', unicode(self.titleLineEdit.text()), html_data.body)
|
html_data.body, u'class', u'serviceTitle')
|
||||||
service_title.set(u'class', u'serviceTitle')
|
|
||||||
for index, item in enumerate(self.serviceManager.serviceItems):
|
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)
|
div = self._addChildToParent(u'div', parent=html_data.body)
|
||||||
# Add the title of the service item.
|
# Add the title of the service item.
|
||||||
item_title = self._addChildToParent(u'h2', parent=div)
|
item_title = self._addChildToParent(
|
||||||
item_title.set(u'class', u'itemTitle')
|
u'h2', parent=div, attribute=u'class', value=u'itemTitle')
|
||||||
icon = self._addChildToParent(u'img', parent=item_title)
|
self._addChildToParent(
|
||||||
icon.set(u'src', item.icon)
|
u'img', parent=item_title, attribute=u'src', value=item.icon)
|
||||||
self._fromstring(
|
self._fromstring(
|
||||||
u'<span> %s</span>' % item.get_display_title(), item_title)
|
u'<span> %s</span>' % item.get_display_title(), item_title)
|
||||||
if self.slideTextCheckBox.isChecked():
|
if self.slideTextCheckBox.isChecked():
|
||||||
@ -185,8 +184,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
|
|||||||
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._addChildToParent(u'p', parent=div,
|
||||||
p.set(u'class', u'itemText')
|
attribute=u'class', value=u'itemText')
|
||||||
else:
|
else:
|
||||||
self._addChildToParent(u'br', parent=p)
|
self._addChildToParent(u'br', parent=p)
|
||||||
self._fromstring(u'<span>%s</span>' % slide[u'html'], p)
|
self._fromstring(u'<span>%s</span>' % slide[u'html'], p)
|
||||||
@ -201,18 +200,17 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
|
|||||||
self._addChildToParent(u'li', item.get_frame_title(slide), ol)
|
self._addChildToParent(u'li', item.get_frame_title(slide), ol)
|
||||||
# add footer
|
# add footer
|
||||||
if item.foot_text:
|
if item.foot_text:
|
||||||
p = self._fromstring(item.foot_text, div)
|
self._fromstring(
|
||||||
p.set(u'class', u'itemFooter')
|
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:
|
||||||
p = self._addChildToParent(u'p', parent=div)
|
p = self._addChildToParent(u'p', parent=div)
|
||||||
title = self._addChildToParent(u'span', unicode(
|
self._addChildToParent(u'span', unicode(
|
||||||
translate('OpenLP.ServiceManager', 'Notes:')), p)
|
translate('OpenLP.ServiceManager', 'Notes:')), p,
|
||||||
title.set(u'class', u'itemNotesTitle')
|
u'class', u'itemNotesTitle')
|
||||||
text = self._fromstring(u'<span> %s</span>' %
|
self._fromstring(u'<span> %s</span>' % item.notes.replace(
|
||||||
item.notes.replace(u'\n', u'<br />'), p)
|
u'\n', u'<br />'), p, u'class', u'itemNotesText')
|
||||||
text.set(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
|
||||||
@ -224,25 +222,43 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
|
|||||||
unicode(datetime.timedelta(seconds=tme)), title)
|
unicode(datetime.timedelta(seconds=tme)), title)
|
||||||
# Add the custom service notes:
|
# Add the custom service notes:
|
||||||
if self.footerTextEdit.toPlainText():
|
if self.footerTextEdit.toPlainText():
|
||||||
footer_title = self._addChildToParent(u'span', translate(
|
self._addChildToParent(u'span', translate('OpenLP.ServiceManager',
|
||||||
'OpenLP.ServiceManager', u'Custom Service Notes:'), div)
|
u'Custom Service Notes:'), div, u'class', u'customNotesTitle')
|
||||||
footer_title.set(u'class', u'customNotesTitle')
|
self._addChildToParent(
|
||||||
footer_text = self._addChildToParent(u'span',
|
u'span', u' %s' % self.footerTextEdit.toPlainText(), div,
|
||||||
u' %s' % self.footerTextEdit.toPlainText(), div)
|
u'class', u'customNotesText')
|
||||||
footer_text.set(u'class', u'customNotesText')
|
|
||||||
self.document.setHtml(html.tostring(html_data))
|
self.document.setHtml(html.tostring(html_data))
|
||||||
self.previewWidget.updatePreview()
|
self.previewWidget.updatePreview()
|
||||||
|
|
||||||
def _addChildToParent(self, tag, text=None, parent=None):
|
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
|
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.
|
||||||
|
|
||||||
|
``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 and meaning,
|
||||||
|
if the attribute is left to its default.
|
||||||
"""
|
"""
|
||||||
element = html.Element(tag)
|
element = html.Element(tag)
|
||||||
if text is not None:
|
if text is not None:
|
||||||
element.text = text
|
element.text = text
|
||||||
if parent is not None:
|
if parent is not None:
|
||||||
parent.append(element)
|
parent.append(element)
|
||||||
|
if attribute is not None:
|
||||||
|
element.set(attribute, value if value is not None else u'')
|
||||||
return element
|
return element
|
||||||
|
|
||||||
def _fromstring(self, string, parent):
|
def _fromstring(self, string, parent):
|
||||||
|
Loading…
Reference in New Issue
Block a user