← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~j-corwin/openlp/general into lp:openlp

 

Jonathan Corwin has proposed merging lp:~j-corwin/openlp/general into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #634771 in OpenLP: "OpenLP 1.9.2+bzr1016-0ubuntu1~lucid1 does not start"
  https://bugs.launchpad.net/openlp/+bug/634771
  Bug #646718 in OpenLP: "Songbook, Number will not loaded, Title will not be saved"
  https://bugs.launchpad.net/openlp/+bug/646718
  Bug #696013 in OpenLP: "song import from powerpoint crashes every second time"
  https://bugs.launchpad.net/openlp/+bug/696013
  Bug #696021 in OpenLP: "presentation loader does not work fine in Windows using Powerpoint Viewer 2007"
  https://bugs.launchpad.net/openlp/+bug/696021
  Bug #696637 in OpenLP: "Alert not positioned correctly in single screen"
  https://bugs.launchpad.net/openlp/+bug/696637
  Bug #727732 in OpenLP: "Openlp 1.9.?? crashes on start"
  https://bugs.launchpad.net/openlp/+bug/727732
  Bug #735039 in OpenLP: "Cannot import PowerPoint Presentations with PowerPoint 2010"
  https://bugs.launchpad.net/openlp/+bug/735039

For more details, see:
https://code.launchpad.net/~j-corwin/openlp/general/+merge/58918

Changes relating to Service Print

1. No longer auto-create a .css file as it makes it difficult in the future to add CSS if required.

2. Rename override .css file from serviceprint.css to service-print.css as I've made changes to the HTML and trying to inform the nightly-build installers to delete the old file will prove problematic

3. Tidy up HTML a bit to make it easier to make some changes via CSS

-- 
https://code.launchpad.net/~j-corwin/openlp/general/+merge/58918
Your team OpenLP Core is requested to review the proposed merge of lp:~j-corwin/openlp/general into lp:openlp.
=== modified file 'openlp/core/ui/printserviceform.py'
--- openlp/core/ui/printserviceform.py	2011-04-15 21:43:59 +0000
+++ openlp/core/ui/printserviceform.py	2011-04-24 20:19:24 +0000
@@ -61,15 +61,23 @@
    color:black;
 }
 
+.itemNotes {
+   color:black;
+}
+
 .itemNotesTitle {
    font-weight:bold;
    font-size:12px;
-   color:black;
 }
 
 .itemNotesText {
    font-size:11px;
-   color:black;
+}
+
+.mediaTitle {
+    font-weight:bold;
+    font-size:11px;
+    color:black;
 }
 
 .customNotesTitle {
@@ -82,6 +90,10 @@
    font-size:11px;
    color:black;
 }
