forked from openlp/openlp
More bible fix ups and added functionality
bzr-revno: 294
This commit is contained in:
parent
e00e328ac1
commit
fdf66b3bd5
@ -89,3 +89,6 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
def getInputFiles(self, dialogname, dialoglocation, dialogfilter):
|
||||
return QtGui.QFileDialog.getOpenFileNames(self, dialogname,dialoglocation, dialogfilter)
|
||||
|
||||
def refresh(self):
|
||||
self.update()
|
||||
|
||||
|
@ -21,6 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
import logging
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
from openlp.core.resources import *
|
||||
from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem
|
||||
@ -235,7 +237,7 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
pass
|
||||
|
||||
def onBibleNewClick(self):
|
||||
self.bibleimportform = BibleImportForm(self.config, self.biblemanager)
|
||||
self.bibleimportform = BibleImportForm(self.config, self.biblemanager, self)
|
||||
self.bibleimportform.setModal(True)
|
||||
self.bibleimportform.show()
|
||||
pass
|
||||
@ -249,6 +251,13 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
def onBibleAddClick(self):
|
||||
pass
|
||||
|
||||
def refresh(self):
|
||||
self.MediaManagerItem.refresh()
|
||||
|
||||
def reload_bibles(self):
|
||||
self.biblemanager.reload_bibles()
|
||||
self._initialise_form()
|
||||
|
||||
def _initialise_form(self):
|
||||
log.debug("_initialise_form")
|
||||
self.QuickSearchComboBox.clear()
|
||||
@ -377,8 +386,12 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
co = search.find(":")
|
||||
if co == -1: # no : found
|
||||
i = search.rfind(" ")
|
||||
book = search[:i]
|
||||
chapter = search[i:len(search)]
|
||||
if i == -1:
|
||||
book = search
|
||||
chapter = ""
|
||||
else:
|
||||
book = search[:i]
|
||||
chapter = search[i:len(search)]
|
||||
hi = chapter.find("-")
|
||||
if hi != -1:
|
||||
schapter= chapter[:hi]
|
||||
@ -402,7 +415,6 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
everse = search[co+1:]
|
||||
else:
|
||||
everse = search
|
||||
print search
|
||||
else:
|
||||
everse = search
|
||||
if echapter == "":
|
||||
@ -411,12 +423,16 @@ class BiblePlugin(Plugin, PluginUtils):
|
||||
sverse = 1
|
||||
if everse == "":
|
||||
everse = 99
|
||||
# print "book = " + book
|
||||
# print "chapter s =" + str(schapter)
|
||||
# print "chapter e =" + str(echapter)
|
||||
# print "verse s =" + str(sverse)
|
||||
# print "verse e =" + str(everse)
|
||||
self.searchresults = self.biblemanager.get_verse_text(bible, book,int(schapter), int(echapter), int(sverse), int(everse))
|
||||
self._display_results(bible)
|
||||
print "book = " + book
|
||||
print "chapter s =" + str(schapter)
|
||||
print "chapter e =" + str(echapter)
|
||||
print "verse s =" + str(sverse)
|
||||
print "verse e =" + str(everse)
|
||||
if not schapter == "":
|
||||
self.searchresults = self.biblemanager.get_verse_text(bible, book,int(schapter), int(echapter), int(sverse), int(everse))
|
||||
self._display_results(bible)
|
||||
else:
|
||||
QMessageBox.information(self,"Information","A plain, informational message")
|
||||
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
def __init__(self, config, biblemanager , parent = None):
|
||||
def __init__(self, config, biblemanager , bibleplugin, parent = None):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
@ -33,6 +33,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
self.setupUi(self)
|
||||
self.biblemanager = biblemanager
|
||||
self.config = config
|
||||
self.bibleplugin = bibleplugin
|
||||
self.bibletype = None
|
||||
self.barmax = 0
|
||||
|
||||
@ -79,7 +80,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0:
|
||||
self.setCSV()
|
||||
else:
|
||||
if self.bibletype == "CVS": # Was CSV and is not any more stops lostFocus running mad
|
||||
if self.bibletype == "CSV": # Was CSV and is not any more stops lostFocus running mad
|
||||
self.bibletype = None
|
||||
self.freeAll()
|
||||
|
||||
@ -103,30 +104,31 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
self.freeAll()
|
||||
|
||||
def on_CopyrightEdit_lostFocus(self):
|
||||
A =1
|
||||
pass
|
||||
|
||||
def on_VersionNameEdit_lostFocus(self):
|
||||
A =1
|
||||
pass
|
||||
|
||||
def on_PermisionEdit_lostFocus(self):
|
||||
A =1
|
||||
pass
|
||||
|
||||
def on_BibleNameEdit_lostFocus(self):
|
||||
A =1
|
||||
pass
|
||||
|
||||
def on_BibleImportButtonBox_clicked(self,button):
|
||||
log.debug("BibleImportButtonBox %s , %s", button.text() , self.bibletype)
|
||||
if button.text() == "Save":
|
||||
if self.biblemanager != None:
|
||||
if not self.bibletype == None:
|
||||
if not self.bibletype == None or len(self.BibleNameEdit.displayText()) > 0:
|
||||
self.MessageLabel.setText("Import Started")
|
||||
self.ProgressBar.setValue(1)
|
||||
self.ProgressBar.setValue(0)
|
||||
self.progress = 0
|
||||
self.biblemanager.process_dialog(self)
|
||||
self._import_bible()
|
||||
self.MessageLabel.setText("Import Complete")
|
||||
self.ProgressBar.setValue(self.barmax)
|
||||
self.update()
|
||||
self.bibleplugin.reload_bibles() # Update form as we have a new bible
|
||||
elif button.text() == "Cancel":
|
||||
self.close()
|
||||
|
||||
@ -142,16 +144,17 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
self.progress +=1
|
||||
self.ProgressBar.setValue(self.progress)
|
||||
self.update()
|
||||
self.bibleplugin.refresh()
|
||||
|
||||
def _import_bible(self):
|
||||
if self.bibletype == "OSIS":
|
||||
self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText())
|
||||
elif self.bibletype == "CSV":
|
||||
self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText())
|
||||
self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.BooksLocationEdit.displayText(), self.VerseLocationEdit.displayText())
|
||||
else:
|
||||
self.setMax(1) # set a value as it will not be needed
|
||||
bname = self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()),str(self.LocationComboBox.currentText()) )
|
||||
self.BibleNameEdit.setText(bname)
|
||||
self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()),str(self.LocationComboBox.currentText()) )
|
||||
self.BibleNameEdit.setText(str(self.BibleComboBox.currentText()))
|
||||
|
||||
self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), str(self.VersionNameEdit.displayText()), str(self.CopyrightEdit.displayText()), str(self.PermisionEdit.displayText()))
|
||||
self.bibletype = None
|
||||
@ -165,7 +168,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
|
||||
self.VersesFileButton.setEnabled(False)
|
||||
|
||||
def setCSV(self):
|
||||
self.bibletype = "CVS"
|
||||
self.bibletype = "CSV"
|
||||
self.BooksLocationEdit.setReadOnly(False)
|
||||
self.VerseLocationEdit.setReadOnly(False)
|
||||
self.BooksFileButton.setEnabled(True)
|
||||
|
@ -15,15 +15,11 @@ 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 os, os.path
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
import logging
|
||||
|
||||
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
|
||||
from openlp.plugins.bibles.lib.common import BibleCommon
|
||||
|
||||
import logging
|
||||
|
||||
class BibleCSVImpl(BibleCommon):
|
||||
global log
|
||||
@ -37,13 +33,7 @@ class BibleCSVImpl(BibleCommon):
|
||||
"""
|
||||
self.bibledb = bibledb
|
||||
|
||||
def load_data(self, booksfile, versesfile):
|
||||
self.bibledb.save_meta("version", "Bible Version")
|
||||
self.bibledb.save_meta("Copyright", "(c) Some Bible company")
|
||||
self.bibledb.save_meta("Permission", "You Have Some")
|
||||
|
||||
#session = self.Session()
|
||||
|
||||
def load_data(self, booksfile, versesfile, dialogobject=None):
|
||||
#Populate the Tables
|
||||
fbooks=open(booksfile, 'r')
|
||||
fverse=open(versesfile, 'r')
|
||||
@ -51,22 +41,19 @@ class BibleCSVImpl(BibleCommon):
|
||||
for line in fbooks:
|
||||
#log.debug( line)
|
||||
p = line.split(",")
|
||||
p1 = p[1].replace('"', '')
|
||||
p2 = p[2].replace('"', '')
|
||||
p3 = p[3].replace('"', '')
|
||||
self.bibledb.create_book(int(p[1]), p2, p3)
|
||||
|
||||
|
||||
book_ptr = ""
|
||||
id = 0
|
||||
self.bibledb.create_book(p2, p3, int(p1))
|
||||
book_ptr = None
|
||||
for line in fverse:
|
||||
#log.debug( line)
|
||||
p = line.split(",", 3) # split into 3 units and leave the rest as a single field
|
||||
p0 = p[0].replace('"', '')
|
||||
p3 = p[3].replace('"', '')
|
||||
if book_ptr is not p0:
|
||||
cl = self.bibledb.get_bible_book(p0)
|
||||
id = self.bibledb.get_bible_book_Id(p0)
|
||||
book_ptr = cl
|
||||
log.debug( id )
|
||||
self.bibledb.add_verse(id[0], p[1], p[2], p3)
|
||||
book = self.bibledb.get_bible_book(p0)
|
||||
book_ptr = book.name
|
||||
dialogobject.incrementBar(book.name) # increament the progress bar
|
||||
self.bibledb.add_verse(book.id, p[1], p[2], p3)
|
||||
|
||||
|
@ -15,24 +15,18 @@ 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 os, os.path
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
import os.path
|
||||
import logging
|
||||
import string
|
||||
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.sql import select
|
||||
from sqlalchemy.orm import sessionmaker, mapper, scoped_session
|
||||
|
||||
from openlp.plugins.bibles.lib.tables import *
|
||||
from openlp.plugins.bibles.lib.classes import *
|
||||
|
||||
from common import BibleCommon
|
||||
from openlp.core.utils import ConfigHelper
|
||||
|
||||
import logging
|
||||
from openlp.plugins.bibles.lib.tables import *
|
||||
from openlp.plugins.bibles.lib.classes import *
|
||||
|
||||
class BibleDBImpl(BibleCommon):
|
||||
global log
|
||||
@ -65,11 +59,11 @@ class BibleDBImpl(BibleCommon):
|
||||
log.debug( "createTables")
|
||||
self.save_meta("dbversion", "2")
|
||||
self._load_testament("Old Testament")
|
||||
self._load_testament("Apocrypha")
|
||||
self._load_testament("New Testament")
|
||||
self._load_testament("Apocrypha")
|
||||
|
||||
def add_verse(self, bookid, chap, vse, text):
|
||||
log.debug( "add_verse %s,%s,%s,%s", bookid, chap, vse, text)
|
||||
log.debug( "add_verse %s,%s,%s", bookid, chap, vse)
|
||||
metadata.bind.echo = False
|
||||
session = self.session()
|
||||
verse = Verse()
|
||||
@ -81,7 +75,7 @@ class BibleDBImpl(BibleCommon):
|
||||
session.commit()
|
||||
|
||||
def create_chapter(self, bookid, chap, textlist):
|
||||
log.debug( "create_chapter %s,%s,%s", bookid, chap, textlist)
|
||||
log.debug( "create_chapter %s,%s", bookid, chap)
|
||||
metadata.bind.echo = False
|
||||
session = self.session()
|
||||
for v , t in textlist.iteritems():
|
||||
@ -93,12 +87,12 @@ class BibleDBImpl(BibleCommon):
|
||||
session.add(verse)
|
||||
session.commit()
|
||||
|
||||
def create_book(self, bookname, bookabbrev):
|
||||
def create_book(self, bookname, bookabbrev, testament = 1):
|
||||
log.debug( "create_book %s,%s", bookname, bookabbrev)
|
||||
metadata.bind.echo = False
|
||||
session = self.session()
|
||||
book = Book()
|
||||
book.testament_id = 1
|
||||
book.testament_id = testament
|
||||
book.name = bookname
|
||||
book.abbreviation = bookabbrev
|
||||
session.add(book)
|
||||
@ -159,9 +153,7 @@ class BibleDBImpl(BibleCommon):
|
||||
def get_bible_chapter(self, id, chapter):
|
||||
log.debug( "get_bible_chapter %s,%s", id, chapter )
|
||||
metadata.bind.echo = False
|
||||
#s = text (""" select book.name FROM verse,book where verse.book_id == book.id AND verse.chapter == :c and book.name == :b """)
|
||||
return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first()
|
||||
#return self.db.execute(s, c=chapter, b=bookname).fetchone()
|
||||
|
||||
def get_bible_text(self, bookname, chapter, sverse, everse):
|
||||
log.debug( "get_bible_text %s,%s,%s,%s ", bookname, chapter, sverse, everse)
|
||||
|
@ -157,14 +157,14 @@ class BibleHTTPImpl():
|
||||
|
||||
def set_bible_source(self,biblesource):
|
||||
"""
|
||||
Set the source of where the bible text is comming from
|
||||
Set the source of where the bible text is coming from
|
||||
"""
|
||||
log.debug("set_bible_source %s", biblesource)
|
||||
self.biblesource = biblesource
|
||||
|
||||
def get_bible_chapter(self, version, bookid, bookname, chapter):
|
||||
"""
|
||||
Recieve the request and call the relevent handler methods
|
||||
Receive the request and call the relevant handler methods
|
||||
"""
|
||||
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
|
||||
log.debug("biblesource = %s", self.biblesource)
|
||||
|
@ -15,13 +15,8 @@ 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 os, os.path
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
|
||||
|
||||
import logging
|
||||
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
|
||||
|
||||
class BibleOSISImpl():
|
||||
global log
|
||||
@ -39,25 +34,19 @@ class BibleOSISImpl():
|
||||
|
||||
|
||||
def load_data(self, osisfile, dialogobject=None):
|
||||
self.bibledb.save_meta("Version", "Bible Version")
|
||||
self.bibledb.save_meta("Copyright", "(c) Some Bible company")
|
||||
self.bibledb.save_meta("Permission", "You Have Some")
|
||||
|
||||
#TODO: need to see if new / old or both testaments
|
||||
dialogobject.setMax(65)
|
||||
|
||||
osis=open(osisfile, 'r')
|
||||
|
||||
book_ptr = ""
|
||||
book_ptr = None
|
||||
id = 0
|
||||
verseText = "<verse osisID="
|
||||
testament = 1
|
||||
for f in osis.readlines():
|
||||
#print f
|
||||
s = f.find(verseText)
|
||||
if s > -1: # we have a verse
|
||||
e= f.find(">", s)
|
||||
ref = f[s+15:e-1] # Book Reference
|
||||
#lets find the bble text
|
||||
#lets find the bible text
|
||||
s = e + 1 # find start of text
|
||||
e = f.find("</verse>", s) # end of text
|
||||
t = f[s:e]
|
||||
@ -81,12 +70,19 @@ class BibleOSISImpl():
|
||||
#print "X", s, e, t
|
||||
s = t.find("<RF>")
|
||||
|
||||
p = ref.split(".", 3) # split u[ the reference
|
||||
p = ref.split(".", 3) # split up the reference
|
||||
if book_ptr != p[0]:
|
||||
if book_ptr == None: # first time through
|
||||
if p[0] == "Gen": # set the max book size depending on the first book read
|
||||
dialogobject.setMax(66)
|
||||
else:
|
||||
dialogobject.setMax(27)
|
||||
if p[0] == "Gen":
|
||||
testament += 1
|
||||
book_ptr = p[0]
|
||||
id = self.bibledb.create_book(int(p[1]), self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]])
|
||||
dialogobject.incrementBar()
|
||||
self.bibledb.add_verse(id, p[1], p[2], t)
|
||||
book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament)
|
||||
dialogobject.incrementBar(self.booksOfBible[p[0]] )
|
||||
self.bibledb.add_verse(book.id, p[1], p[2], t)
|
||||
|
||||
|
||||
|
||||
|
@ -44,16 +44,23 @@ class BibleManager():
|
||||
"""
|
||||
self.config = config
|
||||
log.debug( "Bible Initialising")
|
||||
self.bibleDBCache = {} # dict of bible database classes
|
||||
self.bibleHTTPCache = {} # dict of bible http readers
|
||||
self.bibleDBCache = None # dict of bible database classes
|
||||
self.bibleHTTPCache = None # dict of bible http readers
|
||||
self.biblePath = self.config.get_data_path()
|
||||
self.proxyname = self.config.get_config("proxy name") #get proxy name for screen
|
||||
self.bibleSuffix = "sqlite"
|
||||
self.dialogobject = None
|
||||
self.reload_bibles()
|
||||
|
||||
def reload_bibles(self):
|
||||
log.debug("Reload bibles")
|
||||
|
||||
files = self.config.get_files(self.bibleSuffix)
|
||||
log.debug("Bible Files %s", files )
|
||||
|
||||
self.bibleDBCache = {}
|
||||
self.bibleHTTPCache = {}
|
||||
|
||||
for f in files:
|
||||
nme = f.split('.')
|
||||
bname = nme[0]
|
||||
@ -96,21 +103,21 @@ class BibleManager():
|
||||
nbible.save_meta("proxyid", proxyid) # store the proxy userid
|
||||
if proxypass != None:
|
||||
nbible.save_meta("proxypass", proxypass) # store the proxy password
|
||||
return biblename
|
||||
|
||||
|
||||
def register_cvs_file_bible(self, biblename, booksfile, versefile):
|
||||
def register_csv_file_bible(self, biblename, booksfile, versefile):
|
||||
"""
|
||||
Method to load a bible from a set of files into a database.
|
||||
If the database exists it is deleted and the database is reloaded
|
||||
from scratch.
|
||||
"""
|
||||
log.debug( "register_CSV_file_bible %s,%s,%s", biblename, booksfile, versefile)
|
||||
if self._is_new_bible(biblename):
|
||||
nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible
|
||||
nbible.create_tables() # Create Database
|
||||
self.bibleDBCache[biblename] = nbible # cache the database for use later
|
||||
bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database
|
||||
bcsv.load_data(booksfile, versefile)
|
||||
bcsv.load_data(booksfile, versefile, self.dialogobject)
|
||||
|
||||
def register_osis_file_bible(self, biblename, osisfile):
|
||||
"""
|
||||
@ -176,10 +183,10 @@ class BibleManager():
|
||||
"""
|
||||
Saves the bibles meta data
|
||||
"""
|
||||
log.debug( "save_meta %s,%s, %s,%s", bible, version, copyright, permissions)
|
||||
log.debug( "save_meta data %s,%s, %s,%s", bible, version, copyright, permissions)
|
||||
self.bibleDBCache[bible].save_meta("Version", version)
|
||||
self.bibleDBCache[bible].save_meta("Copyright", copyright)
|
||||
self.bibleDBCache[bible].save_meta("Permissins", permissions)
|
||||
self.bibleDBCache[bible].save_meta("Permissions", permissions)
|
||||
|
||||
def get_meta_data(self, bible, key):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user