veses/chapters comboBoxes now behave differently

This commit is contained in:
Andreas Preikschat 2010-09-26 19:17:29 +02:00
parent 8026eea0e6
commit 2f1134556f

View File

@ -407,21 +407,21 @@ class BibleMediaItem(MediaManagerItem):
self.initialiseChapterVerse(bible, book[u'name'], self.initialiseChapterVerse(bible, book[u'name'],
book[u'chapters']) book[u'chapters'])
def initialiseChapterVerse(self, bible, book, chapters): def initialiseChapterVerse(self, bible, book, chapter_count):
log.debug(u'initialiseChapterVerse %s, %s', bible, book) log.debug(u'initialiseChapterVerse %s, %s', bible, book)
self.chapters_from = chapters self.chapter_count = chapter_count
self.verses = self.parent.manager.get_verse_count(bible, book, 1) verse_count = self.parent.manager.get_verse_count(bible, book, 1)
if self.verses == 0: if verse_count == 0:
self.AdvancedSearchButton.setEnabled(False) self.AdvancedSearchButton.setEnabled(False)
self.AdvancedMessage.setText( self.AdvancedMessage.setText(
translate('BiblesPlugin.MediaItem', 'Bible not fully loaded.')) translate('BiblesPlugin.MediaItem', 'Bible not fully loaded.'))
else: else:
self.AdvancedSearchButton.setEnabled(True) self.AdvancedSearchButton.setEnabled(True)
self.AdvancedMessage.setText(u'') self.AdvancedMessage.setText(u'')
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) self.adjustComboBox(1, self.chapter_count, self.AdvancedFromChapter)
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) self.adjustComboBox(1, self.chapter_count, self.AdvancedToChapter)
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) self.adjustComboBox(1, verse_count, self.AdvancedFromVerse)
self.adjustComboBox(1, self.verses, self.AdvancedToVerse) self.adjustComboBox(1, verse_count, self.AdvancedToVerse)
def onAdvancedVersionComboBox(self): def onAdvancedVersionComboBox(self):
self.initialiseBible( self.initialiseBible(
@ -435,44 +435,65 @@ class BibleMediaItem(MediaManagerItem):
self.AdvancedBookComboBox.itemData(item).toInt()[0]) self.AdvancedBookComboBox.itemData(item).toInt()[0])
def onAdvancedFromVerse(self): def onAdvancedFromVerse(self):
frm = int(self.AdvancedFromVerse.currentText()) chapter_from = int(self.AdvancedFromChapter.currentText())
chapter_frm = int(self.AdvancedFromChapter.currentText())
chapter_to = int(self.AdvancedToChapter.currentText()) chapter_to = int(self.AdvancedToChapter.currentText())
if chapter_frm == chapter_to: if chapter_from == chapter_to:
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
verses = self.parent.manager.get_verse_count(bible, book, chapter_to) verse_from = int(self.AdvancedFromVerse.currentText())
self.adjustComboBox(frm, verses, self.AdvancedToVerse) verse_count = self.parent.manager.get_verse_count(bible, book,
chapter_to)
self.adjustComboBox(verse_from, verse_count,
self.AdvancedToVerse, True)
def onAdvancedToChapter(self): def onAdvancedToChapter(self):
chapter_frm = int(self.AdvancedFromChapter.currentText())
chapter_to = int(self.AdvancedToChapter.currentText())
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
verses = self.parent.manager.get_verse_count(bible, book, chapter_to) chapter_from = int(self.AdvancedFromChapter.currentText())
if chapter_frm != chapter_to: chapter_to = int(self.AdvancedToChapter.currentText())
self.adjustComboBox(1, verses, self.AdvancedToVerse) 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: else:
frm = int(self.AdvancedFromVerse.currentText()) self.adjustComboBox(1, verse_count, self.AdvancedToVerse)
to = int(self.AdvancedToVerse.currentText())
if to < frm:
self.adjustComboBox(frm, verses, self.AdvancedToVerse)
def onAdvancedFromChapter(self): def onAdvancedFromChapter(self):
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
chapter_frm = int(self.AdvancedFromChapter.currentText()) chapter_from = int(self.AdvancedFromChapter.currentText())
self.adjustComboBox(chapter_frm, self.chapters_from, 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) self.AdvancedToChapter)
verse = self.parent.manager.get_verse_count(bible, book, chapter_frm) elif chapter_from == chapter_to:
self.adjustComboBox(1, verse, self.AdvancedToVerse) self.adjustComboBox(chapter_from, self.chapter_count,
self.adjustComboBox(1, verse, self.AdvancedFromVerse) 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) log.debug(u'adjustComboBox %s, %s, %s', combo, range_from, range_to)
if restore:
oldText = unicode(combo.currentText())
combo.clear() combo.clear()
for i in range(int(range_from), int(range_to) + 1): for i in range(int(range_from), int(range_to) + 1):
combo.addItem(unicode(i)) combo.addItem(unicode(i))
if restore and combo.findText(oldText) != -1:
combo.setCurrentIndex(combo.findText(oldText))
def onAdvancedSearchButton(self): def onAdvancedSearchButton(self):
log.debug(u'Advanced Search Button pressed') log.debug(u'Advanced Search Button pressed')