diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index 39a65c5ce..62096ff89 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -1,6 +1,8 @@ """ OpenLP - Open Source Lyrics Projection + Copyright (c) 2008 Raoul Snyman + Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley This program is free software; you can redistribute it and/or modify it under @@ -20,8 +22,8 @@ import os.path import logging from sqlalchemy import * -from sqlalchemy.sql import select -from sqlalchemy.orm import sessionmaker, mapper, scoped_session +from sqlalchemy.sql import select, func +from sqlalchemy.orm import sessionmaker, mapper, scoped_session from common import BibleCommon from openlp.core.utils import ConfigHelper @@ -91,7 +93,7 @@ class BibleDBImpl(BibleCommon): def create_book(self, bookname, bookabbrev, testament = 1): log.debug(u'create_book %s,%s', bookname, bookabbrev) metadata.bind.echo = False - session = self.session() + session = self.session book = Book() book.testament_id = testament book.name = bookname @@ -103,8 +105,8 @@ class BibleDBImpl(BibleCommon): def save_meta(self, key, value): log.debug(u'save_meta %s/%s', key, value) metadata.bind.echo = False - session = self.session() - bmeta= BibleMeta() + session = self.session + bmeta = BibleMeta() bmeta.key = key bmeta.value = value session.add(bmeta) @@ -112,7 +114,7 @@ class BibleDBImpl(BibleCommon): def get_meta(self, metakey): log.debug(u'get meta %s', metakey) - return self.session.query(BibleMeta).filter_by(key = metakey).first() + return self.session.query(BibleMeta).filter_by(key=metakey).first() def delete_meta(self, metakey): biblemeta = self.get_meta(metakey) @@ -126,46 +128,52 @@ class BibleDBImpl(BibleCommon): def _load_testament(self, testament): log.debug(u'load_testaments %s', testament) metadata.bind.echo = False - session = self.session() + session = self.session test = ONTestament() test.name = testament session.add(test) session.commit() def get_bible_books(self): - log.debug(u'get_bible_books ') + log.debug(u'get_bible_books') return self.session.query(Book).order_by(Book.id).all() def get_max_bible_book_verses(self, bookname, chapter): - log.debug(u'get_max_bible_book_verses %s,%s', bookname , chapter) + log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter) metadata.bind.echo = False - s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ') - return self.db.execute(s, c=chapter, b=bookname).fetchone() + #s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ') + #return self.db.execute(s, c=chapter, b=bookname).fetchone() + verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).order_by(Verse.verse.desc()).first() + return verse.verse def get_max_bible_book_chapter(self, bookname): - log.debug(u'get_max_bible_book_chapter %s', bookname ) + log.debug(u'get_max_bible_book_chapter %s', bookname) metadata.bind.echo = False - s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b') - return self.db.execute(s, b=bookname).fetchone() + #s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b') + #return self.db.execute(s, b=bookname).fetchone() + verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).order_by(Verse.chapter.desc()).first() + return verse.chapter def get_bible_book(self, bookname): log.debug(u'get_bible_book %s', bookname) bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first() if bk == None: - bk = self.session.query(Book).filter(Book.abbreviation.like(bookname+u'%')).first() + bk = self.session.query(Book).filter(Book.abbreviation.like(bookname + u'%')).first() return bk def get_bible_chapter(self, id, chapter): - log.debug(u'get_bible_chapter %s,%s', id, chapter ) + log.debug(u'get_bible_chapter %s, %s', id, chapter) metadata.bind.echo = False - return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first() + return self.session.query(Verse).filter_by(chapter=chapter).filter_by(book_id=id).first() def get_bible_text(self, bookname, chapter, sverse, everse): - log.debug(u'get_bible_text %s,%s,%s,%s', bookname, chapter, sverse, everse) + log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, everse) metadata.bind.echo = False - bookname = bookname + u"%" - s = text (u'select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and (book.name like :b)') - return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() + #bookname = bookname + u"%" + #s = text (u'select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and (book.name like :b)') + #return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() + verses = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).filter(Verse.verse>=sverse).filter(Verse.verse<=everse).order_by(Verse.verse).all() + return verses def get_verses_from_text(self,versetext): log.debug(u'get_verses_from_text %s',versetext) diff --git a/openlp/plugins/bibles/lib/bibleOSISimpl.py b/openlp/plugins/bibles/lib/bibleOSISimpl.py index 6f95476d5..b59e7e5f3 100644 --- a/openlp/plugins/bibles/lib/bibleOSISimpl.py +++ b/openlp/plugins/bibles/lib/bibleOSISimpl.py @@ -1,6 +1,8 @@ """ OpenLP - Open Source Lyrics Projection + Copyright (c) 2008 Raoul Snyman + Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley This program is free software; you can redistribute it and/or modify it under @@ -20,37 +22,69 @@ import os.path import logging import chardet import codecs -from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl -from openlp.core.lib import Receiver + from PyQt4 import QtCore +from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl +from openlp.core.lib import Receiver + class BibleOSISImpl(): + """ + OSIS Bible format importer class. + """ global log log = logging.getLogger(u'BibleOSISImpl') log.info(u'BibleOSISImpl loaded') def __init__(self, biblepath, bibledb): + """ + Constructor to create and set up an instance of the + BibleOSISImpl class. + + ``biblepath`` + This does not seem to be used. + + ``bibledb`` + A reference to a Bible database object. + """ self.bibledb = bibledb # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} # 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')) + filepath = os.path.abspath(os.path.join( + filepath, u'..', u'resources',u'osisbooks.csv')) 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.loadbible = True - QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlpstopimport'),self.stop_import) + QtCore.QObject.connect(Receiver().get_receiver(), + QtCore.SIGNAL(u'openlpstopimport'), self.stop_import) def stop_import(self): + """ + Stops the import of the Bible. + """ self.loadbible = False def load_data(self, osisfile_record, dialogobject=None): - osis = codecs.open(osisfile_record, u'r') + """ + Loads a Bible from file. + + ``osisfile_record`` + The file to import from. + + ``dialogobject`` + The Import dialog, so that we can increase the counter on + the progress bar. + """ + detect_file = open(osisfile_record, u'r') + details = chardet.detect(detect_file.read(2048)) + detect_file.close() + osis = codecs.open(osisfile_record, u'r', details['encoding']) book_ptr = None id = 0 count = 0 @@ -110,8 +144,11 @@ class BibleOSISImpl(): if p[0] == u'Matt': testament += 1 book_ptr = p[0] - book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament) - dialogobject.incrementProgressBar(self.booksOfBible[p[0]] ) + book = self.bibledb.create_book( + self.booksOfBible[p[0]], + self.abbrevOfBible[p[0]], testament) + dialogobject.incrementProgressBar( + self.booksOfBible[p[0]]) Receiver().send_message(u'openlpprocessevents') count = 0 self.bibledb.add_verse(book.id, p[1], p[2], text) @@ -121,10 +158,20 @@ class BibleOSISImpl(): Receiver().send_message(u'openlpprocessevents') count = 0 - def remove_block(self, start_tag, end_tag, text): + def remove_block(self, start_tag, end_tag, text): """ - removes a block of text between two tags - Some not wanted 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: @@ -136,10 +183,17 @@ class BibleOSISImpl(): pos = text.find(start_tag) return text - def remove_tag(self, start_tag, text): + def remove_tag(self, start_tag, text): """ - removes a single tag - + 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: diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index bfbad5ba5..bc86ea8b2 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -2,7 +2,9 @@ # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 """ OpenLP - Open Source Lyrics Projection + Copyright (c) 2008 Raoul Snyman + Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley This program is free software; you can redistribute it and/or modify it under @@ -18,7 +20,7 @@ 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, os.path +import os import sys from common import SearchResults @@ -26,72 +28,93 @@ from bibleOSISimpl import BibleOSISImpl from bibleCSVimpl import BibleCSVImpl from bibleDBimpl import BibleDBImpl from bibleHTTPimpl import BibleHTTPImpl + from openlp.plugins.bibles.lib.tables import * from openlp.plugins.bibles.lib.classes import * -class BibleManager(): +class BibleMode(object): + Full = 1 + Partial = 2 + +class BibleManager(object): + """ + The Bible manager which holds and manages all the Bibles. + """ global log log=logging.getLogger(u'BibleManager') log.info(u'Bible manager loaded') + def __init__(self, config): """ - Finds all the bibles defined for the system - Creates an Interface Object for each bible containing connection information - Throws Exception if no Bibles are found. + Finds all the bibles defined for the system and creates an + interface object for each bible containing connection + information. Throws Exception if no Bibles are found. Init confirms the bible exists and stores the database path. + + ``config`` + The plugin's configuration object. """ self.config = config log.debug(u'Bible Initialising') - self.bible_db_cache = None # dict of bible database classes - self.bible_http_cache = None # dict of bible http readers + # dict of bible database objects + self.bible_db_cache = None + # dict of bible http readers + self.bible_http_cache = None self.biblePath = self.config.get_data_path() - self.proxyname = self.config.get_config(u'proxy name') #get proxy name for screen + #get proxy name for screen + self.proxyname = self.config.get_config(u'proxy name') self.bibleSuffix = u'sqlite' self.dialogobject = None self.reload_bibles() def reload_bibles(self): log.debug(u'Reload bibles') - files = self.config.get_files(self.bibleSuffix) log.debug(u'Bible Files %s', files ) - self.bible_db_cache = {} self.bible_http_cache = {} - - self.book_testaments = {} # books of the bible with testaments - self.book_abbreviations = {} # books of the bible with abbreviation + # books of the bible with testaments + self.book_testaments = {} + # books of the bible with abbreviation + self.book_abbreviations = {} self.web_bibles_present = False - - for f in files: nme = f.split(u'.') bname = nme[0] - self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, bname, self.config) - biblesource = self.bible_db_cache[bname].get_meta(u'WEB') # look to see if lazy load bible exists and get create getter. + self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, + bname, self.config) + # look to see if lazy load bible exists and get create getter. + biblesource = self.bible_db_cache[bname].get_meta(u'WEB') if biblesource: self.web_bibles_present = True nhttp = BibleHTTPImpl() - nhttp.set_bible_source(biblesource.value) # tell The Server where to get the verses from. + # tell The Server where to get the verses from. + nhttp.set_bible_source(biblesource.value) self.bible_http_cache [bname] = nhttp - meta = self.bible_db_cache[bname].get_meta(u'proxy') # look to see if lazy load bible exists and get create getter. + # look to see if lazy load bible exists and get create getter. + meta = self.bible_db_cache[bname].get_meta(u'proxy') proxy = None if meta != None: proxy = meta.value - nhttp.set_proxy(proxy) # tell The Server where to get the verses from. - bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value # look to see if lazy load bible exists and get create getter. - nhttp.set_bibleid(bibleid) # tell The Server where to get the verses from. + # tell The Server where to get the verses from. + nhttp.set_proxy(proxy) + # look to see if lazy load bible exists and get create getter. + bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value + # tell The Server where to get the verses from. + nhttp.set_bibleid(bibleid) else: - self.bible_http_cache [bname] = None # makes the Full / partial code easier. - + # makes the Full / partial code easier. + self.bible_http_cache [bname] = None if self.web_bibles_present: - self.book_testaments = {} # books of the bible linked to bibleid {osis , name} - self.book_abbreviations = {} # books of the bible linked to bibleid {osis ,Abbrev } - + # books of the bible linked to bibleid {osis, name} + self.book_testaments = {} + # books of the bible linked to bibleid {osis, abbrev} + self.book_abbreviations = {} filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join(filepath, u'..', u'resources',u'httpbooks.csv')) - fbibles=open(filepath, 'r') + filepath = os.path.abspath(os.path.join( + filepath, u'..', u'resources',u'httpbooks.csv')) + fbibles = open(filepath, u'r') for line in fbibles: p = line.split(u',') self.book_abbreviations[p[0]] = p[1].replace(u'\n', '') @@ -99,31 +122,64 @@ class BibleManager(): log.debug(u'Bible Initialised') def process_dialog(self, dialogobject): + """ + Sets the reference to the dialog with the progress bar on it. + + ``dialogobject`` + The reference to the dialog. + """ self.dialogobject = dialogobject - def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None): + def register_http_bible(self, biblename, biblesource, bibleid, + proxyurl=None, proxyid=None, proxypass=None): """ - Return a list of bibles from a given URL. - The selected Bible can then be registered and LazyLoaded into a database - """ - log.debug(u'register_HTTP_bible %s,%s,%s,%s,%s,%s', biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) - if self._is_new_bible(biblename): - nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible - nbible.create_tables() # Create Database - self.bible_db_cache[biblename] = nbible + Return a list of bibles from a given URL. The selected Bible + can then be registered and LazyLoaded into a database. + ``biblename`` + The name of the bible to register. + + ``biblesource`` + Where this Bible stores it's verses. + + ``bibleid`` + The identifier for a Bible. + + ``proxyurl`` + Defaults to *None*. An optional URL to a proxy server. + + ``proxyid`` + Defaults to *None*. A username for logging into the proxy + server. + + ``proxypass`` + Defaults to *None*. The password to accompany the username. + """ + log.debug(u'register_HTTP_bible %s, %s, %s, %s, %s, %s', + biblename, biblesource, bibleid, proxyurl, proxyid, proxypass) + if self._is_new_bible(biblename): + # Create new Bible + nbible = BibleDBImpl(self.biblePath, biblename, self.config) + # Create Database + nbible.create_tables() + self.bible_db_cache[biblename] = nbible nhttp = BibleHTTPImpl() nhttp.set_bible_source(biblesource) self.bible_http_cache [biblename] = nhttp - nbible.save_meta(u'WEB', biblesource) # register a lazy loading interest - nbible.save_meta(u'bibleid', bibleid) # store the we id of the bible + # register a lazy loading interest + nbible.save_meta(u'WEB', biblesource) + # store the web id of the bible + nbible.save_meta(u'bibleid', bibleid) if proxyurl != None and proxyurl != "": - nbible.save_meta(u'proxy', proxyurl) # store the proxy URL + # store the proxy URL + nbible.save_meta(u'proxy', proxyurl) nhttp.set_proxy(proxyurl) if proxyid != None and proxyid != "": - nbible.save_meta(u'proxyid', proxyid) # store the proxy userid + # store the proxy userid + nbible.save_meta(u'proxyid', proxyid) if proxypass != None and proxypass != "": - nbible.save_meta(u'proxypass', proxypass) # store the proxy password + # store the proxy password + nbible.save_meta(u'proxypass', proxypass) return True else: log.debug(u'register_http_file_bible %s not created already exists', biblename) @@ -165,21 +221,26 @@ class BibleManager(): log.debug(u'register_OSIS_file_bible %s , %s not created already exists', biblename, osisfile) return False - def get_bibles(self, mode=u'full'): + def get_bibles(self, mode=BibleMode.Full): + """ + Returns a list of Books of the bible. When ``mode`` is set to + ``BibleMode.Full`` this method returns all the Bibles for the + Advanced Search, and when the mode is ``BibleMode.Partial`` + this method returns all the bibles for the Quick Search. + + ``mode`` + Defaults to ``BibleMode.Full``. The Bible mode. + """ log.debug(u'get_bibles') - """ - Returns a list of Books of the bible - Mode "Full" - Returns all the bibles for the Queck seearch - Mode "Partial" - Returns CSV and OSIS bbles for the Advanced Search - """ - r=[] - for b , o in self.bible_db_cache.iteritems(): - if mode == u'full': - r.append(b) + bible_list = [] + for bible_name, bible_object in self.bible_db_cache.iteritems(): + if mode == BibleMode.Full: + bible_list.append(bible_name) else: - if self.bible_http_cache [b] == None: # we do not have an http bible - r.append(b) - return r + if self.bible_http_cache[bible_name] is None: + # we do not have an http bible + bible_list.append(bible_name) + return bible_list def get_bible_books(self,bible): """ @@ -192,7 +253,7 @@ class BibleManager(): """ Returns the number of Chapters for a given book """ - log.debug(u'get_book_chapter_count %s,%s', bible, book) + log.debug(u'get_book_chapter_count %s, %s', bible, book) return self.bible_db_cache[bible].get_max_bible_book_chapter(book) def get_book_verse_count(self, bible, book, chapter): @@ -227,7 +288,7 @@ class BibleManager(): log.debug(u'get_meta %s,%s', bible, key) return self.bible_db_cache[bible].get_meta(key) - def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse = 0 ): + def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse=0): """ Returns a list of verses for a given Book, Chapter and ranges of verses. If the end verse(everse) is less then the start verse(sverse) @@ -237,7 +298,7 @@ class BibleManager(): """ text = [] log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse) - if not self.bible_http_cache [bible] == None: + if not self.bible_http_cache[bible] == None: # check to see if book/chapter exists book= self.bible_db_cache[bible].get_bible_book(bookname) if book == None: diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index f5e58f8f0..91699fdbe 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -21,8 +21,10 @@ import logging from PyQt4 import QtCore, QtGui -from openlp.core.lib import ServiceItem, MediaManagerItem, Receiver, translate, contextMenuAction, contextMenuSeparator +from openlp.core.lib import translate, ServiceItem, MediaManagerItem, \ + Receiver, contextMenuAction, contextMenuSeparator from openlp.plugins.bibles.forms import BibleImportForm +from openlp.plugins.bibles.lib.manager import BibleMode class BibleList(QtGui.QListWidget): @@ -255,12 +257,12 @@ class BibleMediaItem(MediaManagerItem): log.debug(u'Loading Bibles') self.QuickVersionComboBox.clear() self.AdvancedVersionComboBox.clear() - bibles = self.parent.biblemanager.get_bibles(u'full') + bibles = self.parent.biblemanager.get_bibles(BibleMode.Full) # load bibles into the combo boxes for bible in bibles: self.QuickVersionComboBox.addItem(bible) - # Without HTT - bibles = self.parent.biblemanager.get_bibles(u'partial') + # Without HTTP + bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial) first = True # load bibles into the combo boxes for bible in bibles: @@ -287,8 +289,8 @@ class BibleMediaItem(MediaManagerItem): self.adjustComboBox(frm, self.verses, self.AdvancedToVerse) def onAdvancedToChapter(self): - t1 = self.AdvancedFromChapter.currentText() - t2 = self.AdvancedToChapter.currentText() + t1 = self.AdvancedFromChapter.currentText() + t2 = self.AdvancedToChapter.currentText() if t1 != t2: bible = unicode(self.AdvancedVersionComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText()) @@ -344,13 +346,14 @@ class BibleMediaItem(MediaManagerItem): bitem = self.ListView.item(item.row()) text = unicode((bitem.data(QtCore.Qt.UserRole)).toString()) verse = text[:text.find(u'(')] - bible = text[text.find(u'(') + 1:text.find(u')')] + bible = text[text.find(u'(') + 1:-1] self.searchByReference(bible, verse) - book = self.search_results[0][0] - chapter = unicode(self.search_results[0][1]) - verse = unicode(self.search_results[0][2]) - text = self.search_results[0][3] - if self.parent.bibles_tab.paragraph_style: #Paragraph + book = self.search_results[0].book.name + chapter = unicode(self.search_results[0].chapter) + verse = unicode(self.search_results[0].verse) + text = self.search_results[0].text + # Paragraph + if self.parent.bibles_tab.paragraph_style: text = text + u'\n\n' if self.parent.bibles_tab.display_style == 1: loc = self.formatVerse(old_chapter, chapter, verse, u'(u', u')') @@ -402,8 +405,8 @@ class BibleMediaItem(MediaManagerItem): def initialiseChapterVerse(self, 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.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book) + self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1) self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter) self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter) self.adjustComboBox(1, self.verses, self.AdvancedFromVerse) @@ -416,10 +419,16 @@ class BibleMediaItem(MediaManagerItem): combo.addItem(unicode(i)) def displayResults(self, bible): - for book, chap, vse , txt in self.search_results: - bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible)) + for verse in self.search_results: + #bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible)) + #bible_verse = QtGui.QListWidgetItem(bible_text) + #bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text)) + #self.ListView.addItem(bible_verse) + bible_text = u' %s %d:%d (%s)' % (verse.book.name, + verse.chapter, verse.verse, bible) bible_verse = QtGui.QListWidgetItem(bible_text) - bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text)) + bible_verse.setData(QtCore.Qt.UserRole, + QtCore.QVariant(bible_text)) self.ListView.addItem(bible_verse) def searchByReference(self, bible, search): diff --git a/openlp/plugins/bibles/lib/tables.py b/openlp/plugins/bibles/lib/tables.py index 9b9fb1ff8..2ddd85d5e 100644 --- a/openlp/plugins/bibles/lib/tables.py +++ b/openlp/plugins/bibles/lib/tables.py @@ -14,39 +14,39 @@ 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 +Place, Suite 330, Boston, MA 02111-1307 USA """ -import string +import string from sqlalchemy import * from sqlalchemy import Column, Table, MetaData, ForeignKey, schema metadata = MetaData() #Define the tables and indexes -meta_table = Table(u'metadata', metadata, - Column(u'key', String(255), primary_key=True), - Column(u'value', String(255)), +meta_table = Table(u'metadata', metadata, + Column(u'key', String(255), primary_key=True), + Column(u'value', String(255)), ) -testament_table = Table(u'testament', metadata, - Column(u'id', Integer, primary_key=True), - Column(u'name', String(30)), +testament_table = Table(u'testament', metadata, + Column(u'id', Integer, primary_key=True), + Column(u'name', String(50)), ) - -book_table = Table(u'book', metadata, - Column(u'id', Integer, primary_key=True), - Column(u'testament_id', Integer, schema.ForeignKey(u'testament.id')), - Column(u'name', String(30)), - Column(u'abbreviation', String(5)), + +book_table = Table(u'book', metadata, + Column(u'id', Integer, primary_key=True), + Column(u'testament_id', Integer, schema.ForeignKey(u'testament.id')), + Column(u'name', String(50)), + Column(u'abbreviation', String(5)), ) Index(u'idx_name', book_table.c.name, book_table.c.id) Index(u'idx_abbrev', book_table.c.abbreviation, book_table.c.id) -verse_table = Table(u'verse', metadata, - Column(u'id', Integer, primary_key=True), - Column(u'book_id', Integer , schema.ForeignKey(u'book.id')), - Column(u'chapter', Integer), - Column(u'verse', Integer), - Column(u'text', Text), +verse_table = Table(u'verse', metadata, + Column(u'id', Integer, primary_key=True), + Column(u'book_id', Integer , schema.ForeignKey(u'book.id')), + Column(u'chapter', Integer), + Column(u'verse', Integer), + Column(u'text', Text), ) Index(u'idx_chapter_verse_book', verse_table.c.chapter, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id) -Index(u'idx_chapter_verse_text', verse_table.c.text, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id) \ No newline at end of file +Index(u'idx_chapter_verse_text', verse_table.c.text, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id)