From d44b42aaff0049ddb318e8a2e530182ab04e7d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20K=C3=B6hler?= Date: Tue, 3 May 2011 13:44:23 +0200 Subject: [PATCH] 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) --- .../plugins/bibles/forms/bibleupgradeform.py | 5 +- openlp/plugins/bibles/forms/booknamedialog.py | 33 ++++++++++-- openlp/plugins/bibles/forms/booknameform.py | 51 +++++++++++++++++-- openlp/plugins/bibles/lib/csvbible.py | 2 +- openlp/plugins/bibles/lib/db.py | 4 +- openlp/plugins/bibles/lib/http.py | 3 +- openlp/plugins/bibles/lib/openlp1.py | 3 +- openlp/plugins/bibles/lib/opensong.py | 2 +- openlp/plugins/bibles/lib/osis.py | 4 +- 9 files changed, 89 insertions(+), 18 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 220942b42..4feb4bd90 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -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) diff --git a/openlp/plugins/bibles/forms/booknamedialog.py b/openlp/plugins/bibles/forms/booknamedialog.py index bb48548c0..ad30812bc 100644 --- a/openlp/plugins/bibles/forms/booknamedialog.py +++ b/openlp/plugins/bibles/forms/booknamedialog.py @@ -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')) diff --git a/openlp/plugins/bibles/forms/booknameform.py b/openlp/plugins/bibles/forms/booknameform.py index 84e1deb96..4ad8270e6 100644 --- a/openlp/plugins/bibles/forms/booknameform.py +++ b/openlp/plugins/bibles/forms/booknameform.py @@ -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): diff --git a/openlp/plugins/bibles/lib/csvbible.py b/openlp/plugins/bibles/lib/csvbible.py index 80216a73e..a5fe59ccc 100644 --- a/openlp/plugins/bibles/lib/csvbible.py +++ b/openlp/plugins/bibles/lib/csvbible.py @@ -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) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 2311c7f00..be3beac2f 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -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 diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index fb60a2b1a..a7f8d1b7e 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -422,7 +422,8 @@ class HTTPBible(BibleDB): self.wizard.incrementProgressBar(unicode(translate( 'BiblesPlugin.HTTPBible', 'Importing %s...', 'Importing ...')) % 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)) diff --git a/openlp/plugins/bibles/lib/openlp1.py b/openlp/plugins/bibles/lib/openlp1.py index 0ed22797e..f1104ffc2 100644 --- a/openlp/plugins/bibles/lib/openlp1.py +++ b/openlp/plugins/bibles/lib/openlp1.py @@ -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) diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index fd79cd440..48a6dc6e3 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -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) diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index 2735648ce..b9039677b 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -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)