← Back to team overview

openlp-core team mailing list archive

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

 

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

Requested reviews:
  OpenLP Core (openlp-core)


Hello!

I changed the comboBoxes' behaviour (chapter from, chapter to, verse from, verse to). Now, the boxes aren't cleared that often.

E. g. (trunk)
1. set "chapter from" to two
2. set "verse to" to whatever (but not one)
3 set "chapter from" to one
-> "verse to" will be cleared (set to one)

(And some code clean ups)
-- 
https://code.launchpad.net/~googol-hush/openlp/bibles/+merge/36902
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/bibles into lp:openlp.
=== modified file 'openlp/plugins/bibles/bibleplugin.py'
--- openlp/plugins/bibles/bibleplugin.py	2010-09-21 17:30:32 +0000
+++ openlp/plugins/bibles/bibleplugin.py	2010-09-28 18:04:40 +0000
@@ -79,8 +79,7 @@
         self.exportBibleItem = QtGui.QAction(export_menu)
         self.exportBibleItem.setObjectName(u'exportBibleItem')
         export_menu.addAction(self.exportBibleItem)
-        self.exportBibleItem.setText(translate(
-            'BiblesPlugin', '&Bible'))
+        self.exportBibleItem.setText(translate('BiblesPlugin', '&Bible'))
         self.exportBibleItem.setVisible(False)
 
     def onBibleImportClick(self):
@@ -96,7 +95,6 @@
     def usesTheme(self, theme):
         """
         Called to find out if the bible plugin is currently using a theme.
-
         Returns True if the theme is being used, otherwise returns False.
         """
         if self.settings_tab.bible_theme == theme:

=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py	2010-09-26 13:38:40 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py	2010-09-28 18:04:40 +0000
@@ -407,21 +407,21 @@
                 self.initialiseChapterVerse(bible, book[u'name'],
                     book[u'chapters'])
 
-    def initialiseChapterVerse(self, bible, book, chapters):
+    def initialiseChapterVerse(self, bible, book, chapter_count):
         log.debug(u'initialiseChapterVerse %s, %s', bible, book)
-        self.chapters_from = chapters
-        self.verses = self.parent.manager.get_verse_count(bible, book, 1)
-        if self.verses == 0:
+        self.chapter_count = chapter_count
+        verse_count = self.parent.manager.get_verse_count(bible, book, 1)
+        if verse_count == 0:
             self.AdvancedSearchButton.setEnabled(False)
             self.AdvancedMessage.setText(
                 translate('BiblesPlugin.MediaItem', 'Bible not fully loaded.'))
         else:
             self.AdvancedSearchButton.setEnabled(True)
             self.AdvancedMessage.setText(u'')
-            self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
-            self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
-            self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
-            self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
+            self.adjustComboBox(1, self.chapter_count, self.AdvancedFromChapter)
+            self.adjustComboBox(1, self.chapter_count, self.AdvancedToChapter)
+            self.adjustComboBox(1, verse_count, self.AdvancedFromVerse)
+            self.adjustComboBox(1, verse_count, self.AdvancedToVerse)
 
     def onAdvancedVersionComboBox(self):
         self.initialiseBible(
@@ -435,44 +435,65 @@
             self.AdvancedBookComboBox.itemData(item).toInt()[0])
 
     def onAdvancedFromVerse(self):
-        frm = int(self.AdvancedFromVerse.currentText())
-        chapter_frm = int(self.AdvancedFromChapter.currentText())
+        chapter_from = int(self.AdvancedFromChapter.currentText())
         chapter_to = int(self.AdvancedToChapter.currentText())
-        if chapter_frm == chapter_to:
+        if chapter_from == chapter_to:
             bible = unicode(self.AdvancedVersionComboBox.currentText())
             book = unicode(self.AdvancedBookComboBox.currentText())
