← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/fixes into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/fixes into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #598393 in OpenLP: "After adding a new image to a selected (image) item in the service manager it is not selected anymore"
  https://bugs.launchpad.net/openlp/+bug/598393
  Bug #719102 in OpenLP: "editing author after editing song causes traceback"
  https://bugs.launchpad.net/openlp/+bug/719102
  Bug #730979 in OpenLP: "Song export crashes"
  https://bugs.launchpad.net/openlp/+bug/730979
  Bug #747206 in OpenLP: "Missing dictionary for spell check prevents program start"
  https://bugs.launchpad.net/openlp/+bug/747206

For more details, see:
https://code.launchpad.net/~googol/openlp/fixes/+merge/104840

Hello,

- fixed regression which I have introduced in r1962 (user defined formatting tags were not considered any longer)
- reworked staticmethods (merged functions etc)
- changed saveButton behaviour to reflect the internal things happening (the button is now only enabled when you can save a change)
-- 
https://code.launchpad.net/~googol/openlp/fixes/+merge/104840
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/fixes into lp:openlp.
=== modified file 'openlp/core/lib/formattingtags.py'
--- openlp/core/lib/formattingtags.py	2012-05-02 18:25:37 +0000
+++ openlp/core/lib/formattingtags.py	2012-05-05 16:05:25 +0000
@@ -46,13 +46,36 @@
         """
         Provide access to the html_expands list.
         """
-        # Load user defined tags otherwise user defined tags are not present.
         return FormattingTags.html_expands
 
     @staticmethod
-    def reset_html_tags():
-        """
-        Resets the html_expands list.
+    def save_html_tags():
+        """
+        Saves all formatting tags except protected ones.
+        """
+        tags = []
+        for tag in FormattingTags.html_expands:
+            if not tag[u'protected'] and not tag.get(u'temporary'):
+                # Using dict ensures that copy is made and encoding of values
+                # a little later does not affect tags in the original list
+                tags.append(dict(tag))
+                tag = tags[-1]
+                # Remove key 'temporary' from tags.
+                # It is not needed to be saved.
+                if u'temporary' in tag:
+                    del tag[u'temporary']
+                for element in tag:
+                    if isinstance(tag[element], unicode):
+                        tag[element] = tag[element].encode('utf8')
+        # Formatting Tags were also known as display tags.
+        QtCore.QSettings().setValue(u'displayTags/html_tags',
+            QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
+
+    @staticmethod
+    def load_tags():
+        """
+        Load the Tags from store so can be used in the system or used to
+        update the display.
         """
         temporary_tags = [tag for tag in FormattingTags.html_expands
             if tag.get(u'temporary')]
@@ -140,38 +163,6 @@
         FormattingTags.add_html_tags(base_tags)
         FormattingTags.add_html_tags(temporary_tags)
 
-    @staticmethod
-    def save_html_tags():
-        """
-        Saves all formatting tags except protected ones.
-        """
-        tags = []
-        for tag in FormattingTags.html_expands:
-            if not tag[u'protected'] and not tag.get(u'temporary'):
-                # Using dict ensures that copy is made and encoding of values
-                # a little later does not affect tags in the original list
-                tags.append(dict(tag))
-                tag = tags[-1]
-                # Remove key 'temporary' from tags.
-                # It is not needed to be saved.
-                if u'temporary' in tag:
-                    del tag[u'temporary']
-                for element in tag:
-                    if isinstance(tag[element], unicode):
-                        tag[element] = tag[element].encode('utf8')
-        # Formatting Tags were also known as display tags.
-        QtCore.QSettings().setValue(u'displayTags/html_tags',
-            QtCore.QVariant(cPickle.dumps(tags) if tags else u''))
-
-    @staticmethod
-    def load_tags():
-        """
-        Load the Tags from store so can be used in the system or used to
-        update the display. If Cancel was selected this is needed to reset the
-        dsiplay to the correct version.
-        """
-        # Initial Load of the Tags
-        FormattingTags.reset_html_tags()
         # Formatting Tags were also known as display tags.
         user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
             QtCore.QVariant(u'')).toString()
@@ -187,17 +178,13 @@
             FormattingTags.add_html_tags(user_tags)
 
     @staticmethod
-    def add_html_tags(tags, save=False):
+    def add_html_tags(tags):
         """
         Add a list of tags to the list.
 
         ``tags``
             The list with tags to add.
 
-        ``save``
-            Defaults to ``False``. If set to ``True`` the given ``tags`` are
-            saved to the config.
-
         Each **tag** has to be a ``dict`` and should have the following keys:
 
         * desc
@@ -225,8 +212,6 @@
             displaying text containing the tag. It has to be a ``boolean``.
         """
         FormattingTags.html_expands.extend(tags)
-        if save:
-            FormattingTags.save_html_tags()
 
     @staticmethod
     def remove_html_tag(tag_id):

=== modified file 'openlp/core/ui/formattingtagform.py'
--- openlp/core/ui/formattingtagform.py	2012-05-02 18:25:37 +0000
+++ openlp/core/ui/formattingtagform.py	2012-05-05 16:05:25 +0000
@@ -57,6 +57,14 @@
             QtCore.SIGNAL(u'clicked()'), self.onDeleteClicked)
         QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'),
             self.close)
+        QtCore.QObject.connect(self.descriptionLineEdit,
+            QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited)
+        QtCore.QObject.connect(self.tagLineEdit,
+            QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited)
+        QtCore.QObject.connect(self.startTagLineEdit,
+            QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited)
+        QtCore.QObject.connect(self.endTagLineEdit,
+            QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited)
         # Forces reloading of tags from openlp configuration.
         FormattingTags.load_tags()
 
@@ -65,7 +73,7 @@
         Load Display and set field state.
         """
         # Create initial copy from master
