split BibleImportRequest in BookNameForm and LanugageForm

This commit is contained in:
Armin Köhler 2011-04-01 22:26:25 +02:00
parent 1923faf18a
commit c04a76e12d
13 changed files with 221 additions and 53 deletions

View File

@ -52,6 +52,7 @@ from the .ui files later if necessary.
"""
from bibleimportform import BibleImportForm
from bibleimportrequestform import BibleImportRequest
from booknameform import BookNameForm
from languageform import LanguageForm
__all__ = ['BibleImportForm']

View File

@ -29,18 +29,18 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate
from openlp.core.lib.ui import create_accept_reject_button_box
class Ui_BibleImportRequest(object):
def setupUi(self, bibleImportRequest):
bibleImportRequest.setObjectName("BibleImportRequest")
bibleImportRequest.resize(400, 175)
class Ui_BookNameDialog(object):
def setupUi(self, bookNameDialog):
bookNameDialog.setObjectName("BookNameDialog")
bookNameDialog.resize(400, 175)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(bibleImportRequest.sizePolicy()
sizePolicy.setHeightForWidth(bookNameDialog.sizePolicy()
.hasHeightForWidth())
bibleImportRequest.setSizePolicy(sizePolicy)
self.widget = QtGui.QWidget(bibleImportRequest)
bookNameDialog.setSizePolicy(sizePolicy)
self.widget = QtGui.QWidget(bookNameDialog)
self.widget.setGeometry(QtCore.QRect(10, 15, 381, 151))
self.widget.setObjectName("widget")
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
@ -79,17 +79,17 @@ class Ui_BibleImportRequest(object):
QtGui.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.formLayout.addWidget(
create_accept_reject_button_box(bibleImportRequest))
self.retranslateUi(bibleImportRequest)
QtCore.QMetaObject.connectSlotsByName(bibleImportRequest)
create_accept_reject_button_box(bookNameDialog))
self.retranslateUi(bookNameDialog)
QtCore.QMetaObject.connectSlotsByName(bookNameDialog)
def retranslateUi(self, bibleImportRequest):
bibleImportRequest.setWindowTitle(
translate("BiblesPlugin.bibleImportRequest", "Dialog"))
def retranslateUi(self, bookNameDialog):
bookNameDialog.setWindowTitle(
translate("BiblesPlugin.BookNameDialog", "Choose Book"))
self.headlineLabel.setText(
translate("BiblesPlugin.bibleImportRequest", "Choose Book:"))
self.infoLabel.setText(translate("BiblesPlugin.bibleImportRequest",
translate("BiblesPlugin.BookNameDialog", "Choose Book:"))
self.infoLabel.setText(translate("BiblesPlugin.BookNameDialog",
"The following books cannot be clearly attributed. \n"
"Please choose the book it is."))
self.requestLabel.setText(translate("BiblesPlugin.bibleImportRequest",
self.requestLabel.setText(translate("BiblesPlugin.BookNameDialog",
"Book:"))

View File

@ -25,7 +25,7 @@
###############################################################################
"""
Module implementing BibleImportRequest.
Module implementing BookNameForm.
"""
import logging
@ -33,17 +33,17 @@ from PyQt4.QtGui import QDialog
from openlp.core.lib import translate
from openlp.core.lib.ui import critical_error_message_box
from openlp.plugins.bibles.forms.bibleimportrequestdialog import \
Ui_BibleImportRequest
from openlp.plugins.bibles.forms.booknamedialog import \
Ui_BookNameDialog
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
class BibleImportRequest(QDialog, Ui_BibleImportRequest):
class BookNameForm(QDialog, Ui_BookNameDialog):
"""
Class documentation goes here.
"""
log.info(u'BibleImportRequest loaded')
log.info(u'BookNameForm loaded')
def __init__(self, parent = None):
"""
@ -52,21 +52,12 @@ class BibleImportRequest(QDialog, Ui_BibleImportRequest):
QDialog.__init__(self, parent)
self.setupUi(self)
def exec_(self, case, name=None):
def exec_(self, name):
items = []
self.requestComboBox.addItem(u'')
if case == u'language':
self.headlineLabel.setText(translate(
"BiblesPlugin.BibleImportRequest", "Choose Language:"))
self.infoLabel.setText(translate("BiblesPlugin.BibleImportRequest",
"Please choose the language the bible is."))
self.requestLabel.setText(
translate("BiblesPlugin.BibleImportRequest", "Language:"))
items = BiblesResourcesDB.get_languages()
elif case == u'book':
self.requestLabel.setText(
translate("BiblesPlugin.BibleImportRequest", name))
items = BiblesResourcesDB.get_books()
self.requestLabel.setText(
translate("BiblesPlugin.BookNameForm", name))
items = BiblesResourcesDB.get_books()
for item in items:
self.requestComboBox.addItem(item[u'name'])
return QDialog.exec_(self)
@ -74,8 +65,8 @@ class BibleImportRequest(QDialog, Ui_BibleImportRequest):
def accept(self):
if self.requestComboBox.currentText() == u"":
critical_error_message_box(
message=translate('BiblesPlugin.BibleImportRequest',
'You need to choose an item.'))
message=translate('BiblesPlugin.BookNameForm',
'You need to choose a book.'))
self.requestComboBox.setFocus()
return False
else:

