openlp/openlp/plugins/bibles/forms/booknameform.py

128 lines
5.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-01-01 16:33:41 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
Module implementing BookNameForm.
"""
import logging
import re
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
2013-01-01 16:33:41 +00:00
from openlp.plugins.bibles.forms.booknamedialog import Ui_BookNameDialog
from openlp.plugins.bibles.lib import BibleStrings
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
2013-03-14 22:22:18 +00:00
class BookNameForm(QDialog, Ui_BookNameDialog):
"""
2012-04-04 07:26:51 +00:00
Class to manage a dialog which help the user to refer a book name a
to a english book name
"""
log.info(u'BookNameForm loaded')
2012-04-04 07:26:51 +00:00
def __init__(self, parent = None):
"""
Constructor
"""
QDialog.__init__(self, parent)
self.setupUi(self)
2013-03-14 22:22:18 +00:00
self.custom_signals()
self.book_names = BibleStrings().BookNames
self.book_id = False
2013-03-14 22:22:18 +00:00
def custom_signals(self):
"""
Set up the signals used in the booknameform.
"""
self.oldTestamentCheckBox.stateChanged.connect(self.onCheckBoxIndexChanged)
self.newTestamentCheckBox.stateChanged.connect(self.onCheckBoxIndexChanged)
self.apocryphaCheckBox.stateChanged.connect(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()
items = BiblesResourcesDB.get_books()
for item in items:
addBook = True
for book in self.books:
if book.book_reference_id == item[u'id']:
addBook = False
break
2013-01-01 16:33:41 +00:00
if self.oldTestamentCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 1:
addBook = False
2013-01-01 16:33:41 +00:00
elif self.newTestamentCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 2:
addBook = False
2013-01-01 16:33:41 +00:00
elif self.apocryphaCheckBox.checkState() == QtCore.Qt.Unchecked and item[u'testament_id'] == 3:
addBook = False
2011-05-03 20:34:39 +00:00
if addBook:
2013-01-01 16:33:41 +00:00
self.correspondingComboBox.addItem(self.book_names[item[u'abbreviation']])
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)
elif maxbooks <= 66:
2011-05-26 20:38:07 +00:00
self.apocryphaCheckBox.setCheckState(QtCore.Qt.Unchecked)
self.reloadComboBox()
self.currentBookLabel.setText(unicode(name))
self.correspondingComboBox.setFocus()
return QDialog.exec_(self)
2012-04-04 07:26:51 +00:00
def accept(self):
2011-05-26 20:38:07 +00:00
if self.correspondingComboBox.currentText() == u'':
2013-01-01 16:33:41 +00:00
critical_error_message_box(message=translate('BiblesPlugin.BookNameForm', 'You need to select a book.'))
2011-05-26 20:38:07 +00:00
self.correspondingComboBox.setFocus()
return False
else:
2012-05-17 18:57:01 +00:00
cor_book = self.correspondingComboBox.currentText()
for character in u'\\.^$*+?{}[]()':
cor_book = cor_book.replace(character, u'\\' + character)
books = filter(lambda key:
2013-01-01 16:33:41 +00:00
re.match(cor_book, unicode(self.book_names[key]), re.UNICODE), self.book_names.keys())
books = filter(None, map(BiblesResourcesDB.get_book, books))
if books:
self.book_id = books[0][u'id']
return QDialog.accept(self)