-        self._resetTable()
+        self._reloadTable()
         self.selected = -1
         return QtGui.QDialog.exec_(self)
 
@@ -73,9 +81,9 @@
         """
         Table Row selected so display items and set field state.
         """
-        row = self.tagTableWidget.currentRow()
-        html = FormattingTags.html_expands[row]
-        self.selected = row
+        self.savePushButton.setEnabled(False)
+        self.selected = self.tagTableWidget.currentRow()
+        html = FormattingTags.get_html_tags()[self.selected]
         self.descriptionLineEdit.setText(html[u'desc'])
         self.tagLineEdit.setText(self._strip(html[u'start tag']))
         self.startTagLineEdit.setText(html[u'start html'])
@@ -85,21 +93,26 @@
             self.tagLineEdit.setEnabled(False)
             self.startTagLineEdit.setEnabled(False)
             self.endTagLineEdit.setEnabled(False)
-            self.savePushButton.setEnabled(False)
             self.deletePushButton.setEnabled(False)
         else:
             self.descriptionLineEdit.setEnabled(True)
             self.tagLineEdit.setEnabled(True)
             self.startTagLineEdit.setEnabled(True)
             self.endTagLineEdit.setEnabled(True)
-            self.savePushButton.setEnabled(True)
             self.deletePushButton.setEnabled(True)
 
+    def onTextEdited(self, text):
+        """
+        Enable the ``savePushButton`` when any of the selected tag's properties
+        has been changed.
+        """
+        self.savePushButton.setEnabled(True)
+
     def onNewClicked(self):
         """
         Add a new tag to list only if it is not a duplicate.
         """
-        for html in FormattingTags.html_expands:
+        for html in FormattingTags.get_html_tags():
             if self._strip(html[u'start tag']) == u'n':
                 critical_error_message_box(
                     translate('OpenLP.FormattingTagForm', 'Update Error'),
@@ -117,11 +130,13 @@
             u'temporary': False
         }
         FormattingTags.add_html_tags([tag])
-        self._resetTable()
+        FormattingTags.save_html_tags()
+        self._reloadTable()
         # Highlight new row
         self.tagTableWidget.selectRow(self.tagTableWidget.rowCount() - 1)
         self.onRowSelected()
         self.tagTableWidget.scrollToBottom()
+        #self.savePushButton.setEnabled(False)
 
     def onDeleteClicked(self):
         """
@@ -130,14 +145,14 @@
         if self.selected != -1:
             FormattingTags.remove_html_tag(self.selected)
             self.selected = -1
-        self._resetTable()
-        FormattingTags.save_html_tags()
+            FormattingTags.save_html_tags()
+            self._reloadTable()
 
     def onSavedClicked(self):
         """
         Update Custom Tag details if not duplicate and save the data.
         """
-        html_expands = FormattingTags.html_expands
+        html_expands = FormattingTags.get_html_tags()
         if self.selected != -1:
             html = html_expands[self.selected]
             tag = unicode(self.tagLineEdit.text())
@@ -157,14 +172,13 @@
             # Keep temporary tags when the user changes one.
             html[u'temporary'] = False
             self.selected = -1
-        self._resetTable()
         FormattingTags.save_html_tags()
+        self._reloadTable()
 
-    def _resetTable(self):
+    def _reloadTable(self):
         """
         Reset List for loading.
         """
-        FormattingTags.load_tags()
         self.tagTableWidget.clearContents()
         self.tagTableWidget.setRowCount(0)
         self.newPushButton.setEnabled(True)

=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py	2012-04-29 15:31:56 +0000
+++ openlp/plugins/songs/lib/xml.py	2012-05-05 16:05:25 +0000
@@ -317,9 +317,7 @@
         tags_element = None
         match = re.search(u'\{/?\w+\}', song.lyrics, re.UNICODE)
         if match:
-            # Reset available tags.
-            FormattingTags.reset_html_tags()
-            # Named 'formatting' - 'format' is built-in fuction in Python.
+            # Named 'format_' - 'format' is built-in fuction in Python.
             format_ = etree.SubElement(song_xml, u'format')
             tags_element = etree.SubElement(format_, u'tags')
             tags_element.set(u'application', u'OpenLP')
@@ -572,7 +570,8 @@
             for tag in FormattingTags.get_html_tags()]
         new_tags = [tag for tag in found_tags
             if tag[u'start tag'] not in existing_tag_ids]
-        FormattingTags.add_html_tags(new_tags, True)
+        FormattingTags.add_html_tags(new_tags)
+        FormattingTags.save_html_tags()
 
     def _process_lines_mixed_content(self, element, newlines=True):
         """


Follow ups