From 74752da6948f0350c305e7a2010851af6761f7b0 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 30 Sep 2010 20:40:10 +0200 Subject: [PATCH 1/4] implemented 'text search' for bibles --- openlp/plugins/bibles/lib/db.py | 8 ++++---- openlp/plugins/bibles/lib/manager.py | 22 +++++++++++++++++++++- openlp/plugins/bibles/lib/mediaitem.py | 20 +++++++++++++------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 49bc82102..ca7fcfda7 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -240,7 +240,7 @@ class BibleDB(QtCore.QObject, Manager): and the value is the verse text. """ log.debug(u'create_chapter %s,%s', book_id, chapter) - #text list has book and chapter as first two elements of the array + # text list has book and chapter as first two elements of the array for verse_number, verse_text in textlist.iteritems(): verse = Verse.populate( book_id = book_id, @@ -353,9 +353,9 @@ class BibleDB(QtCore.QObject, Manager): QtGui.QMessageBox.information(self.bible_plugin.mediaItem, translate('BiblesPlugin.BibleDB', 'Book not found'), translate('BiblesPlugin.BibleDB', 'The book you requested ' - 'could not be found in this bible. Please check your ' - 'spelling and that this is a complete bible not just ' - 'one testament.')) + 'could not be found in this bible. Please check your ' + 'spelling and that this is a complete bible not just ' + 'one testament.')) return verse_list def verse_search(self, text): diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index fd2c2adff..4a5869ca6 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -254,9 +254,29 @@ class BibleManager(object): 'Book Chapter:Verse-Verse\n' 'Book Chapter:Verse-Verse,Verse-Verse\n' 'Book Chapter:Verse-Verse,Chapter:Verse-Verse\n' - 'Book Chapter:Verse-Chapter:Verse\n')) + 'Book Chapter:Verse-Chapter:Verse')) return None + def verse_search(self, bible, text): + """ + ``bible`` + The bible to seach in. + + ``text`` + The text to search for. + """ + log.debug(u'BibleManager.verse_search("%s", "%s")', bible, text) + if text: + return self.db_cache[bible].verse_search(text) + else: + QtGui.QMessageBox.information(self.parent.mediaItem, + translate('BiblesPlugin.BibleManager', + 'Scripture Reference Error'), + translate('BiblesPlugin.BibleManager', 'Your scripture ' + 'reference is not valid. Make sure to state a keyword to search' + ' for. Keywords separated by a comma will be treated as OR.')) + return None + def save_meta_data(self, bible, version, copyright, permissions): """ Saves the bibles meta data diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 92eb200ee..fe0e7409c 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -535,10 +535,19 @@ class BibleMediaItem(MediaManagerItem): bible = unicode(self.QuickVersionComboBox.currentText()) dual_bible = unicode(self.QuickSecondBibleComboBox.currentText()) text = unicode(self.QuickSearchEdit.text()) - self.search_results = self.parent.manager.get_verses(bible, text) - if dual_bible: - self.dual_search_results = self.parent.manager.get_verses( - dual_bible, text) + if self.QuickSearchComboBox.currentIndex() == 0: # Verse Search + self.search_results = self.parent.manager.get_verses(bible, text) + if dual_bible: + self.dual_search_results = self.parent.manager.get_verses( + dual_bible, text) + else: # Text Search + self.search_results = self.parent.manager.verse_search(bible, text) + if dual_bible: + for count, verse in enumerate(self.search_results): + text = u'%s %s:%s' % (verse.book.name, verse.chapter, + verse.verse) + self.dual_search_results[count] = self.parent.manager.\ + get_verses(dual_bible, text)[0] if self.ClearQuickSearchComboBox.currentIndex() == 0: self.listView.clear() if self.listView.count() != 0 and self.search_results: @@ -702,19 +711,16 @@ class BibleMediaItem(MediaManagerItem): if bible_text: raw_slides.append(bible_text) bible_text = u'' - # Service Item: Capabilities if self.parent.settings_tab.layout_style == 2 and not dual_bible: # Split the line but do not replace line breaks in renderer. service_item.add_capability(ItemCapabilities.NoLineBreaks) service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsLoop) - # Service Item: Title for title in raw_title: if not service_item.title: service_item.title = title else: service_item.title += u', ' + title - # Service Item: Theme if len(self.parent.settings_tab.bible_theme) == 0: service_item.theme = None else: From e17f6c7c9ed37d1f1c580dd9ae02d02560836572 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 1 Oct 2010 15:50:29 +0200 Subject: [PATCH 2/4] -disable search buttons while searching, -clean ups --- openlp/plugins/bibles/lib/__init__.py | 2 +- openlp/plugins/bibles/lib/db.py | 26 +++++++++++++------------- openlp/plugins/bibles/lib/manager.py | 12 ++++++------ openlp/plugins/bibles/lib/mediaitem.py | 20 +++++++++++++++----- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 06f9d7cc7..e3f0d8f46 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -75,7 +75,7 @@ def parse_reference(reference): 7 None|[0-9]+|end None or the end of the second verse range. The reference list is a list of tuples, with each tuple structured like - this:: + this: (book, chapter, start_verse, end_verse) ``reference`` diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index ca7fcfda7..6f947cb87 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -281,23 +281,23 @@ class BibleDB(QtCore.QObject, Manager): def create_meta(self, key, value): """ - Utility method to save BibleMeta objects in a Bible database + Utility method to save BibleMeta objects in a Bible database. ``key`` - The key for this instance + The key for this instance. ``value`` - The value for this instance + The value for this instance. """ log.debug(u'save_meta %s/%s', key, value) self.save_object(BibleMeta.populate(key=key, value=value)) def get_book(self, book): """ - Return a book object from the database + Return a book object from the database. ``book`` - The name of the book to return + The name of the book to return. """ log.debug(u'BibleDb.get_book("%s")', book) db_book = self.get_object_filtered(Book, Book.name.like(book + u'%')) @@ -320,14 +320,14 @@ class BibleDB(QtCore.QObject, Manager): ``reference_list`` This is the list of references the media manager item wants. It is - a list of tuples, with the following format:: + a list of tuples, with the following format: (book, chapter, start_verse, end_verse) Therefore, when you are looking for multiple items, simply break them up into references like this, bundle them into a list. This function then runs through the list, and returns an amalgamated - list of ``Verse`` objects. For example:: + list of ``Verse`` objects. For example: [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] """ @@ -387,10 +387,10 @@ class BibleDB(QtCore.QObject, Manager): def get_chapter_count(self, book): """ - Return the number of chapters in a book + Return the number of chapters in a book. ``book`` - The book to get the chapter count for + The book to get the chapter count for. """ log.debug(u'BibleDB.get_chapter_count("%s")', book) count = self.session.query(Verse.chapter).join(Book)\ @@ -403,13 +403,13 @@ class BibleDB(QtCore.QObject, Manager): def get_verse_count(self, book, chapter): """ - Return the number of verses in a chapter + Return the number of verses in a chapter. ``book`` - The book containing the chapter + The book containing the chapter. ``chapter`` - The chapter to get the verse count for + The chapter to get the verse count for. """ log.debug(u'BibleDB.get_verse_count("%s", %s)', book, chapter) count = self.session.query(Verse).join(Book)\ @@ -423,7 +423,7 @@ class BibleDB(QtCore.QObject, Manager): def dump_bible(self): """ - Utility debugging method to dump the contents of a bible + Utility debugging method to dump the contents of a bible. """ log.debug(u'.........Dumping Bible Database') log.debug('...............................Books ') diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 4a5869ca6..78d8e770a 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -137,7 +137,7 @@ class BibleManager(object): name = bible.get_name() log.debug(u'Bible Name: "%s"', name) self.db_cache[name] = bible - # look to see if lazy load bible exists and get create getter. + # Look to see if lazy load bible exists and get create getter. source = self.db_cache[name].get_object(BibleMeta, u'download source') if source: @@ -204,7 +204,7 @@ class BibleManager(object): def get_chapter_count(self, bible, book): """ - Returns the number of Chapters for a given book + Returns the number of Chapters for a given book. """ log.debug(u'get_book_chapter_count %s', book) return self.db_cache[bible].get_chapter_count(book) @@ -212,7 +212,7 @@ class BibleManager(object): def get_verse_count(self, bible, book, chapter): """ Returns all the number of verses for a given - book and chapterMaxBibleBookVerses + book and chapterMaxBibleBookVerses. """ log.debug(u'BibleManager.get_verse_count("%s", "%s", %s)', bible, book, chapter) @@ -279,7 +279,7 @@ class BibleManager(object): def save_meta_data(self, bible, version, copyright, permissions): """ - Saves the bibles meta data + Saves the bibles meta data. """ log.debug(u'save_meta data %s,%s, %s,%s', bible, version, copyright, permissions) @@ -289,14 +289,14 @@ class BibleManager(object): def get_meta_data(self, bible, key): """ - Returns the meta data for a given key + Returns the meta data for a given key. """ log.debug(u'get_meta %s,%s', bible, key) return self.db_cache[bible].get_object(BibleMeta, key) def exists(self, name): """ - Check cache to see if new bible + Check cache to see if new bible. """ if not isinstance(name, unicode): name = unicode(name) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fe0e7409c..ab39665f8 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -497,6 +497,7 @@ class BibleMediaItem(MediaManagerItem): def onAdvancedSearchButton(self): log.debug(u'Advanced Search Button pressed') + self.AdvancedSearchButton.setEnabled(False) bible = unicode(self.AdvancedVersionComboBox.currentText()) dual_bible = unicode(self.AdvancedSecondBibleComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText()) @@ -529,9 +530,11 @@ class BibleMediaItem(MediaManagerItem): self.displayResults(bible, dual_bible) else: self.displayResults(bible, dual_bible) + self.AdvancedSearchButton.setEnabled(True) def onQuickSearchButton(self): log.debug(u'Quick Search Button pressed') + self.QuickSearchButton.setEnabled(False) bible = unicode(self.QuickVersionComboBox.currentText()) dual_bible = unicode(self.QuickSecondBibleComboBox.currentText()) text = unicode(self.QuickSearchEdit.text()) @@ -543,11 +546,17 @@ class BibleMediaItem(MediaManagerItem): else: # Text Search self.search_results = self.parent.manager.verse_search(bible, text) if dual_bible: - for count, verse in enumerate(self.search_results): - text = u'%s %s:%s' % (verse.book.name, verse.chapter, - verse.verse) - self.dual_search_results[count] = self.parent.manager.\ - get_verses(dual_bible, text)[0] + text = [] + for verse in self.search_results: + text.append((verse.book.name, verse.chapter, verse.verse, + verse.verse)) + self.dual_search_results = self.parent.manager.get_verses( + dual_bible, text) +# for count, verse in enumerate(self.search_results): +# text = u'%s %s:%s' % (verse.book.name, verse.chapter, +# verse.verse) +# self.dual_search_results[count] = self.parent.manager.\ +# get_verses(dual_bible, text)[0] if self.ClearQuickSearchComboBox.currentIndex() == 0: self.listView.clear() if self.listView.count() != 0 and self.search_results: @@ -567,6 +576,7 @@ class BibleMediaItem(MediaManagerItem): self.displayResults(bible, dual_bible) elif self.search_results: self.displayResults(bible, dual_bible) + self.QuickSearchButton.setEnabled(True) def displayResults(self, bible, dual_bible=u''): """ From 919b07bd61f07d5569f05154f58234c2cb0c2e4f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 1 Oct 2010 16:18:15 +0200 Subject: [PATCH 3/4] clean ups --- openlp/plugins/bibles/lib/db.py | 6 +++--- openlp/plugins/bibles/lib/http.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 6f947cb87..60b9a8836 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2010 Raoul Snyman # +# Copyright (c) 2008-2010 Raoul Snyman + # # Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # # Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # # Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # @@ -64,10 +64,10 @@ class Verse(BaseModel): def init_schema(url): """ - Setup a bible database connection and initialise the database schema + Setup a bible database connection and initialise the database schema. ``url`` - The database to setup + The database to setup. """ session, metadata = init_db(url) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 415a0cde5..8abb3e62f 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -187,16 +187,16 @@ class BGExtract(object): def get_bible_chapter(self, version, bookname, chapter): """ - Access and decode bibles via the BibleGateway website + Access and decode bibles via the BibleGateway website. ``version`` - The version of the bible like 31 for New International version + The version of the bible like 31 for New International version. ``bookname`` - Name of the Book + Name of the Book. ``chapter`` - Chapter number + Chapter number. """ log.debug(u'get_bible_chapter %s, %s, %s', version, bookname, chapter) url_params = urllib.urlencode( @@ -298,13 +298,13 @@ class CWExtract(object): versetext = versetext + part elif part and part.attrMap and \ (part.attrMap[u'class'] == u'WordsOfChrist' or \ - part.attrMap[u'class'] == u'strongs'): + part.attrMap[u'class'] == u'strongs'): for subpart in part.contents: Receiver.send_message(u'openlp_process_events') if isinstance(subpart, NavigableString): versetext = versetext + subpart elif subpart and subpart.attrMap and \ - subpart.attrMap[u'class'] == u'strongs': + subpart.attrMap[u'class'] == u'strongs': for subsub in subpart.contents: Receiver.send_message(u'openlp_process_events') if isinstance(subsub, NavigableString): @@ -382,14 +382,14 @@ class HTTPBible(BibleDB): ``reference_list`` This is the list of references the media manager item wants. It is - a list of tuples, with the following format:: + a list of tuples, with the following format: (book, chapter, start_verse, end_verse) Therefore, when you are looking for multiple items, simply break them up into references like this, bundle them into a list. This function then runs through the list, and returns an amalgamated - list of ``Verse`` objects. For example:: + list of ``Verse`` objects. For example: [(u'Genesis', 1, 1, 1), (u'Genesis', 2, 2, 3)] """ @@ -428,7 +428,7 @@ class HTTPBible(BibleDB): def get_chapter(self, book, chapter): """ - Receive the request and call the relevant handler methods + Receive the request and call the relevant handler methods. """ log.debug(u'get_chapter %s, %s', book, chapter) log.debug(u'source = %s', self.download_source) From f8ed4acf78fa6168008762525f229f8119bfb0df Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 1 Oct 2010 16:37:51 +0200 Subject: [PATCH 4/4] clean ups --- openlp/plugins/bibles/lib/mediaitem.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index ab39665f8..94519ba88 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -540,23 +540,23 @@ class BibleMediaItem(MediaManagerItem): text = unicode(self.QuickSearchEdit.text()) if self.QuickSearchComboBox.currentIndex() == 0: # Verse Search self.search_results = self.parent.manager.get_verses(bible, text) - if dual_bible: + if dual_bible and self.search_results: self.dual_search_results = self.parent.manager.get_verses( dual_bible, text) else: # Text Search self.search_results = self.parent.manager.verse_search(bible, text) - if dual_bible: - text = [] - for verse in self.search_results: - text.append((verse.book.name, verse.chapter, verse.verse, - verse.verse)) - self.dual_search_results = self.parent.manager.get_verses( - dual_bible, text) -# for count, verse in enumerate(self.search_results): -# text = u'%s %s:%s' % (verse.book.name, verse.chapter, -# verse.verse) -# self.dual_search_results[count] = self.parent.manager.\ -# get_verses(dual_bible, text)[0] + if dual_bible and self.search_results: +# text = [] +# for verse in self.search_results: +# text.append((verse.book.name, verse.chapter, verse.verse, +# verse.verse)) +# self.dual_search_results = self.parent.manager.get_verses( +# dual_bible, text) + for count, verse in enumerate(self.search_results): + text = u'%s %s:%s' % (verse.book.name, verse.chapter, + verse.verse) + self.dual_search_results[count] = self.parent.manager.\ + get_verses(dual_bible, text)[0] if self.ClearQuickSearchComboBox.currentIndex() == 0: self.listView.clear() if self.listView.count() != 0 and self.search_results: