forked from openlp/openlp
improve BookNameForm (add possibility to reduce the books in the ComboBox and try to autodetect if a bible only contains only parts of a bible, so that only a part of the bible books are displayed at startup)
This commit is contained in:
parent
907434c705
commit
d44b42aaff
|
@ -582,7 +582,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||
'Importing %s ...')) %
|
||||
(number+1, self.maxBibles, name, book))
|
||||
book_ref_id = self.newbibles[number].\
|
||||
get_book_ref_id_by_name(book, language_id)
|
||||
get_book_ref_id_by_name(book, len(books), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s - download '\
|
||||
u'name: "%s" aborted by user' % (
|
||||
|
@ -623,7 +623,8 @@ class BibleUpgradeForm(OpenLPWizard):
|
|||
'Importing %s ...')) %
|
||||
(number+1, self.maxBibles, name, book[u'name']))
|
||||
book_ref_id = self.newbibles[number].\
|
||||
get_book_ref_id_by_name(book[u'name'], language_id)
|
||||
get_book_ref_id_by_name(book[u'name'], len(books),
|
||||
language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s " '\
|
||||
'failed - aborted by user' % name)
|
||||
|
|
|
@ -32,7 +32,7 @@ from openlp.core.lib.ui import create_accept_reject_button_box
|
|||
class Ui_BookNameDialog(object):
|
||||
def setupUi(self, bookNameDialog):
|
||||
bookNameDialog.setObjectName(u'BookNameDialog')
|
||||
bookNameDialog.resize(400, 175)
|
||||
bookNameDialog.resize(400, 275)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
|
||||
QtGui.QSizePolicy.MinimumExpanding)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
|
@ -41,7 +41,7 @@ class Ui_BookNameDialog(object):
|
|||
.hasHeightForWidth())
|
||||
bookNameDialog.setSizePolicy(sizePolicy)
|
||||
self.widget = QtGui.QWidget(bookNameDialog)
|
||||
self.widget.setGeometry(QtCore.QRect(10, 15, 381, 151))
|
||||
self.widget.setGeometry(QtCore.QRect(10, 15, 381, 251))
|
||||
self.widget.setObjectName(u'widget')
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
|
||||
self.verticalLayout.setObjectName(u'verticalLayout')
|
||||
|
@ -75,13 +75,28 @@ class Ui_BookNameDialog(object):
|
|||
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
|
||||
self.requestComboBox)
|
||||
self.verticalLayout.addLayout(self.formLayout)
|
||||
self.infoLabelTestaments = QtGui.QLabel(self.widget)
|
||||
self.infoLabelTestaments.setObjectName(u'InfoLabelTestaments')
|
||||
self.verticalLayout.addWidget(self.infoLabelTestaments)
|
||||
self.checkBoxOldTestament = QtGui.QCheckBox(self.widget)
|
||||
self.checkBoxOldTestament.setObjectName(u'OldTestament')
|
||||
self.checkBoxOldTestament.setCheckState(2)
|
||||
self.verticalLayout.addWidget(self.checkBoxOldTestament)
|
||||
self.checkBoxNewTestament = QtGui.QCheckBox(self.widget)
|
||||
self.checkBoxNewTestament.setObjectName(u'OldTestament')
|
||||
self.checkBoxNewTestament.setCheckState(2)
|
||||
self.verticalLayout.addWidget(self.checkBoxNewTestament)
|
||||
self.checkBoxApocrypha = QtGui.QCheckBox(self.widget)
|
||||
self.checkBoxApocrypha.setObjectName(u'OldTestament')
|
||||
self.checkBoxApocrypha.setCheckState(2)
|
||||
self.verticalLayout.addWidget(self.checkBoxApocrypha)
|
||||
self.verticalLayout.addWidget(
|
||||
create_accept_reject_button_box(bookNameDialog))
|
||||
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
|
||||
QtGui.QSizePolicy.Expanding)
|
||||
self.verticalLayout.addItem(spacerItem)
|
||||
self.formLayout.addWidget(
|
||||
create_accept_reject_button_box(bookNameDialog))
|
||||
self.retranslateUi(bookNameDialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(bookNameDialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
def retranslateUi(self, bookNameDialog):
|
||||
bookNameDialog.setWindowTitle(
|
||||
|
@ -93,3 +108,11 @@ class Ui_BookNameDialog(object):
|
|||
'Please choose the book it is.'))
|
||||
self.requestLabel.setText(translate('BiblesPlugin.BookNameDialog',
|
||||
'Book:'))
|
||||
self.infoLabelTestaments.setText(translate(
|
||||
'BiblesPlugin.BookNameDialog', 'Show books from:'))
|
||||
self.checkBoxOldTestament.setText(translate(
|
||||
'BiblesPlugin.BookNameDialog', 'Old Testament'))
|
||||
self.checkBoxNewTestament.setText(translate(
|
||||
'BiblesPlugin.BookNameDialog', 'New Testament'))
|
||||
self.checkBoxApocrypha.setText(translate('BiblesPlugin.BookNameDialog',
|
||||
'Apocrypha'))
|
||||
|
|
|
@ -30,6 +30,7 @@ Module implementing BookNameForm.
|
|||
import logging
|
||||
|
||||
from PyQt4.QtGui import QDialog
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
|
@ -52,20 +53,64 @@ class BookNameForm(QDialog, Ui_BookNameDialog):
|
|||
"""
|
||||
QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.customSignals()
|
||||
|
||||
def exec_(self, name, books):
|
||||
def customSignals(self):
|
||||
"""
|
||||
Set up the signals used in the booknameform.
|
||||
"""
|
||||
QtCore.QObject.connect(self.checkBoxOldTestament,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'),
|
||||
self.onCheckBoxIndexChanged)
|
||||
QtCore.QObject.connect(self.checkBoxNewTestament,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'),
|
||||
self.onCheckBoxIndexChanged)
|
||||
QtCore.QObject.connect(self.checkBoxApocrypha,
|
||||
QtCore.SIGNAL(u'stateChanged(int)'),
|
||||
self.onCheckBoxIndexChanged)
|
||||
|
||||
def onCheckBoxIndexChanged(self, index):
|
||||
'''
|
||||
Reload Combobox if CheckBox state has changed
|
||||
'''
|
||||
self.reloadComboBox()
|
||||
|
||||
def reloadComboBox(self):
|
||||
'''
|
||||
Reload the Combobox items
|
||||
'''
|
||||
items = []
|
||||
self.requestComboBox.clear()
|
||||
self.requestComboBox.addItem(u'')
|
||||
self.requestLabel.setText(name)
|
||||
items = BiblesResourcesDB.get_books()
|
||||
for item in items:
|
||||
addBook = True
|
||||
for book in books:
|
||||
for book in self.books:
|
||||
if book.book_reference_id == item[u'id']:
|
||||
addBook = False
|
||||
break
|
||||
if self.checkBoxOldTestament.checkState() == 0 and \
|
||||
item[u'testament_id'] == 1:
|
||||
addBook = False
|
||||
elif self.checkBoxNewTestament.checkState() == 0 and \
|
||||
item[u'testament_id'] == 2:
|
||||
addBook = False
|
||||
elif self.checkBoxApocrypha.checkState() == 0 and \
|
||||
item[u'testament_id'] == 3:
|
||||
addBook = False
|
||||
if addBook == True:
|
||||
self.requestComboBox.addItem(item[u'name'])
|
||||
|
||||
def exec_(self, name, books, maxbooks):
|
||||
self.books = books
|
||||
log.debug(maxbooks)
|
||||
if maxbooks <= 27:
|
||||
self.checkBoxOldTestament.setCheckState(0)
|
||||
self.checkBoxApocrypha.setCheckState(0)
|
||||
elif maxbooks <= 66:
|
||||
self.checkBoxApocrypha.setCheckState(0)
|
||||
self.reloadComboBox()
|
||||
self.requestLabel.setText(name)
|
||||
return QDialog.exec_(self)
|
||||
|
||||
def accept(self):
|
||||
|
|
|
@ -118,7 +118,7 @@ class CSVBible(BibleDB):
|
|||
translate('BibleDB.Wizard', 'Importing books... %s')) %
|
||||
unicode(line[2], details['encoding']))
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(line[2], details['encoding']), language_id)
|
||||
unicode(line[2], details['encoding']), 67, language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from "%s" '\
|
||||
'failed' % self.booksfile)
|
||||
|
|
|
@ -327,7 +327,7 @@ class BibleDB(QtCore.QObject, Manager):
|
|||
log.debug(u'BibleDB.get_book_by_book_ref_id("%s")', id)
|
||||
return self.get_object_filtered(Book, Book.book_reference_id.like(id))
|
||||
|
||||
def get_book_ref_id_by_name(self, book, language_id=None):
|
||||
def get_book_ref_id_by_name(self, book, maxbooks, language_id=None):
|
||||
log.debug(u'BibleDB.get_book_ref_id_by_name:("%s", "%s")', book,
|
||||
language_id)
|
||||
if BiblesResourcesDB.get_book(book, True):
|
||||
|
@ -341,7 +341,7 @@ class BibleDB(QtCore.QObject, Manager):
|
|||
from openlp.plugins.bibles.forms import BookNameForm
|
||||
book_ref = None
|
||||
book_name = BookNameForm(self.wizard)
|
||||
if book_name.exec_(book, self.get_books()):
|
||||
if book_name.exec_(book, self.get_books(), maxbooks):
|
||||
book_ref = unicode(book_name.requestComboBox.currentText())
|
||||
if not book_ref:
|
||||
return None
|
||||
|
|
|
@ -422,7 +422,8 @@ class HTTPBible(BibleDB):
|
|||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible', 'Importing %s...',
|
||||
'Importing <book name>...')) % book)
|
||||
book_ref_id = self.get_book_ref_id_by_name(book, language_id)
|
||||
book_ref_id = self.get_book_ref_id_by_name(book, len(books),
|
||||
language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from %s - download name: "%s" '\
|
||||
'failed' % (self.download_source, self.download_name))
|
||||
|
|
|
@ -74,7 +74,8 @@ class OpenLP1Bible(BibleDB):
|
|||
testament_id = int(book[1])
|
||||
name = unicode(book[2], u'cp1252')
|
||||
abbreviation = unicode(book[3], u'cp1252')
|
||||
book_ref_id = self.get_book_ref_id_by_name(name, language_id)
|
||||
book_ref_id = self.get_book_ref_id_by_name(name, len(books),
|
||||
language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from "%s" '\
|
||||
'failed' % self.filename)
|
||||
|
|
|
@ -70,7 +70,7 @@ class OpenSongBible(BibleDB):
|
|||
if self.stop_import_flag:
|
||||
break
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(book.attrib[u'n']), language_id)
|
||||
unicode(book.attrib[u'n']), len(bible.b), language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from "%s" '\
|
||||
'failed' % self.filename)
|
||||
|
|
|
@ -128,8 +128,8 @@ class OSISBible(BibleDB):
|
|||
verse_text = match.group(4)
|
||||
if not db_book or db_book.name != self.books[book][0]:
|
||||
log.debug(u'New book: "%s"' % self.books[book][0])
|
||||
book_ref_id = self.get_book_ref_id_by_name(
|
||||
unicode(self.books[book][0]), language_id)
|
||||
book_ref_id = self.get_book_ref_id_by_name(unicode(
|
||||
self.books[book][0]), 67, language_id)
|
||||
if not book_ref_id:
|
||||
log.exception(u'Importing books from "%s" '\
|
||||
'failed' % self.filename)
|
||||
|
|
Loading…
Reference in New Issue