Merge lp:~raoul-snyman/openlp/biblefixes into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Approved by: Raoul Snyman
Approved revision: 773
Merged at revision: not available
Proposed branch: lp:~raoul-snyman/openlp/biblefixes
Merge into: lp:openlp
Diff against target: 196 lines (+46/-10)
5 files modified
openlp/core/utils/__init__.py (+14/-3)
openlp/plugins/bibles/forms/importwizardform.py (+2/-1)
openlp/plugins/bibles/lib/common.py (+1/-1)
openlp/plugins/bibles/lib/http.py (+22/-0)
openlp/plugins/bibles/lib/mediaitem.py (+7/-5)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/biblefixes
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+22305@code.launchpad.net

Description of the change

Bible fixes:
 - Red letter text on CrossWalk import.
 - Removed text on web download progress, moved to an "indeterminable" progress style.
 - Some unicode optimisations.

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/utils/__init__.py'
2--- openlp/core/utils/__init__.py 2010-03-27 12:37:21 +0000
3+++ openlp/core/utils/__init__.py 2010-03-27 20:12:20 +0000
4@@ -29,6 +29,8 @@
5 import urllib2
6 from datetime import datetime
7
8+from PyQt4 import QtCore
9+
10 import openlp
11
12 log = logging.getLogger(__name__)
13@@ -124,16 +126,25 @@
14 log.exception(u'Reason for failure: %s', e.reason)
15 return version_string
16
17+def string_to_unicode(string):
18+ """
19+ Converts a QString to a Python unicode object.
20+ """
21+ if isinstance(string, QtCore.QString):
22+ string = unicode(string.toUtf8(), u'utf8')
23+ return string
24+
25 def variant_to_unicode(variant):
26 """
27- Converts a QVariant to a unicode string.
28+ Converts a QVariant to a Python unicode object.
29
30 ``variant``
31 The QVariant instance to convert to unicode.
32 """
33- string = variant.toString()
34+ if isinstance(variant, QtCore.QVariant):
35+ string = variant.toString()
36 if not isinstance(string, unicode):
37- string = unicode(string, u'utf8')
38+ string = string_to_unicode(string)
39 return string
40
41 from registry import Registry
42
43=== modified file 'openlp/plugins/bibles/forms/importwizardform.py'
44--- openlp/plugins/bibles/forms/importwizardform.py 2010-03-24 21:18:36 +0000
45+++ openlp/plugins/bibles/forms/importwizardform.py 2010-03-27 20:12:20 +0000
46@@ -32,7 +32,7 @@
47
48 from bibleimportwizard import Ui_BibleImportWizard
49 from openlp.core.lib import Receiver
50-from openlp.core.utils import AppLocation, variant_to_unicode
51+from openlp.core.utils import AppLocation, variant_to_unicode, string_to_unicode
52 from openlp.plugins.bibles.lib.manager import BibleFormat
53
54 log = logging.getLogger(__name__)
55@@ -425,3 +425,4 @@
56 self.finishButton.setVisible(True)
57 self.cancelButton.setVisible(False)
58 Receiver.send_message(u'process_events')
59+
60
61=== modified file 'openlp/plugins/bibles/lib/common.py'
62--- openlp/plugins/bibles/lib/common.py 2010-03-21 23:58:01 +0000
63+++ openlp/plugins/bibles/lib/common.py 2010-03-27 20:12:20 +0000
64@@ -33,7 +33,7 @@
65 r'(?:[ ]*-[ ]*([0-9]+|end))?(?:[ ]*,[ ]*([0-9]+)(?:[ ]*-[ ]*([0-9]+|end))?)?',
66 re.UNICODE)
67 chapter_range = re.compile(r'([\w .]+)[ ]+([0-9]+)[ ]*[:|v|V][ ]*'
68- r'([0-9]+)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+)',
69+ r'([0-9]+|end)[ ]*-[ ]*([0-9]+)[ ]*[:|v|V][ ]*([0-9]+|end)',
70 re.UNICODE)
71
72 log = logging.getLogger(__name__)
73
74=== modified file 'openlp/plugins/bibles/lib/http.py'
75--- openlp/plugins/bibles/lib/http.py 2010-03-26 20:50:55 +0000
76+++ openlp/plugins/bibles/lib/http.py 2010-03-27 20:12:20 +0000
77@@ -203,7 +203,9 @@
78 # Let's get the page, and then open it in BeautifulSoup, so as to
79 # attempt to make "easy" work of bad HTML.
80 page = urllib2.urlopen(urlstring)
81+ Receiver.send_message(u'process_events')
82 soup = BeautifulSoup(page)
83+ Receiver.send_message(u'process_events')
84 verses = soup.find(u'div', u'result-text-style-normal')
85 verse_number = 0
86 verse_list = {0: u''}
87@@ -211,6 +213,7 @@
88 # This is a PERFECT example of opening the Cthulu tag!
89 # O Bible Gateway, why doth ye such horrific HTML produce?
90 for verse in verses:
91+ Receiver.send_message(u'process_events')
92 if isinstance(verse, Tag) and verse.name == u'div' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] == u'footnotes':
93 break
94 if isinstance(verse, Tag) and verse.name == u'sup' and filter(lambda a: a[0] == u'class', verse.attrs)[0][1] != u'versenum':
95@@ -219,6 +222,7 @@
96 continue
97 if isinstance(verse, Tag) and (verse.name == u'p' or verse.name == u'font') and verse.contents:
98 for item in verse.contents:
99+ Receiver.send_message(u'process_events')
100 if isinstance(item, Tag) and (item.name == u'h4' or item.name == u'h5'):
101 continue
102 if isinstance(item, Tag) and item.name == u'sup' and filter(lambda a: a[0] == u'class', item.attrs)[0][1] != u'versenum':
103@@ -231,6 +235,7 @@
104 continue
105 if isinstance(item, Tag) and item.name == u'font':
106 for subitem in item.contents:
107+ Receiver.send_message(u'process_events')
108 if isinstance(subitem, Tag) and subitem.name == u'sup' and filter(lambda a: a[0] == u'class', subitem.attrs)[0][1] != u'versenum':
109 continue
110 if isinstance(subitem, Tag) and subitem.name == u'p' and not subitem.contents:
111@@ -289,27 +294,42 @@
112 (version, urlbookname.lower(), chapter)
113 log.debug(u'URL: %s', chapter_url)
114 page = urllib2.urlopen(chapter_url)
115+ Receiver.send_message(u'process_events')
116 if not page:
117 return None
118 soup = BeautifulSoup(page)
119+ Receiver.send_message(u'process_events')
120 htmlverses = soup.findAll(u'span', u'versetext')
121 verses = {}
122 reduce_spaces = re.compile(r'[ ]{2,}')
123+ fix_punctuation = re.compile(r'[ ]+([.,;])')
124 for verse in htmlverses:
125 Receiver.send_message(u'process_events')
126 versenumber = int(verse.contents[0].contents[0])
127 versetext = u''
128 for part in verse.contents:
129+ Receiver.send_message(u'process_events')
130 if isinstance(part, NavigableString):
131 versetext = versetext + part
132 elif part and part.attrMap and \
133 (part.attrMap[u'class'] == u'WordsOfChrist' or \
134 part.attrMap[u'class'] == u'strongs'):
135 for subpart in part.contents:
136+ Receiver.send_message(u'process_events')
137 if isinstance(subpart, NavigableString):
138 versetext = versetext + subpart
139+ elif subpart and subpart.attrMap and \
140+ subpart.attrMap[u'class'] == u'strongs':
141+ for subsub in subpart.contents:
142+ Receiver.send_message(u'process_events')
143+ if isinstance(subsub, NavigableString):
144+ versetext = versetext + subsub
145+ Receiver.send_message(u'process_events')
146+ # Fix up leading and trailing spaces, multiple spaces, and spaces
147+ # between text and , and .
148 versetext = versetext.strip(u'\n\r\t ')
149 versetext = reduce_spaces.sub(u' ', versetext)
150+ versetext = fix_punctuation.sub(r'\1', versetext)
151 verses[versenumber] = versetext
152 return SearchResults(bookname, chapter, verses)
153
154@@ -410,10 +430,12 @@
155 ## we get a correct book. For example it is possible
156 ## to request ac and get Acts back.
157 bookname = search_results.get_book()
158+ Receiver.send_message(u'process_events')
159 # check to see if book/chapter exists
160 db_book = self.get_book(bookname)
161 self.create_chapter(db_book.id, search_results.get_chapter(),
162 search_results.get_verselist())
163+ Receiver.send_message(u'process_events')
164 Receiver.send_message(u'bible_hideprogress')
165 Receiver.send_message(u'process_events')
166 return BibleDB.get_verses(self, reference_list)
167
168=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
169--- openlp/plugins/bibles/lib/mediaitem.py 2010-03-24 19:15:25 +0000
170+++ openlp/plugins/bibles/lib/mediaitem.py 2010-03-27 20:12:20 +0000
171@@ -266,8 +266,9 @@
172 MediaManagerItem.addListViewToToolBar(self)
173 # Progress Bar
174 self.SearchProgress = QtGui.QProgressBar(self)
175- self.SearchProgress.setFormat('%p%')
176- self.SearchProgress.setMaximum(3)
177+ self.SearchProgress.setFormat('')
178+ self.SearchProgress.setMinimum(0)
179+ self.SearchProgress.setMaximum(0)
180 self.SearchProgress.setGeometry(self.ListView.geometry().left(),
181 self.ListView.geometry().top(), 81, 23)
182 self.SearchProgress.setVisible(False)
183@@ -351,9 +352,10 @@
184
185 def onSearchProgressShow(self):
186 self.SearchProgress.setVisible(True)
187- self.SearchProgress.setMinimum(0)
188- self.SearchProgress.setMaximum(2)
189- self.SearchProgress.setValue(1)
190+ Receiver.send_message(u'process_events')
191+ #self.SearchProgress.setMinimum(0)
192+ #self.SearchProgress.setMaximum(2)
193+ #self.SearchProgress.setValue(1)
194
195 def onSearchProgressHide(self):
196 self.SearchProgress.setVisible(False)