forked from openlp/openlp
Bible fixes:
- Red letter text on CrossWalk import. - Removed text on web download progress, moved to an "indeterminable" progress style. - Some unicode optimisations. bzr-revno: 775
This commit is contained in:
commit
85d44554b0
@ -29,6 +29,8 @@ import logging
|
|||||||
import urllib2
|
import urllib2
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
import openlp
|
import openlp
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -124,16 +126,25 @@ def check_latest_version(config, current_version):
|
|||||||
log.exception(u'Reason for failure: %s', e.reason)
|
log.exception(u'Reason for failure: %s', e.reason)
|
||||||
return version_string
|
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):
|
def variant_to_unicode(variant):
|
||||||
"""
|
"""
|
||||||
Converts a QVariant to a unicode string.
|
Converts a QVariant to a Python unicode object.
|
||||||
|
|
||||||
``variant``
|
``variant``
|
||||||
The QVariant instance to convert to unicode.
|
The QVariant instance to convert to unicode.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(variant, QtCore.QVariant):
|
||||||
string = variant.toString()
|
string = variant.toString()
|
||||||
if not isinstance(string, unicode):
|
if not isinstance(string, unicode):
|
||||||
string = unicode(string, u'utf8')
|
string = string_to_unicode(string)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
from registry import Registry
|
from registry import Registry
|
||||||
|
@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
|
|
||||||
from bibleimportwizard import Ui_BibleImportWizard
|
from bibleimportwizard import Ui_BibleImportWizard
|
||||||
from openlp.core.lib import Receiver
|
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
|
from openlp.plugins.bibles.lib.manager import BibleFormat
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -425,3 +425,4 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
self.finishButton.setVisible(True)
|
self.finishButton.setVisible(True)
|
||||||
self.cancelButton.setVisible(False)
|
self.cancelButton.setVisible(False)
|
||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
|
|
||||||
|
@ -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))?)?',
|
r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?',
|
||||||
re.UNICODE)
|
re.UNICODE)
|
||||||
chapter_range = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*'
|
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)
|
re.UNICODE)
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -203,7 +203,9 @@ class BGExtract(BibleCommon):
|
|||||||
# Let's get the page, and then open it in BeautifulSoup, so as to
|
# Let's get the page, and then open it in BeautifulSoup, so as to
|
||||||
# attempt to make "easy" work of bad HTML.
|
# attempt to make "easy" work of bad HTML.
|
||||||
page = urllib2.urlopen(urlstring)
|
page = urllib2.urlopen(urlstring)
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
soup = BeautifulSoup(page)
|
soup = BeautifulSoup(page)
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
verses = soup.find(u'div', u'result-text-style-normal')
|
verses = soup.find(u'div', u'result-text-style-normal')
|
||||||
verse_number = 0
|
verse_number = 0
|
||||||
verse_list = {0: u''}
|
verse_list = {0: u''}
|
||||||
@ -211,6 +213,7 @@ class BGExtract(BibleCommon):
|
|||||||
# This is a PERFECT example of opening the Cthulu tag!
|
# This is a PERFECT example of opening the Cthulu tag!
|
||||||
# O Bible Gateway, why doth ye such horrific HTML produce?
|
# O Bible Gateway, why doth ye such horrific HTML produce?
|
||||||
for verse in verses:
|
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':
|
if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes':
|
||||||
break
|
break
|
||||||
if isinstance(verse, Tag) and verse.name == u'sup' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] != u'versenum':
|
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
|
continue
|
||||||
if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents:
|
if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents:
|
||||||
for item in 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'):
|
if isinstance(item, Tag) and (item.name == u'h4' or item.name == u'h5'):
|
||||||
continue
|
continue
|
||||||
if isinstance(item, Tag) and item.name == u'sup' and filter(lambda a: a[0] == u'class', item.attrs)[0][1] != u'versenum':
|
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
|
continue
|
||||||
if isinstance(item, Tag) and item.name == u'font':
|
if isinstance(item, Tag) and item.name == u'font':
|
||||||
for subitem in item.contents:
|
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':
|
if isinstance(subitem, Tag) and subitem.name == u'sup' and filter(lambda a: a[0] == u'class', subitem.attrs)[0][1] != u'versenum':
|
||||||
continue
|
continue
|
||||||
if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents:
|
if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents:
|
||||||
@ -289,27 +294,42 @@ class CWExtract(BibleCommon):
|
|||||||
(version, urlbookname.lower(), chapter)
|
(version, urlbookname.lower(), chapter)
|
||||||
log.debug(u'URL: %s', chapter_url)
|
log.debug(u'URL: %s', chapter_url)
|
||||||
page = urllib2.urlopen(chapter_url)
|
page = urllib2.urlopen(chapter_url)
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
if not page:
|
if not page:
|
||||||
return None
|
return None
|
||||||
soup = BeautifulSoup(page)
|
soup = BeautifulSoup(page)
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
htmlverses = soup.findAll(u'span', u'versetext')
|
htmlverses = soup.findAll(u'span', u'versetext')
|
||||||
verses = {}
|
verses = {}
|
||||||
reduce_spaces = re.compile(r'[ ]{2,}')
|
reduce_spaces = re.compile(r'[ ]{2,}')
|
||||||
|
fix_punctuation = re.compile(r'[ ]+([.,;])')
|
||||||
for verse in htmlverses:
|
for verse in htmlverses:
|
||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
versenumber = int(verse.contents[0].contents[0])
|
versenumber = int(verse.contents[0].contents[0])
|
||||||
versetext = u''
|
versetext = u''
|
||||||
for part in verse.contents:
|
for part in verse.contents:
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
if isinstance(part, NavigableString):
|
if isinstance(part, NavigableString):
|
||||||
versetext = versetext + part
|
versetext = versetext + part
|
||||||
elif part and part.attrMap and \
|
elif part and part.attrMap and \
|
||||||
(part.attrMap[u'class'] == u'WordsOfChrist' or \
|
(part.attrMap[u'class'] == u'WordsOfChrist' or \
|
||||||
part.attrMap[u'class'] == u'strongs'):
|
part.attrMap[u'class'] == u'strongs'):
|
||||||
for subpart in part.contents:
|
for subpart in part.contents:
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
if isinstance(subpart, NavigableString):
|
if isinstance(subpart, NavigableString):
|
||||||
versetext = versetext + subpart
|
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 = versetext.strip(u'\n\r\t ')
|
||||||
versetext = reduce_spaces.sub(u' ', versetext)
|
versetext = reduce_spaces.sub(u' ', versetext)
|
||||||
|
versetext = fix_punctuation.sub(r'\1', versetext)
|
||||||
verses[versenumber] = versetext
|
verses[versenumber] = versetext
|
||||||
return SearchResults(bookname, chapter, verses)
|
return SearchResults(bookname, chapter, verses)
|
||||||
|
|
||||||
@ -410,10 +430,12 @@ class HTTPBible(BibleDB):
|
|||||||
## we get a correct book. For example it is possible
|
## we get a correct book. For example it is possible
|
||||||
## to request ac and get Acts back.
|
## to request ac and get Acts back.
|
||||||
bookname = search_results.get_book()
|
bookname = search_results.get_book()
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
# check to see if book/chapter exists
|
# check to see if book/chapter exists
|
||||||
db_book = self.get_book(bookname)
|
db_book = self.get_book(bookname)
|
||||||
self.create_chapter(db_book.id, search_results.get_chapter(),
|
self.create_chapter(db_book.id, search_results.get_chapter(),
|
||||||
search_results.get_verselist())
|
search_results.get_verselist())
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
Receiver.send_message(u'bible_hideprogress')
|
Receiver.send_message(u'bible_hideprogress')
|
||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
return BibleDB.get_verses(self, reference_list)
|
return BibleDB.get_verses(self, reference_list)
|
||||||
|
@ -266,8 +266,9 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
MediaManagerItem.addListViewToToolBar(self)
|
MediaManagerItem.addListViewToToolBar(self)
|
||||||
# Progress Bar
|
# Progress Bar
|
||||||
self.SearchProgress = QtGui.QProgressBar(self)
|
self.SearchProgress = QtGui.QProgressBar(self)
|
||||||
self.SearchProgress.setFormat('%p%')
|
self.SearchProgress.setFormat('')
|
||||||
self.SearchProgress.setMaximum(3)
|
self.SearchProgress.setMinimum(0)
|
||||||
|
self.SearchProgress.setMaximum(0)
|
||||||
self.SearchProgress.setGeometry(self.ListView.geometry().left(),
|
self.SearchProgress.setGeometry(self.ListView.geometry().left(),
|
||||||
self.ListView.geometry().top(), 81, 23)
|
self.ListView.geometry().top(), 81, 23)
|
||||||
self.SearchProgress.setVisible(False)
|
self.SearchProgress.setVisible(False)
|
||||||
@ -351,9 +352,10 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
|
|
||||||
def onSearchProgressShow(self):
|
def onSearchProgressShow(self):
|
||||||
self.SearchProgress.setVisible(True)
|
self.SearchProgress.setVisible(True)
|
||||||
self.SearchProgress.setMinimum(0)
|
Receiver.send_message(u'process_events')
|
||||||
self.SearchProgress.setMaximum(2)
|
#self.SearchProgress.setMinimum(0)
|
||||||
self.SearchProgress.setValue(1)
|
#self.SearchProgress.setMaximum(2)
|
||||||
|
#self.SearchProgress.setValue(1)
|
||||||
|
|
||||||
def onSearchProgressHide(self):
|
def onSearchProgressHide(self):
|
||||||
self.SearchProgress.setVisible(False)
|
self.SearchProgress.setVisible(False)
|
||||||
|
Loading…
Reference in New Issue
Block a user