2011-03-17 18:36:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2022-02-06 09:10:17 +00:00
|
|
|
# Copyright (c) 2008-2022 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2011-03-17 18:36:54 +00:00
|
|
|
|
|
|
|
"""
|
2011-04-01 20:26:25 +00:00
|
|
|
Module implementing BookNameForm.
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
|
|
|
import logging
|
2012-04-20 19:14:23 +00:00
|
|
|
import re
|
2011-03-17 18:36:54 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore
|
2017-12-28 08:08:12 +00:00
|
|
|
from PyQt5.QtWidgets import QDialog
|
2011-03-17 18:36:54 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2011-03-17 18:36:54 +00:00
|
|
|
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
|
2012-04-18 20:44:09 +00:00
|
|
|
from openlp.plugins.bibles.lib import BibleStrings
|
2011-03-17 18:36:54 +00:00
|
|
|
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2011-03-17 18:36:54 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-03-14 22:22:18 +00:00
|
|
|
|
2011-04-01 20:26:25 +00:00
|
|
|
class BookNameForm(QDialog, Ui_BookNameDialog):
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
2012-04-04 07:26:51 +00:00
|
|
|
Class to manage a dialog which help the user to refer a book name a
|
2011-04-02 19:17:48 +00:00
|
|
|
to a english book name
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('BookNameForm loaded')
|
2012-04-04 07:26:51 +00:00
|
|
|
|
2014-03-21 18:23:35 +00:00
|
|
|
def __init__(self, parent=None):
|
2011-03-17 18:36:54 +00:00
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2017-06-04 12:14:23 +00:00
|
|
|
super(BookNameForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
|
|
|
|
QtCore.Qt.WindowCloseButtonHint)
|
2018-09-12 05:43:27 +00:00
|
|
|
self.setup_ui(self)
|
2013-03-14 22:22:18 +00:00
|
|
|
self.custom_signals()
|
2012-04-21 22:29:08 +00:00
|
|
|
self.book_names = BibleStrings().BookNames
|
2012-04-20 19:14:23 +00:00
|
|
|
self.book_id = False
|
2011-03-17 18:36:54 +00:00
|
|
|
|
2013-03-14 22:22:18 +00:00
|
|
|
def custom_signals(self):
|
2011-05-03 11:44:23 +00:00
|
|
|
"""
|
|
|
|
Set up the signals used in the booknameform.
|
|
|
|
"""
|
2014-03-21 18:23:35 +00:00
|
|
|
self.old_testament_check_box.stateChanged.connect(self.on_check_box_index_changed)
|
|
|
|
self.new_testament_check_box.stateChanged.connect(self.on_check_box_index_changed)
|
|
|
|
self.apocrypha_check_box.stateChanged.connect(self.on_check_box_index_changed)
|
2011-05-03 11:44:23 +00:00
|
|
|
|
2014-03-21 18:23:35 +00:00
|
|
|
def on_check_box_index_changed(self, index):
|
2011-06-01 06:24:35 +00:00
|
|
|
"""
|
2011-05-03 11:44:23 +00:00
|
|
|
Reload Combobox if CheckBox state has changed
|
2011-06-01 06:24:35 +00:00
|
|
|
"""
|
2013-04-18 17:45:14 +00:00
|
|
|
self.reload_combo_box()
|
2011-05-03 11:44:23 +00:00
|
|
|
|
2013-04-18 17:45:14 +00:00
|
|
|
def reload_combo_box(self):
|
2011-06-01 06:24:35 +00:00
|
|
|
"""
|
2011-05-03 11:44:23 +00:00
|
|
|
Reload the Combobox items
|
2011-06-01 06:24:35 +00:00
|
|
|
"""
|
2013-04-18 17:45:14 +00:00
|
|
|
self.corresponding_combo_box.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:
|
2013-04-18 17:45:14 +00:00
|
|
|
add_book = True
|
2011-05-03 11:44:23 +00:00
|
|
|
for book in self.books:
|
2013-08-31 18:17:38 +00:00
|
|
|
if book.book_reference_id == item['id']:
|
2013-04-18 17:45:14 +00:00
|
|
|
add_book = False
|
2011-05-02 13:45:30 +00:00
|
|
|
break
|
2013-08-31 18:17:38 +00:00
|
|
|
if self.old_testament_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 1:
|
2013-04-18 17:45:14 +00:00
|
|
|
add_book = False
|
2013-08-31 18:17:38 +00:00
|
|
|
elif self.new_testament_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 2:
|
2013-04-18 17:45:14 +00:00
|
|
|
add_book = False
|
2013-08-31 18:17:38 +00:00
|
|
|
elif self.apocrypha_check_box.checkState() == QtCore.Qt.Unchecked and item['testament_id'] == 3:
|
2013-04-18 17:45:14 +00:00
|
|
|
add_book = False
|
|
|
|
if add_book:
|
2013-08-31 18:17:38 +00:00
|
|
|
self.corresponding_combo_box.addItem(self.book_names[item['abbreviation']])
|
2011-05-03 11:44:23 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
def exec(self, name, books, max_books):
|
2011-05-03 11:44:23 +00:00
|
|
|
self.books = books
|
2013-04-18 17:45:14 +00:00
|
|
|
log.debug(max_books)
|
|
|
|
if max_books <= 27:
|
|
|
|
self.old_testament_check_box.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
self.apocrypha_check_box.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
elif max_books <= 66:
|
|
|
|
self.apocrypha_check_box.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
self.reload_combo_box()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.current_book_label.setText(str(name))
|
2013-04-18 17:45:14 +00:00
|
|
|
self.corresponding_combo_box.setFocus()
|
2015-11-07 00:49:40 +00:00
|
|
|
return QDialog.exec(self)
|
2012-04-04 07:26:51 +00:00
|
|
|
|
2011-03-17 18:36:54 +00:00
|
|
|
def accept(self):
|
2013-04-18 17:45:14 +00:00
|
|
|
if not self.corresponding_combo_box.currentText():
|
2013-01-01 16:33:41 +00:00
|
|
|
critical_error_message_box(message=translate('BiblesPlugin.BookNameForm', 'You need to select a book.'))
|
2013-04-18 17:45:14 +00:00
|
|
|
self.corresponding_combo_box.setFocus()
|
2011-03-17 18:36:54 +00:00
|
|
|
return False
|
|
|
|
else:
|
2013-04-18 17:45:14 +00:00
|
|
|
cor_book = self.corresponding_combo_box.currentText()
|
2013-08-31 18:17:38 +00:00
|
|
|
for character in '\\.^$*+?{}[]()':
|
|
|
|
cor_book = cor_book.replace(character, '\\' + character)
|
2017-10-28 10:04:09 +00:00
|
|
|
books = [key for key in list(self.book_names.keys()) if re.match(cor_book, str(self.book_names[key]))]
|
2013-08-31 18:17:38 +00:00
|
|
|
books = [_f for _f in map(BiblesResourcesDB.get_book, books) if _f]
|
2012-04-20 19:14:23 +00:00
|
|
|
if books:
|
2013-08-31 18:17:38 +00:00
|
|
|
self.book_id = books[0]['id']
|
2011-03-17 18:36:54 +00:00
|
|
|
return QDialog.accept(self)
|