Fix up Bible Plugin to new standards.

bzr-revno: 422
This commit is contained in:
Tim Bentley 2009-03-16 17:33:51 +00:00
parent e99239ef12
commit 4bbce39f35
8 changed files with 232 additions and 155 deletions

View File

@ -32,12 +32,12 @@ from openlp.plugins.bibles.lib.classes import *
class BiblePlugin(Plugin, PluginUtils):
global log
log=logging.getLogger("BiblePlugin")
log.info("Bible Plugin loaded")
log=logging.getLogger(u'BiblePlugin')
log.info(u'Bible Plugin loaded')
def __init__(self):
# Call the parent constructor
Plugin.__init__(self, 'Bibles', '1.9.0')
Plugin.__init__(self, u'Bibles', u'1.9.0')
self.weight = -9
# Create the plugin icon
self.icon = QtGui.QIcon()
@ -52,7 +52,7 @@ class BiblePlugin(Plugin, PluginUtils):
def get_media_manager_item(self):
# Create the BibleManagerItem object
self.media_item = BibleMediaItem(self, self.icon, 'Bible Verses')
self.media_item = BibleMediaItem(self, self.icon, u'Bible Verses')
return self.media_item
def add_import_menu_item(self, import_menu):
@ -67,7 +67,8 @@ class BiblePlugin(Plugin, PluginUtils):
self.ExportBibleItem = QtGui.QAction(export_menu)
self.ExportBibleItem.setObjectName("ExportBibleItem")
export_menu.addAction(self.ExportBibleItem)
self.ExportBibleItem.setText(QtGui.QApplication.translate("main_window", "&Bible", None, QtGui.QApplication.UnicodeUTF8))
self.ExportBibleItem.setText(
QtGui.QApplication.translate("main_window", u'&Bible', None, QtGui.QApplication.UnicodeUTF8))
def initialise(self):
pass

View File

@ -17,10 +17,10 @@ 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 textlistdata import TextListData
from common import BibleCommon
from manager import BibleManager
from biblestab import BiblesTab
from biblemediaitem import BibleMediaItem
from mediaitem import BibleMediaItem
__all__ = ['BibleCommon', 'BibleManager', 'BiblesTab']
__all__ = ['BibleCommon', 'BibleManager', 'BiblesTab', 'BibleMediaItem', 'TextListData']

View File

