From 3c70500c23aef9b02735559946ff6181fb885b5d Mon Sep 17 00:00:00 2001 From: suutari-olli Date: Mon, 7 Mar 2016 08:03:41 +0200 Subject: [PATCH] Fixes in this commit: - Fix for some dual triggering errors. - Searches with only spaces now trigger error since they make OLP unresponsive and may crash - Removed old "Empty" search message, integrated it to the new one. - Added some comments - Remodelled/Added nice error messages + needed code to support it - Fixed the issue where Bible book name prediction comes for pure Text search. - Fixed "No passage found" in 2nd bible by using self.main_window.information_message To DO: - If web bible is enabled combined text search triggers double error, fix it. - Pack the new icon - Double check spelling etc... - Write tests --- openlp/plugins/bibles/lib/manager.py | 34 ++++++----- openlp/plugins/bibles/lib/mediaitem.py | 79 +++++++++++++++++++------- 2 files changed, 74 insertions(+), 39 deletions(-) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index dec0011e4..1f10ee322 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -282,14 +282,17 @@ class BibleManager(RegistryProperties): translate('BiblesPlugin.BibleManager', 'Your scripture reference is either not supported by ' 'OpenLP or is invalid. Please make sure your reference ' 'conforms to one of the following patterns or consult the manual:\n\n' - 'Book Chapter\n' - 'Book Chapter%(range)sChapter\n' - 'Book Chapter%(verse)sVerse%(range)sVerse\n' + 'Book Chapter | John 3:16\n' + 'Book Chapter%(range)sChapter | John 3%(range)s4\n' + 'Book Chapter%(verse)sVerse%(range)sVerse | John 3%(verse)s16%(range)s17\n' 'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse' - '%(range)sVerse\n' + '%(range)sVerse | John 3%(verse)s16-17%(list)s20%(range)s22\n' 'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter' - '%(verse)sVerse%(range)sVerse\n' - 'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse', + '%(verse)sVerse%(range)sVerse | John 3%(verse)s16%(range)s17%' + '(list)s5%(verse)s7%(range)s9\n' + 'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse' + ' | John 3%(verse)s16%(range)s4%(verse)s2\n\n' + 'Book names may be shortened from full names but must not contain any additional dots.', 'Please pay attention to the appended "s" of the wildcards ' 'and refrain from translating the words inside the names in the brackets.') % reference_separators @@ -344,23 +347,18 @@ class BibleManager(RegistryProperties): translate('BiblesPlugin.BibleManager', 'Text Search is not available with Web Bibles.') ) return None - - if not len(text) == 0 and len(text) < 3: + if len(text) < 3 or str.isspace(text): self.main_window.information_message( translate('BiblesPlugin.BibleManager', 'Keyword is too short'), - translate('BiblesPlugin.BibleManager', 'The keyword you have entered is shorter ' - 'than 3 characters long.\nPlease try again with ' - 'a longer keyword.') - ) + translate('BiblesPlugin.BibleManager', 'The keyword you have entered is empty or shorter ' + 'than 3 characters long. Please try again with ' + 'a longer keyword.\n \nYou can separate different keywords by ' + ' a space to search for all of your keywords and you can ' + 'separate them by a comma to search for one of them.')) + return None elif text: return self.db_cache[bible].verse_search(text) else: - self.main_window.information_message( - translate('BiblesPlugin.BibleManager', 'Scripture Reference Error'), - translate('BiblesPlugin.BibleManager', 'You did not enter a search keyword.\nYou can separate ' - 'different keywords by a space to search for all of your keywords and you can separate ' - 'them by a comma to search for one of them.') - ) return None def get_verses_combined(self, bible, verse_text, book_ref_id=False, show_error=False): diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 166966579..1a7a172f6 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -436,7 +436,7 @@ class BibleMediaItem(MediaManagerItem): Settings().setValue(self.settings_section + '/quick bible', self.quickVersionComboBox.currentText()) books = [] # We have to do a 'Reference Search' (Or as part of Combined Search). - if self.quick_search_edit.current_search_type() == BibleSearch.Reference or BibleSearch.Combined: + if self.quick_search_edit.current_search_type() is not BibleSearch.Text: bibles = self.plugin.manager.get_bibles() bible = self.quickVersionComboBox.currentText() if bible: @@ -689,24 +689,42 @@ 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(): - # This function appears to be broken / Does nothing? - QtGui.QMessageBox.information( - self, translate('BiblesPlugin.MediaItem', 'Information'), + if passage_not_found: + self.main_window.information_message( + 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)) + 'verses have not been included in the results.') % count) self.search_results = new_search_results self.second_search_results = bibles[second_bible].get_verses(text) + # Combined search, starting with reference search (combined) elif self.quick_search_edit.current_search_type() == BibleSearch.Combined: - # Combined search, starting with reference search (combined) 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: + # If keyword is shorter than 3, message is given and search is finalized. + if len(text) < 3 or str.isspace(text): + self.main_window.information_message( + translate('BiblesPlugin.BibleManager', 'Search is Empty or too Short'), + translate('BiblesPlugin.BibleManager', 'The Search you have entered is empty or shorter ' + 'than 3 characters long. Please try again with ' + 'a longer keyword.\n \nYou can separate different keywords ' + 'by a space to search for all of your keywords and you can ' + 'separate them by a comma to search for one of them.')) + if not self.quickLockButton.isChecked(): + self.list_view.clear() + if self.list_view.count() != 0 and self.search_results: + self.__check_second_bible(bible, second_bible) + elif self.search_results: + self.display_results(bible, second_bible) + self.quickSearchButton.setEnabled(True) + self.check_search_result() + self.application.set_normal_cursor() + # Text search starts here if no reference was found and keyword is longer than 2. + # This is required in order to avoid duplicate error messages for short keywords. + # If only spaces are searched OLP becomes unresponsive and may crash eventually. "isspace" prevents this. + if not self.search_results and len(text) > 2 and not str.isspace(text): self.application.set_busy_cursor() bibles = self.plugin.manager.get_bibles() self.search_results = self.plugin.manager.verse_search(bible, second_bible, text) @@ -725,23 +743,42 @@ 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(): - # This function appears to be broken / Does nothing? - QtGui.QMessageBox.information( - self, translate('BiblesPlugin.MediaItem', 'Information'), + if passage_not_found: + self.main_window.information_message( + 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)) + 'verses have not been included in the results.') % count) self.search_results = new_search_results self.second_search_results = bibles[second_bible].get_verses(text) # If no Text or Reference is found, message is given. if not self.search_results: - self.main_window.information_message( - translate('BiblesPlugin.BibleManager', 'Scripture Reference Errorhhh'), - translate('BiblesPlugin.BibleManager', 'You did not enter a search ' - 'different keywords by a space to search for all of your ' - 'them by a comma to search for one of them.')) + reference_separators = { + 'verse': get_reference_separator('sep_v_display'), + 'range': get_reference_separator('sep_r_display'), + 'list': get_reference_separator('sep_l_display')} + self.main_window.information_message( + translate('BiblesPlugin.BibleManager', 'Nothing found'), + translate('BiblesPlugin.BibleManager', 'OpenLP couldn’t find ' + 'anything with your search.

' + 'If you tried to search with Scripture Reference, please make sure that your ' + 'reference follows one of the following patterns:

' + 'Book Chapter | John 3:16
' + 'Book Chapter%(range)sChapter | John 3%(range)s4
' + 'Book Chapter%(verse)sVerse%(range)sVerse | John 3%(verse)s16%(range)s17
' + 'Book Chapter%(verse)sVerse%(range)sVerse%(list)sVerse' + '%(range)sVerse | John 3%(verse)s16-17%(list)s20%(range)s22
' + 'Book Chapter%(verse)sVerse%(range)sVerse%(list)sChapter' + '%(verse)sVerse%(range)sVerse | John 3%(verse)s16%(range)s17%' + '(list)s5%(verse)s7%(range)s9
' + 'Book Chapter%(verse)sVerse%(range)sChapter%(verse)sVerse' + ' | John 3%(verse)s16%(range)s4%(verse)s2

' + 'Book names may be shortened from full names but' + ' must not contain any additional dots.', + 'Please pay attention to the appended "s" of the wildcards ' + 'and refrain from translating the words inside the names in the brackets.') + % reference_separators + ) # Finalizing the search if not self.quickLockButton.isChecked(): self.list_view.clear()