From b1223927a011766788ed6807a20690fdfcba85f7 Mon Sep 17 00:00:00 2001 From: suutari-olli Date: Sun, 6 Mar 2016 22:35:05 +0200 Subject: [PATCH] - 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" --- openlp/plugins/bibles/lib/manager.py | 57 ++++++++++++++--------- openlp/plugins/bibles/lib/mediaitem.py | 62 +++++++++++++++++++------- resources/images/openlp-2.qrc | 1 + 3 files changed, 85 insertions(+), 35 deletions(-) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 34662ef83..090bb4c79 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -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. diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 683337644..a2ea681d7 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -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: diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index 82c6234aa..d47e5a1ca 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -27,6 +27,7 @@ image_new_group.png + bibles_search_combined.png bibles_search_text.png bibles_search_reference.png bibles_upgrade_alert.png