forked from openlp/openlp
Merge in changes from lp:~raoul-snyman/openlp/biblesplugin
bzr-revno: 693
This commit is contained in:
commit
9be767a388
@ -66,13 +66,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
QtGui.QWizard.__init__(self, parent)
|
QtGui.QWizard.__init__(self, parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.registerFields()
|
self.registerFields()
|
||||||
self.web_bible_list = {}
|
|
||||||
self.finishButton = self.button(QtGui.QWizard.FinishButton)
|
self.finishButton = self.button(QtGui.QWizard.FinishButton)
|
||||||
self.cancelButton = self.button(QtGui.QWizard.CancelButton)
|
self.cancelButton = self.button(QtGui.QWizard.CancelButton)
|
||||||
self.biblemanager = biblemanager
|
self.biblemanager = biblemanager
|
||||||
self.config = config
|
self.config = config
|
||||||
self.bibleplugin = bibleplugin
|
self.bibleplugin = bibleplugin
|
||||||
self.biblemanager.process_dialog(self)
|
self.biblemanager.set_process_dialog(self)
|
||||||
|
self.web_bible_list = {}
|
||||||
self.loadWebBibles()
|
self.loadWebBibles()
|
||||||
QtCore.QObject.connect(self.LocationComboBox,
|
QtCore.QObject.connect(self.LocationComboBox,
|
||||||
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
||||||
@ -89,6 +89,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
QtCore.QObject.connect(self.OpenSongBrowseButton,
|
QtCore.QObject.connect(self.OpenSongBrowseButton,
|
||||||
QtCore.SIGNAL(u'clicked()'),
|
QtCore.SIGNAL(u'clicked()'),
|
||||||
self.onOpenSongBrowseButtonClicked)
|
self.onOpenSongBrowseButtonClicked)
|
||||||
|
QtCore.QObject.connect(self.cancelButton,
|
||||||
|
QtCore.SIGNAL(u'clicked(bool)'),
|
||||||
|
self.onCancelButtonClicked)
|
||||||
QtCore.QObject.connect(self,
|
QtCore.QObject.connect(self,
|
||||||
QtCore.SIGNAL(u'currentIdChanged(int)'),
|
QtCore.SIGNAL(u'currentIdChanged(int)'),
|
||||||
self.onCurrentIdChanged)
|
self.onCurrentIdChanged)
|
||||||
@ -192,6 +195,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
self.getFileName(self.trUtf8('Open OpenSong Bible'),
|
self.getFileName(self.trUtf8('Open OpenSong Bible'),
|
||||||
self.OpenSongFileEdit)
|
self.OpenSongFileEdit)
|
||||||
|
|
||||||
|
def onCancelButtonClicked(self, checked):
|
||||||
|
log.debug('Cancel button pressed!')
|
||||||
|
if self.currentId() == 3:
|
||||||
|
Receiver.send_message(u'openlpstopimport')
|
||||||
|
|
||||||
def onCurrentIdChanged(self, id):
|
def onCurrentIdChanged(self, id):
|
||||||
if id == 3:
|
if id == 3:
|
||||||
self.preImport()
|
self.preImport()
|
||||||
@ -297,8 +305,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
|
|
||||||
def preImport(self):
|
def preImport(self):
|
||||||
self.finishButton.setEnabled(False)
|
self.finishButton.setVisible(False)
|
||||||
self.cancelButton.setVisible(False)
|
|
||||||
self.ImportProgressBar.setMinimum(0)
|
self.ImportProgressBar.setMinimum(0)
|
||||||
self.ImportProgressBar.setMaximum(1188)
|
self.ImportProgressBar.setMaximum(1188)
|
||||||
self.ImportProgressBar.setValue(0)
|
self.ImportProgressBar.setValue(0)
|
||||||
@ -352,13 +359,14 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
|||||||
unicode(self.field(u'license_copyright').toString()),
|
unicode(self.field(u'license_copyright').toString()),
|
||||||
unicode(self.field(u'license_permission').toString())
|
unicode(self.field(u'license_permission').toString())
|
||||||
)
|
)
|
||||||
|
self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
|
||||||
else:
|
else:
|
||||||
self.ImportProgressLabel.setText(
|
self.ImportProgressLabel.setText(
|
||||||
self.trUtf8('Your Bible import failed.'))
|
self.trUtf8('Your Bible import failed.'))
|
||||||
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
|
||||||
|
|
||||||
def postImport(self):
|
def postImport(self):
|
||||||
self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
|
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
||||||
self.finishButton.setEnabled(True)
|
self.finishButton.setVisible(True)
|
||||||
|
self.cancelButton.setVisible(False)
|
||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ class BibleCSVImpl(BibleCommon):
|
|||||||
|
|
||||||
def load_data(self, booksfile, versesfile, dialogobject):
|
def load_data(self, booksfile, versesfile, dialogobject):
|
||||||
#Populate the Tables
|
#Populate the Tables
|
||||||
|
success = True
|
||||||
fbooks = None
|
fbooks = None
|
||||||
try:
|
try:
|
||||||
fbooks = open(booksfile, 'r')
|
fbooks = open(booksfile, 'r')
|
||||||
@ -71,10 +72,12 @@ class BibleCSVImpl(BibleCommon):
|
|||||||
count = 0
|
count = 0
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading books from file failed')
|
log.exception(u'Loading books from file failed')
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
if fbooks:
|
if fbooks:
|
||||||
fbooks.close()
|
fbooks.close()
|
||||||
|
if not success:
|
||||||
|
return False
|
||||||
fverse = None
|
fverse = None
|
||||||
try:
|
try:
|
||||||
fverse = open(versesfile, 'r')
|
fverse = open(versesfile, 'r')
|
||||||
@ -104,6 +107,14 @@ class BibleCSVImpl(BibleCommon):
|
|||||||
self.bibledb.save_verses()
|
self.bibledb.save_verses()
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading verses from file failed')
|
log.exception(u'Loading verses from file failed')
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
if fverse:
|
if fverse:
|
||||||
fverse.close()
|
fverse.close()
|
||||||
|
if not self.loadbible:
|
||||||
|
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||||
|
dialogobject.ImportProgressBar.setValue(
|
||||||
|
dialogobject.ImportProgressBar.maximum())
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return success
|
||||||
|
@ -91,6 +91,7 @@ class BibleOSISImpl():
|
|||||||
"""
|
"""
|
||||||
Stops the import of the Bible.
|
Stops the import of the Bible.
|
||||||
"""
|
"""
|
||||||
|
log.debug('Stopping import!')
|
||||||
self.loadbible = False
|
self.loadbible = False
|
||||||
|
|
||||||
def load_data(self, osisfile_record, dialogobject=None):
|
def load_data(self, osisfile_record, dialogobject=None):
|
||||||
@ -116,19 +117,23 @@ class BibleOSISImpl():
|
|||||||
if detect_file:
|
if detect_file:
|
||||||
detect_file.close()
|
detect_file.close()
|
||||||
osis = None
|
osis = None
|
||||||
|
success = True
|
||||||
try:
|
try:
|
||||||
osis = codecs.open(osisfile_record, u'r', details['encoding'])
|
osis = codecs.open(osisfile_record, u'r', details['encoding'])
|
||||||
last_chapter = 0
|
last_chapter = 0
|
||||||
testament = 1
|
testament = 1
|
||||||
db_book = None
|
db_book = None
|
||||||
for file_record in osis:
|
for file_record in osis:
|
||||||
|
if not self.loadbible:
|
||||||
|
break
|
||||||
match = self.verse_regex.search(file_record)
|
match = self.verse_regex.search(file_record)
|
||||||
if match:
|
if match:
|
||||||
book = match.group(1)
|
book = match.group(1)
|
||||||
chapter = int(match.group(2))
|
chapter = int(match.group(2))
|
||||||
verse = int(match.group(3))
|
verse = int(match.group(3))
|
||||||
verse_text = match.group(4)
|
verse_text = match.group(4)
|
||||||
if not db_book or db_book.name != book:
|
if not db_book or db_book.name != self.books[book][0]:
|
||||||
|
log.debug('New book: "%s"', self.books[book][0])
|
||||||
if book == u'Matt':
|
if book == u'Matt':
|
||||||
testament += 1
|
testament += 1
|
||||||
db_book = self.bibledb.create_book(
|
db_book = self.bibledb.create_book(
|
||||||
@ -166,11 +171,19 @@ class BibleOSISImpl():
|
|||||||
.replace(u'</div>', u'')
|
.replace(u'</div>', u'')
|
||||||
verse_text = self.spaces_regex.sub(u' ', verse_text)
|
verse_text = self.spaces_regex.sub(u' ', verse_text)
|
||||||
self.bibledb.add_verse(db_book.id, chapter, verse, verse_text)
|
self.bibledb.add_verse(db_book.id, chapter, verse, verse_text)
|
||||||
|
Receiver.send_message(u'process_events')
|
||||||
self.bibledb.save_verses()
|
self.bibledb.save_verses()
|
||||||
dialogobject.incrementProgressBar(u'Finishing import...')
|
dialogobject.incrementProgressBar(u'Finishing import...')
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading bible from OSIS file failed')
|
log.exception(u'Loading bible from OSIS file failed')
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
if osis:
|
if osis:
|
||||||
osis.close()
|
osis.close()
|
||||||
|
if not self.loadbible:
|
||||||
|
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||||
|
dialogobject.ImportProgressBar.setValue(
|
||||||
|
dialogobject.ImportProgressBar.maximum())
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return success
|
||||||
|
@ -89,15 +89,22 @@ class BibleOpenSongImpl():
|
|||||||
if detect_file:
|
if detect_file:
|
||||||
detect_file.close()
|
detect_file.close()
|
||||||
opensong_bible = None
|
opensong_bible = None
|
||||||
|
success = True
|
||||||
try:
|
try:
|
||||||
opensong_bible = codecs.open(bible_file, u'r', details['encoding'])
|
opensong_bible = codecs.open(bible_file, u'r', details['encoding'])
|
||||||
opensong = objectify.parse(opensong_bible)
|
opensong = objectify.parse(opensong_bible)
|
||||||
bible = opensong.getroot()
|
bible = opensong.getroot()
|
||||||
for book in bible.b:
|
for book in bible.b:
|
||||||
|
if not self.loadbible:
|
||||||
|
break
|
||||||
dbbook = self.bibledb.create_book(book.attrib[u'n'],
|
dbbook = self.bibledb.create_book(book.attrib[u'n'],
|
||||||
book.attrib[u'n'][:4])
|
book.attrib[u'n'][:4])
|
||||||
for chapter in book.c:
|
for chapter in book.c:
|
||||||
|
if not self.loadbible:
|
||||||
|
break
|
||||||
for verse in chapter.v:
|
for verse in chapter.v:
|
||||||
|
if not self.loadbible:
|
||||||
|
break
|
||||||
self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'],
|
self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'],
|
||||||
verse.attrib[u'n'], verse.text)
|
verse.attrib[u'n'], verse.text)
|
||||||
Receiver.send_message(u'process_events')
|
Receiver.send_message(u'process_events')
|
||||||
@ -106,7 +113,15 @@ class BibleOpenSongImpl():
|
|||||||
self.bibledb.save_verses()
|
self.bibledb.save_verses()
|
||||||
except:
|
except:
|
||||||
log.exception(u'Loading bible from OpenSong file failed')
|
log.exception(u'Loading bible from OpenSong file failed')
|
||||||
|
success = False
|
||||||
finally:
|
finally:
|
||||||
if opensong_bible:
|
if opensong_bible:
|
||||||
opensong_bible.close()
|
opensong_bible.close()
|
||||||
|
if not self.loadbible:
|
||||||
|
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||||
|
dialogobject.ImportProgressBar.setValue(
|
||||||
|
dialogobject.ImportProgressBar.maximum())
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return success
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class BibleManager(object):
|
|||||||
fbibles.close()
|
fbibles.close()
|
||||||
log.debug(u'Bible Initialised')
|
log.debug(u'Bible Initialised')
|
||||||
|
|
||||||
def process_dialog(self, dialogobject):
|
def set_process_dialog(self, dialogobject):
|
||||||
"""
|
"""
|
||||||
Sets the reference to the dialog with the progress bar on it.
|
Sets the reference to the dialog with the progress bar on it.
|
||||||
|
|
||||||
@ -246,8 +246,7 @@ class BibleManager(object):
|
|||||||
self.bible_db_cache[biblename] = nbible
|
self.bible_db_cache[biblename] = nbible
|
||||||
# Create the loader and pass in the database
|
# Create the loader and pass in the database
|
||||||
bcsv = BibleCSVImpl(nbible)
|
bcsv = BibleCSVImpl(nbible)
|
||||||
bcsv.load_data(booksfile, versefile, self.dialogobject)
|
return bcsv.load_data(booksfile, versefile, self.dialogobject)
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
log.debug(u'register_csv_file_bible %s not created already exists',
|
log.debug(u'register_csv_file_bible %s not created already exists',
|
||||||
biblename)
|
biblename)
|
||||||
@ -268,9 +267,8 @@ class BibleManager(object):
|
|||||||
# Cache the database for use later
|
# Cache the database for use later
|
||||||
self.bible_db_cache[biblename] = nbible
|
self.bible_db_cache[biblename] = nbible
|
||||||
# Create the loader and pass in the database
|
# Create the loader and pass in the database
|
||||||
bcsv = BibleOSISImpl(self.biblePath, nbible)
|
bosis = BibleOSISImpl(self.biblePath, nbible)
|
||||||
bcsv.load_data(osisfile, self.dialogobject)
|
return bosis.load_data(osisfile, self.dialogobject)
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
log.debug(
|
log.debug(
|
||||||
u'register_OSIS_file_bible %s, %s not created already exists',
|
u'register_OSIS_file_bible %s, %s not created already exists',
|
||||||
|
@ -1 +1 @@
|
|||||||
1.9.0-692
|
1.9.0-693
|
||||||
|
Loading…
Reference in New Issue
Block a user