View File

@ -0,0 +1,94 @@
# -*- 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 #
###############################################################################
from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate
from openlp.core.lib.ui import create_accept_reject_button_box
class Ui_LanguageDialog(object):
def setupUi(self, languageDialog):
languageDialog.setObjectName("LanugageDialog")
languageDialog.resize(400, 175)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(languageDialog.sizePolicy()
.hasHeightForWidth())
languageDialog.setSizePolicy(sizePolicy)
self.widget = QtGui.QWidget(languageDialog)
self.widget.setGeometry(QtCore.QRect(10, 15, 381, 151))
self.widget.setObjectName("widget")
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
self.verticalLayout.setObjectName("verticalLayout")
self.headlineLabel = QtGui.QLabel(self.widget)
font = QtGui.QFont()
font.setFamily("Arial")
font.setPointSize(11)
font.setWeight(75)
font.setBold(True)
self.headlineLabel.setFont(font)
self.headlineLabel.setObjectName("HeadlineLabel")
self.verticalLayout.addWidget(self.headlineLabel)
self.infoLabel = QtGui.QLabel(self.widget)
self.infoLabel.setObjectName("InfoLabel")
self.verticalLayout.addWidget(self.infoLabel)
self.formLayout = QtGui.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.requestLabel = QtGui.QLabel(self.widget)
self.requestLabel.setObjectName("RequestLabel")
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole,
self.requestLabel)
self.requestComboBox = QtGui.QComboBox(self.widget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.requestComboBox.sizePolicy()
.hasHeightForWidth())
self.requestComboBox.setSizePolicy(sizePolicy)
self.requestComboBox.setObjectName("RequestComboBox")
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole,
self.requestComboBox)
self.verticalLayout.addLayout(self.formLayout)
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
QtGui.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.formLayout.addWidget(
create_accept_reject_button_box(languageDialog))
self.retranslateUi(languageDialog)
QtCore.QMetaObject.connectSlotsByName(languageDialog)
def retranslateUi(self, languageDialog):
languageDialog.setWindowTitle(
translate("BiblesPlugin.LanguageDialog", "Choose Language"))
self.headlineLabel.setText(
translate("BiblesPlugin.LanguageDialog", "Choose Language:"))
self.infoLabel.setText(translate("BiblesPlugin.LanguageDialog",
"Please choose the language the bible is."))
self.requestLabel.setText(translate("BiblesPlugin.languageDialog",
"Language:"))

View File

@ -0,0 +1,71 @@
# -*- 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 #
###############################################################################
"""
Module implementing BookNameForm.
"""
import logging
from PyQt4.QtGui import QDialog
from openlp.core.lib import translate
from openlp.core.lib.ui import critical_error_message_box
from openlp.plugins.bibles.forms.languagedialog import \
Ui_LanguageDialog
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
class LanguageForm(QDialog, Ui_LanguageDialog):
"""
Class documentation goes here.
"""
log.info(u'LanguageForm loaded')
def __init__(self, parent = None):
"""
Constructor
"""
QDialog.__init__(self, parent)
self.setupUi(self)
def exec_(self):
items = []
self.requestComboBox.addItem(u'')
items = BiblesResourcesDB.get_languages()
for item in items:
self.requestComboBox.addItem(item[u'name'])
return QDialog.exec_(self)
def accept(self):
if self.requestComboBox.currentText() == u"":
critical_error_message_box(
message=translate('BiblesPlugin.LanguageForm',
'You need to choose a language.'))
self.requestComboBox.setFocus()
return False
else:
return QDialog.accept(self)

View File

@ -139,7 +139,7 @@ class CSVBible(BibleDB):
self.wizard.progressBar.setMinimum(0)
self.wizard.progressBar.setMaximum(66)
success = True
language = self.parent.mediaItem.importRequest(u'language')
language = self.parent.mediaItem.languageDialog()
if not language:
log.exception(u'Importing books from %s " '\
'failed' % self.booksfile)

View File

@ -198,7 +198,7 @@ class BibleDB(QtCore.QObject, Manager):
self.file = self.clean_filename(self.name)
if u'file' in kwargs:
self.file = kwargs[u'file']
Manager.__init__(self, u'bibles', init_schema, self.file)
Manager.__init__(self, u'bibles/bibles', init_schema, self.file)
if u'file' in kwargs:
self.get_name()
self.wizard = None

