forked from openlp/openlp
An attempt to fix the problems some folks are having.
This commit is contained in:
parent
ab7125c98e
commit
2b5ddb13a4
@ -45,7 +45,7 @@ class BiblePlugin(Plugin):
|
||||
def initialise(self):
|
||||
log.info(u'bibles Initialising')
|
||||
if self.biblemanager is None:
|
||||
self.biblemanager = BibleManager(self.config)
|
||||
self.biblemanager = BibleManager(self, self.config)
|
||||
Plugin.initialise(self)
|
||||
self.insert_toolbox_item()
|
||||
self.ImportBibleItem.setVisible(True)
|
||||
@ -90,4 +90,4 @@ class BiblePlugin(Plugin):
|
||||
about_text = self.trUtf8('<strong>Bible Plugin</strong><br />This '
|
||||
'plugin allows bible verses from different sources to be '
|
||||
'displayed on the screen during the service.')
|
||||
return about_text
|
||||
return about_text
|
||||
|
@ -91,15 +91,6 @@ class Ui_BibleImportWizard(object):
|
||||
self.OsisLayout.setMargin(0)
|
||||
self.OsisLayout.setSpacing(8)
|
||||
self.OsisLayout.setObjectName(u'OsisLayout')
|
||||
self.OsisBibleNameLabel = QtGui.QLabel(self.OsisPage)
|
||||
self.OsisBibleNameLabel.setIndent(0)
|
||||
self.OsisBibleNameLabel.setObjectName(u'OsisBibleNameLabel')
|
||||
self.OsisLayout.setWidget(0, QtGui.QFormLayout.LabelRole,
|
||||
self.OsisBibleNameLabel)
|
||||
self.OsisBibleNameEdit = QtGui.QLineEdit(self.OsisPage)
|
||||
self.OsisBibleNameEdit.setObjectName(u'OsisBibleNameEdit')
|
||||
self.OsisLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
|
||||
self.OsisBibleNameEdit)
|
||||
self.OsisLocationLabel = QtGui.QLabel(self.OsisPage)
|
||||
self.OsisLocationLabel.setObjectName(u'OsisLocationLabel')
|
||||
self.OsisLayout.setWidget(1, QtGui.QFormLayout.LabelRole,
|
||||
@ -307,7 +298,6 @@ class Ui_BibleImportWizard(object):
|
||||
self.ImportLayout.addWidget(self.ImportProgressBar)
|
||||
BibleImportWizard.addPage(self.ImportPage)
|
||||
|
||||
|
||||
self.retranslateUi(BibleImportWizard)
|
||||
self.FormatWidget.setCurrentIndex(0)
|
||||
self.WebDownloadTabWidget.setCurrentIndex(0)
|
||||
@ -333,7 +323,6 @@ class Ui_BibleImportWizard(object):
|
||||
self.FormatComboBox.setItemText(1, self.trUtf8('CSV'))
|
||||
self.FormatComboBox.setItemText(2, self.trUtf8('OpenSong'))
|
||||
self.FormatComboBox.setItemText(3, self.trUtf8('Web Download'))
|
||||
self.OsisBibleNameLabel.setText(self.trUtf8('Bible Name:'))
|
||||
self.OsisLocationLabel.setText(self.trUtf8('File Location:'))
|
||||
self.BooksLocationLabel.setText(self.trUtf8('Books Location:'))
|
||||
self.VerseLocationLabel.setText(self.trUtf8('Verse Location:'))
|
||||
@ -361,4 +350,4 @@ class Ui_BibleImportWizard(object):
|
||||
self.ImportPage.setSubTitle(
|
||||
self.trUtf8('Please wait while your Bible is imported.'))
|
||||
self.ImportProgressLabel.setText(self.trUtf8('Ready.'))
|
||||
#self.ImportProgressBar.setFormat(u'%p')
|
||||
self.ImportProgressBar.setFormat(u'%p%')
|
||||
|
@ -27,6 +27,7 @@ import logging
|
||||
import os
|
||||
import os.path
|
||||
from time import sleep
|
||||
import csv
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
@ -107,14 +108,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
elif self.currentId() == 1:
|
||||
# Select page
|
||||
if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS:
|
||||
if self.field(u'osis_biblename').toString() == u'':
|
||||
QtGui.QMessageBox.critical(self,
|
||||
self.trUtf8('Invalid Bible Name'),
|
||||
self.trUtf8('You need to specify a name for your '
|
||||
'Bible!'),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
||||
self.OsisBibleNameEdit.setFocus()
|
||||
return False
|
||||
if self.field(u'osis_location').toString() == u'':
|
||||
QtGui.QMessageBox.critical(self,
|
||||
self.trUtf8('Invalid Bible Location'),
|
||||
@ -218,8 +211,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
def registerFields(self):
|
||||
self.SelectPage.registerField(
|
||||
u'source_format', self.FormatComboBox)
|
||||
self.SelectPage.registerField(
|
||||
u'osis_biblename', self.OsisBibleNameEdit)
|
||||
self.SelectPage.registerField(
|
||||
u'osis_location', self.OSISLocationEdit)
|
||||
self.SelectPage.registerField(
|
||||
@ -247,7 +238,6 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
|
||||
def setDefaults(self):
|
||||
self.setField(u'source_format', 0)
|
||||
self.setField(u'osis_biblename', u'')
|
||||
self.setField(u'osis_location', u'')
|
||||
self.setField(u'csv_booksfile', u'')
|
||||
self.setField(u'csv_versefile', u'')
|
||||
@ -276,29 +266,33 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
fbibles = None
|
||||
try:
|
||||
self.web_bible_list[DownloadLocation.Crosswalk] = {}
|
||||
fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r')
|
||||
for line in fbibles:
|
||||
parts = line.split(u',')
|
||||
self.web_bible_list[DownloadLocation.Crosswalk][parts[0]] = \
|
||||
parts[1].rstrip()
|
||||
books_file = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r')
|
||||
dialect = csv.Sniffer().sniff(books_file.read(1024))
|
||||
books_file.seek(0)
|
||||
books_reader = csv.reader(books_file, dialect)
|
||||
for line in books_reader:
|
||||
self.web_bible_list[DownloadLocation.Crosswalk][line[0]] = \
|
||||
unicode(line[1], u'utf-8').strip()
|
||||
except:
|
||||
log.exception(u'Crosswalk resources missing')
|
||||
finally:
|
||||
if fbibles:
|
||||
fbibles.close()
|
||||
if books_file:
|
||||
books_file.close()
|
||||
#Load and store BibleGateway Bibles
|
||||
try:
|
||||
self.web_bible_list[DownloadLocation.BibleGateway] = {}
|
||||
fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r')
|
||||
for line in fbibles:
|
||||
parts = line.split(u',')
|
||||
self.web_bible_list[DownloadLocation.BibleGateway][parts[0]] = \
|
||||
parts[1].rstrip()
|
||||
books_file = open(os.path.join(filepath, u'biblegateway.csv'), 'r')
|
||||
dialect = csv.Sniffer().sniff(books_file.read(1024))
|
||||
books_file.seek(0)
|
||||
books_reader = csv.reader(books_file, dialect)
|
||||
for line in books_reader:
|
||||
self.web_bible_list[DownloadLocation.BibleGateway][line[0]] = \
|
||||
unicode(line[1], u'utf-8').strip()
|
||||
except:
|
||||
log.exception(u'Biblegateway resources missing')
|
||||
finally:
|
||||
if fbibles:
|
||||
fbibles.close()
|
||||
if books_file:
|
||||
books_file.close()
|
||||
|
||||
def getFileName(self, title, editbox):
|
||||
filename = QtGui.QFileDialog.getOpenFileName(self, title,
|
||||
|
@ -37,13 +37,13 @@ class CSVBible(BibleDB):
|
||||
This class provides a specialisation for importing of CSV Bibles.
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
Loads a Bible from a pair of CVS files passed in
|
||||
This class assumes the files contain all the information and
|
||||
a clean bible is being loaded.
|
||||
"""
|
||||
BibleDB.__init__(self, **kwargs)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
log.info(self.__class__.__name__)
|
||||
if u'booksfile' not in kwargs:
|
||||
raise KeyError(u'You have to supply a file to import books from.')
|
||||
|
@ -42,7 +42,7 @@ class BibleDB(QtCore.QObject):
|
||||
rather than depending on yet another object.
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
The constructor loads up the database and creates and initialises the
|
||||
tables if the database doesn't exist.
|
||||
@ -60,6 +60,7 @@ class BibleDB(QtCore.QObject):
|
||||
The configuration object, passed in from the plugin.
|
||||
"""
|
||||
log.info(u'BibleDBimpl loaded')
|
||||
QtCore.QObject.__init__(self)
|
||||
if u'path' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "path".')
|
||||
if u'name' not in kwargs:
|
||||
|
@ -142,7 +142,7 @@ class CWExtract(BibleCommon):
|
||||
class HTTPBible(BibleDB):
|
||||
log.info(u'%s loaded', __name__)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
Finds all the bibles defined for the system
|
||||
Creates an Interface Object for each bible containing connection
|
||||
@ -152,7 +152,7 @@ class HTTPBible(BibleDB):
|
||||
|
||||
Init confirms the bible exists and stores the database path.
|
||||
"""
|
||||
BibleDB.__init__(self, **kwargs)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
if u'download_source' not in kwargs:
|
||||
raise KeyError(u'Missing keyword argument "download_source"')
|
||||
if u'download_name' not in kwargs:
|
||||
@ -267,13 +267,10 @@ class HTTPBible(BibleDB):
|
||||
def set_books(self, books):
|
||||
self.books = books
|
||||
|
||||
def lookup_book(self, book):
|
||||
log.debug('Looking up "%s" in %s', (book, self.books))
|
||||
if book in self.books:
|
||||
return self.books[book]
|
||||
else:
|
||||
for details in self.books:
|
||||
if self.books[details][u'abbr'] == book:
|
||||
return self.books[details]
|
||||
return None
|
||||
def lookup_book(self, name):
|
||||
log.debug('Looking up "%s" in %s', (name, self.books))
|
||||
for book in self.books:
|
||||
if book[u'name'] == name or book[u'abbr'] == name:
|
||||
return book
|
||||
return None
|
||||
|
||||
|
@ -90,7 +90,7 @@ class BibleManager(object):
|
||||
log = logging.getLogger(u'BibleManager')
|
||||
log.info(u'Bible manager loaded')
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, parent, config):
|
||||
"""
|
||||
Finds all the bibles defined for the system and creates an interface
|
||||
object for each bible containing connection information. Throws
|
||||
@ -101,8 +101,9 @@ class BibleManager(object):
|
||||
``config``
|
||||
The plugin's configuration object.
|
||||
"""
|
||||
self.config = config
|
||||
log.debug(u'Bible Initialising')
|
||||
self.config = config
|
||||
self.parent = parent
|
||||
self.web = u'Web'
|
||||
self.db_cache = None
|
||||
self.http_cache = None
|
||||
@ -120,18 +121,19 @@ class BibleManager(object):
|
||||
filepath, u'..', u'resources', u'httpbooks.csv'))
|
||||
books_file = None
|
||||
try:
|
||||
self.http_books = {}
|
||||
self.http_books = []
|
||||
books_file = open(filepath, u'r')
|
||||
dialect = csv.Sniffer().sniff(books_file.read(1024))
|
||||
books_file.seek(0)
|
||||
books_reader = csv.reader(books_file, dialect)
|
||||
for line in books_reader:
|
||||
self.http_books[line[0]] = {
|
||||
u'name': line[0],
|
||||
u'abbr': line[1],
|
||||
self.http_books.append({
|
||||
u'name': unicode(line[0]),
|
||||
u'abbr': unicode(line[1]),
|
||||
u'test': line[2],
|
||||
u'chap': line[3]
|
||||
}
|
||||
u'chap': line[3],
|
||||
u'ordr': order
|
||||
})
|
||||
except:
|
||||
log.exception(u'Failed to load http books.')
|
||||
finally:
|
||||
@ -148,13 +150,13 @@ class BibleManager(object):
|
||||
self.web_bibles_present = False
|
||||
for filename in files:
|
||||
name, extension = os.path.splitext(filename)
|
||||
self.db_cache[name] = BibleDB(path=self.path, name=name, config=self.config)
|
||||
self.db_cache[name] = BibleDB(self.parent, path=self.path, name=name, config=self.config)
|
||||
# look to see if lazy load bible exists and get create getter.
|
||||
source = self.db_cache[name].get_meta(u'download source')
|
||||
if source:
|
||||
self.web_bibles_present = True
|
||||
download_name = self.db_cache[name].get_meta(u'download name').value
|
||||
web_bible = HTTPBible(path=self.path, name=name,
|
||||
web_bible = HTTPBible(self.parent, path=self.path, name=name,
|
||||
config=self.config, download_source=source.value,
|
||||
download_name=download_name)
|
||||
meta_proxy = self.db_cache[name].get_meta(u'proxy url')
|
||||
@ -187,7 +189,7 @@ class BibleManager(object):
|
||||
class_ = BibleFormat.get_class(type)
|
||||
kwargs['path'] = self.path
|
||||
kwargs['config'] = self.config
|
||||
importer = class_(**kwargs)
|
||||
importer = class_(self.parent, **kwargs)
|
||||
name = importer.register(self.import_wizard)
|
||||
self.db_cache[name] = importer
|
||||
return importer.do_import()
|
||||
@ -381,8 +383,12 @@ class BibleManager(object):
|
||||
"""
|
||||
Check cache to see if new bible
|
||||
"""
|
||||
if not isinstance(name, unicode):
|
||||
name = unicode(name, u'utf8')
|
||||
for bible, db_object in self.db_cache.iteritems():
|
||||
log.debug(u'Bible from cache in is_new_bible %s', bible)
|
||||
if not isinstance(bible, unicode):
|
||||
bible = unicode(bible, u'utf8')
|
||||
if bible == name:
|
||||
return True
|
||||
return False
|
||||
|
@ -357,7 +357,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
def onNoBookFound(self):
|
||||
QtGui.QMessageBox.critical(self,
|
||||
self.trUtf8('No Book Found'),
|
||||
self.trUtf8('No matching Book could be found in this Bible.'),
|
||||
self.trUtf8('No matching book could be found in this Bible.'),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
|
||||
QtGui.QMessageBox.Ok
|
||||
)
|
||||
|
@ -42,18 +42,18 @@ class OpenSongBible(BibleDB):
|
||||
OpenSong Bible format importer class.
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
Constructor to create and set up an instance of the OpenSongBible
|
||||
class. This class is used to import Bibles from OpenSong's XML format.
|
||||
"""
|
||||
log.debug(__name__)
|
||||
BibleDB.__init__(self, **kwargs)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
if 'filename' not in kwargs:
|
||||
raise KeyError(u'You have to supply a file name to import from.')
|
||||
self.filename = kwargs['filename']
|
||||
#QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'openlpstopimport'), self.stop_import)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'openlpstopimport'), self.stop_import)
|
||||
|
||||
def stop_import(self):
|
||||
"""
|
||||
@ -69,27 +69,20 @@ class OpenSongBible(BibleDB):
|
||||
log.debug(u'Starting OpenSong import from "%s"' % self.filename)
|
||||
self.filename = unicode(self.filename, u'utf-8')
|
||||
self.wizard.incrementProgressBar(u'Preparing for import...')
|
||||
detect_file = None
|
||||
try:
|
||||
detect_file = open(self.filename, u'r')
|
||||
details = chardet.detect(detect_file.read())
|
||||
except:
|
||||
log.exception(u'Failed to detect OpenSong file encoding')
|
||||
return False
|
||||
finally:
|
||||
if detect_file:
|
||||
detect_file.close()
|
||||
file = None
|
||||
success = True
|
||||
try:
|
||||
file = codecs.open(self.filename, u'r', details['encoding'])
|
||||
# NOTE: We don't need to do any of the normal encoding detection
|
||||
# here, because lxml does it's own encoding detection, and the two
|
||||
# mechanisms together interfere with each other.
|
||||
file = open(self.filename, u'r')
|
||||
opensong = objectify.parse(file)
|
||||
bible = opensong.getroot()
|
||||
for book in bible.b:
|
||||
if self.stop_import:
|
||||
break
|
||||
db_book = self.create_book(book.attrib[u'n'],
|
||||
book.attrib[u'n'][:4])
|
||||
db_book = self.create_book(unicode(book.attrib[u'n']),
|
||||
unicode(book.attrib[u'n'][:4]))
|
||||
for chapter in book.c:
|
||||
if self.stop_import:
|
||||
break
|
||||
@ -100,12 +93,12 @@ class OpenSongBible(BibleDB):
|
||||
db_book.id,
|
||||
int(chapter.attrib[u'n']),
|
||||
int(verse.attrib[u'n']),
|
||||
verse.text
|
||||
unicode(verse.text)
|
||||
)
|
||||
Receiver.send_message(u'process_events')
|
||||
self.wizard.incrementProgressBar(
|
||||
QtCore.QString('Importing %s %s' % \
|
||||
(db_book.name, chapter.attrib[u'n'])))
|
||||
QtCore.QString('%s %s %s' % (self.trUtf8('Importing'),\
|
||||
db_book.name, chapter.attrib[u'n'])))
|
||||
self.commit()
|
||||
except:
|
||||
log.exception(u'Loading bible from OpenSong file failed')
|
||||
|
@ -43,13 +43,13 @@ class OSISBible(BibleDB):
|
||||
log = logging.getLogger(u'BibleOSISImpl')
|
||||
log.info(u'BibleOSISImpl loaded')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, parent, **kwargs):
|
||||
"""
|
||||
Constructor to create and set up an instance of the OpenSongBible
|
||||
class. This class is used to import Bibles from OpenSong's XML format.
|
||||
"""
|
||||
log.debug(__name__)
|
||||
BibleDB.__init__(self, **kwargs)
|
||||
BibleDB.__init__(self, parent, **kwargs)
|
||||
if u'filename' not in kwargs:
|
||||
raise KeyError(u'You have to supply a file name to import from.')
|
||||
self.filename = kwargs[u'filename']
|
||||
|
@ -153,10 +153,10 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
|
||||
sxml.add_verse_to_lyrics(u'custom', unicode(count),
|
||||
unicode(self.VerseListView.item(i).text()))
|
||||
count += 1
|
||||
self.customSlide.title = unicode(self.TitleEdit.displayText())
|
||||
self.customSlide.text = unicode(sxml.extract_xml())
|
||||
self.customSlide.credits = unicode(self.CreditEdit.displayText())
|
||||
self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText())
|
||||
self.customSlide.title = unicode(self.TitleEdit.displayText(), u'utf-8')
|
||||
self.customSlide.text = unicode(sxml.extract_xml(), u'utf-8')
|
||||
self.customSlide.credits = unicode(self.CreditEdit.displayText(), u'utf-8')
|
||||
self.customSlide.theme_name = unicode(self.ThemeComboBox.currentText(), u'utf-8')
|
||||
self.custommanager.save_slide(self.customSlide)
|
||||
return True
|
||||
|
||||
@ -257,4 +257,4 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
|
||||
if len(self.VerseTextEdit.toPlainText()) > 0:
|
||||
self.VerseTextEdit.setFocus()
|
||||
return False, self.trUtf8('You have unsaved data')
|
||||
return True, u''
|
||||
return True, u''
|
||||
|
@ -185,8 +185,13 @@ class SongMediaItem(MediaManagerItem):
|
||||
if author_list != u'':
|
||||
author_list = author_list + u', '
|
||||
author_list = author_list + author.display_name
|
||||
song_detail = unicode(self.trUtf8('%s (%s)' % \
|
||||
(unicode(song.title), unicode(author_list))))
|
||||
if not isinstance(author_list, unicode):
|
||||
author_list = unicode(author_list, u'utf8')
|
||||
if isinstance(song.title, unicode):
|
||||
song_title = song.title
|
||||
else:
|
||||
song_title = unicode(song.title, u'utf8')
|
||||
song_detail = u'%s (%s)' % (song_title, author_list)
|
||||
song_name = QtGui.QListWidgetItem(song_detail)
|
||||
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
|
||||
self.ListView.addItem(song_name)
|
||||
@ -339,4 +344,4 @@ class SongMediaItem(MediaManagerItem):
|
||||
service_item.audit = [
|
||||
song.title, author_audit, song.copyright, song.ccli_number
|
||||
]
|
||||
return True
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user