-            verses = self.parent.manager.get_verse_count(bible, book, chapter_to)
-            self.adjustComboBox(frm, verses, self.AdvancedToVerse)
+            verse_from = int(self.AdvancedFromVerse.currentText())
+            verse_count = self.parent.manager.get_verse_count(bible, book,
+                chapter_to)
+            self.adjustComboBox(verse_from, verse_count,
+                self.AdvancedToVerse, True)
 
     def onAdvancedToChapter(self):
-        chapter_frm = int(self.AdvancedFromChapter.currentText())
-        chapter_to = int(self.AdvancedToChapter.currentText())
         bible = unicode(self.AdvancedVersionComboBox.currentText())
         book = unicode(self.AdvancedBookComboBox.currentText())
-        verses = self.parent.manager.get_verse_count(bible, book, chapter_to)
-        if chapter_frm != chapter_to:
-            self.adjustComboBox(1, verses, self.AdvancedToVerse)
+        chapter_from = int(self.AdvancedFromChapter.currentText())
+        chapter_to = int(self.AdvancedToChapter.currentText())
+        verse_from = int(self.AdvancedFromVerse.currentText())
+        verse_to = int(self.AdvancedToVerse.currentText())
+        verse_count = self.parent.manager.get_verse_count(bible, book,
+            chapter_to)
+        if chapter_from == chapter_to and verse_from > verse_to:
+            self.adjustComboBox(verse_from, verse_count, self.AdvancedToVerse)
         else:
-            frm = int(self.AdvancedFromVerse.currentText())
-            to = int(self.AdvancedToVerse.currentText())
-            if to < frm:
-                self.adjustComboBox(frm, verses, self.AdvancedToVerse)
+            self.adjustComboBox(1, verse_count, self.AdvancedToVerse)
 
     def onAdvancedFromChapter(self):
         bible = unicode(self.AdvancedVersionComboBox.currentText())
         book = unicode(self.AdvancedBookComboBox.currentText())
-        chapter_frm = int(self.AdvancedFromChapter.currentText())
-        self.adjustComboBox(chapter_frm, self.chapters_from,
-            self.AdvancedToChapter)
-        verse = self.parent.manager.get_verse_count(bible, book, chapter_frm)
-        self.adjustComboBox(1, verse, self.AdvancedToVerse)
-        self.adjustComboBox(1, verse, self.AdvancedFromVerse)
+        chapter_from = int(self.AdvancedFromChapter.currentText())
+        chapter_to = int(self.AdvancedToChapter.currentText())
+        verse_count = self.parent.manager.get_verse_count(bible, book,
+            chapter_from)
+        self.adjustComboBox(1, verse_count, self.AdvancedFromVerse)
+        if chapter_from > chapter_to:
+            self.adjustComboBox(1, verse_count, self.AdvancedToVerse)
+            self.adjustComboBox(chapter_from, self.chapter_count,
+                self.AdvancedToChapter)
+        elif chapter_from == chapter_to:
+            self.adjustComboBox(chapter_from, self.chapter_count,
+                self.AdvancedToChapter)
+            self.adjustComboBox(1, verse_count, self.AdvancedToVerse, True)
+        else:
+            self.adjustComboBox(chapter_from, self.chapter_count,
+                self.AdvancedToChapter, True)
 
-    def adjustComboBox(self, range_from, range_to, combo):
+    def adjustComboBox(self, range_from, range_to, combo, restore=False):
+        """
+        ``restore``
+            If True, then the combo's currentText will be restored after
+            adjusting (if possible).
+        """
         log.debug(u'adjustComboBox %s, %s, %s', combo, range_from, range_to)
+        if restore:
+            old_text = unicode(combo.currentText())
         combo.clear()
         for i in range(int(range_from), int(range_to) + 1):
             combo.addItem(unicode(i))
+        if restore and combo.findText(old_text) != -1:
+            combo.setCurrentIndex(combo.findText(old_text))
 
     def onAdvancedSearchButton(self):
         log.debug(u'Advanced Search Button pressed')


Follow ups