View File

@ -414,7 +414,7 @@ class HTTPBible(BibleDB):
if bible[u'language_id']:
language_id = bible[u'language_id']
else:
language = self.parent.mediaItem.importRequest(u'language')
language = self.parent.mediaItem.languageDialog()
if not language:
log.exception(u'Importing books from %s - download name: "%s" '\
'failed' % (self.download_source, self.download_name))

View File

@ -121,7 +121,7 @@ class BibleManager(object):
"""
log.debug(u'Bible Initialising')
self.parent = parent
self.settingsSection = u'bibles'
self.settingsSection = u'bibles/bibles'
self.web = u'Web'
self.db_cache = None
self.path = AppLocation.get_section_data_path(self.settingsSection)
@ -131,7 +131,8 @@ class BibleManager(object):
self.suffix = u'.sqlite'
self.import_wizard = None
self.reload_bibles()
self.reload_alternative_book_names()
#TODO: Delete unused code
#self.reload_alternative_book_names()
self.media = None
def reload_bibles(self):
@ -169,6 +170,8 @@ class BibleManager(object):
self.db_cache[name] = web_bible
log.debug(u'Bibles reloaded')
#TODO: Delete unused code
'''
def reload_alternative_book_names(self):
"""
Reloads the alternative book names from the local alternative book names
@ -178,6 +181,7 @@ class BibleManager(object):
self.alternative_book_names_cache = AlternativeBookNamesDB(self.parent,
path=self.path)
log.debug(u'AlternativeBookNames reloaded')
'''
def set_process_dialog(self, wizard):
"""
@ -331,6 +335,8 @@ class BibleManager(object):
def get_book_ref_id_by_name(self, book, language_id=None):
log.debug(u'BibleManager.get_book_ref_id_by_name:("%s", "%s")', book,
language_id)
self.alternative_book_names_cache = AlternativeBookNamesDB(self.parent,
path=self.path)
if BiblesResourcesDB.get_book(book):
book_temp = BiblesResourcesDB.get_book(book)
book_id = book_temp[u'id']
@ -342,7 +348,7 @@ class BibleManager(object):
book_id = self.alternative_book_names_cache.get_book_reference_id(
book, language_id)
else:
book_ref = self.parent.mediaItem.importRequest(u'book', book)
book_ref = self.parent.mediaItem.bookNameDialog(book)
log.debug(book_ref)
book_temp = BiblesResourcesDB.get_book(book_ref)
log.debug(book_temp)

View File

@ -33,10 +33,10 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings, add_widget_completer, \
media_item_combo_box, critical_error_message_box
from openlp.plugins.bibles.forms import BibleImportForm
from openlp.plugins.bibles.forms import BibleImportForm, BookNameForm, \
LanguageForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
VerseReferenceList, get_reference_match
from openlp.plugins.bibles.forms import BibleImportRequest
log = logging.getLogger(__name__)
@ -287,10 +287,15 @@ class BibleMediaItem(MediaManagerItem):
if self.import_wizard.exec_():
self.reloadBibles()
def importRequest(self, case, name=None):
self.import_request = BibleImportRequest(self)
if self.import_request.exec_(case, name):
return unicode(self.import_request.requestComboBox.currentText())
def bookNameDialog(self, name):
self.book_name = BookNameForm(self)
if self.book_name.exec_(name):
return unicode(self.book_name.requestComboBox.currentText())
def languageDialog(self):
self.language = LanguageForm(self)
if self.language.exec_():
return unicode(self.language.requestComboBox.currentText())
def loadBibles(self):
log.debug(u'Loading Bibles')

View File

@ -58,7 +58,7 @@ class OpenLP1Bible(BibleDB):
except:
return False
#Create the bible language
language = self.parent.mediaItem.importRequest(u'language')
language = self.parent.mediaItem.languageDialog()
if not language:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)

View File

@ -62,7 +62,7 @@ class OpenSongBible(BibleDB):
file = open(self.filename, u'r')
opensong = objectify.parse(file)
bible = opensong.getroot()
language = self.parent.mediaItem.importRequest(u'language')
language = self.parent.mediaItem.languageDialog()
if not language:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)

View File

@ -107,7 +107,7 @@ class OSISBible(BibleDB):
if detect_file:
detect_file.close()
# Set meta language_id
language = self.parent.mediaItem.importRequest(u'language')
language = self.parent.mediaItem.languageDialog()
if not language:
log.exception(u'Importing books from %s " '\
'failed' % self.filename)
@ -128,7 +128,7 @@ class OSISBible(BibleDB):
verse = int(match.group(3))
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])
log.debug(u'New book: "%s"' % self.books[book][0])
#TODO: Delete unused code
#if book == u'Matt' or book == u'Jdt':
# testament += 1