+
+.newPage {
+    page-break-before:always;
+}
 """
 
 class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog):
@@ -153,86 +165,89 @@
         """
         Creates the html text and updates the html of *self.document*.
         """
-        html_data = html.fromstring(
-            u'<title>%s</title>' % unicode(self.titleLineEdit.text()))
+        html_data = self._addElement(u'html')
+        self._addElement(u'head', parent=html_data)
+        self._addElement(u'title', unicode(self.titleLineEdit.text()),
+            html_data.head)
         css_path = os.path.join(
-            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()
+            AppLocation.get_data_path(), u'service_print.css')
         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')
+        if not custom_css:
+            custom_css = DEFAULT_CSS
+        self._addElement(u'style', custom_css, html_data.head,
+            attribute=(u'type', u'text/css'))
+        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):
-            item = item[u'service_item']
-            div = self._addChildToParent(u'div', parent=html_data.body)
-            # Add the title of the service item.
-            item_title = self._addChildToParent(
-                u'h2', parent=div, attribute=u'class', value=u'itemTitle')
-            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():
-                # Add the text of the service item.
-                if item.is_text():
-                    verse_def = None
-                    for slide in item.get_frames():
-                        if not verse_def or verse_def != slide[u'verseTag']:
-                            p = self._addChildToParent(u'p', parent=div,
-                                attribute=u'class', value=u'itemText')
-                        else:
-                            self._addChildToParent(u'br', parent=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():
-                    ol = self._addChildToParent(u'ol', parent=div)
-                    for slide in range(len(item.get_frames())):
-                        self._addChildToParent(u'li', item.get_frame_title(slide), ol)
-                # add footer
-                if item.foot_text:
-                    self._fromstring(
-                        item.foot_text, div, u'class', u'itemFooter')
-            # Add service items' notes.
-            if self.notesCheckBox.isChecked():
-                if item.notes:
-                    p = self._addChildToParent(u'p', parent=div)
-                    self._addChildToParent(u'span', unicode(
-                        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.
-            if item.is_media() and self.metaDataCheckBox.isChecked():
-                tme = item.media_length
-                if item.end_time > 0:
-                    tme = item.end_time - item.start_time
-                title = self._fromstring(u'<p><strong>%s</strong> </p>' %
-                    translate('OpenLP.ServiceManager', 'Playing time:'), div)
-                self._fromstring(u'<span>%s</span>' %
-                    unicode(datetime.timedelta(seconds=tme)), title)
+            self._addPreviewItem(html_data.body, item[u'service_item'], index)
         # Add the custom service notes:
         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')
+            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 _addChildToParent(self, tag, text=None, parent=None, attribute=None,
-        value=None):
+    def _addPreviewItem(self, body, item, index):
+        div = self._addElement(u'div', classId=u'item', parent=body)
+        # Add the title of the service item.
+        item_title = self._addElement(u'h2', parent=div, classId=u'itemTitle')
+        self._addElement(u'img', parent=item_title,
+             attribute=(u'src', item.icon))
+        self._addElement(u'span', item.get_display_title(), item_title)
+        if self.slideTextCheckBox.isChecked():
+            # Add the text of the service item.
+            if item.is_text():
+                verse_def = None
+                for slide in item.get_frames():
+                    if not verse_def or verse_def != slide[u'verseTag']:
+                        p = self._addElement(u'div', parent=div,
+                            classId=u'itemText')
+                    else:
+                        self._addElement(u'br', parent=p)
+                    self._addElement(u'p', 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'class', u'item newPage')
+            # Add the image names of the service item.
+            elif item.is_image():
+                ol = self._addElement(u'ol', parent=div, classId=u'imageList')
+                for slide in range(len(item.get_frames())):
+                    self._addElement(u'li', item.get_frame_title(slide), ol)
+            # add footer
+            foot_text = item.foot_text
+            foot_text = foot_text.partition(u'<br>')[2]
+            if foot_text:
+                foot = self._addElement(u'div', foot_text, parent=div,
+                    classId=u'itemFooter')
+        # Add service items' notes.
+        if self.notesCheckBox.isChecked():
+            if item.notes:
+                p = self._addElement(u'div', classId=u'itemNotes', parent=div)
+                self._addElement(u'span',
+                    translate('OpenLP.ServiceManager', 'Notes: '), p,
+                    classId=u'itemNotesTitle')
+                notes = self._addElement(u'span',
+                    item.notes.replace(u'\n', u'<br />'), p,
+                    classId=u'itemNotesText')
+        # Add play length of media files.
+        if item.is_media() and self.metaDataCheckBox.isChecked():
+            tme = item.media_length
+            if item.end_time > 0:
+                tme = item.end_time - item.start_time
+            title = self._addElement(u'div', classId=u'media', parent=div)
+            self._addElement(u'span', translate('OpenLP.ServiceManager',
+                'Playing time: '), title, classId=u'mediaTitle')
+            self._addElement(u'span', unicode(datetime.timedelta(seconds=tme)),
+                 title, classId=u'mediaText')
+
+    def _addElement(self, tag, text=None, parent=None, classId=None,
+         attribute=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.
@@ -246,30 +261,22 @@
         ``parent``
             The parent element. Defaults to ``None``.
 
+        ``classId``
+            Value for the class attribute
+
         ``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.
+            Tuple name/value pair to add as an optional attribute
         """
-        element = html.Element(tag)
         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:
             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)
+        if classId is not None:
+            element.set(u'class', classId)
+        if attribute is not None:
+            element.set(attribute[0], attribute[1])
         return element
 
     def paintRequested(self, printer):
@@ -380,4 +387,4 @@
             QtCore.QVariant(self.metaDataCheckBox.isChecked()))
         settings.setValue(u'print notes',
             QtCore.QVariant(self.notesCheckBox.isChecked()))
-        settings.endGroup()
\ No newline at end of file
+        settings.endGroup()


Follow ups