diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index a64b0c06b..67bdf4778 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -29,6 +29,8 @@ import logging import urllib2 from datetime import datetime +from PyQt4 import QtCore + import openlp log = logging.getLogger(__name__) @@ -123,16 +125,25 @@ def check_latest_version(config, current_version): log.exception(u'Reason for failure: %s', e.reason) return version_string +def string_to_unicode(string): + """ + Converts a QString to a Python unicode object. + """ + if isinstance(string, QtCore.QString): + string = unicode(string.toUtf8(), u'utf8') + return string + def variant_to_unicode(variant): """ - Converts a QVariant to a unicode string. + Converts a QVariant to a Python unicode object. ``variant`` The QVariant instance to convert to unicode. """ - string = variant.toString() + if isinstance(variant, QtCore.QVariant): + string = variant.toString() if not isinstance(string, unicode): - string = unicode(string, u'utf8') + string = string_to_unicode(string) return string from registry import Registry diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index a717a4f44..a803b7481 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui from bibleimportwizard import Ui_BibleImportWizard from openlp.core.lib import Receiver -from openlp.core.utils import AppLocation, variant_to_unicode +from openlp.core.utils import AppLocation, variant_to_unicode, string_to_unicode from openlp.plugins.bibles.lib.manager import BibleFormat log = logging.getLogger(__name__) @@ -425,3 +425,4 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.finishButton.setVisible(True) self.cancelButton.setVisible(False) Receiver.send_message(u'process_events') + diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index eef9b4dc3..48e55cb7e 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -33,7 +33,7 @@ only_verses = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)' r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?', re.UNICODE) chapter_range = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*' - r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)', + r'([0-9]+|end)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+|end)', re.UNICODE) log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 2c3e433f6..b14f9b3a2 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -203,7 +203,9 @@ class BGExtract(BibleCommon): # Let's get the page, and then open it in BeautifulSoup, so as to # attempt to make "easy" work of bad HTML. page = urllib2.urlopen(urlstring) + Receiver.send_message(u'process_events') soup = BeautifulSoup(page) + Receiver.send_message(u'process_events') verses = soup.find(u'div', u'result-text-style-normal') verse_number = 0 verse_list = {0: u''} @@ -211,6 +213,7 @@ class BGExtract(BibleCommon): # This is a PERFECT example of opening the Cthulu tag! # O Bible Gateway, why doth ye such horrific HTML produce? for verse in verses: + Receiver.send_message(u'process_events') if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes': break if isinstance(verse, Tag) and verse.name == u'sup' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] != u'versenum': @@ -219,6 +222,7 @@ class BGExtract(BibleCommon): continue if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents: for item in verse.contents: + Receiver.send_message(u'process_events') if isinstance(item, Tag) and (item.name == u'h4' or item.name == u'h5'): continue if isinstance(item, Tag) and item.name == u'sup' and filter(lambda a: a[0] == u'class', item.attrs)[0][1] != u'versenum': @@ -231,6 +235,7 @@ class BGExtract(BibleCommon): continue if isinstance(item, Tag) and item.name == u'font': for subitem in item.contents: + Receiver.send_message(u'process_events') if isinstance(subitem, Tag) and subitem.name == u'sup' and filter(lambda a: a[0] == u'class', subitem.attrs)[0][1] != u'versenum': continue if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents: @@ -289,27 +294,42 @@ class CWExtract(BibleCommon): (version, urlbookname.lower(), chapter) log.debug(u'URL: %s', chapter_url) page = urllib2.urlopen(chapter_url) + Receiver.send_message(u'process_events') if not page: return None soup = BeautifulSoup(page) + Receiver.send_message(u'process_events') htmlverses = soup.findAll(u'span', u'versetext') verses = {} reduce_spaces = re.compile(r'[ ]{2,}') + fix_punctuation = re.compile(r'[ ]+([.,;])') for verse in htmlverses: Receiver.send_message(u'process_events') versenumber = int(verse.contents[0].contents[0]) versetext = u'' for part in verse.contents: + Receiver.send_message(u'process_events') if isinstance(part, NavigableString): versetext = versetext + part elif part and part.attrMap and \ (part.attrMap[u'class'] == u'WordsOfChrist' or \ part.attrMap[u'class'] == u'strongs'): for subpart in part.contents: + Receiver.send_message(u'process_events') if isinstance(subpart, NavigableString): versetext = versetext + subpart + elif subpart and subpart.attrMap and \ + subpart.attrMap[u'class'] == u'strongs': + for subsub in subpart.contents: + Receiver.send_message(u'process_events') + if isinstance(subsub, NavigableString): + versetext = versetext + subsub + Receiver.send_message(u'process_events') + # Fix up leading and trailing spaces, multiple spaces, and spaces + # between text and , and . versetext = versetext.strip(u'\n\r\t ') versetext = reduce_spaces.sub(u' ', versetext) + versetext = fix_punctuation.sub(r'\1', versetext) verses[versenumber] = versetext return SearchResults(bookname, chapter, verses) @@ -410,10 +430,12 @@ class HTTPBible(BibleDB): ## we get a correct book. For example it is possible ## to request ac and get Acts back. bookname = search_results.get_book() + Receiver.send_message(u'process_events') # check to see if book/chapter exists db_book = self.get_book(bookname) self.create_chapter(db_book.id, search_results.get_chapter(), search_results.get_verselist()) + Receiver.send_message(u'process_events') Receiver.send_message(u'bible_hideprogress') Receiver.send_message(u'process_events') return BibleDB.get_verses(self, reference_list) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 3bcc0b426..cf17a4e12 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -266,8 +266,9 @@ class BibleMediaItem(MediaManagerItem): MediaManagerItem.addListViewToToolBar(self) # Progress Bar self.SearchProgress = QtGui.QProgressBar(self) - self.SearchProgress.setFormat('%p%') - self.SearchProgress.setMaximum(3) + self.SearchProgress.setFormat('') + self.SearchProgress.setMinimum(0) + self.SearchProgress.setMaximum(0) self.SearchProgress.setGeometry(self.ListView.geometry().left(), self.ListView.geometry().top(), 81, 23) self.SearchProgress.setVisible(False) @@ -351,9 +352,10 @@ class BibleMediaItem(MediaManagerItem): def onSearchProgressShow(self): self.SearchProgress.setVisible(True) - self.SearchProgress.setMinimum(0) - self.SearchProgress.setMaximum(2) - self.SearchProgress.setValue(1) + Receiver.send_message(u'process_events') + #self.SearchProgress.setMinimum(0) + #self.SearchProgress.setMaximum(2) + #self.SearchProgress.setValue(1) def onSearchProgressHide(self): self.SearchProgress.setVisible(False)