2008-11-29 07:56:21 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Module implementing BibleImportDialog.
|
|
|
|
"""
|
|
|
|
import sys
|
2008-11-29 13:38:11 +00:00
|
|
|
import os, os.path
|
|
|
|
import sys
|
2008-11-30 18:31:43 +00:00
|
|
|
import time
|
2009-01-24 08:06:36 +00:00
|
|
|
import logging
|
2008-11-30 18:31:43 +00:00
|
|
|
|
2009-01-06 19:04:54 +00:00
|
|
|
from openlp.core.resources import *
|
2008-11-29 07:56:21 +00:00
|
|
|
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
from PyQt4.QtGui import QDialog
|
|
|
|
from PyQt4.QtCore import pyqtSignature
|
|
|
|
|
|
|
|
from bibleimportdialog import Ui_BibleImportDialog
|
2009-02-08 15:25:00 +00:00
|
|
|
from openlp.core.lib import PluginUtils, Receiver
|
|
|
|
|
2008-11-29 07:56:21 +00:00
|
|
|
|
2009-01-20 19:51:20 +00:00
|
|
|
class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
2009-01-24 08:06:36 +00:00
|
|
|
global log
|
|
|
|
log=logging.getLogger("BibleImportForm")
|
|
|
|
log.info("BibleImportForm loaded")
|
2008-11-29 07:56:21 +00:00
|
|
|
"""
|
|
|
|
Class documentation goes here.
|
|
|
|
"""
|
2009-02-02 19:54:38 +00:00
|
|
|
def __init__(self, config, biblemanager , bibleplugin, parent = None):
|
2008-11-29 07:56:21 +00:00
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
|
|
|
QDialog.__init__(self, parent)
|
|
|
|
self.setupUi(self)
|
2008-12-06 19:34:48 +00:00
|
|
|
self.biblemanager = biblemanager
|
2009-01-20 19:51:20 +00:00
|
|
|
self.config = config
|
2009-02-02 19:54:38 +00:00
|
|
|
self.bibleplugin = bibleplugin
|
2009-01-24 08:06:36 +00:00
|
|
|
self.bibletype = None
|
|
|
|
self.barmax = 0
|
2009-02-13 20:52:36 +00:00
|
|
|
self.AddressEdit.setText(self.config.get_config("addressedit", ""))
|
|
|
|
self.UsernameEdit.setText(self.config.get_config("usernameedit", ""))
|
|
|
|
self.PasswordEdit.setText(self.config.get_config("passwordedit",""))
|
2009-02-15 19:11:27 +00:00
|
|
|
|
|
|
|
filepath = os.path.split(os.path.abspath(__file__))[0]
|
|
|
|
filepath = os.path.abspath(os.path.join(filepath, '..', 'resources','crosswalkbooks.csv'))
|
|
|
|
fbibles=open(filepath, 'r')
|
|
|
|
self.bible_versions = {}
|
|
|
|
self.BibleComboBox.clear()
|
|
|
|
for line in fbibles:
|
|
|
|
p = line.split(",")
|
|
|
|
self.bible_versions[p[0]] = p[1].replace('\n', '')
|
|
|
|
self.BibleComboBox.addItem(str(p[0]))
|
|
|
|
|
2008-11-29 07:56:21 +00:00
|
|
|
|
2009-01-24 08:06:36 +00:00
|
|
|
QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL("activated(int)"), self.onLocationComboBox)
|
|
|
|
QtCore.QObject.connect(self.BibleComboBox, QtCore.SIGNAL("activated(int)"), self.onBibleComboBox)
|
2009-02-08 15:25:00 +00:00
|
|
|
|
2008-11-29 07:56:21 +00:00
|
|
|
@pyqtSignature("")
|
|
|
|
def on_VersesFileButton_clicked(self):
|
2009-02-15 19:11:27 +00:00
|
|
|
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self._get_last_dir(1))
|
2009-01-20 19:51:20 +00:00
|
|
|
self.VerseLocationEdit.setText(filename)
|
2009-02-15 19:11:27 +00:00
|
|
|
if filename != "":
|
|
|
|
self._save_last_directory(filename, 1)
|
2009-01-24 08:06:36 +00:00
|
|
|
self.setCSV()
|
2008-11-29 07:56:21 +00:00
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_BooksFileButton_clicked(self):
|
2009-02-15 19:11:27 +00:00
|
|
|
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self._get_last_dir(2))
|
2008-11-29 07:56:21 +00:00
|
|
|
self.BooksLocationEdit.setText(filename)
|
2009-02-15 19:11:27 +00:00
|
|
|
if filename != "":
|
|
|
|
self._save_last_directory(filename, 2)
|
2009-01-24 08:06:36 +00:00
|
|
|
self.setCSV()
|
2008-11-29 07:56:21 +00:00
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_OsisFileButton_clicked(self):
|
2009-02-15 19:11:27 +00:00
|
|
|
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self._get_last_dir(3))
|
2008-11-29 07:56:21 +00:00
|
|
|
self.OSISLocationEdit.setText(filename)
|
2009-02-15 19:11:27 +00:00
|
|
|
if filename != "":
|
|
|
|
self._save_last_directory(filename, 3)
|
2009-01-24 08:06:36 +00:00
|
|
|
self.setOSIS()
|
|
|
|
|
2008-11-30 18:31:43 +00:00
|
|
|
def on_OSISLocationEdit_lostFocus(self):
|
2009-01-24 08:06:36 +00:00
|
|
|
if len(self.OSISLocationEdit.displayText() ) > 0:
|
|
|
|
self.setOSIS()
|
2008-12-13 19:42:25 +00:00
|
|
|
else:
|
2009-01-24 08:06:36 +00:00
|
|
|
if self.bibletype == "OSIS": # Was OSIS and is not any more stops lostFocus running mad
|
|
|
|
self.bibletype = None
|
|
|
|
self.freeAll()
|
2008-12-13 19:42:25 +00:00
|
|
|
|
2009-01-24 08:06:36 +00:00
|
|
|
def on_BooksLocationEdit_lostFocus(self):
|
|
|
|
self._checkcsv()
|
|
|
|
|
2008-12-13 19:42:25 +00:00
|
|
|
def on_VerseLocationEdit_lostFocus(self):
|
2009-01-24 08:06:36 +00:00
|
|
|
self._checkcsv()
|
|
|
|
|
|
|
|
def _checkcsv(self):
|
|
|
|
if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0:
|
|
|
|
self.setCSV()
|
2008-12-13 19:42:25 +00:00
|
|
|
else:
|
2009-02-02 19:54:38 +00:00
|
|
|
if self.bibletype == "CSV": # Was CSV and is not any more stops lostFocus running mad
|
2009-01-24 08:06:36 +00:00
|
|
|
self.bibletype = None
|
|
|
|
self.freeAll()
|
2009-02-13 20:52:36 +00:00
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_AddressEdit_lostFocus(self):
|
|
|
|
self.config.set_config("addressedit", str(self.AddressEdit.displayText()))
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_UsernameEdit_lostFocus(self):
|
|
|
|
self.config.set_config("usernameedit", str(self.UsernameEdit.displayText()))
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_PasswordEdit_lostFocus(self):
|
|
|
|
self.config.set_config("passwordedit", str(self.PasswordEdit.displayText()))
|
|
|
|
|
2009-01-24 08:06:36 +00:00
|
|
|
def onLocationComboBox(self):
|
|
|
|
self._checkhttp()
|
|
|
|
|
|
|
|
def onBibleComboBox(self):
|
|
|
|
self._checkhttp()
|
|
|
|
|
|
|
|
def _checkhttp(self):
|
|
|
|
if len(self.LocationComboBox.currentText()) > 0 or \
|
|
|
|
len(self.BibleComboBox.currentText()) >0 :
|
|
|
|
self.setHTTP()
|
|
|
|
else:
|
|
|
|
if self.bibletype == "HTTP": # Was HTTP and is not any more stops lostFocus running mad
|
|
|
|
self.bibletype = None
|
|
|
|
self.freeAll()
|
|
|
|
|
2008-11-30 18:31:43 +00:00
|
|
|
def on_CopyrightEdit_lostFocus(self):
|
2009-02-02 19:54:38 +00:00
|
|
|
pass
|
2009-01-06 19:04:54 +00:00
|
|
|
|
2008-11-30 18:31:43 +00:00
|
|
|
def on_VersionNameEdit_lostFocus(self):
|
2009-02-02 19:54:38 +00:00
|
|
|
pass
|
2009-01-06 19:04:54 +00:00
|
|
|
|
2008-11-30 18:31:43 +00:00
|
|
|
def on_PermisionEdit_lostFocus(self):
|
2009-02-02 19:54:38 +00:00
|
|
|
pass
|
2009-01-06 19:04:54 +00:00
|
|
|
|
2008-11-30 18:31:43 +00:00
|
|
|
def on_BibleNameEdit_lostFocus(self):
|
2009-02-02 19:54:38 +00:00
|
|
|
pass
|
2009-01-06 19:04:54 +00:00
|
|
|
|
2009-02-11 18:33:54 +00:00
|
|
|
@pyqtSignature("")
|
|
|
|
def on_CancelButton_clicked(self):
|
2009-02-11 19:07:34 +00:00
|
|
|
Receiver().send_message("openlpstopimport")
|
2009-02-11 18:33:54 +00:00
|
|
|
self.close()
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
|
def on_ImportButton_clicked(self):
|
|
|
|
if self.biblemanager != None:
|
2009-02-14 13:52:23 +00:00
|
|
|
if not self.bibletype == None and len(self.BibleNameEdit.displayText()) > 0:
|
2009-02-11 18:33:54 +00:00
|
|
|
self.MessageLabel.setText("Import Started")
|
2009-02-14 13:52:05 +00:00
|
|
|
self.ProgressBar.setMinimum(0)
|
|
|
|
self.setMax(65)
|
2009-02-11 18:33:54 +00:00
|
|
|
self.ProgressBar.setValue(0)
|
|
|
|
self.progress = 0
|
|
|
|
self.biblemanager.process_dialog(self)
|
|
|
|
self._import_bible()
|
|
|
|
self.MessageLabel.setText("Import Complete")
|
2009-02-11 19:07:34 +00:00
|
|
|
self.ProgressBar.setValue(self.barmax)
|
2009-02-14 13:52:23 +00:00
|
|
|
Receiver().send_message("openlpreloadbibles") # tell bibleplugin to reload the bibles
|
2009-01-20 19:51:20 +00:00
|
|
|
|
2008-12-13 19:42:25 +00:00
|
|
|
def setMax(self, max):
|
2009-02-08 15:25:00 +00:00
|
|
|
log.debug("set Max %s", max)
|
2009-01-24 08:06:36 +00:00
|
|
|
self.barmax = max
|
2008-12-13 19:42:25 +00:00
|
|
|
self.ProgressBar.setMaximum(max)
|
2008-11-30 18:31:43 +00:00
|
|
|
|
2009-02-08 15:25:00 +00:00
|
|
|
def incrementBar(self, text ):
|
|
|
|
log.debug("IncrementBar %s", text)
|
|
|
|
self.MessageLabel.setText("Import processing " + text)
|
2008-12-13 19:42:25 +00:00
|
|
|
self.progress +=1
|
2009-02-08 15:25:00 +00:00
|
|
|
self.ProgressBar.setValue(self.progress)
|
|
|
|
|
2009-01-24 08:06:36 +00:00
|
|
|
def _import_bible(self):
|
2009-02-08 15:25:00 +00:00
|
|
|
log.debug("Import Bible ")
|
2009-01-24 08:06:36 +00:00
|
|
|
if self.bibletype == "OSIS":
|
|
|
|
self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText())
|
|
|
|
elif self.bibletype == "CSV":
|
2009-02-02 19:54:38 +00:00
|
|
|
self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.BooksLocationEdit.displayText(), self.VerseLocationEdit.displayText())
|
2009-01-24 08:06:36 +00:00
|
|
|
else:
|
|
|
|
self.setMax(1) # set a value as it will not be needed
|
2009-02-15 19:11:27 +00:00
|
|
|
bible = self.bible_versions[str(self.BibleComboBox.currentText())]
|
|
|
|
print bible
|
2009-02-13 20:52:36 +00:00
|
|
|
self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()), \
|
|
|
|
str(self.LocationComboBox.currentText()), \
|
|
|
|
str(self.AddressEdit.displayText()), \
|
|
|
|
str(self.UsernameEdit .displayText()), \
|
|
|
|
str(self.PasswordEdit.displayText()))
|
2009-02-02 19:54:38 +00:00
|
|
|
self.BibleNameEdit.setText(str(self.BibleComboBox.currentText()))
|
2009-01-24 08:06:36 +00:00
|
|
|
|
|
|
|
self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), str(self.VersionNameEdit.displayText()), str(self.CopyrightEdit.displayText()), str(self.PermisionEdit.displayText()))
|
|
|
|
self.bibletype = None
|
2009-02-11 20:52:06 +00:00
|
|
|
self.freeAll() # free the screen state restrictions
|
2009-01-24 08:06:36 +00:00
|
|
|
self.resetAll() # reset all the screen fields
|
|
|
|
|
|
|
|
def blockCSV(self):
|
|
|
|
self.BooksLocationEdit.setReadOnly(True)
|
|
|
|
self.VerseLocationEdit.setReadOnly(True)
|
|
|
|
self.BooksFileButton.setEnabled(False)
|
|
|
|
self.VersesFileButton.setEnabled(False)
|
|
|
|
|
|
|
|
def setCSV(self):
|
2009-02-02 19:54:38 +00:00
|
|
|
self.bibletype = "CSV"
|
2009-01-24 08:06:36 +00:00
|
|
|
self.BooksLocationEdit.setReadOnly(False)
|
|
|
|
self.VerseLocationEdit.setReadOnly(False)
|
|
|
|
self.BooksFileButton.setEnabled(True)
|
|
|
|
self.VersesFileButton.setEnabled(True)
|
|
|
|
self.blockOSIS()
|
|
|
|
self.blockHTTP()
|
|
|
|
|
|
|
|
def setOSIS(self):
|
|
|
|
self.bibletype = "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.bibletype = "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 freeAll(self):
|
|
|
|
if self.bibletype == None: # only reset if no bible type set.
|
|
|
|
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)
|
2008-11-30 18:31:43 +00:00
|
|
|
|
2009-01-24 08:06:36 +00:00
|
|
|
def resetAll(self):
|
|
|
|
self.BooksLocationEdit.setText("")
|
|
|
|
self.VerseLocationEdit.setText("")
|
|
|
|
self.OSISLocationEdit.setText("")
|
2009-02-11 20:52:06 +00:00
|
|
|
self.BibleNameEdit.setText("")
|
2009-01-24 08:06:36 +00:00
|
|
|
self.LocationComboBox.setCurrentIndex(0)
|
|
|
|
self.BibleComboBox.setCurrentIndex(0)
|