@ -24,8 +24,8 @@ from openlp.core.lib import Receiver
class BibleCSVImpl(BibleCommon):
global log
log=logging.getLogger("BibleCSVImpl")
log.info("BibleCVSImpl loaded")
log=logging.getLogger(u'BibleCSVImpl')
log.info(u'BibleCVSImpl loaded')
def __init__(self, bibledb):
"""
Loads a Bible from a pair of CVS files passed in
@ -49,10 +49,10 @@ class BibleCSVImpl(BibleCommon):
#log.debug( line)
if self.loadbible == False: # cancel pressed
break
p = line.split(",")
p1 = p[1].replace('"', '')
p2 = p[2].replace('"', '')
p3 = p[3].replace('"', '')
p = line.split(u',')
p1 = p[1].replace(u'"', u'')
p2 = p[2].replace(u'"', u'')
p3 = p[3].replace(u'"', u'')
self.bibledb.create_book(p2, p3, int(p1))
count += 1
if count % 3 == 0: #Every x verses repaint the screen
@ -65,9 +65,9 @@ class BibleCSVImpl(BibleCommon):
if self.loadbible == False: # cancel pressed
break
#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('"', '')
p = line.split(u',', 3) # split into 3 units and leave the rest as a single field
p0 = p[0].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

View File

@ -30,8 +30,8 @@ from openlp.plugins.bibles.lib.classes import *
class BibleDBImpl(BibleCommon):
global log
log=logging.getLogger("BibleDBImpl")
log.info("BibleDBimpl loaded")
log=logging.getLogger(u'BibleDBImpl')
log.info(u'BibleDBimpl loaded')
def __init__(self, biblepath , biblename, config):
# Connect to database
@ -42,11 +42,11 @@ class BibleDBImpl(BibleCommon):
if db_type == u'sqlite':
self.db = create_engine("sqlite:///"+self.biblefile)
else:
self.db_url = db_type + 'u://' + \
self.config.get_config(u'db username') + u':' + \
self.config.get_config(u'db password') + u'@' + \
self.config.get_config(u'db hostname') + u'/' + \
self.config.get_config(u'db database')
self.db_url = u'%s://%s:%s@%s/%s' % \
(db_type, self.config.get_config(u'db username'),
self.config.get_config(u'db password'),
self.config.get_config(u'db hostname'),
self.config.get_config(u'db database'))
self.db.echo = False
metadata.bind = self.db
metadata.bind.echo = False
@ -55,8 +55,8 @@ class BibleDBImpl(BibleCommon):
metadata.create_all(self.db)
def create_tables(self):
log.debug( "createTables")
self.save_meta("dbversion", "2")
log.debug( u'createTables')
self.save_meta(u'dbversion', u'2')
self._load_testament("Old Testament")
self._load_testament("New Testament")
self._load_testament("Apocrypha")
@ -174,10 +174,10 @@ class BibleDBImpl(BibleCommon):
return self.db.execute(s, t=versetext).fetchall()
def dump_bible(self):
log.debug( ".........Dumping Bible Database")
log.debug( "...............................Books ")
log.debug( u'.........Dumping Bible Database')
log.debug( '...............................Books ')
s = text (""" select * FROM book """)
log.debug( self.db.execute(s).fetchall())
log.debug( "...............................Verses ")
log.debug( u'...............................Verses ')
s = text (""" select * FROM verse """)
log.debug( self.db.execute(s).fetchall())

View File

@ -26,11 +26,13 @@ import logging
class BGExtract(BibleCommon):
global log
log=logging.getLogger("BibleHTTPMgr(BG_extract)")
log.info("BG_extract loaded")
log=logging.getLogger(u'BibleHTTPMgr(BG_extract)')
log.info(u'BG_extract loaded')
def __init__(self, proxyurl= None):
log.debug("init %s", proxyurl)
self.proxyurl = proxyurl
def get_bible_chapter(self, version, bookid, bookname, chapter) :
"""
Access and decode bibles via the BibleGateway website
@ -41,35 +43,35 @@ class BGExtract(BibleCommon):
"""
version = 49
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
urlstring = "http://www.biblegateway.com/passage/?book_id="+str(bookid)+"&chapter"+str(chapter)+"&version="+str(version)
log.debug( u"get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
urlstring = u"http://www.biblegateway.com/passage/?book_id="+str(bookid)+"&chapter"+str(chapter)+"&version="+str(version)
xml_string = self._get_web_text(urlstring, self.proxyurl)
print xml_string
VerseSearch = "class="+'"'+"sup"+'"'+">"
VerseSearch = u'class='+'"'+u'sup'+'"'+u'>'
verse = 1
i= xml_string.find("result-text-style-normal")
i= xml_string.find(u'result-text-style-normal')
xml_string = xml_string[i:len(xml_string)]
versePos = xml_string.find(VerseSearch)
#print versePos
bible = {}
while versePos > -1:
verseText = "" # clear out string
versePos = xml_string.find("</span", versePos)
verseText = '' # clear out string
versePos = xml_string.find(u'</span', versePos)
i = xml_string.find(VerseSearch, versePos+1)
#print i , versePos
if i == -1:
i = xml_string.find("</div", versePos+1)
j = xml_string.find("<strong", versePos+1)
i = xml_string.find(u'</div', versePos+1)
j = xml_string.find(u'<strong', versePos+1)
#print i , j
if j > 0 and j < i:
i = j
verseText = xml_string[versePos + 7 : i ]
#print xml_string
#print "VerseText = " + str(verse) +" "+ verseText
#print 'VerseText = ' + str(verse) +' '+ verseText
bible[verse] = self._clean_text(verseText) # store the verse
versePos = -1
else:
i = xml_string[:i].rfind("<span")+1
i = xml_string[:i].rfind(u'<span')+1
verseText = xml_string[versePos + 7 : i - 1 ] # Loose the </span>
xml_string = xml_string[i - 1 :len(xml_string)] # chop off verse 1
versePos = xml_string.find(VerseSearch) #look for the next verse
@ -79,13 +81,15 @@ class BGExtract(BibleCommon):
class CWExtract(BibleCommon):
global log
log=logging.getLogger("BibleHTTPMgr(CWExtract)")
log.info("CWExtract loaded")
log=logging.getLogger(u'BibleHTTPMgr(CWExtract)')
log.info(u'CWExtract loaded')
def __init__(self, proxyurl=None):
log.debug("init %s", proxyurl)
log.debug(u"init %s", proxyurl)
self.proxyurl = proxyurl
def get_bible_chapter(self, version, bookid, bookname, chapter) :
log.debug( "getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug( u"getBibleChapter %s,%s,%s,%s", version, bookid, bookname, chapter)
"""
Access and decode bibles via the Crosswalk website
Version - the version of the bible like niv for New International version
@ -94,48 +98,48 @@ class CWExtract(BibleCommon):
chapter - chapter number
"""
log.debug( "get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
bookname = bookname.replace(" ", "")
bookname = bookname.replace(' ', '')
urlstring = "http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word="+bookname+"+"+str(chapter)+"&version="+version
xml_string = self._get_web_text(urlstring, self.proxyurl)
#log.debug("Return data %s", xml_string)
#log.debug('Return data %s', xml_string)
## Strip Book Title from Heading to return it to system
##
i= xml_string.find("<title>")
j= xml_string.find("-", i)
i= xml_string.find(u'<title>')
j= xml_string.find(u'-', i)
book_title = xml_string[i + 7:j]
book_title = book_title.rstrip()
log.debug("Book Title %s", book_title)
log.debug(u"Book Title %s", book_title)
i = book_title.rfind(" ")
book_chapter = book_title[i+1:len(book_title)].rstrip()
book_title = book_title[:i].rstrip()
log.debug("Book Title %s", book_title)
log.debug("Book Chapter %s", book_chapter)
log.debug(u"Book Title %s", book_title)
log.debug(u"Book Chapter %s", book_chapter)
## Strip Verse Data from Page and build an array
##
i= xml_string.find("NavCurrentChapter")
i= xml_string.find(u'NavCurrentChapter')
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<TABLE")
i= xml_string.find(u'<TABLE')
xml_string = xml_string[i:len(xml_string)]
i= xml_string.find("<B>")
i= xml_string.find(u'<B>')
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
i= xml_string.find("<B>") # Remove the heading for the book
i= xml_string.find(u'<B>') # Remove the heading for the book
xml_string = xml_string[i + 3 :len(xml_string)] #remove the <B> at the front
versePos = xml_string.find("<BLOCKQUOTE>")
versePos = xml_string.find(u'<BLOCKQUOTE>')
#log.debug( versePos)
bible = {}
while versePos > 0:
verseText = "" # clear out string
versePos = xml_string.find("<B><I>", versePos) + 6
i = xml_string.find("</I></B>", versePos)
verseText = '' # clear out string
versePos = xml_string.find(u'<B><I>', versePos) + 6
i = xml_string.find(u'</I></B>', versePos)
#log.debug( versePos, i)
verse= xml_string[versePos:i] # Got the Chapter
#verse = int(temp)
#log.debug( "Chapter = " + str(temp))
#log.debug( 'Chapter = ' + str(temp))
versePos = i + 8 # move the starting position to negining of the text
i = xml_string.find("<B><I>", versePos) # fine the start of the next verse
i = xml_string.find(u'<B><I>', versePos) # fine the start of the next verse
if i == -1:
i = xml_string.find("</BLOCKQUOTE>",versePos)
i = xml_string.find(u'</BLOCKQUOTE>',versePos)
verseText = xml_string[versePos: i]
versePos = 0
else:
@ -150,8 +154,8 @@ class CWExtract(BibleCommon):
class BibleHTTPImpl():
global log
log=logging.getLogger("BibleHTTPMgr")
log.info("BibleHTTP manager loaded")
log=logging.getLogger(u'BibleHTTPMgr')
log.info(u'BibleHTTP manager loaded')
def __init__(self):
"""
Finds all the bibles defined for the system
@ -161,7 +165,7 @@ class BibleHTTPImpl():
Init confirms the bible exists and stores the database path.
"""
bible = {}
biblesource = ""
biblesource = ''
proxyurl = None
bibleid = None
@ -169,7 +173,7 @@ class BibleHTTPImpl():
"""
Set the Proxy Url
"""
log.debug("set_proxy %s", proxyurl)
log.debug(u"set_proxy %s", proxyurl)
self.proxyurl = proxyurl
def set_bibleid(self,bibleid):
@ -177,30 +181,30 @@ class BibleHTTPImpl():
Set the bible id.
The shore identifier of the the bible.
"""
log.debug("set_bibleid %s", bibleid)
log.debug(u"set_bibleid %s", bibleid)
self.bibleid = bibleid
def set_bible_source(self,biblesource):
"""
Set the source of where the bible text is coming from
"""
log.debug("set_bible_source %s", biblesource)
log.debug(u"set_bible_source %s", biblesource)
self.biblesource = biblesource
def get_bible_chapter(self, version, bookid, bookname, chapter):
"""
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)
log.debug(u"get_bible_chapter %s,%s,%s,%s", version, bookid, bookname, chapter)
log.debug(u"biblesource = %s", self.biblesource)
try:
if self.biblesource.lower() == 'crosswalk':
if self.biblesource.lower() == u'crosswalk':
ev = CWExtract(self.proxyurl)
else:
ev = BGExtract(self.proxyurl)
return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter)
except:
log.error("Error thrown = %s", sys.exc_info()[1])
log.error(u"Error thrown = %s", sys.exc_info()[1])

View File

@ -24,8 +24,9 @@ from PyQt4 import QtCore
class BibleOSISImpl():
global log
log=logging.getLogger("BibleOSISImpl")
log.info("BibleOSISImpl loaded")
log=logging.getLogger(u'BibleOSISImpl')
log.info(u'BibleOSISImpl loaded')
def __init__(self, biblepath, bibledb):
self.bibledb = bibledb
self.booksOfBible = {} # books of the bible linked to bibleid {osis , name}
@ -50,7 +51,7 @@ class BibleOSISImpl():
book_ptr = None
id = 0
count = 0
verseText = "<verse osisID="
verseText = u'<verse osisID='
testament = 1
for file in osis.readlines():
# cancel pressed on UI
@ -69,45 +70,45 @@ class BibleOSISImpl():
#print pos, e, f[pos:e] # Found Basic Text
#remove tags of extra information
text = self.remove_block('<title','</title>', text)
text = self.remove_block('<note','</note>', text)
text = self.remove_block('<divineName','</divineName>', text)
text = self.remove_block(u'<title',u'</title>', text)
text = self.remove_block(u'<note',u'</note>', text)
text = self.remove_block(u'<divineName',u'</divineName>', text)
text = self.remove_tag('<lb', text)
text = self.remove_tag('<q', text)
text = self.remove_tag('<l', text)
text = self.remove_tag('<lg', text)
text = self.remove_tag(u'<lb', text)
text = self.remove_tag(u'<q', text)
text = self.remove_tag(u'<l', text)
text = self.remove_tag(u'<lg', 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("<FI>")
pos = text.find(u'<FI>')
while pos > -1:
epos = text.find("<Fi>", pos)
epos = text.find(u'<Fi>', pos)
if epos == -1: # TODO
#print "Y", search_text, e
pos = -1
else:
text = text[:pos] + text[epos + 4: ]
pos = text.find("<FI>")
pos = text.find(u'<FI>')
pos = text.find("<RF>")
pos = text.find(u'<RF>')
while pos > -1:
epos = text.find("<Rf>", pos)
epos = text.find(u'<Rf>', pos)
text = text[:pos] + text[epos + 4: ]
#print "X", pos, epos, text
pos = text.find("<RF>")
pos = text.find(u'<RF>')
p = ref.split(".", 3) # split up the reference
p = ref.split(u'.', 3) # split up the reference
#print p, ">>>", text
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
if p[0] == u'Gen': # set the max book size depending on the first book read
dialogobject.setMax(65)
else:
dialogobject.setMax(27)
if p[0] == "Matt": # First book of NT
if p[0] == u'Matt': # First book of NT
testament += 1
book_ptr = p[0]
book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament)
@ -143,12 +144,7 @@ class BibleOSISImpl():
"""
pos = text.find(start_tag)
while pos > -1:
epos = text.find('/>', pos)
epos = text.find(u'/>', pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find(start_tag)
return text

View File

@ -26,15 +26,15 @@ from openlp.core.lib import MediaManagerItem, Receiver
from openlp.core.resources import *
from openlp.plugins.bibles.forms import BibleImportForm
#from openlp.plugins.bibles.lib import BiblesTab
from openlp.plugins.bibles.lib import TextListData
class BibleMediaItem(MediaManagerItem):
"""
This is the custom media manager item for Bibles.
"""
global log
log=logging.getLogger("BibleMediaItem")
log.info("Bible Media Item loaded")
log=logging.getLogger(u'BibleMediaItem')
log.info(u'Bible Media Item loaded')
def __init__(self, parent, icon, title):
MediaManagerItem.__init__(self, parent, icon, title)
@ -47,19 +47,27 @@ class BibleMediaItem(MediaManagerItem):
self.addToolbar()
# Create buttons for the toolbar
## New Bible Button ##
self.addToolbarButton('New Bible', 'Register a new Bible',
self.addToolbarButton(
translate(u'BibleMediaItem','New Bible'),
translate(u'BibleMediaItem','Register a new Bible'),
':/themes/theme_import.png', self.onBibleNewClick, 'BibleNewItem')
## Separator Line ##
self.addToolbarSeparator()
## Preview Bible Button ##
self.addToolbarButton('Preview Bible', 'Preview the selected Bible Verse',
self.addToolbarButton(
translate(u'BibleMediaItem','Preview Bible'),
translate(u'BibleMediaItem','Preview the selected Bible Verse'),
':/system/system_preview.png', self.onBiblePreviewClick, 'BiblePreviewItem')
## Live Bible Button ##
self.addToolbarButton('Go Live', 'Send the selected Bible Verse(s) live',
self.addToolbarButton(
translate(u'BibleMediaItem','Go Live'),
translate(u'BibleMediaItem','Send the selected Bible Verse(s) live'),
':/system/system_live.png', self.onBibleLiveClick, 'BibleLiveItem')
## Add Bible Button ##
self.addToolbarButton('Add Bible Verse(s) To Service',
'Add the selected Bible(s) to the service', ':/system/system_add.png',
self.addToolbarButton(
translate(u'BibleMediaItem','Add Bible Verse(s) To Service'),
translate(u'BibleMediaItem','Add the selected Bible(s) to the service'),
':/system/system_add.png',
self.onBibleAddClick, 'BibleAddItem')
# Create the tab widget
@ -171,19 +179,27 @@ class BibleMediaItem(MediaManagerItem):
# Add the search tab widget to the page layout
self.PageLayout.addWidget(self.SearchTabWidget)
self.BibleListView = QtGui.QTableWidget()
self.BibleListView.setColumnCount(2)
self.BibleListView.setColumnHidden(0, True)
self.BibleListView.setColumnWidth(1, 275)
self.BibleListView.setShowGrid(False)
self.BibleListView.setSortingEnabled(False)
self.BibleListView.setAlternatingRowColors(True)
self.BibleListView.verticalHeader().setVisible(False)
self.BibleListView.horizontalHeader().setVisible(False)
self.BibleListView.setGeometry(QtCore.QRect(10, 200, 256, 391))
self.BibleListView.setObjectName(u'BibleListView')
# self.BibleListView = QtGui.QTableWidget()
# self.BibleListView.setColumnCount(2)
# self.BibleListView.setColumnHidden(0, True)
# self.BibleListView.setColumnWidth(1, 275)
# self.BibleListView.setShowGrid(False)
# self.BibleListView.setSortingEnabled(False)
# self.BibleListView.setAlternatingRowColors(True)
# self.BibleListView.verticalHeader().setVisible(False)
# self.BibleListView.horizontalHeader().setVisible(False)
# self.BibleListView.setGeometry(QtCore.QRect(10, 200, 256, 391))
# self.BibleListView.setObjectName(u'BibleListView')
# self.BibleListView.setAlternatingRowColors(True)
# self.PageLayout.addWidget(self.BibleListView)
self.BibleListView = QtGui.QListView()
self.BibleListView.setAlternatingRowColors(True)
self.BibleListData = TextListData()
self.BibleListView.setModel(self.BibleListData)
self.PageLayout.addWidget(self.BibleListView)
# Combo Boxes
QtCore.QObject.connect(self.AdvancedVersionComboBox,
QtCore.SIGNAL("activated(int)"), self.onAdvancedVersionComboBox)
@ -204,15 +220,16 @@ class BibleMediaItem(MediaManagerItem):
self.BibleListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.BibleListView.addAction(self.contextMenuAction(
self.BibleListView, ':/system/system_preview.png',
"&Preview Verse", self.onBiblePreviewClick))
translate(u'BibleMediaItem',u'&Preview Verse'), self.onBiblePreviewClick))
self.BibleListView.addAction(self.contextMenuAction(
self.BibleListView, ':/system/system_live.png',
"&Show Live", self.onBibleLiveClick))
translate(u'BibleMediaItem',u'&Show Live'), self.onBibleLiveClick))
self.BibleListView.addAction(self.contextMenuAction(
self.BibleListView, ':/system/system_add.png',
"&Add to Service", self.onBibleAddClick))
translate(u'BibleMediaItem',u'&Add to Service'), self.onBibleAddClick))
def retranslateUi(self):
log.debug(u'retranslateUi')
self.QuickVersionLabel.setText(translate(u'BibleMediaItem', u'Version:'))
self.QuickSearchLabel.setText(translate(u'BibleMediaItem', u'Search Type:'))
self.QuickSearchLabel.setText(translate(u'BibleMediaItem', u'Find:'))
@ -234,21 +251,20 @@ class BibleMediaItem(MediaManagerItem):
self.ClearAdvancedSearchComboBox.addItem(translate(u'BibleMediaItem', u'Keep'))
def initialise(self):
log.debug(u'initialise')
self.loadBibles()
def initialiseForm(self):
self.QuickSearchComboBox.clear()
def loadBibles(self):
log.debug(u'Loading Bibles')
self.QuickVersionComboBox.clear()
self.AdvancedVersionComboBox.clear()
self.ClearQuickSearchComboBox.clear()
self.ClearAdvancedSearchComboBox.clear()
def loadBibles(self):
log.debug("Loading Bibles")
bibles = self.parent.biblemanager.get_bibles('full')
bibles = self.parent.biblemanager.get_bibles(u'full')
for bible in bibles: # load bibles into the combo boxes
self.QuickVersionComboBox.addItem(bible)
bibles = self.parent.biblemanager.get_bibles('partial') # Without HTTP
bibles = self.parent.biblemanager.get_bibles(u'partial') # Without HTTP
first = True
for bible in bibles: # load bibles into the combo boxes
self.AdvancedVersionComboBox.addItem(bible)
@ -258,10 +274,9 @@ class BibleMediaItem(MediaManagerItem):
def onAdvancedVersionComboBox(self):
self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # restet the bible info
pass
def onAdvancedBookComboBox(self):
self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # restet the bible info
self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # reset the bible info
def onBibleNewClick(self):
self.bibleimportform = BibleImportForm(self.parent.config, self.parent.biblemanager, self)
@ -288,7 +303,7 @@ class BibleMediaItem(MediaManagerItem):
self.adjustComboBox(1, vse, self.AdvancedToVerse)
def onAdvancedSearchButton(self):
log.debug("Advanced Search Button pressed")
log.debug(u'Advanced Search Button pressed')
bible = str(self.AdvancedVersionComboBox.currentText())
book = str(self.AdvancedBookComboBox.currentText())
chapter_from = int(self.AdvancedFromChapter.currentText())
@ -298,9 +313,8 @@ class BibleMediaItem(MediaManagerItem):
self.search_results = self.parent.biblemanager.get_verse_text(bible, book,
chapter_from, chapter_to, verse_from, verse_to)
if self.ClearAdvancedSearchComboBox.currentIndex() == 0:
self.BibleListView.clear() # clear the results
self.BibleListView.setRowCount(0)
self.displayResults(bible)
self.BibleListData.resetStore()
self.displayResults(bible)
def onAdvancedFromChapter(self):
bible = str(self.AdvancedVersionComboBox.currentText())
@ -312,12 +326,11 @@ class BibleMediaItem(MediaManagerItem):
self._adjust_combobox(1, vse, self.AdvancedToVerse)
def onQuickSearchButton(self):
log.debug("Quick Search Button pressed")
log.debug(u'Quick Search Button pressed')
bible = str(self.QuickVersionComboBox.currentText())
text = str(self.QuickSearchEdit.displayText())
if self.ClearQuickSearchComboBox.currentIndex() == 0:
self.BibleListView.clear() # clear the results
self.BibleListView.setRowCount(0)
self.BibleListData.resetStore()
if self.QuickSearchComboBox.currentIndex() == 1:
self.search_results = self.parent.biblemanager.get_verse_from_text(bible, text)
else:
@ -326,11 +339,11 @@ class BibleMediaItem(MediaManagerItem):
self.displayResults(bible)
def onBiblePreviewClick(self):
log.debug("Bible Preview Button pressed")
items = self.BibleListView.selectedItems()
log.debug(u'Bible Preview Button pressed')
items = self.BibleListView.selectedIndexes()
old_chapter = ''
for item in items:
text = str(item.text())
text = self.BibleListData.getValue(item)
verse = text[:text.find("(")]
bible = text[text.find("(") + 1:text.find(")")]
self.searchByReference(bible, verse)
@ -364,17 +377,16 @@ class BibleMediaItem(MediaManagerItem):
return loc
def reloadBibles(self):
log.debug("Reloading Bibles")
log.debug(u'Reloading Bibles')
self.parent.biblemanager.reload_bibles()
#self.initialiseForm()
self.loadBibles()
def initialiseBible(self, bible):
log.debug('initialiseBible %s', bible)
log.debug(u"initialiseBible %s", bible)
current_book = str(self.AdvancedBookComboBox.currentText())
chapter_count = self.parent.biblemanager.get_book_chapter_count(bible,
current_book)[0]
log.debug('Book change bible %s book %s ChapterCount %s', bible,
log.debug(u'Book change bible %s book %s ChapterCount %s', bible,
current_book, chapter_count)
if chapter_count == None:
# Only change the search details if the book is missing from the new bible
@ -389,7 +401,7 @@ class BibleMediaItem(MediaManagerItem):
self.initialiseChapterVerse(bible, book.name)
def initialiseChapterVerse(self, bible, book):
log.debug("initialiseChapterVerse %s , %s", bible, book)
log.debug(u"initialiseChapterVerse %s , %s", bible, book)
self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book)[0]
self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1)[0]
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
@ -398,23 +410,18 @@ class BibleMediaItem(MediaManagerItem):
self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
def adjustComboBox(self, frm, to , combo):
log.debug("adjustComboBox %s , %s , %s", combo, frm, to)
log.debug(u"adjustComboBox %s , %s , %s", combo, frm, to)
combo.clear()
for i in range(int(frm), int(to) + 1):
combo.addItem(str(i))
def displayResults(self, bible):
for book, chap, vse , txt in self.search_results:
row_count = self.BibleListView.rowCount()
self.BibleListView.setRowCount(row_count+1)
table_data = QtGui.QTableWidgetItem(str(bible))
self.BibleListView.setItem(row_count , 0, table_data)
table_data = QtGui.QTableWidgetItem(str(book + " " +str(chap) + ":"+ str(vse)) + " ("+str(bible)+")")
self.BibleListView.setItem(row_count , 1, table_data)
self.BibleListView.setRowHeight(row_count, 20)
text = str(u" %s %d:%d (%s)"%(book , chap,vse, bible))
self.BibleListData.addRow(0,text)
def searchByReference(self, bible, search):
log.debug("searchByReference %s ,%s", bible, search)
log.debug(u"searchByReference %s ,%s", bible, search)
book = ''
start_chapter = ''
end_chapter = ''

