forked from openlp/openlp
- Combined search is now working, own "combined" function for scripture reference search.
- Book name prediction as typing is not yet working - Icon does not appear correctly (If used) Now using Reference icon, even thou combined icon was added. - Renamed to "Combined search"
This commit is contained in:
parent
2255f05505
commit
b1223927a0
@ -237,26 +237,6 @@ class BibleManager(RegistryProperties):
|
||||
log.debug('BibleManager.get_verse_count_by_book_ref_id("%s", "%s", "%s")', bible, book_ref_id, chapter)
|
||||
return self.db_cache[bible].get_verse_count(book_ref_id, chapter)
|
||||
|
||||
def get_language_selection(self, bible):
|
||||
"""
|
||||
Returns the language selection of a bible.
|
||||
|
||||
:param bible: Unicode. The Bible to get the language selection from.
|
||||
"""
|
||||
log.debug('BibleManager.get_language_selection("%s")', bible)
|
||||
language_selection = self.get_meta_data(bible, 'book_name_language')
|
||||
if not language_selection or language_selection.value == "None" or language_selection.value == "-1":
|
||||
# If None is returned, it's not the singleton object but a
|
||||
# BibleMeta object with the value "None"
|
||||
language_selection = Settings().value(self.settings_section + '/book name language')
|
||||
else:
|
||||
language_selection = language_selection.value
|
||||
try:
|
||||
language_selection = int(language_selection)
|
||||
except (ValueError, TypeError):
|
||||
language_selection = LanguageSelection.Application
|
||||
return language_selection
|
||||
|
||||
def get_verses(self, bible, verse_text, book_ref_id=False, show_error=True):
|
||||
"""
|
||||
Parses a scripture reference, fetches the verses from the Bible
|
||||
@ -316,6 +296,26 @@ class BibleManager(RegistryProperties):
|
||||
)
|
||||
return None
|
||||
|
||||
def get_language_selection(self, bible):
|
||||
"""
|
||||
Returns the language selection of a bible.
|
||||
|
||||
:param bible: Unicode. The Bible to get the language selection from.
|
||||
"""
|
||||
log.debug('BibleManager.get_language_selection("%s")', bible)
|
||||
language_selection = self.get_meta_data(bible, 'book_name_language')
|
||||
if not language_selection or language_selection.value == "None" or language_selection.value == "-1":
|
||||
# If None is returned, it's not the singleton object but a
|
||||
# BibleMeta object with the value "None"
|
||||
language_selection = Settings().value(self.settings_section + '/book name language')
|
||||
else:
|
||||
language_selection = language_selection.value
|
||||
try:
|
||||
language_selection = int(language_selection)
|
||||
except (ValueError, TypeError):
|
||||
language_selection = LanguageSelection.Application
|
||||
return language_selection
|
||||
|
||||
def verse_search(self, bible, second_bible, text):
|
||||
"""
|
||||
Does a verse search for the given bible and text.
|
||||
@ -363,6 +363,23 @@ class BibleManager(RegistryProperties):
|
||||
)
|
||||
return None
|
||||
|
||||
def get_verses_combined(self, bible, verse_text, book_ref_id=False, show_error=False):
|
||||
log.debug('BibleManager.get_verses("%s", "%s")', bible, verse_text)
|
||||
if not bible:
|
||||
if show_error:
|
||||
self.main_window.information_message(
|
||||
translate('BiblesPlugin.BibleManager', 'No Bibles Available'),
|
||||
translate('BiblesPlugin.BibleManager', 'There are no Bibles currently installed. Please use the '
|
||||
'Import Wizard to install one or more Bibles.')
|
||||
)
|
||||
return None
|
||||
language_selection = self.get_language_selection(bible)
|
||||
ref_list = parse_reference(verse_text, self.db_cache[bible], language_selection, book_ref_id)
|
||||
if ref_list:
|
||||
return self.db_cache[bible].get_verses(ref_list, show_error)
|
||||
else:
|
||||
return None
|
||||
|
||||
def save_meta_data(self, bible, version, copyright, permissions, book_name_language=None):
|
||||
"""
|
||||
Saves the bibles meta data.
|
||||
|
@ -45,7 +45,7 @@ class BibleSearch(object):
|
||||
"""
|
||||
Reference = 1
|
||||
Text = 2
|
||||
Quick = 3
|
||||
Combined = 3
|
||||
|
||||
|
||||
class BibleMediaItem(MediaManagerItem):
|
||||
@ -310,8 +310,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.plugin.manager.media = self
|
||||
self.load_bibles()
|
||||
self.quick_search_edit.set_search_types([
|
||||
(BibleSearch.Quick, ':/bibles/bibles_search_reference.png',
|
||||
translate('BiblesPlugin.MediaItem', 'Quick search'),
|
||||
(BibleSearch.Combined, ':/bibles/bibles_search_reference.png',
|
||||
translate('BiblesPlugin.MediaItem', 'Text or Scripture Reference'),
|
||||
translate('BiblesPlugin.MediaItem', 'Search Text or Scripture Reference...')),
|
||||
(BibleSearch.Reference, ':/bibles/bibles_search_reference.png',
|
||||
translate('BiblesPlugin.MediaItem', 'Scripture Reference'),
|
||||
@ -663,20 +663,14 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bible = self.quickVersionComboBox.currentText()
|
||||
second_bible = self.quickSecondComboBox.currentText()
|
||||
text = self.quick_search_edit.text()
|
||||
if self.quick_search_edit.current_search_type() == BibleSearch.Quick:
|
||||
if self.quick_search_edit.current_search_type() == BibleSearch.Reference:
|
||||
# We are doing a 'Reference Search'.
|
||||
self.search_results = self.plugin.manager.get_verses(bible, text)
|
||||
if second_bible and self.search_results:
|
||||
self.second_search_results = \
|
||||
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
||||
elif self.quick_search_edit.current_search_type() == BibleSearch.Reference:
|
||||
# We are doing a 'Reference Search'.
|
||||
self.search_results = self.plugin.manager.get_verses(bible, text)
|
||||
if second_bible and self.search_results:
|
||||
self.second_search_results = \
|
||||
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
||||
else:
|
||||
# We are doing a 'Text Search'.
|
||||
elif self.quick_search_edit.current_search_type() == BibleSearch.Text:
|
||||
# We are doing a 'Text Search'.
|
||||
self.application.set_busy_cursor()
|
||||
bibles = self.plugin.manager.get_bibles()
|
||||
self.search_results = self.plugin.manager.verse_search(bible, second_bible, text)
|
||||
@ -695,15 +689,53 @@ class BibleMediaItem(MediaManagerItem):
|
||||
continue
|
||||
new_search_results.append(verse)
|
||||
text.append((verse.book.book_reference_id, verse.chapter, verse.verse, verse.verse))
|
||||
if passage_not_found:
|
||||
QtWidgets.QMessageBox.information(
|
||||
if passage_not_found():
|
||||
# This function appears to be broken / Does nothing?
|
||||
QtGui.QMessageBox.information(
|
||||
self, translate('BiblesPlugin.MediaItem', 'Information'),
|
||||
translate('BiblesPlugin.MediaItem', 'The second Bible does not contain all the verses '
|
||||
'that are in the main Bible. Only verses found in both Bibles will be shown. %d '
|
||||
'verses have not been included in the results.') % count,
|
||||
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
||||
self.search_results = new_search_results
|
||||
self.second_search_results = bibles[second_bible].get_verses(text)
|
||||
elif self.quick_search_edit.current_search_type() == BibleSearch.Combined:
|
||||
# Combined search, starting with reference search
|
||||
self.search_results = self.plugin.manager.get_verses_combined(bible, text)
|
||||
if second_bible and self.search_results:
|
||||
self.second_search_results = \
|
||||
self.plugin.manager.get_verses(second_bible, text, self.search_results[0].book.book_reference_id)
|
||||
# Text search starts here if no reference was found
|
||||
if not self.search_results:
|
||||
self.application.set_busy_cursor()
|
||||
bibles = self.plugin.manager.get_bibles()
|
||||
self.search_results = self.plugin.manager.verse_search(bible, second_bible, text)
|
||||
if second_bible and self.search_results:
|
||||
text = []
|
||||
new_search_results = []
|
||||
count = 0
|
||||
passage_not_found = False
|
||||
for verse in self.search_results:
|
||||
db_book = bibles[second_bible].get_book_by_book_ref_id(verse.book.book_reference_id)
|
||||
if not db_book:
|
||||
log.debug('Passage "%s %d:%d" not found in Second Bible' %
|
||||
(verse.book.name, verse.chapter, verse.verse))
|
||||
passage_not_found = True
|
||||
count += 1
|
||||
continue
|
||||
new_search_results.append(verse)
|
||||
text.append((verse.book.book_reference_id, verse.chapter, verse.verse, verse.verse))
|
||||
if passage_not_found():
|
||||
# This function appears to be broken / Does nothing?
|
||||
QtGui.QMessageBox.information(
|
||||
self, translate('BiblesPlugin.MediaItem', 'Information'),
|
||||
translate('BiblesPlugin.MediaItem', 'The second Bible does not contain all the verses '
|
||||
'that are in the main Bible. Only verses found in both Bibles will be shown. %d '
|
||||
'verses have not been included in the results.') % count,
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
||||
self.search_results = new_search_results
|
||||
self.second_search_results = bibles[second_bible].get_verses(text)
|
||||
# Finalizing the search
|
||||
if not self.quickLockButton.isChecked():
|
||||
self.list_view.clear()
|
||||
if self.list_view.count() != 0 and self.search_results:
|
||||
|
@ -27,6 +27,7 @@
|
||||
<file>image_new_group.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="bibles">
|
||||
<file>bibles_search_combined.png</file>
|
||||
<file>bibles_search_text.png</file>
|
||||
<file>bibles_search_reference.png</file>
|
||||
<file>bibles_upgrade_alert.png</file>
|
||||
|
Loading…
Reference in New Issue
Block a user