From 34231003ce292b9e64102636a286439aa1c03193 Mon Sep 17 00:00:00 2001 From: suutari-olli Date: Sat, 9 Apr 2016 17:43:02 +0300 Subject: [PATCH] Noticed "No bibles available" was defined 3 times > Moved it to uistrings. Added "Must have bibles" condition for other error messages in combined search. To do: Add a setting for controlling visibility of the no results error, it may be of annoyance. Tests... --- openlp/core/common/uistrings.py | 28 +++++++++++++++++--------- openlp/plugins/bibles/lib/manager.py | 25 +++++++++-------------- openlp/plugins/bibles/lib/mediaitem.py | 7 +++++-- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/openlp/core/common/uistrings.py b/openlp/core/common/uistrings.py index 96cfb90a8..85a3fc1fc 100644 --- a/openlp/core/common/uistrings.py +++ b/openlp/core/common/uistrings.py @@ -23,6 +23,7 @@ The :mod:`uistrings` module provides standard strings for OpenLP. """ import logging +import itertools from openlp.core.common import translate @@ -151,23 +152,28 @@ class UiStrings(object): self.Version = translate('OpenLP.Ui', 'Version') self.View = translate('OpenLP.Ui', 'View') self.ViewMode = translate('OpenLP.Ui', 'View Mode') + # Translations used in both, bibles\lib\mediaitem.py and bibles\lib\manager.py self.BibleShortSearchTitle = translate('OpenLP.Ui', 'Search is Empty or too Short') self.BibleShortSearch = translate('OpenLP.Ui', 'The search you have entered is empty or shorter ' 'than 3 characters long.
Please try again with ' 'a longer search.


You 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.') - import itertools - #b = book, c = chapter, ve = verse - bc = translate('OpenLP.Ui', 'Book Chapter') - cha = translate('OpenLP.Ui', 'Chapter') - ver = translate('OpenLP.Ui', 'Verse') + self.BibleNoBiblesTitle = translate('OpenLP.Ui', 'No Bibles Available') + self.BibleNoBibles = translate('OpenLP.Ui', 'There are no Bibles currently installed.

' + 'Please use the Import Wizard to install one or more Bibles.') + # Scripture reference error combined from small translation stings by using itertools. + book_chapter = translate('OpenLP.Ui', 'Book Chapter') + bc = book_chapter + chapter = translate('OpenLP.Ui', 'Chapter') + cha = chapter + verse = translate('OpenLP.Ui', 'Verse') + ver = verse interval = ' | ' psalm = translate('OpenLP.Ui', 'Psalm') may_shorten = translate('OpenLP.Ui', 'Book names may be shortened from full names, for an example Ps 23 = ' 'Psalm 23') - - bible_items = [bc, interval, psalm, ' 23
', + bible_scripture_items = [bc, interval, psalm, ' 23
', bc, '%(range)s', cha, interval, psalm, ' 23%(range)s24
', bc, '%(verse)s', ver, '%(range)s', ver, interval, psalm, ' 23%(verse)s1%(range)s2
', bc, '%(verse)s', ver, '%(range)s', ver, '%(list)s', ver, '%(range)s', ver, interval, psalm, @@ -176,6 +182,8 @@ class UiStrings(object): interval, psalm, ' 23%(verse)s1%(range)s2%(list)s24%(verse)s1%(range)s3
', bc, '%(verse)s', ver, '%(range)s', cha, '%(verse)s', ver, interval, psalm, ' 23%(verse)s1%(range)s24%(verse)s1

', may_shorten] - itertools.chain.from_iterable(itertools.repeat(x, 1) if isinstance(x, str) else x for x in bible_items) - bible_scripture_error_all = ''.join(str(e) for e in bible_items) - self.BibleScriptureError = bible_scripture_error_all + itertools.chain.from_iterable(itertools.repeat(strings, 1) if isinstance(strings, str) else strings for strings + in bible_scripture_items) + bible_scripture_error_joined = ''.join(str(joined) for joined in bible_scripture_items) + # This is the actual + self.BibleScriptureError = bible_scripture_error_joined diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 3b884ba69..500a5c57d 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -262,10 +262,8 @@ class BibleManager(RegistryProperties): 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.') - ) + ('%s' % UiStrings().BibleNoBiblesTitle), + ('%s' % UiStrings().BibleNoBibles)) return None language_selection = self.get_language_selection(bible) ref_list = parse_reference(verse_text, self.db_cache[bible], language_selection, book_ref_id) @@ -316,11 +314,8 @@ class BibleManager(RegistryProperties): log.debug('BibleManager.verse_search("%s", "%s")', bible, text) if not bible: 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.') - ) + ('%s' % UiStrings().BibleNoBiblesTitle), + ('%s' % UiStrings().BibleNoBibles)) return None # Check if the bible or second_bible is a web bible. web_bible = self.db_cache[bible].get_object(BibleMeta, 'download_source') @@ -345,15 +340,15 @@ class BibleManager(RegistryProperties): else: return None - def get_verses_combined(self, bible, verse_text, book_ref_id=False, show_error=False): + def get_verses_combined(self, bible, verse_text, book_ref_id=False, show_error=True): 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.') - ) + if not bible: + self.main_window.information_message( + ('%s' % UiStrings().BibleNoBiblesTitle), + ('%s' % UiStrings().BibleNoBibles)) + return None return None language_selection = self.get_language_selection(bible) ref_list = parse_reference(verse_text, self.db_cache[bible], language_selection, book_ref_id) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fc970bdbf..e30b0ec40 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -660,8 +660,10 @@ class BibleMediaItem(MediaManagerItem): # This will check if field has any '.' and removes them. Eg. Gen. 1 = Gen 1 = Genesis 1 text_direct = self.quick_search_edit.text() text = text_direct.replace('. ', ' ') + # If we are doing "Reference" search, use the search from manager.py if self.quick_search_edit.current_search_type() == BibleSearch.Reference: self.search_results = self.plugin.manager.get_verses(bible, text) + # If we are doing "Combined Reference" search, use the get_verses_combined from manager.py (No error included) else: self.search_results = self.plugin.manager.get_verses_combined(bible, text) if second_bible and self.search_results: @@ -724,13 +726,14 @@ class BibleMediaItem(MediaManagerItem): # If keyword is shorter than 3 (not including spaces), message is given and search is finalized. # It's actually to find verses with less than 3 chars (Eg. G1 = Genesis 1) thus this error is not shown if # any results are found. This check needs to be here in order to avoid duplicate errors. - if not self.search_results and len(text) - text.count(' ') < 3: + # if no Bibles are installed, this message is not shown - "No bibles" message is whon instead. (and bible) + if not self.search_results and len(text) - text.count(' ') < 3 and bible: self.main_window.information_message( ('%s' % UiStrings().BibleShortSearchTitle), ('%s' % UiStrings().BibleShortSearch)) # 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 not self.search_results and len(text) - text.count(' ') > 2: + if not self.search_results and len(text) - text.count(' ') > 2 and bible: self.on_quick_text_search() # If no Text or Reference is found, message is given. if not self.search_results: