← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/songs into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/songs into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)


Hello!

I implemented onVerseTypeComboBoxChanged which does something similar like onCursorPositionChanged.

When the comboBox is changed, that the method looks what the verse number should be (in regard to the verse type and the cursor's position).


-- 
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/38249
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/songs into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/editverseform.py'
--- openlp/plugins/songs/forms/editverseform.py	2010-10-11 15:26:48 +0000
+++ openlp/plugins/songs/forms/editverseform.py	2010-10-12 16:50:55 +0000
@@ -53,6 +53,9 @@
         QtCore.QObject.connect(self.verseTextEdit,
             QtCore.SIGNAL(u'cursorPositionChanged()'),
             self.onCursorPositionChanged)
+        QtCore.QObject.connect(self.verseTypeComboBox,
+            QtCore.SIGNAL(u'currentIndexChanged(int)'),
+            self.onVerseTypeComboBoxChanged)
         self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---')
 
     def contextMenu(self, point):
@@ -71,6 +74,33 @@
             self.insertVerse(VerseType.to_string(verse_type),
                 self.verseNumberBox.value())
 
+    def onVerseTypeComboBoxChanged(self):
+        """
+        Adjusts the verse number SpinBox in regard to the selected verse type
+        and the cursor's position.
+        """
+        position = self.verseTextEdit.textCursor().position()
+        text = unicode(self.verseTextEdit.toPlainText())
+        verse_type = VerseType.to_string(self.verseTypeComboBox.currentIndex())
+        if not text:
+            return
+        position = text.rfind(u'---[%s' % verse_type, 0, position)
+        if position == -1:
+            self.verseNumberBox.setValue(1)
+            return
+        text = text[position:]
+        position = text.find(u']---')
+        if position == -1:
+            return
+        text = text[:position + 4]
+        match = self.verse_regex.match(text)
+        if match:
+            verse_type = match.group(1)
+            verse_number = int(match.group(2))
+            verse_type_index = VerseType.from_string(verse_type)
+            if verse_type_index is not None:
+                self.verseNumberBox.setValue(verse_number)
+
     def onCursorPositionChanged(self):
         """
         Determines the previous verse type and number in regard to the cursor's


Follow ups