2011-03-17 18:36:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
|
|
|
# Gorven, Scott Guerrieri, Meinert Jordan, Armin Köhler, Andreas Preikschat, #
|
|
|
|
# Christian Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon #
|
|
|
|
# Tibble, Carsten Tinggaard, Frode Woldsund #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
2011-04-01 20:26:25 +00:00
|
|
|
Module implementing BookNameForm.
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from PyQt4.QtGui import QDialog
|
2011-05-03 11:44:23 +00:00
|
|
|
from PyQt4 import QtCore
|
2011-03-17 18:36:54 +00:00
|
|
|
|
|
|
|
from openlp.core.lib import translate
|
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2011-04-01 20:26:25 +00:00
|
|
|
from openlp.plugins.bibles.forms.booknamedialog import \
|
|
|
|
Ui_BookNameDialog
|
2011-03-17 18:36:54 +00:00
|
|
|
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2011-04-01 20:26:25 +00:00
|
|
|
class BookNameForm(QDialog, Ui_BookNameDialog):
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
2011-04-02 19:17:48 +00:00
|
|
|
Class to manage a dialog which help the user to refer a book name a
|
|
|
|
to a english book name
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
2011-04-01 20:26:25 +00:00
|
|
|
log.info(u'BookNameForm loaded')
|
2011-03-17 18:36:54 +00:00
|
|
|
|
|
|
|
def __init__(self, parent = None):
|
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
|
|
|
QDialog.__init__(self, parent)
|
|
|
|
self.setupUi(self)
|
2011-05-03 11:44:23 +00:00
|
|
|
self.customSignals()
|
2011-03-17 18:36:54 +00:00
|
|
|
|
2011-05-03 11:44:23 +00:00
|
|
|
def customSignals(self):
|
|
|
|
"""
|
|
|
|
Set up the signals used in the booknameform.
|
|
|
|
"""
|
2011-05-26 20:38:07 +00:00
|
|
|
QtCore.QObject.connect(self.oldTestamentCheckBox,
|
2011-05-03 11:44:23 +00:00
|
|
|
QtCore.SIGNAL(u'stateChanged(int)'),
|
|
|
|
self.onCheckBoxIndexChanged)
|
2011-05-26 20:38:07 +00:00
|
|
|
QtCore.QObject.connect(self.newTestamentCheckBox,
|
2011-05-03 11:44:23 +00:00
|
|
|
QtCore.SIGNAL(u'stateChanged(int)'),
|
|
|
|
self.onCheckBoxIndexChanged)
|
2011-05-26 20:38:07 +00:00
|
|
|
QtCore.QObject.connect(self.apocryphaCheckBox,
|
2011-05-03 11:44:23 +00:00
|
|
|
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
|
|
|
|
'''
|
2011-05-26 20:38:07 +00:00
|
|
|
self.correspondingComboBox.clear()
|
2011-04-01 20:26:25 +00:00
|
|
|
items = BiblesResourcesDB.get_books()
|
2011-03-17 18:36:54 +00:00
|
|
|
for item in items:
|
2011-05-02 13:45:30 +00:00
|
|
|
addBook = True
|
2011-05-03 11:44:23 +00:00
|
|
|
for book in self.books:
|
2011-05-02 13:45:30 +00:00
|
|
|
if book.book_reference_id == item[u'id']:
|
|
|
|
addBook = False
|
|
|
|
break
|
2011-05-26 20:38:07 +00:00
|
|
|
if self.oldTestamentCheckBox.checkState() == QtCore.Qt.Unchecked \
|
2011-05-03 20:34:39 +00:00
|
|
|
and item[u'testament_id'] == 1:
|
2011-05-03 11:44:23 +00:00
|
|
|
addBook = False
|
2011-05-26 20:38:07 +00:00
|
|
|
elif self.newTestamentCheckBox.checkState() == QtCore.Qt.Unchecked \
|
2011-05-03 20:34:39 +00:00
|
|
|
and item[u'testament_id'] == 2:
|
2011-05-03 11:44:23 +00:00
|
|
|
addBook = False
|
2011-05-26 20:38:07 +00:00
|
|
|
elif self.apocryphaCheckBox.checkState() == QtCore.Qt.Unchecked \
|
2011-05-03 20:34:39 +00:00
|
|
|
and item[u'testament_id'] == 3:
|
2011-05-03 11:44:23 +00:00
|
|
|
addBook = False
|
2011-05-03 20:34:39 +00:00
|
|
|
if addBook:
|
2011-05-26 20:38:07 +00:00
|
|
|
self.correspondingComboBox.addItem(item[u'name'])
|
2011-05-03 11:44:23 +00:00
|
|
|
|
|
|
|
def exec_(self, name, books, maxbooks):
|
|
|
|
self.books = books
|
|
|
|
log.debug(maxbooks)
|
|
|
|
if maxbooks <= 27:
|
2011-05-26 20:38:07 +00:00
|
|
|
self.oldTestamentCheckBox.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
self.apocryphaCheckBox.setCheckState(QtCore.Qt.Unchecked)
|
2011-05-03 11:44:23 +00:00
|
|
|
elif maxbooks <= 66:
|
2011-05-26 20:38:07 +00:00
|
|
|
self.apocryphaCheckBox.setCheckState(QtCore.Qt.Unchecked)
|
2011-05-03 11:44:23 +00:00
|
|
|
self.reloadComboBox()
|
2011-05-27 20:33:23 +00:00
|
|
|
self.currentBookLabel.setText(unicode(name))
|
2011-05-27 09:39:58 +00:00
|
|
|
self.correspondingComboBox.setFocus()
|
2011-03-17 18:36:54 +00:00
|
|
|
return QDialog.exec_(self)
|
|
|
|
|
|
|
|
def accept(self):
|
2011-05-26 20:38:07 +00:00
|
|
|
if self.correspondingComboBox.currentText() == u'':
|
2011-03-17 18:36:54 +00:00
|
|
|
critical_error_message_box(
|
2011-04-01 20:26:25 +00:00
|
|
|
message=translate('BiblesPlugin.BookNameForm',
|
2011-05-25 19:13:37 +00:00
|
|
|
'You need to select a book.'))
|
2011-05-26 20:38:07 +00:00
|
|
|
self.correspondingComboBox.setFocus()
|
2011-03-17 18:36:54 +00:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return QDialog.accept(self)
|