forked from openlp/openlp
r1618
This commit is contained in:
commit
4c3c6e8b37
@ -92,7 +92,7 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.hide()
|
||||
self.whitespace = re.compile(r'\W+', re.UNICODE)
|
||||
self.whitespace = re.compile(r'[\W_]+', re.UNICODE)
|
||||
self.plugin = plugin
|
||||
visible_title = self.plugin.getString(StringContent.VisibleName)
|
||||
self.title = unicode(visible_title[u'title'])
|
||||
|
@ -300,6 +300,12 @@ class Plugin(QtCore.QObject):
|
||||
if self.mediaItem:
|
||||
self.mediadock.remove_dock(self.mediaItem)
|
||||
|
||||
def appStartup(self):
|
||||
"""
|
||||
Perform tasks on application starup
|
||||
"""
|
||||
pass
|
||||
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to find out if a plugin is currently using a theme.
|
||||
|
@ -655,7 +655,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
# Give all the plugins a chance to perform some tasks at startup
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
for plugin in self.pluginManager.plugins:
|
||||
if plugin.isActive() and hasattr(plugin, u'appStartup'):
|
||||
if plugin.isActive():
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
plugin.appStartup()
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
|
@ -132,6 +132,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
self.activePlugin.toggleStatus(PluginStatus.Active)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
self.activePlugin.appStartup()
|
||||
else:
|
||||
self.activePlugin.toggleStatus(PluginStatus.Inactive)
|
||||
status_text = unicode(
|
||||
|
@ -106,7 +106,7 @@ class ScreenList(object):
|
||||
"""
|
||||
# Do not log at start up.
|
||||
if changed_screen != -1:
|
||||
log.info(u'screen_count_changed %d' % number)
|
||||
log.info(u'screen_count_changed %d' % self.desktop.numScreens())
|
||||
# Remove unplugged screens.
|
||||
for screen in copy.deepcopy(self.screen_list):
|
||||
if screen[u'number'] == self.desktop.numScreens():
|
||||
|
@ -959,6 +959,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
treewidgetitem.setToolTip(0, serviceitem.notes)
|
||||
treewidgetitem.setData(0, QtCore.Qt.UserRole,
|
||||
QtCore.QVariant(item[u'order']))
|
||||
treewidgetitem.setSelected(item[u'selected'])
|
||||
# Add the children to their parent treewidgetitem.
|
||||
for count, frame in enumerate(serviceitem.get_frames()):
|
||||
child = QtGui.QTreeWidgetItem(treewidgetitem)
|
||||
@ -1030,16 +1031,34 @@ class ServiceManager(QtGui.QWidget):
|
||||
# force reset of renderer as theme data has changed
|
||||
self.mainwindow.renderer.themedata = None
|
||||
if self.serviceItems:
|
||||
for item in self.serviceItems:
|
||||
item[u'selected'] = False
|
||||
serviceIterator = QtGui.QTreeWidgetItemIterator(
|
||||
self.serviceManagerList)
|
||||
while serviceIterator.value():
|
||||
if serviceIterator.value().isSelected():
|
||||
selectedItem = serviceIterator.value()
|
||||
serviceIterator += 1
|
||||
if selectedItem is not None:
|
||||
if selectedItem.parent() is None:
|
||||
pos = selectedItem.data(0, QtCore.Qt.UserRole).toInt()[0]
|
||||
else:
|
||||
pos = selectedItem.parent().data(0, QtCore.Qt.UserRole). \
|
||||
toInt()[0]
|
||||
self.serviceItems[pos - 1][u'selected'] = True
|
||||
tempServiceItems = self.serviceItems
|
||||
self.serviceManagerList.clear()
|
||||
self.serviceItems = []
|
||||
self.isNew = True
|
||||
for item in tempServiceItems:
|
||||
self.addServiceItem(
|
||||
item[u'service_item'], False, expand=item[u'expanded'])
|
||||
item[u'service_item'], False, expand=item[u'expanded'],
|
||||
repaint=False, selected=item[u'selected'])
|
||||
# Set to False as items may have changed rendering
|
||||
# does not impact the saved song so True may also be valid
|
||||
self.setModified()
|
||||
# Repaint it once only at the end
|
||||
self.repaintServiceList(-1, -1)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
def serviceItemUpdate(self, message):
|
||||
@ -1069,7 +1088,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
self.setModified()
|
||||
|
||||
def addServiceItem(self, item, rebuild=False, expand=None, replace=False,
|
||||
repaint=True):
|
||||
repaint=True, selected=False):
|
||||
"""
|
||||
Add a Service item to the list
|
||||
|
||||
@ -1097,17 +1116,17 @@ class ServiceManager(QtGui.QWidget):
|
||||
for inditem in item:
|
||||
self.serviceItems.append({u'service_item': inditem,
|
||||
u'order': len(self.serviceItems) + 1,
|
||||
u'expanded': expand})
|
||||
u'expanded': expand, u'selected': selected})
|
||||
else:
|
||||
self.serviceItems.append({u'service_item': item,
|
||||
u'order': len(self.serviceItems) + 1,
|
||||
u'expanded': expand})
|
||||
u'expanded': expand, u'selected': selected})
|
||||
if repaint:
|
||||
self.repaintServiceList(len(self.serviceItems) - 1, -1)
|
||||
else:
|
||||
self.serviceItems.insert(self.dropPosition,
|
||||
{u'service_item': item, u'order': self.dropPosition,
|
||||
u'expanded': expand})
|
||||
u'expanded': expand, u'selected': selected})
|
||||
self.repaintServiceList(self.dropPosition, -1)
|
||||
# if rebuilding list make sure live is fixed.
|
||||
if rebuild:
|
||||
|
@ -115,6 +115,8 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
self.stop_import_flag = True
|
||||
if not self.currentPage() == self.progressPage:
|
||||
self.done(QtGui.QDialog.Rejected)
|
||||
else:
|
||||
self.postWizard()
|
||||
|
||||
def onCurrentIdChanged(self, pageId):
|
||||
"""
|
||||
@ -127,14 +129,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
elif self.page(pageId) == self.selectPage and self.maxBibles == 0:
|
||||
self.next()
|
||||
|
||||
def onFinishButton(self):
|
||||
"""
|
||||
Some cleanup while finishing
|
||||
"""
|
||||
for number, filename in enumerate(self.files):
|
||||
if number in self.success and self.success[number] == True:
|
||||
delete_file(os.path.join(self.path, filename[0]))
|
||||
|
||||
def onBackupBrowseButtonClicked(self):
|
||||
"""
|
||||
Show the file open dialog for the OSIS file.
|
||||
@ -180,8 +174,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
"""
|
||||
Set up the signals used in the bible importer.
|
||||
"""
|
||||
QtCore.QObject.connect(self.finishButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onFinishButton)
|
||||
QtCore.QObject.connect(self.backupBrowseButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onBackupBrowseButtonClicked)
|
||||
QtCore.QObject.connect(self.noBackupCheckBox,
|
||||
@ -536,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
"""
|
||||
Perform the actual upgrade.
|
||||
"""
|
||||
include_webbible = False
|
||||
self.include_webbible = False
|
||||
proxy_server = None
|
||||
if self.maxBibles == 0:
|
||||
self.progressLabel.setText(
|
||||
@ -578,19 +570,19 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
name = unicode(self.versionNameEdit[biblenumber].text())
|
||||
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path,
|
||||
name=name)
|
||||
self.newbibles[number].register(self.plugin.upgrade_wizard)
|
||||
metadata = oldbible.get_metadata()
|
||||
webbible = False
|
||||
meta_data = {}
|
||||
for meta in metadata:
|
||||
meta_data[meta[u'key']] = meta[u'value']
|
||||
if not meta[u'key'] == u'Version':
|
||||
if not meta[u'key'] == u'Version' and not meta[u'key'] == \
|
||||
u'dbversion':
|
||||
self.newbibles[number].create_meta(meta[u'key'],
|
||||
meta[u'value'])
|
||||
else:
|
||||
self.newbibles[number].create_meta(meta[u'key'], name)
|
||||
if meta[u'key'] == u'download source':
|
||||
webbible = True
|
||||
include_webbible = True
|
||||
self.include_webbible = True
|
||||
if meta.has_key(u'proxy server'):
|
||||
proxy_server = meta[u'proxy server']
|
||||
if webbible:
|
||||
@ -602,12 +594,11 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
handler = BSExtract(proxy_server)
|
||||
books = handler.get_books_from_http(meta_data[u'download name'])
|
||||
if not books:
|
||||
log.exception(u'Upgrading books from %s - download '\
|
||||
log.error(u'Upgrading books from %s - download '\
|
||||
u'name: "%s" failed' % (
|
||||
meta_data[u'download source'],
|
||||
meta_data[u'download name']))
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin.UpgradeWizardForm',
|
||||
@ -626,16 +617,15 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
bible = BiblesResourcesDB.get_webbible(
|
||||
meta_data[u'download name'],
|
||||
meta_data[u'download source'].lower())
|
||||
if bible[u'language_id']:
|
||||
if bible and bible[u'language_id']:
|
||||
language_id = bible[u'language_id']
|
||||
self.newbibles[number].create_meta(u'language_id',
|
||||
language_id)
|
||||
else:
|
||||
language_id = self.newbibles[number].get_language(name)
|
||||
if not language_id:
|
||||
log.exception(u'Upgrading from "%s" failed' % filename[0])
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
log.warn(u'Upgrading from "%s" failed' % filename[0])
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
@ -657,27 +647,42 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
book_ref_id = self.newbibles[number].\
|
||||
get_book_ref_id_by_name(book, len(books), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Upgrading books from %s - download '\
|
||||
log.warn(u'Upgrading books from %s - download '\
|
||||
u'name: "%s" aborted by user' % (
|
||||
meta_data[u'download source'],
|
||||
meta_data[u'download name']))
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
bible_failed = True
|
||||
break
|
||||
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
|
||||
self.newbibles[number].create_book(book, book_ref_id,
|
||||
book_details[u'testament_id'])
|
||||
db_book = self.newbibles[number].create_book(book,
|
||||
book_ref_id, book_details[u'testament_id'])
|
||||
# Try to import still downloaded verses
|
||||
oldbook = oldbible.get_book(book)
|
||||
if oldbook:
|
||||
verses = oldbible.get_verses(oldbook[u'id'])
|
||||
if not verses:
|
||||
log.warn(u'No verses found to import for book '
|
||||
u'"%s"', book)
|
||||
continue
|
||||
for verse in verses:
|
||||
if self.stop_import_flag:
|
||||
bible_failed = True
|
||||
break
|
||||
self.newbibles[number].create_verse(db_book.id,
|
||||
int(verse[u'chapter']),
|
||||
int(verse[u'verse']), unicode(verse[u'text']))
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
self.newbibles[number].session.commit()
|
||||
else:
|
||||
language_id = self.newbibles[number].get_object(BibleMeta,
|
||||
u'language_id')
|
||||
if not language_id:
|
||||
language_id = self.newbibles[number].get_language(name)
|
||||
if not language_id:
|
||||
log.exception(u'Upgrading books from "%s" failed' % name)
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
log.warn(u'Upgrading books from "%s" failed' % name)
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
@ -701,10 +706,9 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
get_book_ref_id_by_name(book[u'name'], len(books),
|
||||
language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Upgrading books from %s " '\
|
||||
log.warn(u'Upgrading books from %s " '\
|
||||
'failed - aborted by user' % name)
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
bible_failed = True
|
||||
break
|
||||
@ -713,7 +717,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
book_ref_id, book_details[u'testament_id'])
|
||||
verses = oldbible.get_verses(book[u'id'])
|
||||
if not verses:
|
||||
log.exception(u'No verses found to import for book '
|
||||
log.warn(u'No verses found to import for book '
|
||||
u'"%s"', book[u'name'])
|
||||
self.newbibles[number].delete_book(db_book)
|
||||
continue
|
||||
@ -727,6 +731,8 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
self.newbibles[number].session.commit()
|
||||
if not bible_failed:
|
||||
self.newbibles[number].create_meta(u'Version', name)
|
||||
delete_file(os.path.join(self.path, filename[0]))
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
'Upgrading Bible %s of %s: "%s"\n'
|
||||
@ -739,10 +745,13 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
'Upgrading Bible %s of %s: "%s"\nFailed')) %
|
||||
(number + 1, self.maxBibles, name),
|
||||
self.progressBar.maximum() - self.progressBar.value())
|
||||
delete_database(self.path,
|
||||
clean_filename(name))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
number += 1
|
||||
self.mediaItem.reloadBibles()
|
||||
|
||||
def postWizard(self):
|
||||
"""
|
||||
Clean up the UI after the import has finished.
|
||||
"""
|
||||
successful_import = 0
|
||||
failed_import = 0
|
||||
for number, filename in enumerate(self.files):
|
||||
@ -757,7 +766,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
else:
|
||||
failed_import_text = u''
|
||||
if successful_import > 0:
|
||||
if include_webbible:
|
||||
if self.include_webbible:
|
||||
self.progressLabel.setText(unicode(
|
||||
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrading '
|
||||
'Bible(s): %s successful%s\nPlease note, that verses from '
|
||||
@ -773,3 +782,4 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
self.progressLabel.setText(
|
||||
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade '
|
||||
'failed.'))
|
||||
OpenLPWizard.postWizard(self)
|
||||
|
@ -1045,6 +1045,28 @@ class OldBibleDB(QtCore.QObject, Manager):
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_book(self, name):
|
||||
"""
|
||||
Return a book by name or abbreviation.
|
||||
|
||||
``name``
|
||||
The name or abbreviation of the book.
|
||||
"""
|
||||
if not isinstance(name, unicode):
|
||||
name = unicode(name)
|
||||
books = self.run_sql(u'SELECT id, testament_id, name, '
|
||||
u'abbreviation FROM book WHERE LOWER(name) = ? OR '
|
||||
u'LOWER(abbreviation) = ?', (name.lower(), name.lower()))
|
||||
if books:
|
||||
return {
|
||||
u'id': books[0][0],
|
||||
u'testament_id': books[0][1],
|
||||
u'name': unicode(books[0][2]),
|
||||
u'abbreviation': unicode(books[0][3])
|
||||
}
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_books(self):
|
||||
"""
|
||||
Returns the books of the Bible.
|
||||
|
@ -109,7 +109,7 @@ class BGExtract(object):
|
||||
try:
|
||||
clean_verse_num = int(str(raw_verse_num))
|
||||
except ValueError:
|
||||
log.exception(u'Illegal verse number in %s %s %s:%s',
|
||||
log.warn(u'Illegal verse number in %s %s %s:%s',
|
||||
version, bookname, chapter, unicode(raw_verse_num))
|
||||
if clean_verse_num:
|
||||
verse_text = raw_verse_num.next
|
||||
@ -139,16 +139,17 @@ class BGExtract(object):
|
||||
"""
|
||||
log.debug(u'BGExtract.get_books_from_http("%s")', version)
|
||||
url_params = urllib.urlencode(
|
||||
{u'search': 'Bible-List', u'version': u'%s' % version})
|
||||
reference_url = u'http://www.biblegateway.com/passage/?%s' % url_params
|
||||
{u'action': 'getVersionInfo', u'vid': u'%s' % version})
|
||||
reference_url = u'http://www.biblegateway.com/versions/?%s#books' % \
|
||||
url_params
|
||||
page = get_web_page(reference_url)
|
||||
if not page:
|
||||
send_error_message(u'download')
|
||||
return None
|
||||
page_source = page.read()
|
||||
page_source = unicode(page_source, 'utf8')
|
||||
page_source_temp = re.search(u'<table id="booklist".*?>.*?</table>', \
|
||||
page_source, re.DOTALL)
|
||||
page_source_temp = re.search(u'<table .*?class="infotable".*?>.*?'\
|
||||
u'</table>', page_source, re.DOTALL)
|
||||
if page_source_temp:
|
||||
soup = page_source_temp.group(0)
|
||||
else:
|
||||
@ -156,15 +157,17 @@ class BGExtract(object):
|
||||
try:
|
||||
soup = BeautifulSoup(soup)
|
||||
except HTMLParseError:
|
||||
log.exception(u'BeautifulSoup could not parse the Bible page.')
|
||||
log.error(u'BeautifulSoup could not parse the Bible page.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
if not soup:
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
content = soup.find(u'table', {u'id': u'booklist'})
|
||||
content = soup.find(u'table', {u'class': u'infotable'})
|
||||
content = content.findAll(u'tr')
|
||||
if not content:
|
||||
log.exception(u'No books found in the Biblegateway response.')
|
||||
log.error(u'No books found in the Biblegateway response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
books = []
|
||||
@ -199,9 +202,10 @@ class BSExtract(object):
|
||||
"""
|
||||
log.debug(u'BSExtract.get_bible_chapter("%s", "%s", "%s")', version,
|
||||
bookname, chapter)
|
||||
urlversion = urllib.quote(version.encode("utf-8"))
|
||||
urlbookname = urllib.quote(bookname.encode("utf-8"))
|
||||
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
|
||||
(version, urlbookname, chapter)
|
||||
chapter_url = u'http://m.bibleserver.com/text/%s/%s%d' % \
|
||||
(urlversion, urlbookname, chapter)
|
||||
header = (u'Accept-Language', u'en')
|
||||
soup = get_soup_for_bible_ref(chapter_url, header)
|
||||
if not soup:
|
||||
@ -209,7 +213,7 @@ class BSExtract(object):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
content = soup.find(u'div', u'content')
|
||||
if not content:
|
||||
log.exception(u'No verses found in the Bibleserver response.')
|
||||
log.error(u'No verses found in the Bibleserver response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.find(u'div').findAll(u'div')
|
||||
@ -230,14 +234,15 @@ class BSExtract(object):
|
||||
The version of the Bible like NIV for New International Version
|
||||
"""
|
||||
log.debug(u'BSExtract.get_books_from_http("%s")', version)
|
||||
urlversion = urllib.quote(version.encode("utf-8"))
|
||||
chapter_url = u'http://m.bibleserver.com/overlay/selectBook?'\
|
||||
'translation=%s' % (version)
|
||||
'translation=%s' % (urlversion)
|
||||
soup = get_soup_for_bible_ref(chapter_url)
|
||||
if not soup:
|
||||
return None
|
||||
content = soup.find(u'ul')
|
||||
if not content:
|
||||
log.exception(u'No books found in the Bibleserver response.')
|
||||
log.error(u'No books found in the Bibleserver response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.findAll(u'li')
|
||||
@ -281,7 +286,7 @@ class CWExtract(object):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
htmlverses = soup.findAll(u'span', u'versetext')
|
||||
if not htmlverses:
|
||||
log.debug(u'No verses found in the CrossWalk response.')
|
||||
log.error(u'No verses found in the CrossWalk response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
verses = {}
|
||||
@ -333,7 +338,7 @@ class CWExtract(object):
|
||||
content = soup.find(u'div', {u'class': u'Body'})
|
||||
content = content.find(u'ul', {u'class': u'parent'})
|
||||
if not content:
|
||||
log.exception(u'No books found in the Crosswalk response.')
|
||||
log.error(u'No books found in the Crosswalk response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.findAll(u'li')
|
||||
|
@ -772,7 +772,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
log.exception(u'The second_search_results does not have as '
|
||||
'many verses as the search_results.')
|
||||
break
|
||||
bible_text = u' %s %d%s%d (%s, %s)' % (verse.book.name,
|
||||
bible_text = u'%s %d%s%d (%s, %s)' % (verse.book.name,
|
||||
verse.chapter, verse_separator, verse.verse, version,
|
||||
second_version)
|
||||
else:
|
||||
@ -830,7 +830,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bible_text = u''
|
||||
# If we are 'Verse Per Line' then force a new line.
|
||||
elif self.settings.layout_style == LayoutStyle.VersePerLine:
|
||||
bible_text = u'%s %s %s\n' % (bible_text, verse_text, text)
|
||||
bible_text = u'%s%s %s\n' % (bible_text, verse_text, text)
|
||||
# We have to be 'Continuous'.
|
||||
else:
|
||||
bible_text = u'%s %s %s\n' % (bible_text, verse_text, text)
|
||||
|
Binary file not shown.
@ -125,7 +125,7 @@ class ImpressController(PresentationController):
|
||||
try:
|
||||
uno_instance = get_uno_instance(resolver)
|
||||
except:
|
||||
log.exception(u'Unable to find running instance ')
|
||||
log.warn(u'Unable to find running instance ')
|
||||
self.start_process()
|
||||
loop += 1
|
||||
try:
|
||||
@ -136,7 +136,7 @@ class ImpressController(PresentationController):
|
||||
"com.sun.star.frame.Desktop", uno_instance)
|
||||
return desktop
|
||||
except:
|
||||
log.exception(u'Failed to get UNO desktop')
|
||||
log.warn(u'Failed to get UNO desktop')
|
||||
return None
|
||||
|
||||
def get_com_desktop(self):
|
||||
@ -151,7 +151,7 @@ class ImpressController(PresentationController):
|
||||
try:
|
||||
desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop')
|
||||
except AttributeError:
|
||||
log.exception(u'Failure to find desktop - Impress may have closed')
|
||||
log.warn(u'Failure to find desktop - Impress may have closed')
|
||||
return desktop if desktop else None
|
||||
|
||||
def get_com_servicemanager(self):
|
||||
@ -162,7 +162,7 @@ class ImpressController(PresentationController):
|
||||
try:
|
||||
return Dispatch(u'com.sun.star.ServiceManager')
|
||||
except pywintypes.com_error:
|
||||
log.exception(u'Failed to get COM service manager. '
|
||||
log.warn(u'Failed to get COM service manager. '
|
||||
u'Impress Controller has been disabled')
|
||||
return None
|
||||
|
||||
@ -180,7 +180,7 @@ class ImpressController(PresentationController):
|
||||
else:
|
||||
desktop = self.get_com_desktop()
|
||||
except:
|
||||
log.exception(u'Failed to find an OpenOffice desktop to terminate')
|
||||
log.warn(u'Failed to find an OpenOffice desktop to terminate')
|
||||
if not desktop:
|
||||
return
|
||||
docs = desktop.getComponents()
|
||||
@ -191,7 +191,7 @@ class ImpressController(PresentationController):
|
||||
desktop.terminate()
|
||||
log.debug(u'OpenOffice killed')
|
||||
except:
|
||||
log.exception(u'Failed to terminate OpenOffice')
|
||||
log.warn(u'Failed to terminate OpenOffice')
|
||||
|
||||
|
||||
class ImpressDocument(PresentationDocument):
|
||||
@ -244,7 +244,7 @@ class ImpressDocument(PresentationDocument):
|
||||
self.document = desktop.loadComponentFromURL(url, u'_blank',
|
||||
0, properties)
|
||||
except:
|
||||
log.exception(u'Failed to load presentation %s' % url)
|
||||
log.warn(u'Failed to load presentation %s' % url)
|
||||
return False
|
||||
if os.name == u'nt':
|
||||
# As we can't start minimized the Impress window gets in the way.
|
||||
@ -323,7 +323,7 @@ class ImpressDocument(PresentationDocument):
|
||||
self.presentation = None
|
||||
self.document.dispose()
|
||||
except:
|
||||
log.exception("Closing presentation failed")
|
||||
log.warn("Closing presentation failed")
|
||||
self.document = None
|
||||
self.controller.remove_doc(self)
|
||||
|
||||
@ -341,7 +341,7 @@ class ImpressDocument(PresentationDocument):
|
||||
log.debug("getPresentation failed to find a presentation")
|
||||
return False
|
||||
except:
|
||||
log.exception("getPresentation failed to find a presentation")
|
||||
log.warn("getPresentation failed to find a presentation")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -77,7 +77,7 @@ class PresentationPlugin(Plugin):
|
||||
try:
|
||||
self.controllers[controller].start_process()
|
||||
except:
|
||||
log.exception(u'Failed to start controller process')
|
||||
log.warn(u'Failed to start controller process')
|
||||
self.controllers[controller].available = False
|
||||
self.mediaItem.buildFileMaskString()
|
||||
|
||||
@ -128,7 +128,7 @@ class PresentationPlugin(Plugin):
|
||||
try:
|
||||
__import__(modulename, globals(), locals(), [])
|
||||
except ImportError:
|
||||
log.exception(u'Failed to import %s on path %s',
|
||||
log.warn(u'Failed to import %s on path %s',
|
||||
modulename, path)
|
||||
controller_classes = PresentationController.__subclasses__()
|
||||
for controller_class in controller_classes:
|
||||
|
@ -32,6 +32,9 @@ from openlp.core.lib import translate
|
||||
from db import Author
|
||||
from ui import SongStrings
|
||||
|
||||
WHITESPACE = re.compile(r'[\W_]+', re.UNICODE)
|
||||
APOSTROPHE = re.compile(u'[\'`’ʻ′]', re.UNICODE)
|
||||
|
||||
class VerseType(object):
|
||||
"""
|
||||
VerseType provides an enumeration for the tags that may be associated
|
||||
@ -246,6 +249,12 @@ def retrieve_windows_encoding(recommendation=None):
|
||||
return None
|
||||
return filter(lambda item: item[1] == choice[0], encodings)[0][0]
|
||||
|
||||
def clean_string(string):
|
||||
"""
|
||||
Strips punctuation from the passed string to assist searching
|
||||
"""
|
||||
return WHITESPACE.sub(u' ', APOSTROPHE.sub(u'', string)).lower()
|
||||
|
||||
def clean_song(manager, song):
|
||||
"""
|
||||
Cleans the search title, rebuilds the search lyrics, adds a default author
|
||||
@ -262,9 +271,8 @@ def clean_song(manager, song):
|
||||
if song.alternate_title is None:
|
||||
song.alternate_title = u''
|
||||
song.alternate_title = song.alternate_title.strip()
|
||||
whitespace = re.compile(r'\W+', re.UNICODE)
|
||||
song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' +
|
||||
whitespace.sub(u' ', song.alternate_title).strip()).strip().lower()
|
||||
song.search_title = clean_string(song.title) + u'@' + \
|
||||
clean_string(song.alternate_title)
|
||||
# Only do this, if we the song is a 1.9.4 song (or older).
|
||||
if song.lyrics.find(u'<lyrics language="en">') != -1:
|
||||
# Remove the old "language" attribute from lyrics tag (prior to 1.9.5).
|
||||
@ -273,8 +281,8 @@ def clean_song(manager, song):
|
||||
song.lyrics = song.lyrics.replace(
|
||||
u'<lyrics language="en">', u'<lyrics>')
|
||||
verses = SongXML().get_verses(song.lyrics)
|
||||
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
|
||||
song.search_lyrics = lyrics.lower()
|
||||
song.search_lyrics = u' '.join([clean_string(verse[1])
|
||||
for verse in verses])
|
||||
# We need a new and clean SongXML instance.
|
||||
sxml = SongXML()
|
||||
# Rebuild the song's verses, to remove any wrong verse names (for
|
||||
@ -316,6 +324,11 @@ def clean_song(manager, song):
|
||||
if order not in compare_order:
|
||||
song.verse_order = u''
|
||||
break
|
||||
else:
|
||||
verses = SongXML().get_verses(song.lyrics)
|
||||
song.search_lyrics = u' '.join([clean_string(verse[1])
|
||||
for verse in verses])
|
||||
|
||||
# The song does not have any author, add one.
|
||||
if not song.authors:
|
||||
name = SongStrings.AuthorUnknown
|
||||
|
@ -38,7 +38,8 @@ from openlp.core.lib.searchedit import SearchEdit
|
||||
from openlp.core.lib.ui import UiStrings
|
||||
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||
SongImportForm, SongExportForm
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
|
||||
clean_string
|
||||
from openlp.plugins.songs.lib.db import Author, Song
|
||||
from openlp.plugins.songs.lib.ui import SongStrings
|
||||
|
||||
@ -181,13 +182,14 @@ class SongMediaItem(MediaManagerItem):
|
||||
elif search_type == SongSearch.Titles:
|
||||
log.debug(u'Titles Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords.lower()) + u'%'))
|
||||
Song.search_title.like(u'%' + clean_string(search_keywords) +
|
||||
u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == SongSearch.Lyrics:
|
||||
log.debug(u'Lyrics Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'))
|
||||
Song.search_lyrics.like(u'%' + clean_string(search_keywords) +
|
||||
u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == SongSearch.Authors:
|
||||
log.debug(u'Authors Search')
|
||||
@ -198,16 +200,16 @@ class SongMediaItem(MediaManagerItem):
|
||||
elif search_type == SongSearch.Themes:
|
||||
log.debug(u'Theme Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.theme_name.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords) + u'%'))
|
||||
Song.theme_name.like(u'%' + search_keywords + u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
self.check_search_result()
|
||||
|
||||
def searchEntire(self, search_keywords):
|
||||
return self.plugin.manager.get_all_objects(Song,
|
||||
or_(Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords.lower()) + u'%'),
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'),
|
||||
or_(Song.search_title.like(u'%' + clean_string(search_keywords)
|
||||
+ u'%'),
|
||||
Song.search_lyrics.like(u'%' + clean_string(search_keywords)
|
||||
+ u'%'),
|
||||
Song.comments.like(u'%' + search_keywords.lower() + u'%')))
|
||||
|
||||
def onSongListLoad(self):
|
||||
|
@ -102,6 +102,13 @@ psvince.dll
|
||||
the install will fail. The dll can be obtained from here:
|
||||
http://www.vincenzo.net/isxkb/index.php?title=PSVince)
|
||||
|
||||
Mako
|
||||
Mako Templates for Python. This package is required for building the
|
||||
remote plugin. It can be installed by going to your
|
||||
python_directory\scripts\.. and running "easy_install Mako". If you do not
|
||||
have easy_install, the Mako package can be obtained here:
|
||||
http://www.makotemplates.org/download.html
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
@ -194,7 +201,8 @@ def write_version_file():
|
||||
code = bzr.wait()
|
||||
if code != 0:
|
||||
raise Exception(u'Error running bzr log')
|
||||
latest = output.split(u':')[0]
|
||||
outputAscii = unicode(output, errors='ignore')
|
||||
latest = outputAscii.split(u':')[0]
|
||||
versionstring = latest == revision and tag or u'%s-bzr%s' % (tag, latest)
|
||||
f = open(os.path.join(dist_path, u'.version'), u'w')
|
||||
f.write(versionstring)
|
||||
|
Loading…
Reference in New Issue
Block a user