From 438c5cf00af43be38372ff1e97b0a5b492d50783 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 15 Dec 2009 21:37:56 +0200 Subject: [PATCH 01/11] Added an OpenSong implementation, a new import wizard, and validation for the import wizard. --- openlp/plugins/bibles/forms/__init__.py | 3 +- .../plugins/bibles/forms/bibleimportwizard.py | 319 +++++++++ .../plugins/bibles/forms/importwizardform.py | 132 ++++ openlp/plugins/bibles/lib/bibleCSVimpl.py | 1 + openlp/plugins/bibles/lib/bibleDBimpl.py | 3 + openlp/plugins/bibles/lib/bibleOSISimpl.py | 4 +- .../plugins/bibles/lib/bibleOpenSongimply.py | 110 ++++ openlp/plugins/bibles/lib/mediaitem.py | 9 +- resources/forms/bibleimportwizard.ui | 619 ++++++++++++++++++ 9 files changed, 1195 insertions(+), 5 deletions(-) create mode 100644 openlp/plugins/bibles/forms/bibleimportwizard.py create mode 100644 openlp/plugins/bibles/forms/importwizardform.py create mode 100644 openlp/plugins/bibles/lib/bibleOpenSongimply.py create mode 100644 resources/forms/bibleimportwizard.ui diff --git a/openlp/plugins/bibles/forms/__init__.py b/openlp/plugins/bibles/forms/__init__.py index b7215167a..30b9c5b1e 100644 --- a/openlp/plugins/bibles/forms/__init__.py +++ b/openlp/plugins/bibles/forms/__init__.py @@ -24,5 +24,6 @@ ############################################################################### from bibleimportform import BibleImportForm +from importwizardform import ImportWizardForm -__all__ = ['BibleImportForm'] +__all__ = ['BibleImportForm', 'ImportWizardForm'] diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py new file mode 100644 index 000000000..cf2033af0 --- /dev/null +++ b/openlp/plugins/bibles/forms/bibleimportwizard.py @@ -0,0 +1,319 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2009 Raoul Snyman # +# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard # +# --------------------------------------------------------------------------- # +# 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 + +class Ui_BibleImportWizard(object): + def setupUi(self, BibleImportWizard): + BibleImportWizard.setObjectName(u'BibleImportWizard') + BibleImportWizard.resize(550, 386) + BibleImportWizard.setModal(True) + BibleImportWizard.setWizardStyle(QtGui.QWizard.ModernStyle) + BibleImportWizard.setOptions( + QtGui.QWizard.IndependentPages | \ + QtGui.QWizard.NoBackButtonOnStartPage | \ + QtGui.QWizard.NoBackButtonOnLastPage) + self.WelcomePage = QtGui.QWizardPage() + self.WelcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, + QtGui.QPixmap(u':/wizards/wizard_importbible.bmp')) + self.WelcomePage.setObjectName(u'WelcomePage') + self.WelcomeLayout = QtGui.QVBoxLayout(self.WelcomePage) + self.WelcomeLayout.setSpacing(8) + self.WelcomeLayout.setMargin(0) + self.WelcomeLayout.setObjectName(u'WelcomeLayout') + self.TitleLabel = QtGui.QLabel(self.WelcomePage) + self.TitleLabel.setObjectName(u'TitleLabel') + self.WelcomeLayout.addWidget(self.TitleLabel) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) + self.WelcomeLayout.addItem(spacerItem) + self.InformationLabel = QtGui.QLabel(self.WelcomePage) + self.InformationLabel.setWordWrap(True) + self.InformationLabel.setMargin(10) + self.InformationLabel.setObjectName(u'InformationLabel') + self.WelcomeLayout.addWidget(self.InformationLabel) + spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.WelcomeLayout.addItem(spacerItem1) + BibleImportWizard.addPage(self.WelcomePage) + self.SelectPage = QtGui.QWizardPage() + self.SelectPage.setObjectName(u'SelectPage') + self.SelectPageLayout = QtGui.QVBoxLayout(self.SelectPage) + self.SelectPageLayout.setSpacing(8) + self.SelectPageLayout.setMargin(20) + self.SelectPageLayout.setObjectName(u'SelectPageLayout') + self.FormatSelectLayout = QtGui.QHBoxLayout() + self.FormatSelectLayout.setSpacing(8) + self.FormatSelectLayout.setObjectName(u'FormatSelectLayout') + self.FormatLabel = QtGui.QLabel(self.SelectPage) + self.FormatLabel.setObjectName(u'FormatLabel') + self.FormatSelectLayout.addWidget(self.FormatLabel) + self.FormatComboBox = QtGui.QComboBox(self.SelectPage) + self.FormatComboBox.setObjectName(u'FormatComboBox') + self.FormatComboBox.addItem(u'') + self.FormatComboBox.addItem(u'') + self.FormatComboBox.addItem(u'') + self.FormatComboBox.addItem(u'') + self.FormatSelectLayout.addWidget(self.FormatComboBox) + spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.FormatSelectLayout.addItem(spacerItem2) + self.SelectPageLayout.addLayout(self.FormatSelectLayout) + self.FormatWidget = QtGui.QStackedWidget(self.SelectPage) + self.FormatWidget.setObjectName(u'FormatWidget') + self.OsisPage = QtGui.QWidget() + self.OsisPage.setObjectName(u'OsisPage') + self.OsisLayout = QtGui.QFormLayout(self.OsisPage) + self.OsisLayout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow) + self.OsisLayout.setMargin(0) + self.OsisLayout.setSpacing(8) + self.OsisLayout.setObjectName(u'OsisLayout') + self.OsisBibleNameLabel = QtGui.QLabel(self.OsisPage) + self.OsisBibleNameLabel.setIndent(0) + self.OsisBibleNameLabel.setObjectName(u'OsisBibleNameLabel') + self.OsisLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.OsisBibleNameLabel) + self.OsisBibleNameEdit = QtGui.QLineEdit(self.OsisPage) + self.OsisBibleNameEdit.setObjectName(u'OsisBibleNameEdit') + self.OsisLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.OsisBibleNameEdit) + self.OsisLocationLabel = QtGui.QLabel(self.OsisPage) + self.OsisLocationLabel.setObjectName(u'OsisLocationLabel') + self.OsisLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.OsisLocationLabel) + self.OsisLocationLayout = QtGui.QHBoxLayout() + self.OsisLocationLayout.setSpacing(8) + self.OsisLocationLayout.setObjectName(u'OsisLocationLayout') + self.OSISLocationEdit = QtGui.QLineEdit(self.OsisPage) + self.OSISLocationEdit.setObjectName(u'OSISLocationEdit') + self.OsisLocationLayout.addWidget(self.OSISLocationEdit) + self.OsisFileButton = QtGui.QToolButton(self.OsisPage) + self.OsisFileButton.setMaximumSize(QtCore.QSize(32, 16777215)) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(u':/imports/import_load.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.OsisFileButton.setIcon(icon) + self.OsisFileButton.setObjectName(u'OsisFileButton') + self.OsisLocationLayout.addWidget(self.OsisFileButton) + self.OsisLayout.setLayout(1, QtGui.QFormLayout.FieldRole, self.OsisLocationLayout) + self.FormatWidget.addWidget(self.OsisPage) + self.CsvPage = QtGui.QWidget() + self.CsvPage.setObjectName(u'CsvPage') + self.CsvSourceLayout = QtGui.QFormLayout(self.CsvPage) + self.CsvSourceLayout.setFieldGrowthPolicy(QtGui.QFormLayout.ExpandingFieldsGrow) + self.CsvSourceLayout.setLabelAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing) + self.CsvSourceLayout.setFormAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) + self.CsvSourceLayout.setMargin(0) + self.CsvSourceLayout.setSpacing(8) + self.CsvSourceLayout.setObjectName(u'CsvSourceLayout') + self.BooksLocationLabel = QtGui.QLabel(self.CsvPage) + self.BooksLocationLabel.setObjectName(u'BooksLocationLabel') + self.CsvSourceLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.BooksLocationLabel) + self.CsvBooksLayout = QtGui.QHBoxLayout() + self.CsvBooksLayout.setSpacing(8) + self.CsvBooksLayout.setObjectName(u'CsvBooksLayout') + self.BooksLocationEdit = QtGui.QLineEdit(self.CsvPage) + self.BooksLocationEdit.setObjectName(u'BooksLocationEdit') + self.CsvBooksLayout.addWidget(self.BooksLocationEdit) + self.BooksFileButton = QtGui.QToolButton(self.CsvPage) + self.BooksFileButton.setMaximumSize(QtCore.QSize(32, 16777215)) + self.BooksFileButton.setIcon(icon) + self.BooksFileButton.setObjectName(u'BooksFileButton') + self.CsvBooksLayout.addWidget(self.BooksFileButton) + self.CsvSourceLayout.setLayout(0, QtGui.QFormLayout.FieldRole, self.CsvBooksLayout) + self.VerseLocationLabel = QtGui.QLabel(self.CsvPage) + self.VerseLocationLabel.setObjectName(u'VerseLocationLabel') + self.CsvSourceLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.VerseLocationLabel) + self.CsvVerseLayout = QtGui.QHBoxLayout() + self.CsvVerseLayout.setSpacing(8) + self.CsvVerseLayout.setObjectName(u'CsvVerseLayout') + self.CsvVerseLocationEdit = QtGui.QLineEdit(self.CsvPage) + self.CsvVerseLocationEdit.setObjectName(u'CsvVerseLocationEdit') + self.CsvVerseLayout.addWidget(self.CsvVerseLocationEdit) + self.CsvVersesFileButton = QtGui.QToolButton(self.CsvPage) + self.CsvVersesFileButton.setMaximumSize(QtCore.QSize(32, 16777215)) + self.CsvVersesFileButton.setIcon(icon) + self.CsvVersesFileButton.setObjectName(u'CsvVersesFileButton') + self.CsvVerseLayout.addWidget(self.CsvVersesFileButton) + self.CsvSourceLayout.setLayout(1, QtGui.QFormLayout.FieldRole, self.CsvVerseLayout) + self.FormatWidget.addWidget(self.CsvPage) + self.OpenSongPage = QtGui.QWidget() + self.OpenSongPage.setObjectName(u'OpenSongPage') + self.OpenSongLayout = QtGui.QFormLayout(self.OpenSongPage) + self.OpenSongLayout.setMargin(0) + self.OpenSongLayout.setSpacing(8) + self.OpenSongLayout.setObjectName(u'OpenSongLayout') + self.OpenSongFileLabel = QtGui.QLabel(self.OpenSongPage) + self.OpenSongFileLabel.setObjectName(u'OpenSongFileLabel') + self.OpenSongLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.OpenSongFileLabel) + self.OpenSongFileLayout = QtGui.QHBoxLayout() + self.OpenSongFileLayout.setSpacing(8) + self.OpenSongFileLayout.setObjectName(u'OpenSongFileLayout') + self.OpenSongFileEdit = QtGui.QLineEdit(self.OpenSongPage) + self.OpenSongFileEdit.setObjectName(u'OpenSongFileEdit') + self.OpenSongFileLayout.addWidget(self.OpenSongFileEdit) + self.OpenSongBrowseButton = QtGui.QToolButton(self.OpenSongPage) + self.OpenSongBrowseButton.setIcon(icon) + self.OpenSongBrowseButton.setObjectName(u'OpenSongBrowseButton') + self.OpenSongFileLayout.addWidget(self.OpenSongBrowseButton) + self.OpenSongLayout.setLayout(0, QtGui.QFormLayout.FieldRole, self.OpenSongFileLayout) + self.FormatWidget.addWidget(self.OpenSongPage) + self.WebDownloadPage = QtGui.QWidget() + self.WebDownloadPage.setObjectName(u'WebDownloadPage') + self.WebDownloadLayout = QtGui.QVBoxLayout(self.WebDownloadPage) + self.WebDownloadLayout.setSpacing(8) + self.WebDownloadLayout.setMargin(0) + self.WebDownloadLayout.setObjectName(u'WebDownloadLayout') + self.WebDownloadTabWidget = QtGui.QTabWidget(self.WebDownloadPage) + self.WebDownloadTabWidget.setObjectName(u'WebDownloadTabWidget') + self.DownloadOptionsTab = QtGui.QWidget() + self.DownloadOptionsTab.setObjectName(u'DownloadOptionsTab') + self.DownloadOptionsLayout = QtGui.QFormLayout(self.DownloadOptionsTab) + self.DownloadOptionsLayout.setMargin(8) + self.DownloadOptionsLayout.setSpacing(8) + self.DownloadOptionsLayout.setObjectName(u'DownloadOptionsLayout') + self.LocationLabel = QtGui.QLabel(self.DownloadOptionsTab) + self.LocationLabel.setObjectName(u'LocationLabel') + self.DownloadOptionsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.LocationLabel) + self.LocationComboBox = QtGui.QComboBox(self.DownloadOptionsTab) + self.LocationComboBox.setObjectName(u'LocationComboBox') + self.LocationComboBox.addItem(u'') + self.DownloadOptionsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.LocationComboBox) + self.BibleLabel = QtGui.QLabel(self.DownloadOptionsTab) + self.BibleLabel.setObjectName(u'BibleLabel') + self.DownloadOptionsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.BibleLabel) + self.BibleComboBox = QtGui.QComboBox(self.DownloadOptionsTab) + self.BibleComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) + self.BibleComboBox.setObjectName(u'BibleComboBox') + self.BibleComboBox.addItem(u'') + self.BibleComboBox.addItem(u'') + self.BibleComboBox.addItem(u'') + self.DownloadOptionsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.BibleComboBox) + self.WebDownloadTabWidget.addTab(self.DownloadOptionsTab, u'') + self.ProxyServerTab = QtGui.QWidget() + self.ProxyServerTab.setObjectName(u'ProxyServerTab') + self.ProxyServerLayout = QtGui.QFormLayout(self.ProxyServerTab) + self.ProxyServerLayout.setObjectName(u'ProxyServerLayout') + self.AddressLabel = QtGui.QLabel(self.ProxyServerTab) + self.AddressLabel.setObjectName(u'AddressLabel') + self.ProxyServerLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.AddressLabel) + self.AddressEdit = QtGui.QLineEdit(self.ProxyServerTab) + self.AddressEdit.setObjectName(u'AddressEdit') + self.ProxyServerLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.AddressEdit) + self.UsernameLabel = QtGui.QLabel(self.ProxyServerTab) + self.UsernameLabel.setObjectName(u'UsernameLabel') + self.ProxyServerLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.UsernameLabel) + self.UsernameEdit = QtGui.QLineEdit(self.ProxyServerTab) + self.UsernameEdit.setObjectName(u'UsernameEdit') + self.ProxyServerLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.UsernameEdit) + self.PasswordLabel = QtGui.QLabel(self.ProxyServerTab) + self.PasswordLabel.setObjectName(u'PasswordLabel') + self.ProxyServerLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.PasswordLabel) + self.PasswordEdit = QtGui.QLineEdit(self.ProxyServerTab) + self.PasswordEdit.setObjectName(u'PasswordEdit') + self.ProxyServerLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.PasswordEdit) + self.WebDownloadTabWidget.addTab(self.ProxyServerTab, u'') + self.WebDownloadLayout.addWidget(self.WebDownloadTabWidget) + self.FormatWidget.addWidget(self.WebDownloadPage) + self.SelectPageLayout.addWidget(self.FormatWidget) + BibleImportWizard.addPage(self.SelectPage) + self.LicenseDetailsPage = QtGui.QWizardPage() + self.LicenseDetailsPage.setObjectName(u'LicenseDetailsPage') + self.LicenseDetailsLayout = QtGui.QFormLayout(self.LicenseDetailsPage) + self.LicenseDetailsLayout.setMargin(20) + self.LicenseDetailsLayout.setSpacing(8) + self.LicenseDetailsLayout.setObjectName(u'LicenseDetailsLayout') + self.VersionNameLabel = QtGui.QLabel(self.LicenseDetailsPage) + self.VersionNameLabel.setObjectName(u'VersionNameLabel') + self.LicenseDetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.VersionNameLabel) + self.VersionNameEdit = QtGui.QLineEdit(self.LicenseDetailsPage) + self.VersionNameEdit.setObjectName(u'VersionNameEdit') + self.LicenseDetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.VersionNameEdit) + self.CopyrightLabel = QtGui.QLabel(self.LicenseDetailsPage) + self.CopyrightLabel.setObjectName(u'CopyrightLabel') + self.LicenseDetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.CopyrightLabel) + self.CopyrightEdit = QtGui.QLineEdit(self.LicenseDetailsPage) + self.CopyrightEdit.setObjectName(u'CopyrightEdit') + self.LicenseDetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.CopyrightEdit) + self.PermissionLabel = QtGui.QLabel(self.LicenseDetailsPage) + self.PermissionLabel.setObjectName(u'PermissionLabel') + self.LicenseDetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.PermissionLabel) + self.PermissionEdit = QtGui.QLineEdit(self.LicenseDetailsPage) + self.PermissionEdit.setObjectName(u'PermissionEdit') + self.LicenseDetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.PermissionEdit) + BibleImportWizard.addPage(self.LicenseDetailsPage) + self.ImportPage = QtGui.QWizardPage() + self.ImportPage.setObjectName(u'ImportPage') + self.ImportLayout = QtGui.QVBoxLayout(self.ImportPage) + self.ImportLayout.setSpacing(8) + self.ImportLayout.setMargin(50) + self.ImportLayout.setObjectName(u'ImportLayout') + self.ImportProgressLabel = QtGui.QLabel(self.ImportPage) + self.ImportProgressLabel.setObjectName(u'ImportProgressLabel') + self.ImportLayout.addWidget(self.ImportProgressLabel) + self.ImportProgressBar = QtGui.QProgressBar(self.ImportPage) + self.ImportProgressBar.setProperty(u'value', 0) + self.ImportProgressBar.setInvertedAppearance(False) + self.ImportProgressBar.setObjectName(u'ImportProgressBar') + self.ImportLayout.addWidget(self.ImportProgressBar) + BibleImportWizard.addPage(self.ImportPage) + + + self.retranslateUi(BibleImportWizard) + self.FormatWidget.setCurrentIndex(0) + self.WebDownloadTabWidget.setCurrentIndex(0) + QtCore.QObject.connect(self.FormatComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), self.FormatWidget.setCurrentIndex) + QtCore.QMetaObject.connectSlotsByName(BibleImportWizard) + + def retranslateUi(self, BibleImportWizard): + BibleImportWizard.setWindowTitle(self.trUtf8('Bible Import Wizard')) + self.TitleLabel.setText(u'' + self.trUtf8('Welcome to the Bible Import Wizard') + u'') + self.InformationLabel.setText(self.trUtf8('This wizard will help you to import Bibles from a variety of formats. Click the next button below to start the process by selecting a format to import from.')) + self.SelectPage.setTitle(self.trUtf8('Select Import Source')) + self.SelectPage.setSubTitle(self.trUtf8('Select the import format, and where to import from.')) + self.FormatLabel.setText(self.trUtf8('Format:')) + self.FormatComboBox.setItemText(0, self.trUtf8('OSIS')) + self.FormatComboBox.setItemText(1, self.trUtf8('CSV')) + self.FormatComboBox.setItemText(2, self.trUtf8('OpenSong')) + self.FormatComboBox.setItemText(3, self.trUtf8('Web Download')) + self.OsisBibleNameLabel.setText(self.trUtf8('Bible Name:')) + self.OsisLocationLabel.setText(self.trUtf8('File Location:')) + self.BooksLocationLabel.setText(self.trUtf8('Books Location:')) + self.VerseLocationLabel.setText(self.trUtf8('Verse Location:')) + self.OpenSongFileLabel.setText(self.trUtf8('Bible Filename:')) + self.LocationLabel.setText(self.trUtf8('Location:')) + self.LocationComboBox.setItemText(0, self.trUtf8('Crosswalk')) + self.BibleLabel.setText(self.trUtf8('Bible:')) + self.BibleComboBox.setItemText(0, self.trUtf8('English Standard Version')) + self.BibleComboBox.setItemText(1, self.trUtf8('King James Version')) + self.BibleComboBox.setItemText(2, self.trUtf8('New International Version')) + self.WebDownloadTabWidget.setTabText(self.WebDownloadTabWidget.indexOf(self.DownloadOptionsTab), self.trUtf8('Download Options')) + self.AddressLabel.setText(self.trUtf8('Server:')) + self.UsernameLabel.setText(self.trUtf8('Username:')) + self.PasswordLabel.setText(self.trUtf8('Password:')) + self.WebDownloadTabWidget.setTabText(self.WebDownloadTabWidget.indexOf(self.ProxyServerTab), self.trUtf8('Proxy Server (Optional)')) + self.LicenseDetailsPage.setTitle(self.trUtf8('License Details')) + self.LicenseDetailsPage.setSubTitle(self.trUtf8('Set up the Bible\'s license details.')) + self.VersionNameLabel.setText(self.trUtf8('Version Name:')) + self.CopyrightLabel.setText(self.trUtf8('Copyright:')) + self.PermissionLabel.setText(self.trUtf8('Permission:')) + self.ImportPage.setTitle(self.trUtf8('Importing')) + self.ImportPage.setSubTitle(self.trUtf8('Please wait while your Bible is imported.')) + self.ImportProgressLabel.setText(self.trUtf8('Ready.')) + self.ImportProgressBar.setFormat(u'%p') + diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py new file mode 100644 index 000000000..95eaada04 --- /dev/null +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -0,0 +1,132 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2009 Raoul Snyman # +# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +import logging +import os +import os.path + +from PyQt4 import QtCore, QtGui + +from bibleimportwizard import Ui_BibleImportWizard +from openlp.core.lib import Receiver + +class BibleFormat(object): + Unknown = -1 + OSIS = 0 + CSV = 1 + OpenSong = 2 + WebDownload = 3 + + +class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): + """ + This is the Bible Import Wizard, which allows easy importing of Bibles + into OpenLP from other formats like OSIS, CSV and OpenSong. + """ + + global log + log = logging.getLogger(u'BibleImportForm') + log.info(u'BibleImportForm loaded') + + def __init__(self, parent, config, biblemanager, bibleplugin): + ''' + Constructor + ''' + QtGui.QWizard.__init__(self, parent) + self.setupUi(self) + self.registerFields() + self.biblemanager = biblemanager + self.config = config + self.bibleplugin = bibleplugin + self.bible_type = BibleFormat.Unknown + + def registerFields(self): + self.SelectPage.registerField(u'source_format', self.FormatComboBox) + self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) + self.SelectPage.registerField(u'osis_location', self.OSISLocationEdit) + self.SelectPage.registerField(u'csv_booksfile', self.BooksLocationEdit) + self.SelectPage.registerField(u'csv_versefile', self.CsvVerseLocationEdit) + self.SelectPage.registerField(u'opensong_file', self.OpenSongFileEdit) + self.SelectPage.registerField(u'web_location', self.LocationComboBox) + self.SelectPage.registerField(u'web_biblename', self.BibleComboBox) + self.SelectPage.registerField(u'web_server', self.AddressEdit) + self.SelectPage.registerField(u'web_username', self.UsernameEdit) + self.SelectPage.registerField(u'web_password', self.PasswordEdit) + self.LicenseDetailsPage.registerField(u'license_version', self.VersionNameEdit) + self.LicenseDetailsPage.registerField(u'license_copyright', self.CopyrightEdit) + self.LicenseDetailsPage.registerField(u'license_permission', self.PermissionEdit) + + def validateCurrentPage(self): + if self.currentId() == 0: + # Welcome page + return True + elif self.currentId() == 1: + # Select page + if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS: + if self.field(u'osis_biblename').toString() == u'': + QtGui.QMessageBox.critical(self, + self.trUtf8('Invalid Bible Name'), + self.trUtf8('You need to specify a name for your Bible!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.OsisBibleNameEdit.setFocus() + return False + if self.field(u'osis_location').toString() == u'': + QtGui.QMessageBox.critical(self, + self.trUtf8('Invalid Bible Location'), + self.trUtf8('You need to specify a file to import your Bible from!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.OSISLocationEdit.setFocus() + return False + elif self.field(u'source_format').toInt()[0] == BibleFormat.CSV: + if self.field(u'csv_booksfile').toString() == QtCore.QString(u''): + QtGui.QMessageBox.critical(self, + self.trUtf8('Invalid Books File'), + self.trUtf8('You need to specify a file with books of the Bible to use in the import!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.BooksLocationEdit.setFocus() + return False + elif self.field(u'csv_versefile').toString() == QtCore.QString(u''): + QtGui.QMessageBox.critical(self, + self.trUtf8('Invalid Verse File'), + self.trUtf8('You need to specify a file of Bible verses to import!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.CsvVerseLocationEdit.setFocus() + return False + elif self.field(u'source_format').toInt()[0] == BibleFormat.OpenSong: + if self.field(u'opensong_file').toString() == QtCore.QString(u''): + QtGui.QMessageBox.critical(self, + self.trUtf8('Invalid OpenSong Bible'), + self.trUtf8('You need to specify an OpenSong Bible file to import!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.OpenSongFileEdit.setFocus() + return False + return True + + def show(self): + self.FormatComboBox.setCurrentIndex(0) + self.FormatWidget.setCurrentIndex(0) + self.WebDownloadTabWidget.setCurrentIndex(0) + return QtGui.QWizard.show() + diff --git a/openlp/plugins/bibles/lib/bibleCSVimpl.py b/openlp/plugins/bibles/lib/bibleCSVimpl.py index e356f4c4f..0d419072c 100644 --- a/openlp/plugins/bibles/lib/bibleCSVimpl.py +++ b/openlp/plugins/bibles/lib/bibleCSVimpl.py @@ -100,6 +100,7 @@ class BibleCSVImpl(BibleCommon): if count % 3 == 0: Receiver.send_message(u'process_events') count = 0 + self.bibledb.save_verses() except: log.exception(u'Loading verses from file failed') finally: diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index d0810f27c..f6e5d5480 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -67,6 +67,9 @@ class BibleDBImpl(BibleCommon): verse.verse = vse verse.text = text self.session.add(verse) + return verse + + def save_verses(self): self.session.commit() def create_chapter(self, bookid, chap, textlist): diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 089649b89..5c60e4617 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -112,7 +112,7 @@ class BibleOSISImpl(): count = 0 verseText = u' + + Wizard + + + + 0 + 0 + 550 + 386 + + + + Bible Import Wizard + + + true + + + QWizard::ModernStyle + + + QWizard::NoBackButtonOnLastPage|QWizard::NoBackButtonOnStartPage + + + + + + + + + + + 8 + + + 0 + + + + + + 163 + 0 + + + + + 163 + 16777215 + + + + 0 + + + + + + :/wizards/wizard_importbible.bmp + + + 0 + + + + + + + 8 + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body > +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;">Welcome to the Bible Import Wizard</span></p></body></html> + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 40 + + + + + + + + This wizard will help you to import Bibles from a variety of formats. Click the next button below to start the process by selecting a format to import from. + + + true + + + 10 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Select Import Source + + + Select the import format, and where to import from. + + + + 8 + + + 20 + + + + + 8 + + + + + Format: + + + + + + + + OSIS + + + + + CSV + + + + + OpenSong + + + + + Web Download + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + + QFormLayout::ExpandingFieldsGrow + + + 8 + + + 8 + + + 0 + + + + + Bible Name: + + + 0 + + + + + + + + + + File Location: + + + + + + + 8 + + + + + + + + + 32 + 16777215 + + + + + + + + :/imports/import_load.png:/imports/import_load.png + + + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 8 + + + 8 + + + 0 + + + + + Books Location: + + + + + + + 8 + + + + + + + + + 32 + 16777215 + + + + + + + + :/imports/import_load.png:/imports/import_load.png + + + + + + + + + Verse Location: + + + + + + + 8 + + + + + + + + + 32 + 16777215 + + + + + + + + :/imports/import_load.png:/imports/import_load.png + + + + + + + + + + + 8 + + + 8 + + + 0 + + + + + Bible Filename: + + + + + + + 8 + + + + + + + + + + + + :/imports/import_load.png:/imports/import_load.png + + + + + + + + + + + 8 + + + 0 + + + + + 0 + + + + Download Options + + + + 8 + + + 8 + + + 8 + + + + + Location: + + + + + + + + Crosswalk + + + + + + + + Bible: + + + + + + + QComboBox::AdjustToContents + + + + English Standard Version + + + + + King James Version + + + + + New International Version + + + + + + + + + Proxy Server (Optional) + + + + + + Server: + + + + + + + + + + Username: + + + + + + + + + + Password: + + + + + + + + + + + + + + + + + + + License Details + + + Set up the Bible's license details. + + + + 8 + + + 8 + + + 20 + + + + + Version Name: + + + + + + + + + + Copyright: + + + + + + + + + + Permission: + + + + + + + + + + + Importing + + + Please wait while your Bible is imported. + + + + 8 + + + 50 + + + + + Ready. + + + + + + + 0 + + + false + + + %p + + + + + + + + + + + + FormatComboBox + currentIndexChanged(int) + FormatWidget + setCurrentIndex(int) + + + 106 + 76 + + + 296 + 147 + + + + + From 77bf9b6f9a28653c14dce99df473fb631e6a92db Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 16 Dec 2009 04:22:16 +0200 Subject: [PATCH 02/11] Web download bibles now load correctly. --- .../plugins/bibles/forms/bibleimportwizard.py | 2 + .../plugins/bibles/forms/importwizardform.py | 100 ++++++++++++++---- openlp/plugins/custom/forms/editcustomform.py | 3 +- 3 files changed, 82 insertions(+), 23 deletions(-) diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py index cf2033af0..f0c12046b 100644 --- a/openlp/plugins/bibles/forms/bibleimportwizard.py +++ b/openlp/plugins/bibles/forms/bibleimportwizard.py @@ -193,6 +193,7 @@ class Ui_BibleImportWizard(object): self.LocationComboBox = QtGui.QComboBox(self.DownloadOptionsTab) self.LocationComboBox.setObjectName(u'LocationComboBox') self.LocationComboBox.addItem(u'') + self.LocationComboBox.addItem(u'') self.DownloadOptionsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.LocationComboBox) self.BibleLabel = QtGui.QLabel(self.DownloadOptionsTab) self.BibleLabel.setObjectName(u'BibleLabel') @@ -298,6 +299,7 @@ class Ui_BibleImportWizard(object): self.OpenSongFileLabel.setText(self.trUtf8('Bible Filename:')) self.LocationLabel.setText(self.trUtf8('Location:')) self.LocationComboBox.setItemText(0, self.trUtf8('Crosswalk')) + self.LocationComboBox.setItemText(1, self.trUtf8('BibleGateway')) self.BibleLabel.setText(self.trUtf8('Bible:')) self.BibleComboBox.setItemText(0, self.trUtf8('English Standard Version')) self.BibleComboBox.setItemText(1, self.trUtf8('King James Version')) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 95eaada04..e14fb54e1 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -60,23 +60,15 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.biblemanager = biblemanager self.config = config self.bibleplugin = bibleplugin - self.bible_type = BibleFormat.Unknown + self.web_bible_list = {} + self.loadWebBibles() + QtCore.QObject.connect(self.LocationComboBox, + QtCore.SIGNAL(u'currentIndexChanged(int)'), + self.onLocationComboBoxChanged) - def registerFields(self): - self.SelectPage.registerField(u'source_format', self.FormatComboBox) - self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) - self.SelectPage.registerField(u'osis_location', self.OSISLocationEdit) - self.SelectPage.registerField(u'csv_booksfile', self.BooksLocationEdit) - self.SelectPage.registerField(u'csv_versefile', self.CsvVerseLocationEdit) - self.SelectPage.registerField(u'opensong_file', self.OpenSongFileEdit) - self.SelectPage.registerField(u'web_location', self.LocationComboBox) - self.SelectPage.registerField(u'web_biblename', self.BibleComboBox) - self.SelectPage.registerField(u'web_server', self.AddressEdit) - self.SelectPage.registerField(u'web_username', self.UsernameEdit) - self.SelectPage.registerField(u'web_password', self.PasswordEdit) - self.LicenseDetailsPage.registerField(u'license_version', self.VersionNameEdit) - self.LicenseDetailsPage.registerField(u'license_copyright', self.CopyrightEdit) - self.LicenseDetailsPage.registerField(u'license_permission', self.PermissionEdit) + def show(self): + self.setDefaults() + return QtGui.QWizard.show() def validateCurrentPage(self): if self.currentId() == 0: @@ -124,9 +116,75 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): return False return True - def show(self): - self.FormatComboBox.setCurrentIndex(0) - self.FormatWidget.setCurrentIndex(0) - self.WebDownloadTabWidget.setCurrentIndex(0) - return QtGui.QWizard.show() + def onLocationComboBoxChanged(self, index): + self.BibleComboBox.clear() + for bible, abbreviation in self.web_bible_list[index]: + row = self.BibleComboBox.count() + self.BibleComboBox.addItem(unicode(self.trUtf8(bible))) + self.BibleComboBox.setItemData(row, QtCore.QVariant(bible)) + + def registerFields(self): + self.SelectPage.registerField(u'source_format', self.FormatComboBox) + self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) + self.SelectPage.registerField(u'osis_location', self.OSISLocationEdit) + self.SelectPage.registerField(u'csv_booksfile', self.BooksLocationEdit) + self.SelectPage.registerField(u'csv_versefile', self.CsvVerseLocationEdit) + self.SelectPage.registerField(u'opensong_file', self.OpenSongFileEdit) + self.SelectPage.registerField(u'web_location', self.LocationComboBox) + self.SelectPage.registerField(u'web_biblename', self.BibleComboBox) + self.SelectPage.registerField(u'proxy_server', self.AddressEdit) + self.SelectPage.registerField(u'proxy_username', self.UsernameEdit) + self.SelectPage.registerField(u'proxy_password', self.PasswordEdit) + self.LicenseDetailsPage.registerField(u'license_version', self.VersionNameEdit) + self.LicenseDetailsPage.registerField(u'license_copyright', self.CopyrightEdit) + self.LicenseDetailsPage.registerField(u'license_permission', self.PermissionEdit) + + def setDefaults(self): + self.setField(u'source_format', 0) + self.setField(u'osis_biblename', u'') + self.setField(u'osis_location', u'') + self.setField(u'csv_booksfile', u'') + self.setField(u'csv_versefile', u'') + self.setField(u'opensong_file', u'') + self.setField(u'web_location', 0) + self.setField(u'web_biblename', self.BibleComboBox) + self.setField(u'proxy_server', self.config.get_config(u'proxy address', u'')) + self.setField(u'proxy_username', self.config.get_config(u'proxy username',u'')) + self.setField(u'proxy_password', self.config.get_config(u'proxy password',u'')) + self.setField(u'license_version', self.VersionNameEdit) + self.setField(u'license_copyright', self.CopyrightEdit) + self.setField(u'license_permission', self.PermissionEdit) + self.onLocationComboBoxChanged(0) + + def loadWebBibles(self): + #Load and store Crosswalk Bibles + filepath = os.path.abspath(os.path.join( + os.path.split(os.path.abspath(__file__))[0], + u'..', u'resources')) + print filepath + fbibles = None + try: + self.web_bible_list[0] = [] + fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') + for line in fbibles: + p = line.split(u',') + self.web_bible_list[0].append((p[0], p[1].rstrip())) #replace(u'\n', u'') + except: + log.exception(u'Crosswalk resources missing') + finally: + if fbibles: + fbibles.close() + #Load and store BibleGateway Bibles + try: + self.web_bible_list[1] = [] + fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r') + for line in fbibles: + p = line.split(u',') + self.web_bible_list[1].append((p[0], p[1].rstrip())) + except: + log.exception(u'Biblegateway resources missing') + finally: + if fbibles: + fbibles.close() + print self.web_bible_list diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index e238b42c7..fe4a99139 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -106,14 +106,13 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog): for themename in themelist: self.ThemeComboBox.addItem(themename) - def loadCustom(self, id, preview): + def loadCustom(self, id, preview=False): self.customSlide = CustomSlide() self.initialise() if id != 0: self.customSlide = self.custommanager.get_custom(id) self.TitleEdit.setText(self.customSlide.title) self.CreditEdit.setText(self.customSlide.credits) - songXML = SongXMLParser(self.customSlide.text) verseList = songXML.get_verses() for verse in verseList: From fa93b10b9407501e6feedc95aa7cf0c411dbd859 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 16 Dec 2009 22:52:44 +0200 Subject: [PATCH 03/11] A pre-import working Import Wizard. --- .../plugins/bibles/forms/importwizardform.py | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index e14fb54e1..2076c39a7 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -65,6 +65,18 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), self.onLocationComboBoxChanged) + QtCore.QObject.connect(self.OsisFileButton, + QtCore.SIGNAL(u'clicked()'), + self.onOsisFileButtonClicked) + QtCore.QObject.connect(self.BooksFileButton, + QtCore.SIGNAL(u'clicked()'), + self.onBooksFileButtonClicked) + QtCore.QObject.connect(self.CsvVersesFileButton, + QtCore.SIGNAL(u'clicked()'), + self.onCsvVersesFileButtonClicked) + QtCore.QObject.connect(self.OpenSongBrowseButton, + QtCore.SIGNAL(u'clicked()'), + self.onOpenSongBrowseButtonClicked) def show(self): self.setDefaults() @@ -92,14 +104,14 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.OSISLocationEdit.setFocus() return False elif self.field(u'source_format').toInt()[0] == BibleFormat.CSV: - if self.field(u'csv_booksfile').toString() == QtCore.QString(u''): + if self.field(u'csv_booksfile').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Books File'), self.trUtf8('You need to specify a file with books of the Bible to use in the import!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.BooksLocationEdit.setFocus() return False - elif self.field(u'csv_versefile').toString() == QtCore.QString(u''): + elif self.field(u'csv_versefile').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Verse File'), self.trUtf8('You need to specify a file of Bible verses to import!'), @@ -107,7 +119,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.CsvVerseLocationEdit.setFocus() return False elif self.field(u'source_format').toInt()[0] == BibleFormat.OpenSong: - if self.field(u'opensong_file').toString() == QtCore.QString(u''): + if self.field(u'opensong_file').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid OpenSong Bible'), self.trUtf8('You need to specify an OpenSong Bible file to import!'), @@ -115,6 +127,21 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.OpenSongFileEdit.setFocus() return False return True + elif self.currentId() == 2: + if self.field(u'license_version').toString() == u'': + QtGui.QMessageBox.critical(self, + self.trUtf8('Empty Version Name'), + self.trUtf8('You need to specify a version name for your Bible!'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.VersionNameEdit.setFocus() + return False + elif self.field(u'license_copyright').toString() == u'': + QtGui.QMessageBox.critical(self, + self.trUtf8('Empty Copyright'), + self.trUtf8('You need to set a copyright for your Bible! Bibles in the Public Domain need to be marked as such.'), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + self.CopyrightEdit.setFocus() + return False def onLocationComboBoxChanged(self, index): self.BibleComboBox.clear() @@ -123,6 +150,18 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.BibleComboBox.addItem(unicode(self.trUtf8(bible))) self.BibleComboBox.setItemData(row, QtCore.QVariant(bible)) + def onOsisFileButtonClicked(self): + self.getFileName(self.trUtf8('Open OSIS file'), self.OSISLocationEdit) + + def onBooksFileButtonClicked(self): + self.getFileName(self.trUtf8('Open Books CSV file'), self.BooksLocationEdit) + + def onCsvVersesFileButtonClicked(self): + self.getFileName(self.trUtf8('Open Verses CSV file'), self.CsvVerseLocationEdit) + + def onOpenSongBrowseButtonClicked(self): + self.getFileName(self.trUtf8('Open OpenSong Bible'), self.OpenSongFileEdit) + def registerFields(self): self.SelectPage.registerField(u'source_format', self.FormatComboBox) self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) @@ -157,11 +196,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.onLocationComboBoxChanged(0) def loadWebBibles(self): + """ + Load the list of Crosswalk and BibleGateway bibles. + """ #Load and store Crosswalk Bibles filepath = os.path.abspath(os.path.join( os.path.split(os.path.abspath(__file__))[0], u'..', u'resources')) - print filepath fbibles = None try: self.web_bible_list[0] = [] @@ -186,5 +227,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): finally: if fbibles: fbibles.close() - print self.web_bible_list + + def getFileName(self, title, editbox): + filename = QtGui.QFileDialog.getOpenFileName(self, title, + self.config.get_last_dir(1)) + if filename: + editbox.setText(filename) + self.config.set_last_dir(filename, 1) From e29a88e9a343e2899d3af2807d94cdf67c9a11d3 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 19 Dec 2009 00:31:28 +0200 Subject: [PATCH 04/11] Final touches to the import Wizard; Fixed a few bugs in the OpenSong implementation. --- .../plugins/bibles/forms/bibleimportform.py | 2 +- .../plugins/bibles/forms/importwizardform.py | 118 ++++++++++++++++-- ...eOpenSongimply.py => bibleOpenSongimpl.py} | 15 +-- openlp/plugins/bibles/lib/manager.py | 25 +++- 4 files changed, 143 insertions(+), 17 deletions(-) rename openlp/plugins/bibles/lib/{bibleOpenSongimply.py => bibleOpenSongimpl.py} (90%) diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index af2a61daa..481222eeb 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -230,7 +230,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog): self.barmax = max self.ProgressBar.setMaximum(max) - def incrementProgressBar(self, text ): + def incrementProgressBar(self, text): log.debug(u'IncrementBar %s', text) self.MessageLabel.setText(unicode(self.trUtf8('Import processing')) + ' - %s' % text) self.ProgressBar.setValue(self.ProgressBar.value() + 1) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index 2076c39a7..ec23637db 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -26,6 +26,7 @@ import logging import os import os.path +from time import sleep from PyQt4 import QtCore, QtGui @@ -40,6 +41,21 @@ class BibleFormat(object): WebDownload = 3 +class DownloadLocation(object): + Unknown = -1 + Crosswalk = 0 + BibleGateway = 1 + + Names = { + 0: u'Crosswalk', + 1: u'BibleGateway' + } + + @classmethod + def get_name(class_, id): + return class_.Names[id] + + class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): """ This is the Bible Import Wizard, which allows easy importing of Bibles @@ -57,10 +73,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtGui.QWizard.__init__(self, parent) self.setupUi(self) self.registerFields() + self.web_bible_list = {} + self.finishButton = self.button(QtGui.QWizard.FinishButton) + self.cancelButton = self.button(QtGui.QWizard.CancelButton) self.biblemanager = biblemanager self.config = config self.bibleplugin = bibleplugin - self.web_bible_list = {} + self.biblemanager.process_dialog(self) self.loadWebBibles() QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), @@ -77,6 +96,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.QObject.connect(self.OpenSongBrowseButton, QtCore.SIGNAL(u'clicked()'), self.onOpenSongBrowseButtonClicked) + QtCore.QObject.connect(self, + QtCore.SIGNAL(u'currentIdChanged(int)'), + self.onCurrentIdChanged) def show(self): self.setDefaults() @@ -128,6 +150,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): return False return True elif self.currentId() == 2: + # License details if self.field(u'license_version').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Empty Version Name'), @@ -142,13 +165,15 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.CopyrightEdit.setFocus() return False + return True + if self.currentId() == 3: + # Progress page + return True def onLocationComboBoxChanged(self, index): self.BibleComboBox.clear() - for bible, abbreviation in self.web_bible_list[index]: - row = self.BibleComboBox.count() + for bible, abbreviation in self.web_bible_list[index].iteritems(): self.BibleComboBox.addItem(unicode(self.trUtf8(bible))) - self.BibleComboBox.setItemData(row, QtCore.QVariant(bible)) def onOsisFileButtonClicked(self): self.getFileName(self.trUtf8('Open OSIS file'), self.OSISLocationEdit) @@ -162,6 +187,12 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): def onOpenSongBrowseButtonClicked(self): self.getFileName(self.trUtf8('Open OpenSong Bible'), self.OpenSongFileEdit) + def onCurrentIdChanged(self, id): + if id == 3: + self.preImport() + self.performImport() + self.postImport() + def registerFields(self): self.SelectPage.registerField(u'source_format', self.FormatComboBox) self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) @@ -205,11 +236,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): u'..', u'resources')) fbibles = None try: - self.web_bible_list[0] = [] + self.web_bible_list[DownloadLocation.Crosswalk] = {} fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') for line in fbibles: p = line.split(u',') - self.web_bible_list[0].append((p[0], p[1].rstrip())) #replace(u'\n', u'') + self.web_bible_list[DownloadLocation.Crosswalk][p[0]] = p[1].rstrip() except: log.exception(u'Crosswalk resources missing') finally: @@ -217,11 +248,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): fbibles.close() #Load and store BibleGateway Bibles try: - self.web_bible_list[1] = [] + self.web_bible_list[DownloadLocation.BibleGateway] = {} fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r') for line in fbibles: p = line.split(u',') - self.web_bible_list[1].append((p[0], p[1].rstrip())) + self.web_bible_list[DownloadLocation.BibleGateway][p[0]] = p[1].rstrip() except: log.exception(u'Biblegateway resources missing') finally: @@ -235,3 +266,74 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): editbox.setText(filename) self.config.set_last_dir(filename, 1) + def incrementProgressBar(self, status_text): + log.debug(u'IncrementBar %s', status_text) + self.ImportProgressLabel.setText(status_text) + self.ImportProgressBar.setValue(self.ImportProgressBar.value() + 1) + Receiver.send_message(u'process_events') + + def preImport(self): + self.finishButton.setEnabled(False) + self.cancelButton.setVisible(False) + self.ImportProgressBar.setMinimum(0) + self.ImportProgressBar.setMaximum(65) + self.ImportProgressBar.setValue(0) + self.ImportProgressLabel.setText(self.trUtf8('Starting import...')) + Receiver.send_message(u'process_events') + + def performImport(self): + bible_type = self.field(u'source_format').toInt()[0] + success = False + if bible_type == BibleFormat.OSIS: + # Import an OSIS bible + success = self.biblemanager.register_osis_file_bible( + unicode(self.field(u'license_version').toString()), + unicode(self.field(u'osis_location').toString()) + ) + elif bible_type == BibleFormat.CSV: + # Import a CSV bible + success = self.biblemanager.register_csv_file_bible( + unicode(self.field(u'license_version').toString()), + self.field(u'csv_booksfile').toString(), + self.field(u'csv_versefile').toString() + ) + elif bible_type == BibleFormat.OpenSong: + # Import an OpenSong bible + success = self.biblemanager.register_opensong_bible( + unicode(self.field(u'license_version').toString()), + self.field(u'opensong_file').toString() + ) + elif bible_type == BibleFormat.WebDownload: + # Import a bible from the web + self.ImportProgressBar.setMaximum(1) + download_location = self.field(u'web_location').toInt()[0] + if download_location == DownloadLocation.Crosswalk: + bible = self.web_bible_list[DownloadLocation.Crosswalk][ + unicode(self.BibleComboBox.currentText())] + elif download_location == DownloadLocation.BibleGateway: + bible = self.web_bible_list[DownloadLocation.BibleGateway][ + unicode(self.BibleComboBox.currentText())] + success = self.biblemanager.register_http_bible( + unicode(self.field(u'license_version').toString()), + unicode(DownloadLocation.get_name(download_location)), + unicode(bible), + unicode(self.field(u'proxy_server').toString()), + unicode(self.field(u'proxy_username').toString()), + unicode(self.field(u'proxy_password').toString()) + ) + if success: + self.biblemanager.save_meta_data( + unicode(self.field(u'license_version').toString()), + unicode(self.field(u'license_version').toString()), + unicode(self.field(u'license_copyright').toString()), + unicode(self.field(u'license_permission').toString()) + ) + else: + self.ImportProgressLabel.setText(self.trUtf8('Your Bible import failed.')) + self.ImportProgressBar.setValue(self.ImportProgressBar.maximum()) + + def postImport(self): + self.ImportProgressLabel.setText(self.trUtf8('Finished import.')) + self.finishButton.setEnabled(True) + Receiver.send_message(u'process_events') + diff --git a/openlp/plugins/bibles/lib/bibleOpenSongimply.py b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py similarity index 90% rename from openlp/plugins/bibles/lib/bibleOpenSongimply.py rename to openlp/plugins/bibles/lib/bibleOpenSongimpl.py index 7a500967f..cc7e02f7a 100644 --- a/openlp/plugins/bibles/lib/bibleOpenSongimply.py +++ b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py @@ -76,7 +76,8 @@ class BibleOpenSongImpl(): The Import dialog, so that we can increase the counter on the progress bar. """ - log.info(u'Load data for %s' % opensong_bible) + log.info(u'Load data for %s' % bible_file) + bible_file = unicode(bible_file) detect_file = None try: detect_file = open(bible_file, u'r') @@ -91,16 +92,16 @@ class BibleOpenSongImpl(): try: opensong_bible = codecs.open(bible_file, u'r', details['encoding']) opensong = objectify.parse(opensong_bible) - bible_tag = opensong.getroot() + bible = opensong.getroot() for book in bible.b: - dbbook = self.bibledb.create_book(book.attrib['n'], - book.attrib['n'][:4]) - dialogobject.incrementProgressBar(dbbook.name) + dbbook = self.bibledb.create_book(book.attrib[u'n'], + book.attrib[u'n'][:4]) for chapter in book.c: for verse in chapter.v: - self.bibledb.add_verse(dbbook.id, chapter.attrib['n'], - verse.attrib['n'], verse.text) + self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'], + verse.attrib[u'n'], verse.text) Receiver.send_message(u'process_events') + dialogobject.incrementProgressBar(dbbook.name + str(chapter.attrib[u'n'])) self.bibledb.save_verses() except: log.exception(u'Loading bible from OpenSong file failed') diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index a1f1e8c29..20e4ee75d 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -26,6 +26,7 @@ import logging import os +from bibleOpenSongimpl import BibleOpenSongImpl from bibleOSISimpl import BibleOSISImpl from bibleCSVimpl import BibleCSVImpl from bibleDBimpl import BibleDBImpl @@ -176,7 +177,7 @@ class BibleManager(object): self.bible_db_cache[biblename] = nbible nhttp = BibleHTTPImpl() nhttp.set_bible_source(biblesource) - self.bible_http_cache [biblename] = nhttp + self.bible_http_cache[biblename] = nhttp # register a lazy loading interest nbible.save_meta(u'WEB', biblesource) # store the web id of the bible @@ -245,6 +246,28 @@ class BibleManager(object): biblename, osisfile) return False + def register_opensong_bible(self, biblename, opensongfile): + """ + Method to load a bible from an OpenSong xml file. If the database + exists it is deleted and the database is reloaded from scratch. + """ + log.debug(u'register_opensong_file_bible %s, %s', biblename, opensongfile) + if self._is_new_bible(biblename): + # Create new Bible + nbible = BibleDBImpl(self.biblePath, biblename, self.config) + # Create Database + nbible.create_tables() + # Cache the database for use later + self.bible_db_cache[biblename] = nbible + # Create the loader and pass in the database + bcsv = BibleOpenSongImpl(self.biblePath, nbible) + bcsv.load_data(opensongfile, self.dialogobject) + return True + else: + log.debug(u'register_opensong_file_bible %s, %s not created ' + u'already exists', biblename, opensongfile) + return False + def get_bibles(self, mode=BibleMode.Full): """ Returns a list of Books of the bible. When ``mode`` is set to From dc0f7e7f5a68990745e382eafd30310c9c4ef630 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 21 Dec 2009 22:58:00 +0200 Subject: [PATCH 05/11] Finishing touches on the Import wizard and the OpenSong bible importer. --- .../plugins/bibles/forms/importwizardform.py | 11 ++----- openlp/plugins/bibles/lib/bibleCSVimpl.py | 5 +-- openlp/plugins/bibles/lib/bibleDBimpl.py | 4 +-- openlp/plugins/bibles/lib/bibleOSISimpl.py | 26 +++++++++------- .../plugins/bibles/lib/bibleOpenSongimpl.py | 3 +- openlp/plugins/bibles/lib/manager.py | 31 +++++++++++++++++++ 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index ec23637db..c3a91c736 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -32,14 +32,7 @@ from PyQt4 import QtCore, QtGui from bibleimportwizard import Ui_BibleImportWizard from openlp.core.lib import Receiver - -class BibleFormat(object): - Unknown = -1 - OSIS = 0 - CSV = 1 - OpenSong = 2 - WebDownload = 3 - +from openlp.plugins.bibles.lib.manager import BibleFormat class DownloadLocation(object): Unknown = -1 @@ -276,7 +269,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.finishButton.setEnabled(False) self.cancelButton.setVisible(False) self.ImportProgressBar.setMinimum(0) - self.ImportProgressBar.setMaximum(65) + self.ImportProgressBar.setMaximum(1188) self.ImportProgressBar.setValue(0) self.ImportProgressLabel.setText(self.trUtf8('Starting import...')) Receiver.send_message(u'process_events') diff --git a/openlp/plugins/bibles/lib/bibleCSVimpl.py b/openlp/plugins/bibles/lib/bibleCSVimpl.py index 0d419072c..72a0f30d2 100644 --- a/openlp/plugins/bibles/lib/bibleCSVimpl.py +++ b/openlp/plugins/bibles/lib/bibleCSVimpl.py @@ -88,12 +88,13 @@ class BibleCSVImpl(BibleCommon): # split into 3 units and leave the rest as a single field p = line.split(u',', 3) p0 = p[0].replace(u'"', u'') - p3 = p[3].replace(u'"',u'') + p3 = p[3].replace(u'"', u'') if book_ptr is not p0: book = self.bibledb.get_bible_book(p0) book_ptr = book.name # increament the progress bar - dialogobject.incrementProgressBar(book.name) + dialogobject.incrementProgressBar(u'Importing %s %s' % \ + book.name) self.bibledb.add_verse(book.id, p[1], p[2], p3) count += 1 #Every x verses repaint the screen diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index f6e5d5480..2875c96b8 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -53,14 +53,14 @@ class BibleDBImpl(BibleCommon): self.metadata.create_all(checkfirst=True) def create_tables(self): - log.debug( u'createTables') + log.debug(u'createTables') self.save_meta(u'dbversion', u'2') self._load_testament(u'Old Testament') self._load_testament(u'New Testament') self._load_testament(u'Apocrypha') def add_verse(self, bookid, chap, vse, text): - #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse) + log.debug(u'add_verse %s,%s,%s', bookid, chap, vse) verse = Verse() verse.book_id = bookid verse.chapter = chap diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 5c60e4617..fdfa6cc07 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -53,6 +53,7 @@ class BibleOSISImpl(): A reference to a Bible database object. """ log.info(u'BibleOSISImpl Initialising') + self.verse_regex = re.compile(r'(.*)') self.bibledb = bibledb # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} @@ -98,7 +99,7 @@ class BibleOSISImpl(): detect_file = None try: detect_file = open(osisfile_record, u'r') - details = chardet.detect(detect_file.read(2048)) + details = chardet.detect(detect_file.read(3000)) except: log.exception(u'Failed to detect OSIS file encoding') return @@ -153,6 +154,8 @@ class BibleOSISImpl(): epos = text.find(u'', pos) text = text[:pos] + text[epos + 4: ] pos = text.find(u'') + print ref + continue # split up the reference p = ref.split(u'.', 3) if book_ptr != p[0]: @@ -161,28 +164,29 @@ class BibleOSISImpl(): # set the max book size depending # on the first book read if p[0] == u'Gen': - dialogobject.setMax(65) + dialogobject.ImportProgressBar.setMaximum(1188) else: - dialogobject.setMax(27) + dialogobject.ImportProgressBar.setMaximum(260) # First book of NT if p[0] == u'Matt': testament += 1 + dialogobject.incrementProgressBar(u'Importing %s %s...' % \ + (self.booksOfBible[p[0]], p[1])) + Receiver.send_message(u'process_events') + self.bibledb.save_verses() book_ptr = p[0] book = self.bibledb.create_book( unicode(self.booksOfBible[p[0]]), unicode(self.abbrevOfBible[p[0]]), testament) - dialogobject.incrementProgressBar( - self.booksOfBible[p[0]]) count = 0 - self.bibledb.save_verses() self.bibledb.add_verse(book.id, p[1], p[2], text) - count += 1 + #count += 1 #Every 3 verses repaint the screen - if count % 3 == 0: - Receiver.send_message(u'process_events') - count = 0 - self.bibledb.save_verses() + #if count % 3 == 0: + # Receiver.send_message(u'process_events') + # count = 0 + #self.bibledb.save_verses() except: log.exception(u'Loading bible from OSIS file failed') finally: diff --git a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py index cc7e02f7a..eebbfe5b4 100644 --- a/openlp/plugins/bibles/lib/bibleOpenSongimpl.py +++ b/openlp/plugins/bibles/lib/bibleOpenSongimpl.py @@ -101,7 +101,8 @@ class BibleOpenSongImpl(): self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'], verse.attrib[u'n'], verse.text) Receiver.send_message(u'process_events') - dialogobject.incrementProgressBar(dbbook.name + str(chapter.attrib[u'n'])) + dialogobject.incrementProgressBar(u'Importing %s %s' % \ + (dbbook.name, str(chapter.attrib[u'n']))) self.bibledb.save_verses() except: log.exception(u'Loading bible from OpenSong file failed') diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 20e4ee75d..5a60c13aa 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -36,6 +36,28 @@ class BibleMode(object): Full = 1 Partial = 2 + +class BibleFormat(object): + Unknown = -1 + OSIS = 0 + CSV = 1 + OpenSong = 2 + WebDownload = 3 + + @classmethod + def get_handler(class_, id): + if id == class_.OSIS: + return BibleOSISImpl + elif id == class_.CSV: + return BibleCSVImpl + elif id == class_.OpenSong: + return BibleOpenSongImpl + elif id == class_.WebDownload: + return BibleHTTPImpl + else: + return None + + class BibleManager(object): """ The Bible manager which holds and manages all the Bibles. @@ -142,6 +164,15 @@ class BibleManager(object): """ self.dialogobject = dialogobject + def import_bible(self, type, **kwargs): + """ + Register a bible in the bible cache, and then import the verses. + + ``type`` + What type of Bible, + """ + pass + def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None): """ From 1181152c5aff3f6cb8f88ae1645f5bd61e305197 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 23 Dec 2009 23:09:07 +0200 Subject: [PATCH 06/11] Trying to regexify and make the OSIS importer more robust. --- openlp/plugins/bibles/lib/bibleOSISimpl.py | 178 ++++++++++++--------- 1 file changed, 99 insertions(+), 79 deletions(-) diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index fdfa6cc07..9b7063ef0 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -28,6 +28,7 @@ import os.path import logging import chardet import codecs +import re from PyQt4 import QtCore @@ -53,7 +54,8 @@ class BibleOSISImpl(): A reference to a Bible database object. """ log.info(u'BibleOSISImpl Initialising') - self.verse_regex = re.compile(r'(.*)') + self.verse_regex = re.compile(r'(.*?)') + self.note_regex = re.compile(r'(.*?)') self.bibledb = bibledb # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} @@ -61,7 +63,7 @@ class BibleOSISImpl(): self.abbrevOfBible = {} filepath = os.path.split(os.path.abspath(__file__))[0] filepath = os.path.abspath(os.path.join( - filepath, u'..', u'resources',u'osisbooks.csv')) + filepath, u'..', u'resources', u'osisbooks.csv')) fbibles = None self.loadbible = True try: @@ -109,84 +111,102 @@ class BibleOSISImpl(): osis = None try: osis = codecs.open(osisfile_record, u'r', details['encoding']) - book_ptr = None - count = 0 - verseText = u' -1: - epos = file_record.find(u'>', pos) - # Book Reference - ref = file_record[pos+15:epos-1] - #lets find the bible text only - # find start of text - pos = epos + 1 - # end of text - epos = file_record.find(u'', pos) - text = file_record[pos : epos] - #remove tags of extra information - text = self.remove_block(u'', text) - text = self.remove_block(u'', text) - text = self.remove_block( - u'', text) - text = self.remove_tag(u'') - while pos > -1: - epos = text.find(u'', pos) - if epos == -1: # TODO - pos = -1 - else: - text = text[:pos] + text[epos + 4: ] - pos = text.find(u'') - pos = text.find(u'') - while pos > -1: - epos = text.find(u'', pos) - text = text[:pos] + text[epos + 4: ] - pos = text.find(u'') - print ref - continue - # split up the reference - p = ref.split(u'.', 3) - if book_ptr != p[0]: - # first time through - if book_ptr is None: - # set the max book size depending - # on the first book read - if p[0] == u'Gen': - dialogobject.ImportProgressBar.setMaximum(1188) - else: - dialogobject.ImportProgressBar.setMaximum(260) - # First book of NT - if p[0] == u'Matt': - testament += 1 - dialogobject.incrementProgressBar(u'Importing %s %s...' % \ - (self.booksOfBible[p[0]], p[1])) - Receiver.send_message(u'process_events') - self.bibledb.save_verses() - book_ptr = p[0] - book = self.bibledb.create_book( - unicode(self.booksOfBible[p[0]]), - unicode(self.abbrevOfBible[p[0]]), - testament) - count = 0 - self.bibledb.add_verse(book.id, p[1], p[2], text) - #count += 1 - #Every 3 verses repaint the screen - #if count % 3 == 0: - # Receiver.send_message(u'process_events') - # count = 0 - #self.bibledb.save_verses() + match = self.verse_regex.search(file_record) + if match: + print 'Found:', match.group(4) + #if last_chapter != match.group(2): + print match.group(2) + # dialogobject.incrementProgressBar( + # u'Importing %s %s...' % \ + # (self.books[match.group(1)], match.group(2))) + # last_chapter = match.group(2) + verse_text = match.group(4) + #verse_text = self.remove_block( + #verse_text = self.note_regex.sub(lambda match: u'', verse_text) + print verse_text + else: + print 'Not found...', file_record[:10] +# (self.booksOfBible[p[0]], p[1])) +# book_ptr = None +# count = 0 +# verseText = u'', pos) +# # Book Reference +# ref = file_record[pos+15:epos-1] +# #lets find the bible text only +# # find start of text +# pos = epos + 1 +# # end of text +# epos = file_record.find(u'', pos) +# text = file_record[pos : epos] +# #remove tags of extra information +# text = self.remove_block(u'', text) +# text = self.remove_block(u'', text) +# text = self.remove_block( +# u'', text) +# text = self.remove_tag(u'') +# while pos > -1: +# epos = text.find(u'', pos) +# if epos == -1: # TODO +# pos = -1 +# else: +# text = text[:pos] + text[epos + 4: ] +# pos = text.find(u'') +# pos = text.find(u'') +# while pos > -1: +# epos = text.find(u'', pos) +# text = text[:pos] + text[epos + 4: ] +# pos = text.find(u'') +# print ref +# continue +# # split up the reference +# p = ref.split(u'.', 3) +# if book_ptr != p[0]: +# # first time through +# if book_ptr is None: +# # set the max book size depending +# # on the first book read +# if p[0] == u'Gen': +# dialogobject.ImportProgressBar.setMaximum(1188) +# else: +# dialogobject.ImportProgressBar.setMaximum(260) +# # First book of NT +# if p[0] == u'Matt': +# testament += 1 +# dialogobject.incrementProgressBar(u'Importing %s %s...' % \ +# (self.booksOfBible[p[0]], p[1])) +# Receiver.send_message(u'process_events') +# self.bibledb.save_verses() +# book_ptr = p[0] +# book = self.bibledb.create_book( +# unicode(self.booksOfBible[p[0]]), +# unicode(self.abbrevOfBible[p[0]]), +# testament) +# count = 0 +# self.bibledb.add_verse(book.id, p[1], p[2], text) +# #count += 1 +# #Every 3 verses repaint the screen +# #if count % 3 == 0: +# # Receiver.send_message(u'process_events') +# # count = 0 +# #self.bibledb.save_verses() except: log.exception(u'Loading bible from OSIS file failed') finally: From b7f224e28056893252916c02d237611433f598e1 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Dec 2009 00:31:14 +0200 Subject: [PATCH 07/11] 99% of OSIS import now working. --- openlp/plugins/bibles/lib/bibleOSISimpl.py | 129 ++++++++------------- 1 file changed, 50 insertions(+), 79 deletions(-) diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 9b7063ef0..1dc2423f4 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -55,10 +55,18 @@ class BibleOSISImpl(): """ log.info(u'BibleOSISImpl Initialising') self.verse_regex = re.compile(r'(.*?)') - self.note_regex = re.compile(r'(.*?)') + self.note_regex = re.compile(r'(.*?)') + self.title_regex = re.compile(r'(.*?)') + self.milestone_regex = re.compile(r'') + self.lb_regex = re.compile(r'') + self.l_regex = re.compile(r'') + self.w_regex = re.compile(r'') + self.q_regex = re.compile(r'') + self.spaces_regex = re.compile(r'([ ]{2,})') self.bibledb = bibledb # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} + self.books = {} # books of the bible linked to bibleid {osis ,Abbrev } self.abbrevOfBible = {} filepath = os.path.split(os.path.abspath(__file__))[0] @@ -70,8 +78,9 @@ class BibleOSISImpl(): fbibles = open(filepath, u'r') for line in fbibles: p = line.split(u',') - self.booksOfBible[p[0]] = p[1].replace(u'\n', u'') - self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'') + #self.booksOfBible[p[0]] = p[1].replace(u'\n', u'') + self.books[p[0]] = (p[1].lstrip().rstrip(), p[2].lstrip().rstrip()) + #self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'') except: log.exception(u'OSIS bible import failed') finally: @@ -111,53 +120,46 @@ class BibleOSISImpl(): osis = None try: osis = codecs.open(osisfile_record, u'r', details['encoding']) - last_chapter = u'0' + last_chapter = 0 + testament = 1 for file_record in osis: match = self.verse_regex.search(file_record) if match: - print 'Found:', match.group(4) - #if last_chapter != match.group(2): - print match.group(2) - # dialogobject.incrementProgressBar( - # u'Importing %s %s...' % \ - # (self.books[match.group(1)], match.group(2))) - # last_chapter = match.group(2) + book = match.group(1) + chapter = int(match.group(2)) + verse = int(match.group(3)) verse_text = match.group(4) - #verse_text = self.remove_block( - #verse_text = self.note_regex.sub(lambda match: u'', verse_text) - print verse_text - else: - print 'Not found...', file_record[:10] -# (self.booksOfBible[p[0]], p[1])) -# book_ptr = None -# count = 0 -# verseText = u'', pos) -# # Book Reference -# ref = file_record[pos+15:epos-1] -# #lets find the bible text only -# # find start of text -# pos = epos + 1 -# # end of text -# epos = file_record.find(u'', pos) -# text = file_record[pos : epos] -# #remove tags of extra information -# text = self.remove_block(u'', text) -# text = self.remove_block(u'', text) -# text = self.remove_block( -# u'', text) -# text = self.remove_tag(u'', u'')\ + .replace(u'', u'').replace(u'', u'')\ + .replace(u'', u'').replace(u'', u'')\ + .replace(u'', u'') + verse_text = self.spaces_regex.sub(u' ', verse_text) + self.bibledb.add_verse(db_book.id, chapter, verse, verse_text) # # Strange tags where the end is not the same as the start # # The must be in this order as at least one bible has them # # crossing and the removal does not work. @@ -174,39 +176,8 @@ class BibleOSISImpl(): # epos = text.find(u'', pos) # text = text[:pos] + text[epos + 4: ] # pos = text.find(u'') -# print ref -# continue -# # split up the reference -# p = ref.split(u'.', 3) -# if book_ptr != p[0]: -# # first time through -# if book_ptr is None: -# # set the max book size depending -# # on the first book read -# if p[0] == u'Gen': -# dialogobject.ImportProgressBar.setMaximum(1188) -# else: -# dialogobject.ImportProgressBar.setMaximum(260) -# # First book of NT -# if p[0] == u'Matt': -# testament += 1 -# dialogobject.incrementProgressBar(u'Importing %s %s...' % \ -# (self.booksOfBible[p[0]], p[1])) -# Receiver.send_message(u'process_events') -# self.bibledb.save_verses() -# book_ptr = p[0] -# book = self.bibledb.create_book( -# unicode(self.booksOfBible[p[0]]), -# unicode(self.abbrevOfBible[p[0]]), -# testament) -# count = 0 -# self.bibledb.add_verse(book.id, p[1], p[2], text) -# #count += 1 -# #Every 3 verses repaint the screen -# #if count % 3 == 0: -# # Receiver.send_message(u'process_events') -# # count = 0 -# #self.bibledb.save_verses() + self.bibledb.save_verses() + dialogobject.incrementProgressBar(u'Finishing import...') except: log.exception(u'Loading bible from OSIS file failed') finally: From 3e425803e3f7981121a407470c48b2e89c5073f2 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Dec 2009 17:12:09 +0200 Subject: [PATCH 08/11] Last few fixes for the OSIS importer. --- openlp/plugins/bibles/lib/bibleOSISimpl.py | 93 +++++----------------- 1 file changed, 20 insertions(+), 73 deletions(-) diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 1dc2423f4..711f49cdb 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -58,17 +58,15 @@ class BibleOSISImpl(): self.note_regex = re.compile(r'(.*?)') self.title_regex = re.compile(r'(.*?)') self.milestone_regex = re.compile(r'') + self.fi_regex = re.compile(r'(.*?)') + self.rf_regex = re.compile(r'(.*?)') self.lb_regex = re.compile(r'') self.l_regex = re.compile(r'') self.w_regex = re.compile(r'') self.q_regex = re.compile(r'') self.spaces_regex = re.compile(r'([ ]{2,})') self.bibledb = bibledb - # books of the bible linked to bibleid {osis , name} - self.booksOfBible = {} self.books = {} - # books of the bible linked to bibleid {osis ,Abbrev } - self.abbrevOfBible = {} filepath = os.path.split(os.path.abspath(__file__))[0] filepath = os.path.abspath(os.path.join( filepath, u'..', u'resources', u'osisbooks.csv')) @@ -77,10 +75,9 @@ class BibleOSISImpl(): try: fbibles = open(filepath, u'r') for line in fbibles: - p = line.split(u',') - #self.booksOfBible[p[0]] = p[1].replace(u'\n', u'') - self.books[p[0]] = (p[1].lstrip().rstrip(), p[2].lstrip().rstrip()) - #self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'') + book = line.split(u',') + self.books[book[0]] = (book[1].lstrip().rstrip(), + book[2].lstrip().rstrip()) except: log.exception(u'OSIS bible import failed') finally: @@ -122,6 +119,7 @@ class BibleOSISImpl(): osis = codecs.open(osisfile_record, u'r', details['encoding']) last_chapter = 0 testament = 1 + db_book = None for file_record in osis: match = self.verse_regex.search(file_record) if match: @@ -129,6 +127,14 @@ class BibleOSISImpl(): chapter = int(match.group(2)) verse = int(match.group(3)) verse_text = match.group(4) + print book, chapter, verse + if not db_book or db_book.name != book: + if book == u'Matt': + testament += 1 + db_book = self.bibledb.create_book( + unicode(self.books[book][0]), + unicode(self.books[book][1]), + testament) if last_chapter == 0: if book == u'Gen': dialogobject.ImportProgressBar.setMaximum(1188) @@ -140,16 +146,16 @@ class BibleOSISImpl(): dialogobject.incrementProgressBar( u'Importing %s %s...' % \ (self.books[match.group(1)][0], chapter)) - if book == u'Matt': - testament += 1 - db_book = self.bibledb.create_book( - unicode(self.books[book][0]), - unicode(self.books[book][1]), - testament) last_chapter = chapter + # All of this rigmarol below is because the mod2osis + # tool from the Sword library embeds XML in the OSIS + # but neglects to enclose the verse text (with XML) in + # <[CDATA[ ]]> tags. verse_text = self.note_regex.sub(u'', verse_text) verse_text = self.title_regex.sub(u'', verse_text) verse_text = self.milestone_regex.sub(u'', verse_text) + verse_text = self.fi_regex.sub(u'', verse_text) + verse_text = self.rf_regex.sub(u'', verse_text) verse_text = self.lb_regex.sub(u'', verse_text) verse_text = self.l_regex.sub(u'', verse_text) verse_text = self.w_regex.sub(u'', verse_text) @@ -160,22 +166,6 @@ class BibleOSISImpl(): .replace(u'', u'') verse_text = self.spaces_regex.sub(u' ', verse_text) self.bibledb.add_verse(db_book.id, chapter, verse, verse_text) -# # Strange tags where the end is not the same as the start -# # The must be in this order as at least one bible has them -# # crossing and the removal does not work. -# pos = text.find(u'') -# while pos > -1: -# epos = text.find(u'', pos) -# if epos == -1: # TODO -# pos = -1 -# else: -# text = text[:pos] + text[epos + 4: ] -# pos = text.find(u'') -# pos = text.find(u'') -# while pos > -1: -# epos = text.find(u'', pos) -# text = text[:pos] + text[epos + 4: ] -# pos = text.find(u'') self.bibledb.save_verses() dialogobject.incrementProgressBar(u'Finishing import...') except: @@ -184,46 +174,3 @@ class BibleOSISImpl(): if osis: osis.close() - def remove_block(self, start_tag, end_tag, text): - """ - Removes a block of text between two tags:: - - Some not wanted text - - ``start_tag`` - The XML tag to look for. - - ``end_tag`` - The ending XML tag. - - ``text`` - The string of XML to search. - """ - pos = text.find(start_tag) - while pos > -1: - epos = text.find(end_tag, pos) - if epos == -1: - pos = -1 - else: - text = text[:pos] + text[epos + len(end_tag): ] - pos = text.find(start_tag) - return text - - def remove_tag(self, start_tag, text): - """ - Removes a single tag:: - - - - ``start_tag`` - The XML tag to remove. - - ``text`` - The string of XML to search. - """ - pos = text.find(start_tag) - while pos > -1: - epos = text.find(u'/>', pos) - text = text[:pos] + text[epos + 2: ] - pos = text.find(start_tag) - return text From 4500b028242c4573c1403ffa90e763c6c690b68b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Dec 2009 17:21:03 +0200 Subject: [PATCH 09/11] Moved openlp database upgrade script to scripts directory. Removed old bible import form. Removed some debugging in the OSIS and bible db classes. --- .../plugins/bibles/forms/bibleimportdialog.py | 259 ------------- .../plugins/bibles/forms/bibleimportform.py | 355 ------------------ openlp/plugins/bibles/lib/bibleDBimpl.py | 2 +- openlp/plugins/bibles/lib/bibleOSISimpl.py | 1 - .../openlp-1to2-converter.py | 0 5 files changed, 1 insertion(+), 616 deletions(-) delete mode 100644 openlp/plugins/bibles/forms/bibleimportdialog.py delete mode 100644 openlp/plugins/bibles/forms/bibleimportform.py rename openlp-1to2-converter.py => scripts/openlp-1to2-converter.py (100%) diff --git a/openlp/plugins/bibles/forms/bibleimportdialog.py b/openlp/plugins/bibles/forms/bibleimportdialog.py deleted file mode 100644 index 728f0217f..000000000 --- a/openlp/plugins/bibles/forms/bibleimportdialog.py +++ /dev/null @@ -1,259 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2009 Raoul Snyman # -# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # -# Carsten Tinggaard # -# --------------------------------------------------------------------------- # -# 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 build_icon - -class Ui_BibleImportDialog(object): - def setupUi(self, BibleImportDialog): - BibleImportDialog.setObjectName(u'BibleImportDialog') - BibleImportDialog.resize(500, 686) - icon = build_icon(u':/icon/openlp.org-icon-32.bmp') - BibleImportDialog.setWindowIcon(icon) - self.LicenceDetailsGroupBox = QtGui.QGroupBox(BibleImportDialog) - self.LicenceDetailsGroupBox.setGeometry(QtCore.QRect(10, 400, 480, 151)) - self.LicenceDetailsGroupBox.setMinimumSize(QtCore.QSize(0, 123)) - self.LicenceDetailsGroupBox.setObjectName(u'LicenceDetailsGroupBox') - self.formLayout = QtGui.QFormLayout(self.LicenceDetailsGroupBox) - self.formLayout.setMargin(8) - self.formLayout.setHorizontalSpacing(8) - self.formLayout.setObjectName(u'formLayout') - self.VersionNameLabel = QtGui.QLabel(self.LicenceDetailsGroupBox) - self.VersionNameLabel.setObjectName(u'VersionNameLabel') - self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.VersionNameLabel) - self.VersionNameEdit = QtGui.QLineEdit(self.LicenceDetailsGroupBox) - self.VersionNameEdit.setObjectName(u'VersionNameEdit') - self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.VersionNameEdit) - self.CopyrightLabel = QtGui.QLabel(self.LicenceDetailsGroupBox) - self.CopyrightLabel.setObjectName(u'CopyrightLabel') - self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.CopyrightLabel) - self.CopyrightEdit = QtGui.QLineEdit(self.LicenceDetailsGroupBox) - self.CopyrightEdit.setObjectName(u'CopyrightEdit') - self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.CopyrightEdit) - self.PermisionLabel = QtGui.QLabel(self.LicenceDetailsGroupBox) - self.PermisionLabel.setObjectName(u'PermisionLabel') - self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.PermisionLabel) - self.PermisionEdit = QtGui.QLineEdit(self.LicenceDetailsGroupBox) - self.PermisionEdit.setObjectName(u'PermisionEdit') - self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.PermisionEdit) - self.MessageLabel = QtGui.QLabel(BibleImportDialog) - self.MessageLabel.setGeometry(QtCore.QRect(20, 670, 271, 17)) - self.MessageLabel.setObjectName(u'MessageLabel') - self.ProgressGroupBox = QtGui.QGroupBox(BibleImportDialog) - self.ProgressGroupBox.setGeometry(QtCore.QRect(10, 550, 480, 70)) - self.ProgressGroupBox.setObjectName(u'ProgressGroupBox') - self.gridLayout_3 = QtGui.QGridLayout(self.ProgressGroupBox) - self.gridLayout_3.setObjectName(u'gridLayout_3') - self.ProgressBar = QtGui.QProgressBar(self.ProgressGroupBox) - self.ProgressBar.setProperty(u'value', QtCore.QVariant(0)) - self.ProgressBar.setInvertedAppearance(False) - self.ProgressBar.setObjectName(u'ProgressBar') - self.gridLayout_3.addWidget(self.ProgressBar, 0, 0, 1, 1) - self.layoutWidget = QtGui.QWidget(BibleImportDialog) - self.layoutWidget.setGeometry(QtCore.QRect(310, 630, 180, 38)) - self.layoutWidget.setObjectName(u'layoutWidget') - self.horizontalLayout = QtGui.QHBoxLayout(self.layoutWidget) - self.horizontalLayout.setMargin(6) - self.horizontalLayout.setObjectName(u'horizontalLayout') - self.ImportButton = QtGui.QPushButton(self.layoutWidget) - self.ImportButton.setObjectName(u'ImportButton') - self.horizontalLayout.addWidget(self.ImportButton) - self.CancelButton = QtGui.QPushButton(self.layoutWidget) - self.CancelButton.setObjectName(u'CancelButton') - self.horizontalLayout.addWidget(self.CancelButton) - self.tabWidget = QtGui.QTabWidget(BibleImportDialog) - self.tabWidget.setGeometry(QtCore.QRect(10, 30, 480, 361)) - self.tabWidget.setObjectName(u'tabWidget') - self.OsisTab = QtGui.QWidget() - self.OsisTab.setObjectName(u'OsisTab') - self.OSISGroupBox = QtGui.QGroupBox(self.OsisTab) - self.OSISGroupBox.setGeometry(QtCore.QRect(10, 10, 460, 141)) - self.OSISGroupBox.setObjectName(u'OSISGroupBox') - self.gridLayout_2 = QtGui.QGridLayout(self.OSISGroupBox) - self.gridLayout_2.setObjectName(u'gridLayout_2') - self.horizontalLayout_2 = QtGui.QHBoxLayout() - self.horizontalLayout_2.setObjectName(u'horizontalLayout_2') - self.BibleNameLabel = QtGui.QLabel(self.OSISGroupBox) - self.BibleNameLabel.setObjectName(u'BibleNameLabel') - self.horizontalLayout_2.addWidget(self.BibleNameLabel) - self.BibleNameEdit = QtGui.QLineEdit(self.OSISGroupBox) - self.BibleNameEdit.setObjectName(u'BibleNameEdit') - self.horizontalLayout_2.addWidget(self.BibleNameEdit) - self.gridLayout_2.addLayout(self.horizontalLayout_2, 0, 0, 1, 1) - self.horizontalLayout_3 = QtGui.QHBoxLayout() - self.horizontalLayout_3.setObjectName(u'horizontalLayout_3') - self.LocatioLabel = QtGui.QLabel(self.OSISGroupBox) - self.LocatioLabel.setObjectName(u'LocatioLabel') - self.horizontalLayout_3.addWidget(self.LocatioLabel) - self.OSISLocationEdit = QtGui.QLineEdit(self.OSISGroupBox) - self.OSISLocationEdit.setObjectName(u'OSISLocationEdit') - self.horizontalLayout_3.addWidget(self.OSISLocationEdit) - self.OsisFileButton = QtGui.QPushButton(self.OSISGroupBox) - icon1 = build_icon(u':/imports/import_load.png') - self.OsisFileButton.setIcon(icon1) - self.OsisFileButton.setObjectName(u'OsisFileButton') - self.horizontalLayout_3.addWidget(self.OsisFileButton) - self.gridLayout_2.addLayout(self.horizontalLayout_3, 1, 0, 1, 1) - self.tabWidget.addTab(self.OsisTab, u'') - self.CsvTab = QtGui.QWidget() - self.CsvTab.setObjectName(u'CsvTab') - self.CVSGroupBox = QtGui.QGroupBox(self.CsvTab) - self.CVSGroupBox.setGeometry(QtCore.QRect(10, 10, 460, 191)) - self.CVSGroupBox.setObjectName(u'CVSGroupBox') - self.gridLayout = QtGui.QGridLayout(self.CVSGroupBox) - self.gridLayout.setMargin(8) - self.gridLayout.setSpacing(8) - self.gridLayout.setObjectName(u'gridLayout') - self.BooksLocationLabel = QtGui.QLabel(self.CVSGroupBox) - self.BooksLocationLabel.setObjectName(u'BooksLocationLabel') - self.gridLayout.addWidget(self.BooksLocationLabel, 0, 0, 1, 1) - self.VerseLocationLabel = QtGui.QLabel(self.CVSGroupBox) - self.VerseLocationLabel.setObjectName(u'VerseLocationLabel') - self.gridLayout.addWidget(self.VerseLocationLabel, 4, 0, 1, 1) - self.VerseLocationEdit = QtGui.QLineEdit(self.CVSGroupBox) - self.VerseLocationEdit.setObjectName(u'VerseLocationEdit') - self.gridLayout.addWidget(self.VerseLocationEdit, 4, 1, 1, 1) - self.BooksLocationEdit = QtGui.QLineEdit(self.CVSGroupBox) - self.BooksLocationEdit.setObjectName(u'BooksLocationEdit') - self.gridLayout.addWidget(self.BooksLocationEdit, 0, 1, 1, 1) - self.BooksFileButton = QtGui.QPushButton(self.CVSGroupBox) - self.BooksFileButton.setIcon(icon1) - self.BooksFileButton.setObjectName(u'BooksFileButton') - self.gridLayout.addWidget(self.BooksFileButton, 0, 2, 1, 1) - self.VersesFileButton = QtGui.QPushButton(self.CVSGroupBox) - self.VersesFileButton.setIcon(icon1) - self.VersesFileButton.setObjectName(u'VersesFileButton') - self.gridLayout.addWidget(self.VersesFileButton, 4, 2, 1, 1) - self.tabWidget.addTab(self.CsvTab, u'') - self.HttpTab = QtGui.QWidget() - self.HttpTab.setObjectName(u'HttpTab') - self.OptionsGroupBox = QtGui.QGroupBox(self.HttpTab) - self.OptionsGroupBox.setGeometry(QtCore.QRect(10, 10, 460, 141)) - self.OptionsGroupBox.setObjectName(u'OptionsGroupBox') - self.verticalLayout = QtGui.QVBoxLayout(self.OptionsGroupBox) - self.verticalLayout.setObjectName(u'verticalLayout') - self.horizontalLayout_4 = QtGui.QHBoxLayout() - self.horizontalLayout_4.setObjectName(u'horizontalLayout_4') - self.LocationLabel = QtGui.QLabel(self.OptionsGroupBox) - self.LocationLabel.setObjectName(u'LocationLabel') - self.horizontalLayout_4.addWidget(self.LocationLabel) - self.LocationComboBox = QtGui.QComboBox(self.OptionsGroupBox) - self.LocationComboBox.setObjectName(u'LocationComboBox') - self.LocationComboBox.addItem(QtCore.QString()) - self.LocationComboBox.addItem(QtCore.QString()) - self.horizontalLayout_4.addWidget(self.LocationComboBox) - self.verticalLayout.addLayout(self.horizontalLayout_4) - self.horizontalLayout_5 = QtGui.QHBoxLayout() - self.horizontalLayout_5.setObjectName(u'horizontalLayout_5') - self.BibleLabel = QtGui.QLabel(self.OptionsGroupBox) - self.BibleLabel.setObjectName(u'BibleLabel') - self.horizontalLayout_5.addWidget(self.BibleLabel) - self.BibleComboBox = QtGui.QComboBox(self.OptionsGroupBox) - self.BibleComboBox.setObjectName(u'BibleComboBox') - self.BibleComboBox.addItem(QtCore.QString()) - self.BibleComboBox.setItemText(0, u'') - self.BibleComboBox.setItemText(1, u'') - self.BibleComboBox.addItem(QtCore.QString()) - self.BibleComboBox.addItem(QtCore.QString()) - self.horizontalLayout_5.addWidget(self.BibleComboBox) - self.verticalLayout.addLayout(self.horizontalLayout_5) - self.ProxyGroupBox = QtGui.QGroupBox(self.HttpTab) - self.ProxyGroupBox.setGeometry(QtCore.QRect(10, 160, 460, 161)) - self.ProxyGroupBox.setObjectName(u'ProxyGroupBox') - self.ProxySettingsLayout = QtGui.QFormLayout(self.ProxyGroupBox) - self.ProxySettingsLayout.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow) - self.ProxySettingsLayout.setMargin(8) - self.ProxySettingsLayout.setSpacing(8) - self.ProxySettingsLayout.setObjectName(u'ProxySettingsLayout') - self.AddressLabel = QtGui.QLabel(self.ProxyGroupBox) - self.AddressLabel.setObjectName(u'AddressLabel') - self.ProxySettingsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.AddressLabel) - self.AddressEdit = QtGui.QLineEdit(self.ProxyGroupBox) - self.AddressEdit.setObjectName(u'AddressEdit') - self.ProxySettingsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.AddressEdit) - self.UsernameLabel = QtGui.QLabel(self.ProxyGroupBox) - self.UsernameLabel.setObjectName(u'UsernameLabel') - self.ProxySettingsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.UsernameLabel) - self.UsernameEdit = QtGui.QLineEdit(self.ProxyGroupBox) - self.UsernameEdit.setObjectName(u'UsernameEdit') - self.ProxySettingsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.UsernameEdit) - self.PasswordLabel = QtGui.QLabel(self.ProxyGroupBox) - self.PasswordLabel.setObjectName(u'PasswordLabel') - self.ProxySettingsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.PasswordLabel) - self.PasswordEdit = QtGui.QLineEdit(self.ProxyGroupBox) - self.PasswordEdit.setObjectName(u'PasswordEdit') - self.ProxySettingsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.PasswordEdit) - self.tabWidget.addTab(self.HttpTab, u'') - - self.retranslateUi(BibleImportDialog) - self.tabWidget.setCurrentIndex(2) - QtCore.QMetaObject.connectSlotsByName(BibleImportDialog) - BibleImportDialog.setTabOrder(self.BibleNameEdit, self.OSISLocationEdit) - BibleImportDialog.setTabOrder(self.OSISLocationEdit, self.OsisFileButton) - BibleImportDialog.setTabOrder(self.OsisFileButton, self.BooksLocationEdit) - BibleImportDialog.setTabOrder(self.BooksLocationEdit, self.BooksFileButton) - BibleImportDialog.setTabOrder(self.BooksFileButton, self.VerseLocationEdit) - BibleImportDialog.setTabOrder(self.VerseLocationEdit, self.VersesFileButton) - BibleImportDialog.setTabOrder(self.VersesFileButton, self.LocationComboBox) - BibleImportDialog.setTabOrder(self.LocationComboBox, self.BibleComboBox) - BibleImportDialog.setTabOrder(self.BibleComboBox, self.AddressEdit) - BibleImportDialog.setTabOrder(self.AddressEdit, self.UsernameEdit) - BibleImportDialog.setTabOrder(self.UsernameEdit, self.PasswordEdit) - BibleImportDialog.setTabOrder(self.PasswordEdit, self.VersionNameEdit) - BibleImportDialog.setTabOrder(self.VersionNameEdit, self.CopyrightEdit) - BibleImportDialog.setTabOrder(self.CopyrightEdit, self.PermisionEdit) - - def retranslateUi(self, BibleImportDialog): - BibleImportDialog.setWindowTitle(self.trUtf8('Bible Registration')) - self.LicenceDetailsGroupBox.setTitle(self.trUtf8('Licence Details')) - self.VersionNameLabel.setText(self.trUtf8('Version Name:')) - self.CopyrightLabel.setText(self.trUtf8('Copyright:')) - self.PermisionLabel.setText(self.trUtf8('Permission:')) - self.ProgressGroupBox.setTitle(self.trUtf8('Import Progress')) - self.ProgressBar.setFormat(self.trUtf8('%p')) - self.ImportButton.setText(self.trUtf8('Import')) - self.CancelButton.setText(self.trUtf8('Cancel')) - self.OSISGroupBox.setTitle(self.trUtf8('OSIS Bible')) - self.BibleNameLabel.setText(self.trUtf8('Bible Name:')) - self.LocatioLabel.setText(self.trUtf8('File Location:')) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.OsisTab), - self.trUtf8('Osis (Sword) Imports')) - self.CVSGroupBox.setTitle(self.trUtf8('CVS Bible')) - self.BooksLocationLabel.setText(self.trUtf8('Books Location:')) - self.VerseLocationLabel.setText(self.trUtf8('Verse Location:')) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.CsvTab), - self.trUtf8('CSV File Imports')) - self.OptionsGroupBox.setTitle(self.trUtf8('Download Options')) - self.LocationLabel.setText(self.trUtf8('Location:')) - self.LocationComboBox.setItemText(0, self.trUtf8('Crosswalk')) - self.LocationComboBox.setItemText(1, self.trUtf8('BibleGateway')) - self.BibleLabel.setText(self.trUtf8('Bible:')) - self.ProxyGroupBox.setTitle(self.trUtf8('Proxy Settings (Optional)')) - self.AddressLabel.setText(self.trUtf8('Proxy Address:')) - self.UsernameLabel.setText(self.trUtf8('Username:')) - self.PasswordLabel.setText(self.trUtf8('Password:')) - self.tabWidget.setTabText(self.tabWidget.indexOf(self.HttpTab), - self.trUtf8('Web Downloads')) diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py deleted file mode 100644 index 481222eeb..000000000 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ /dev/null @@ -1,355 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2009 Raoul Snyman # -# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # -# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # -# Carsten Tinggaard # -# --------------------------------------------------------------------------- # -# 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 # -############################################################################### - -import logging -import os -import os.path - -from PyQt4 import QtCore, QtGui - -from bibleimportdialog import Ui_BibleImportDialog -from openlp.core.lib import Receiver - -class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog): - global log - log = logging.getLogger(u'BibleImportForm') - log.info(u'BibleImportForm loaded') - """ - Class documentation goes here. - """ - def __init__(self, config, biblemanager, bibleplugin, parent=None): - ''' - Constructor - ''' - QtGui.QDialog.__init__(self, parent) - self.setupUi(self) - self.biblemanager = biblemanager - self.config = config - self.bibleplugin = bibleplugin - self.bible_type = None - self.barmax = 0 - self.tabWidget.setCurrentIndex(0) - self.cwBibleVersions = {} - self.bgBibleVersions = {} - self.AddressEdit.setText(self.config.get_config(u'proxy address', u'')) - self.UsernameEdit.setText(self.config.get_config(u'proxy username',u'')) - self.PasswordEdit.setText(self.config.get_config(u'proxy password',u'')) - #Load and store Crosswalk Bibles - filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join(filepath, u'..', - u'resources', u'crosswalkbooks.csv')) - fbibles = None - try: - fbibles = open(filepath, 'r') - for line in fbibles: - p = line.split(u',') - self.cwBibleVersions[p[0]] = p[1].replace(u'\n', u'') - except: - log.exception(u'Crosswalk resources missing') - finally: - if fbibles: - fbibles.close() - #Load and store BibleGateway Bibles - filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join(filepath, u'..', - u'resources', u'biblegateway.csv')) - try: - fbibles = open(filepath, 'r') - for line in fbibles: - p = line.split(u',') - self.bgBibleVersions[p[0]] = p[1].replace(u'\n', u'') - except: - log.exception(u'Biblegateway resources missing') - finally: - if fbibles: - fbibles.close() - self.loadBibleCombo(self.cwBibleVersions) - self.cwActive = True - - def loadBibleCombo(self, biblesList): - self.BibleComboBox.clear() - self.BibleComboBox.addItem(u'') - for bible in biblesList: - row = self.BibleComboBox.count() - self.BibleComboBox.addItem(unicode(self.trUtf8(bible))) - self.BibleComboBox.setItemData(row, QtCore.QVariant(bible)) - - #Combo Boxes - QtCore.QObject.connect(self.LocationComboBox, - QtCore.SIGNAL(u'activated(int)'), self.onLocationComboBoxSelected) - QtCore.QObject.connect(self.BibleComboBox, - QtCore.SIGNAL(u'activated(int)'), self.onBibleComboBoxSelected) - - #Buttons - QtCore.QObject.connect(self.ImportButton, - QtCore.SIGNAL(u'pressed()'), self.onImportButtonClicked) - QtCore.QObject.connect(self.CancelButton, - QtCore.SIGNAL(u'pressed()'), self.onCancelButtonClicked) - QtCore.QObject.connect(self.VersesFileButton, - QtCore.SIGNAL(u'pressed()'), self.onVersesFileButtonClicked) - QtCore.QObject.connect(self.BooksFileButton, - QtCore.SIGNAL(u'pressed()'), self.onBooksFileButtonClicked) - QtCore.QObject.connect(self.OsisFileButton, - QtCore.SIGNAL(u'pressed()'), self.onOsisFileButtonClicked) - - #Lost Focus - QtCore.QObject.connect(self.OSISLocationEdit, - QtCore.SIGNAL(u'lostFocus()'), self.onOSISLocationEditLostFocus) - QtCore.QObject.connect(self.BooksLocationEdit, - QtCore.SIGNAL(u'lostFocus()'),self.onBooksLocationEditLostFocus) - QtCore.QObject.connect(self.VerseLocationEdit, - QtCore.SIGNAL(u'lostFocus()'), self.onVerseLocationEditLostFocus) - QtCore.QObject.connect(self.AddressEdit, - QtCore.SIGNAL(u'lostFocus()'), self.onProxyAddressEditLostFocus) - QtCore.QObject.connect(self.UsernameEdit, - QtCore.SIGNAL(u'lostFocus()'), self.onProxyUsernameEditLostFocus) - QtCore.QObject.connect(self.PasswordEdit, - QtCore.SIGNAL(u'lostFocus()'), self.onProxyPasswordEditLostFocus) - - - def onVersesFileButtonClicked(self): - filename = QtGui.QFileDialog.getOpenFileName( - self, self.trUtf8('Open Bible Verses file'), - self.config.get_last_dir(1)) - if filename: - self.VerseLocationEdit.setText(filename) - self.config.set_last_dir(filename, 1) - self.setCsv() - - def onBooksFileButtonClicked(self): - filename = QtGui.QFileDialog.getOpenFileName( - self, self.trUtf8('Open Bible Books file'), - self.config.get_last_dir(2)) - if filename: - self.BooksLocationEdit.setText(filename) - self.config.set_last_dir(filename, 2) - self.setCsv() - - def onOsisFileButtonClicked(self): - filename = QtGui.QFileDialog.getOpenFileName( - self, self.trUtf8('Open OSIS import file'), - self.config.get_last_dir(3)) - if filename: - self.OSISLocationEdit.setText(filename) - self.config.set_last_dir(filename, 3) - self.setOsis() - - def onOSISLocationEditLostFocus(self): - if len(self.OSISLocationEdit.displayText() ) > 0: - self.setOsis() - else: - # Was OSIS and is not any more stops lostFocus running mad - if self.bible_type == u'OSIS': - self.bible_type = None - self.resetScreenFieldStates() - - def onBooksLocationEditLostFocus(self): - self.checkOsis() - - def onVerseLocationEditLostFocus(self): - self.checkOsis() - - def onProxyAddressEditLostFocus(self): - self.config.set_config( - u'proxy address', unicode(self.AddressEdit.displayText())) - - def onProxyUsernameEditLostFocus(self): - self.config.set_config( - u'proxy username', unicode(self.UsernameEdit.displayText())) - - def onProxyPasswordEditLostFocus(self): - self.config.set_config( - u'proxy password', unicode(self.PasswordEdit.displayText())) - - def onLocationComboBoxSelected(self, value): - if value == 0: - self.loadBibleCombo(self.cwBibleVersions) - self.cwActive = True - else: - self.loadBibleCombo(self.bgBibleVersions) - self.cwActive = False - self.checkHttp() - - def onBibleComboBoxSelected(self, value): - self.checkHttp() - self.BibleNameEdit.setText(unicode(self.BibleComboBox.currentText())) - self.VersionNameEdit.setText(unicode(self.BibleComboBox.currentText())) - - def onCancelButtonClicked(self): - # tell import to stop - self.message = self.trUtf8('Bible import stopped') - Receiver.send_message(u'stop_import') - # tell bibleplugin to reload the bibles - Receiver.send_message(u'pre_load_bibles') - self.close() - - def onImportButtonClicked(self): - message = self.trUtf8('Bible import completed') - if self.biblemanager: - if not self.bible_type is None and \ - len(self.BibleNameEdit.displayText()) > 0: - self.MessageLabel.setText(self.trUtf8('Import Started')) - self.ProgressBar.setMinimum(0) - self.setMax(65) - self.ProgressBar.setValue(0) - self.biblemanager.process_dialog(self) - status, msg = self.importBible() - if msg: - message = msg - self.MessageLabel.setText(message) - self.ProgressBar.setValue(self.barmax) - # tell bibleplugin to reload the bibles - Receiver.send_message(u'pre_load_bibles') - QtGui.QMessageBox.information(self, - self.trUtf8('Information'), self.trUtf8(message)) - - def setMax(self, max): - log.debug(u'set Max %s', max) - self.barmax = max - self.ProgressBar.setMaximum(max) - - def incrementProgressBar(self, text): - log.debug(u'IncrementBar %s', text) - self.MessageLabel.setText(unicode(self.trUtf8('Import processing')) + ' - %s' % text) - self.ProgressBar.setValue(self.ProgressBar.value() + 1) - - def importBible(self): - log.debug(u'Import Bible %s' % self.bible_type) - message = None - if self.bible_type == u'OSIS': - loaded = self.biblemanager.register_osis_file_bible( - unicode(self.BibleNameEdit.displayText()), - self.OSISLocationEdit.displayText()) - elif self.bible_type == u'CSV': - loaded = self.biblemanager.register_csv_file_bible( - unicode(self.BibleNameEdit.displayText()), - self.BooksLocationEdit.displayText(), - self.VerseLocationEdit.displayText()) - else: - # set a value as it will not be needed - self.setMax(1) - if self.cwActive: - bible = self.cwBibleVersions[ - unicode(self.BibleComboBox.currentText())] - else: - bible = self.bgBibleVersions[ - unicode(self.BibleComboBox.currentText())] - loaded = self.biblemanager.register_http_bible( - unicode(self.BibleComboBox.currentText()), - unicode(self.LocationComboBox.currentText()), - unicode(bible), unicode(self.AddressEdit.displayText()), - unicode(self.UsernameEdit .displayText()), - unicode(self.PasswordEdit.displayText())) - if loaded: - self.biblemanager.save_meta_data( - unicode(self.BibleNameEdit.displayText()), - unicode(self.VersionNameEdit.displayText()), - unicode(self.CopyrightEdit.displayText()), - unicode(self.PermisionEdit.displayText())) - else: - message = self.trUtf8('Bible import failed as name is already in use') - self.bible_type = None - # free the screen state restrictions - self.resetScreenFieldStates() - # reset all the screen fields - self.resetEntryFields() - return loaded, message - - def checkOsis(self): - if len(self.BooksLocationEdit.displayText()) > 0 or \ - len(self.VerseLocationEdit.displayText()) > 0: - self.setCsv() - else: - # Was CSV and is not any more stops lostFocus running mad - if self.bible_type == u'CSV': - self.bible_type = None - self.resetScreenFieldStates() - - def checkHttp(self): - if self.BibleComboBox.currentIndex() != 0 : - # First slot is blank so no bible - self.setHttp() - else: - # Was HTTP and is not any more stops lostFocus running mad - if self.bible_type == u'HTTP': - self.bible_type = None - self.resetScreenFieldStates() - - def blockCsv(self): - self.BooksLocationEdit.setReadOnly(True) - self.VerseLocationEdit.setReadOnly(True) - self.BooksFileButton.setEnabled(False) - self.VersesFileButton.setEnabled(False) - - def setCsv(self): - self.bible_type = u'CSV' - self.BooksLocationEdit.setReadOnly(False) - self.VerseLocationEdit.setReadOnly(False) - self.BooksFileButton.setEnabled(True) - self.VersesFileButton.setEnabled(True) - self.blockOsis() - self.blockHttp() - - def setOsis(self): - self.bible_type = u'OSIS' - self.OSISLocationEdit.setReadOnly(False) - self.OsisFileButton.setEnabled(True) - self.blockCsv() - self.blockHttp() - - def blockOsis(self): - self.OSISLocationEdit.setReadOnly(True) - self.OsisFileButton.setEnabled(False) - - def setHttp(self): - self.bible_type = u'HTTP' - self.LocationComboBox.setEnabled(True) - self.BibleComboBox.setEnabled(True) - self.blockCsv() - self.blockOsis() - - def blockHttp(self): - self.LocationComboBox.setEnabled(False) - self.BibleComboBox.setEnabled(False) - - def resetScreenFieldStates(self): - # only reset if no bible type set. - if self.bible_type is None: - self.BooksLocationEdit.setReadOnly(False) - self.VerseLocationEdit.setReadOnly(False) - self.BooksFileButton.setEnabled(True) - self.VersesFileButton.setEnabled(True) - self.OSISLocationEdit.setReadOnly(False) - self.OsisFileButton.setEnabled(True) - self.LocationComboBox.setEnabled(True) - self.BibleComboBox.setEnabled(True) - - def resetEntryFields(self): - self.BooksLocationEdit.setText(u'') - self.VerseLocationEdit.setText(u'') - self.OSISLocationEdit.setText(u'') - self.BibleNameEdit.setText(u'') - self.LocationComboBox.setCurrentIndex(0) - self.BibleComboBox.setCurrentIndex(0) diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index 2875c96b8..ffc2f5c9b 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -60,7 +60,6 @@ class BibleDBImpl(BibleCommon): self._load_testament(u'Apocrypha') def add_verse(self, bookid, chap, vse, text): - log.debug(u'add_verse %s,%s,%s', bookid, chap, vse) verse = Verse() verse.book_id = bookid verse.chapter = chap @@ -70,6 +69,7 @@ class BibleDBImpl(BibleCommon): return verse def save_verses(self): + log.debug('Saving verses...') self.session.commit() def create_chapter(self, bookid, chap, textlist): diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 711f49cdb..e095f9448 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -127,7 +127,6 @@ class BibleOSISImpl(): chapter = int(match.group(2)) verse = int(match.group(3)) verse_text = match.group(4) - print book, chapter, verse if not db_book or db_book.name != book: if book == u'Matt': testament += 1 diff --git a/openlp-1to2-converter.py b/scripts/openlp-1to2-converter.py similarity index 100% rename from openlp-1to2-converter.py rename to scripts/openlp-1to2-converter.py From 4f09b260db18cddbb0baefc62c1f48768bdea0c0 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Dec 2009 20:01:39 +0200 Subject: [PATCH 10/11] This time had to bribe the Line Length Police! --- .../plugins/bibles/forms/importwizardform.py | 98 ++++++++++++------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/openlp/plugins/bibles/forms/importwizardform.py b/openlp/plugins/bibles/forms/importwizardform.py index c3a91c736..0d95f51dc 100644 --- a/openlp/plugins/bibles/forms/importwizardform.py +++ b/openlp/plugins/bibles/forms/importwizardform.py @@ -107,14 +107,16 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): if self.field(u'osis_biblename').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Bible Name'), - self.trUtf8('You need to specify a name for your Bible!'), + self.trUtf8('You need to specify a name for your ' + 'Bible!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.OsisBibleNameEdit.setFocus() return False if self.field(u'osis_location').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Bible Location'), - self.trUtf8('You need to specify a file to import your Bible from!'), + self.trUtf8('You need to specify a file to import your ' + 'Bible from!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.OSISLocationEdit.setFocus() return False @@ -122,14 +124,16 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): if self.field(u'csv_booksfile').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Books File'), - self.trUtf8('You need to specify a file with books of the Bible to use in the import!'), + self.trUtf8('You need to specify a file with books of ' + 'the Bible to use in the import!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.BooksLocationEdit.setFocus() return False elif self.field(u'csv_versefile').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid Verse File'), - self.trUtf8('You need to specify a file of Bible verses to import!'), + self.trUtf8('You need to specify a file of Bible ' + 'verses to import!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.CsvVerseLocationEdit.setFocus() return False @@ -137,7 +141,8 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): if self.field(u'opensong_file').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Invalid OpenSong Bible'), - self.trUtf8('You need to specify an OpenSong Bible file to import!'), + self.trUtf8('You need to specify an OpenSong Bible ' + 'file to import!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.OpenSongFileEdit.setFocus() return False @@ -147,14 +152,17 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): if self.field(u'license_version').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Empty Version Name'), - self.trUtf8('You need to specify a version name for your Bible!'), + self.trUtf8('You need to specify a version name for your ' + 'Bible!'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.VersionNameEdit.setFocus() return False elif self.field(u'license_copyright').toString() == u'': QtGui.QMessageBox.critical(self, self.trUtf8('Empty Copyright'), - self.trUtf8('You need to set a copyright for your Bible! Bibles in the Public Domain need to be marked as such.'), + self.trUtf8('You need to set a copyright for your Bible! ' + 'Bibles in the Public Domain need to be marked as ' + 'such.'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.CopyrightEdit.setFocus() return False @@ -169,16 +177,20 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.BibleComboBox.addItem(unicode(self.trUtf8(bible))) def onOsisFileButtonClicked(self): - self.getFileName(self.trUtf8('Open OSIS file'), self.OSISLocationEdit) + self.getFileName(self.trUtf8('Open OSIS file'), + self.OSISLocationEdit) def onBooksFileButtonClicked(self): - self.getFileName(self.trUtf8('Open Books CSV file'), self.BooksLocationEdit) + self.getFileName(self.trUtf8('Open Books CSV file'), + self.BooksLocationEdit) def onCsvVersesFileButtonClicked(self): - self.getFileName(self.trUtf8('Open Verses CSV file'), self.CsvVerseLocationEdit) + self.getFileName(self.trUtf8('Open Verses CSV file'), + self.CsvVerseLocationEdit) def onOpenSongBrowseButtonClicked(self): - self.getFileName(self.trUtf8('Open OpenSong Bible'), self.OpenSongFileEdit) + self.getFileName(self.trUtf8('Open OpenSong Bible'), + self.OpenSongFileEdit) def onCurrentIdChanged(self, id): if id == 3: @@ -187,20 +199,34 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.postImport() def registerFields(self): - self.SelectPage.registerField(u'source_format', self.FormatComboBox) - self.SelectPage.registerField(u'osis_biblename', self.OsisBibleNameEdit) - self.SelectPage.registerField(u'osis_location', self.OSISLocationEdit) - self.SelectPage.registerField(u'csv_booksfile', self.BooksLocationEdit) - self.SelectPage.registerField(u'csv_versefile', self.CsvVerseLocationEdit) - self.SelectPage.registerField(u'opensong_file', self.OpenSongFileEdit) - self.SelectPage.registerField(u'web_location', self.LocationComboBox) - self.SelectPage.registerField(u'web_biblename', self.BibleComboBox) - self.SelectPage.registerField(u'proxy_server', self.AddressEdit) - self.SelectPage.registerField(u'proxy_username', self.UsernameEdit) - self.SelectPage.registerField(u'proxy_password', self.PasswordEdit) - self.LicenseDetailsPage.registerField(u'license_version', self.VersionNameEdit) - self.LicenseDetailsPage.registerField(u'license_copyright', self.CopyrightEdit) - self.LicenseDetailsPage.registerField(u'license_permission', self.PermissionEdit) + self.SelectPage.registerField( + u'source_format', self.FormatComboBox) + self.SelectPage.registerField( + u'osis_biblename', self.OsisBibleNameEdit) + self.SelectPage.registerField( + u'osis_location', self.OSISLocationEdit) + self.SelectPage.registerField( + u'csv_booksfile', self.BooksLocationEdit) + self.SelectPage.registerField( + u'csv_versefile', self.CsvVerseLocationEdit) + self.SelectPage.registerField( + u'opensong_file', self.OpenSongFileEdit) + self.SelectPage.registerField( + u'web_location', self.LocationComboBox) + self.SelectPage.registerField( + u'web_biblename', self.BibleComboBox) + self.SelectPage.registerField( + u'proxy_server', self.AddressEdit) + self.SelectPage.registerField( + u'proxy_username', self.UsernameEdit) + self.SelectPage.registerField( + u'proxy_password', self.PasswordEdit) + self.LicenseDetailsPage.registerField( + u'license_version', self.VersionNameEdit) + self.LicenseDetailsPage.registerField( + u'license_copyright', self.CopyrightEdit) + self.LicenseDetailsPage.registerField( + u'license_permission', self.PermissionEdit) def setDefaults(self): self.setField(u'source_format', 0) @@ -211,9 +237,12 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.setField(u'opensong_file', u'') self.setField(u'web_location', 0) self.setField(u'web_biblename', self.BibleComboBox) - self.setField(u'proxy_server', self.config.get_config(u'proxy address', u'')) - self.setField(u'proxy_username', self.config.get_config(u'proxy username',u'')) - self.setField(u'proxy_password', self.config.get_config(u'proxy password',u'')) + self.setField(u'proxy_server', + self.config.get_config(u'proxy address', u'')) + self.setField(u'proxy_username', + self.config.get_config(u'proxy username',u'')) + self.setField(u'proxy_password', + self.config.get_config(u'proxy password',u'')) self.setField(u'license_version', self.VersionNameEdit) self.setField(u'license_copyright', self.CopyrightEdit) self.setField(u'license_permission', self.PermissionEdit) @@ -232,8 +261,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.web_bible_list[DownloadLocation.Crosswalk] = {} fbibles = open(os.path.join(filepath, u'crosswalkbooks.csv'), 'r') for line in fbibles: - p = line.split(u',') - self.web_bible_list[DownloadLocation.Crosswalk][p[0]] = p[1].rstrip() + parts = line.split(u',') + self.web_bible_list[DownloadLocation.Crosswalk][parts[0]] = \ + parts[1].rstrip() except: log.exception(u'Crosswalk resources missing') finally: @@ -244,8 +274,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): self.web_bible_list[DownloadLocation.BibleGateway] = {} fbibles = open(os.path.join(filepath, u'biblegateway.csv'), 'r') for line in fbibles: - p = line.split(u',') - self.web_bible_list[DownloadLocation.BibleGateway][p[0]] = p[1].rstrip() + parts = line.split(u',') + self.web_bible_list[DownloadLocation.BibleGateway][parts[0]] = \ + parts[1].rstrip() except: log.exception(u'Biblegateway resources missing') finally: @@ -322,7 +353,8 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard): unicode(self.field(u'license_permission').toString()) ) else: - self.ImportProgressLabel.setText(self.trUtf8('Your Bible import failed.')) + self.ImportProgressLabel.setText( + self.trUtf8('Your Bible import failed.')) self.ImportProgressBar.setValue(self.ImportProgressBar.maximum()) def postImport(self): From 8d04e4cc1138037644db08a52e33ccdfd23d2076 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 24 Dec 2009 20:03:49 +0200 Subject: [PATCH 11/11] YEEEHAH! Revision 700! --- openlp/plugins/bibles/lib/bibleOSISimpl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index e095f9448..fb7c7866a 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -54,7 +54,8 @@ class BibleOSISImpl(): A reference to a Bible database object. """ log.info(u'BibleOSISImpl Initialising') - self.verse_regex = re.compile(r'(.*?)') + self.verse_regex = re.compile( + r'(.*?)') self.note_regex = re.compile(r'(.*?)') self.title_regex = re.compile(r'(.*?)') self.milestone_regex = re.compile(r'')