View File

@ -0,0 +1,69 @@
import logging
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class TextListData(QAbstractListModel):
"""
An abstract list of strings
"""
global log
log=logging.getLogger(u'TextListData')
log.info(u'started')
def __init__(self):
QAbstractListModel.__init__(self)
self.items=[] # will be a list of (database id , title) tuples
def resetStore(self):
#reset list so can be reloaded
self.items=[]
def rowCount(self, parent):
return len(self.items)
def insertRow(self, row, id, title):
self.beginInsertRows(QModelIndex(),row,row)
log.debug("insert row %d:%s for id %d"%(row,title, id))
self.items.insert(row, (id, title))
self.endInsertRows()
def removeRow(self, row):
self.beginRemoveRows(QModelIndex(), row,row)
self.items.pop(row)
self.endRemoveRows()
def addRow(self, id, title):
self.insertRow(len(self.items), id, title)
def data(self, index, role):
row=index.row()
if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row!
return QVariant()
if role==Qt.DisplayRole:
retval= self.items[row][1]
# elif role == Qt.ToolTipRole: #not sure if need as it shows the database row number
# retval= self.items[row][0]
else:
retval= QVariant()
# log.info("Returning"+ str(retval))
if type(retval) is not type(QVariant):
return QVariant(retval)
else:
return retval
def getIdList(self):
filelist = [item[0] for item in self.items];
return filelist
def getValue(self, index):
row = index.row()
return self.items[row][1]
def deleteRow(self, index):
row = index.row()
self.removeRow(row)
if __name__=="__main__":
sxml=TextListData()