Merge lp:~raoul-snyman/openlp/biblefixes into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: not available
Proposed branch: lp:~raoul-snyman/openlp/biblefixes
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~raoul-snyman/openlp/biblefixes
Reviewer Review Type Date Requested Status
Martin Thompson (community) Approve
Tim Bentley Approve
Review via email: mp+8841@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Some more fixes!

lp:~raoul-snyman/openlp/biblefixes updated
493. By Tim Bentley

Various bug fixes and code improvements.

Revision history for this message
Tim Bentley (trb143) wrote :

Looks good.
Approved.

review: Approve
lp:~raoul-snyman/openlp/biblefixes updated
494. By Raoul Snyman

Merged in the changes from the biblefixes branch.

Revision history for this message
Martin Thompson (mjthompson) wrote :

I can't comment on much of the code, not familiar with sqlalchemy, but while I'm here...

Niggles:
420 + osis = codecs.open(osisfile_record, u'r', details['encoding'])
Is there a reason 'encoding' shouldn't be unicode?

1088 +mapper(ONTestament, testament_table,
1089 + properties={'books': relation(Book, backref='testament')})
1090 +mapper(Book, book_table,
1091 + properties={'verses': relation(Verse, backref='book')})

More unicode strings?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py 2009-07-11 05:18:34 +0000
+++ openlp/core/ui/slidecontroller.py 2009-07-12 20:38:34 +0000
@@ -212,11 +212,12 @@
212 self.ControllerLayout.addWidget(self.Toolbar)212 self.ControllerLayout.addWidget(self.Toolbar)
213 self.BaseToolbar.addServiceManagerItem(item, slideno)213 self.BaseToolbar.addServiceManagerItem(item, slideno)
214214
215
215class MasterPreview(QtCore.QObject):216class MasterPreview(QtCore.QObject):
216 """217 """
217 Class from which all Previews should extend allowing plugins to have their own218 Class from which all Previews should extend allowing plugins to
218 previews219 have their own previews
219s """220 """
220 def __init__(self, parent):221 def __init__(self, parent):
221 self.parent = parent222 self.parent = parent
222 QtCore.QObject.__init__(self)223 QtCore.QObject.__init__(self)
@@ -369,28 +370,30 @@
369 Display the slide number passed370 Display the slide number passed
370 """371 """
371 log.debug(u'add Service Manager Item')372 log.debug(u'add Service Manager Item')
373 self.serviceitem = serviceitem
374 slide_pixmap = QtGui.QPixmap.fromImage(self.serviceitem.frames[0][u'image'])
375 slide_width = 300
376 slide_height = slide_width * slide_pixmap.height() / slide_pixmap.width()
372 self.PreviewListWidget.clear()377 self.PreviewListWidget.clear()
373 self.PreviewListWidget.setRowCount(0)378 self.PreviewListWidget.setRowCount(0)
374 self.serviceitem = serviceitem379 self.PreviewListWidget.setColumnWidth(0, slide_width)
375 framenumber = 0380 for framenumber, frame in enumerate(self.serviceitem.frames):
376 for frame in self.serviceitem.frames:
377 self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1)381 self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1)
378 pixmap = QtGui.QPixmap.fromImage(frame[u'image'])382 pixmap = QtGui.QPixmap.fromImage(frame[u'image'])
379 item = QtGui.QTableWidgetItem()383 item = QtGui.QTableWidgetItem()
380 label = QtGui.QLabel()384 label = QtGui.QLabel()
381 label.setMargin(15)385 label.setMargin(8)
382 label.setScaledContents(True)386 label.setScaledContents(True)
383 width = 300
384 height = width * pixmap.height() / pixmap.width()
385 label.setPixmap(pixmap)387 label.setPixmap(pixmap)
386 self.PreviewListWidget.setCellWidget(framenumber, 0,label)388 self.PreviewListWidget.setCellWidget(framenumber, 0, label)
387 self.PreviewListWidget.setItem( framenumber, 0, item)389 self.PreviewListWidget.setItem(framenumber, 0, item)
388 self.PreviewListWidget.setRowHeight(framenumber, height)390 self.PreviewListWidget.setRowHeight(framenumber, slide_height)
389 self.PreviewListWidget.setColumnWidth(0, width)391 slide_width = self.PreviewListWidget.viewport().size().width()
390 framenumber += 1392 self.PreviewListWidget.setColumnWidth(0, slide_width)
391 if slideno > self.PreviewListWidget.rowCount():393 if slideno > self.PreviewListWidget.rowCount():
392 self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount())394 self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount())
393 else:395 else:
394 self.PreviewListWidget.selectRow(slideno)396 self.PreviewListWidget.selectRow(slideno)
395 self.onSlideSelected()397 self.onSlideSelected()
396 self.serviceLoaded()398 self.serviceLoaded()
399 self.PreviewListWidget.setFocus()
397400
=== modified file 'openlp/plugins/bibles/lib/bibleDBimpl.py'
--- openlp/plugins/bibles/lib/bibleDBimpl.py 2009-06-16 18:21:24 +0000
+++ openlp/plugins/bibles/lib/bibleDBimpl.py 2009-07-14 19:44:15 +0000
@@ -1,6 +1,10 @@
1# -*- coding: utf-8 -*-
2# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
1"""3"""
2OpenLP - Open Source Lyrics Projection4OpenLP - Open Source Lyrics Projection
5
3Copyright (c) 2008 Raoul Snyman6Copyright (c) 2008 Raoul Snyman
7
4Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley8Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley
59
6This program is free software; you can redistribute it and/or modify it under10This program is free software; you can redistribute it and/or modify it under
@@ -16,43 +20,34 @@
16Place, Suite 330, Boston, MA 02111-1307 USA20Place, Suite 330, Boston, MA 02111-1307 USA
17"""21"""
18import os22import os
19import os.path
20import logging23import logging
2124
22from sqlalchemy import *
23from sqlalchemy.sql import select
24from sqlalchemy.orm import sessionmaker, mapper, scoped_session
25
26from common import BibleCommon25from common import BibleCommon
27from openlp.core.utils import ConfigHelper26from openlp.core.utils import ConfigHelper
28from openlp.plugins.bibles.lib.tables import *27from openlp.plugins.bibles.lib.models import *
29from openlp.plugins.bibles.lib.classes import *
3028
31class BibleDBImpl(BibleCommon):29class BibleDBImpl(BibleCommon):
32 global log30 global log
33 log=logging.getLogger(u'BibleDBImpl')31 log=logging.getLogger(u'BibleDBImpl')
34 log.info(u'BibleDBimpl loaded')32 log.info(u'BibleDBimpl loaded')
3533
36 def __init__(self, biblepath , biblename, config):34 def __init__(self, biblepath, biblename, config):
37 # Connect to database35 # Connect to database
38 self.config = config36 self.config = config
39 self.biblefile = os.path.join(biblepath, biblename+u'.sqlite')37 self.biblefile = os.path.join(biblepath, biblename + u'.sqlite')
40 log.debug(u'Load bible %s on path %s', biblename, self.biblefile)38 log.debug(u'Load bible %s on path %s', biblename, self.biblefile)
41 db_type = self.config.get_config(u'db type', u'sqlite')39 db_type = self.config.get_config(u'db type', u'sqlite')
40 db_url = u''
42 if db_type == u'sqlite':41 if db_type == u'sqlite':
43 self.db = create_engine(u'sqlite:///' + self.biblefile)42 db_url = u'sqlite:///' + self.biblefile
44 else:43 else:
45 self.db_url = u'%s://%s:%s@%s/%s' % \44 db_url = u'%s://%s:%s@%s/%s' % \
46 (db_type, self.config.get_config(u'db username'),45 (db_type, self.config.get_config(u'db username'),
47 self.config.get_config(u'db password'),46 self.config.get_config(u'db password'),
48 self.config.get_config(u'db hostname'),47 self.config.get_config(u'db hostname'),
49 self.config.get_config(u'db database'))48 self.config.get_config(u'db database'))
50 self.db.echo = False49 self.metadata, self.session = init_models(db_url)
51 metadata.bind = self.db50 self.metadata.create_all(checkfirst=True)
52 metadata.bind.echo = False
53 self.session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
54 self.session.configure(bind=self.db)
55 metadata.create_all(self.db)
5651
57 def create_tables(self):52 def create_tables(self):
58 log.debug( u'createTables')53 log.debug( u'createTables')
@@ -63,122 +58,127 @@
6358
64 def add_verse(self, bookid, chap, vse, text):59 def add_verse(self, bookid, chap, vse, text):
65 #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse)60 #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse)
66 metadata.bind.echo = False61 #metadata.bind.echo = False
67 session = self.session()
68 verse = Verse()62 verse = Verse()
69 verse.book_id = bookid63 verse.book_id = bookid
70 verse.chapter = chap64 verse.chapter = chap
71 verse.verse = vse65 verse.verse = vse
72 verse.text = text66 verse.text = text
73 session.add(verse)67 self.session.add(verse)
74 session.commit()68 self.session.commit()
7569
76 def create_chapter(self, bookid, chap, textlist):70 def create_chapter(self, bookid, chap, textlist):
77 log.debug(u'create_chapter %s,%s', bookid, chap)71 log.debug(u'create_chapter %s,%s', bookid, chap)
78 #log.debug(u'Text %s ", textlist)72 #log.debug(u'Text %s ", textlist)
79 metadata.bind.echo = False73 #metadata.bind.echo = False
80 session = self.session()
81 #text list has book and chapter as first to elements of the array74 #text list has book and chapter as first to elements of the array
82 for v , t in textlist.iteritems():75 for verse_number, verse_text in textlist.iteritems():
83 verse = Verse()76 verse = Verse()
84 verse.book_id = bookid77 verse.book_id = bookid
85 verse.chapter = chap78 verse.chapter = chap
86 verse.verse = v79 verse.verse = verse_number
87 verse.text = t80 verse.text = verse_text
88 session.add(verse)81 self.session.add(verse)
89 session.commit()82 self.session.commit()
9083
91 def create_book(self, bookname, bookabbrev, testament = 1):84 def create_book(self, bookname, bookabbrev, testament=1):
92 log.debug(u'create_book %s,%s', bookname, bookabbrev)85 log.debug(u'create_book %s,%s', bookname, bookabbrev)
93 metadata.bind.echo = False86 #metadata.bind.echo = False
94 session = self.session()
95 book = Book()87 book = Book()
96 book.testament_id = testament88 book.testament_id = testament
97 book.name = bookname89 book.name = bookname
98 book.abbreviation = bookabbrev90 book.abbreviation = bookabbrev
99 session.add(book)91 self.session.add(book)
100 session.commit()92 self.session.commit()
101 return book93 return book
10294
103 def save_meta(self, key, value):95 def save_meta(self, key, value):
104 log.debug(u'save_meta %s/%s', key, value)96 log.debug(u'save_meta %s/%s', key, value)
105 metadata.bind.echo = False97 #metadata.bind.echo = False
106 session = self.session()98 bmeta = BibleMeta()
107 bmeta= BibleMeta()
108 bmeta.key = key99 bmeta.key = key
109 bmeta.value = value100 bmeta.value = value
110 session.add(bmeta)101 self.session.add(bmeta)
111 session.commit()102 self.session.commit()
112103
113 def get_meta(self, metakey):104 def get_meta(self, metakey):
114 log.debug(u'get meta %s', metakey)105 log.debug(u'get meta %s', metakey)
115 return self.session.query(BibleMeta).filter_by(key = metakey).first()106 return self.session.query(BibleMeta).filter_by(key=metakey).first()
116107
117 def delete_meta(self, metakey):108 def delete_meta(self, metakey):
118 biblemeta = self.get_meta(metakey)109 biblemeta = self.get_meta(metakey)
119 try:110 try:
120 session.delete(biblemeta)111 self.session.delete(biblemeta)
121 session.commit()112 self.session.commit()
122 return True113 return True
123 except:114 except:
124 return False115 return False
125116
126 def _load_testament(self, testament):117 def _load_testament(self, testament):
127 log.debug(u'load_testaments %s', testament)118 log.debug(u'load_testaments %s', testament)
128 metadata.bind.echo = False119 #metadata.bind.echo = False
129 session = self.session()
130 test = ONTestament()120 test = ONTestament()
131 test.name = testament121 test.name = testament
132 session.add(test)122 self.session.add(test)
133 session.commit()123 self.session.commit()
134124
135 def get_bible_books(self):125 def get_bible_books(self):
136 log.debug(u'get_bible_books ')126 log.debug(u'get_bible_books')
137 return self.session.query(Book).order_by(Book.id).all()127 return self.session.query(Book).order_by(Book.id).all()
138128
139 def get_max_bible_book_verses(self, bookname, chapter):129 def get_max_bible_book_verses(self, bookname, chapter):
140 log.debug(u'get_max_bible_book_verses %s,%s', bookname , chapter)130 log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter)
141 metadata.bind.echo = False131 #metadata.bind.echo = False
142 s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ')132 #s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ')
143 return self.db.execute(s, c=chapter, b=bookname).fetchone()133 #return self.db.execute(s, c=chapter, b=bookname).fetchone()
134 verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).order_by(Verse.verse.desc()).first()
135 return verse.verse
144136
145 def get_max_bible_book_chapter(self, bookname):137 def get_max_bible_book_chapter(self, bookname):
146 log.debug(u'get_max_bible_book_chapter %s', bookname )138 log.debug(u'get_max_bible_book_chapter %s', bookname)
147 metadata.bind.echo = False139 #metadata.bind.echo = False
148 s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b')140 #s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b')
149 return self.db.execute(s, b=bookname).fetchone()141 #return self.db.execute(s, b=bookname).fetchone()
142 verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).order_by(Verse.chapter.desc()).first()
143 return verse.chapter
150144
151 def get_bible_book(self, bookname):145 def get_bible_book(self, bookname):
152 log.debug(u'get_bible_book %s', bookname)146 log.debug(u'get_bible_book %s', bookname)
153 bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first()147 bk = self.session.query(Book).filter(Book.name.like(bookname + u'%')).first()
154 if bk == None:148 if bk == None:
155 bk = self.session.query(Book).filter(Book.abbreviation.like(bookname+u'%')).first()149 bk = self.session.query(Book).filter(Book.abbreviation.like(bookname + u'%')).first()
156 return bk150 return bk
157151
158 def get_bible_chapter(self, id, chapter):152 def get_bible_chapter(self, id, chapter):
159 log.debug(u'get_bible_chapter %s,%s', id, chapter )153 log.debug(u'get_bible_chapter %s, %s', id, chapter)
160 metadata.bind.echo = False154 #metadata.bind.echo = False
161 return self.session.query(Verse).filter_by(chapter = chapter ).filter_by(book_id = id).first()155 return self.session.query(Verse).filter_by(chapter=chapter).filter_by(book_id=id).first()
162156
163 def get_bible_text(self, bookname, chapter, sverse, everse):157 def get_bible_text(self, bookname, chapter, sverse, everse):
164 log.debug(u'get_bible_text %s,%s,%s,%s', bookname, chapter, sverse, everse)158 log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, everse)
165 metadata.bind.echo = False159 #metadata.bind.echo = False
166 bookname = bookname + u"%"160 #bookname = bookname + u"%"
167 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)')161 #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)')
168 return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall()162 #return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall()
163 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()
164 return verses
169165
170 def get_verses_from_text(self,versetext):166 def get_verses_from_text(self, versetext):
171 log.debug(u'get_verses_from_text %s',versetext)167 log.debug(u'get_verses_from_text %s',versetext)
172 metadata.bind.echo = False168 #metadata.bind.echo = False
173 versetext = "%"+versetext+"%"169 versetext = u'%%%s%%' % versetext
174 s = text (u'select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t')170 #s = text (u'select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t')
175 return self.db.execute(s, t=versetext).fetchall()171 #return self.db.execute(s, t=versetext).fetchall()
172 verses = self.session.query(Verse).filter(Verse.text.like(versetext)).all()
173 return verses
176174
177 def dump_bible(self):175 def dump_bible(self):
178 log.debug( u'.........Dumping Bible Database')176 log.debug( u'.........Dumping Bible Database')
179 log.debug( '...............................Books ')177 log.debug( '...............................Books ')
180 s = text (u'select * FROM book ')178 #s = text (u'select * FROM book ')
181 log.debug( self.db.execute(s).fetchall())179 books = self.session.query(Book).all()
180 log.debug(books)
182 log.debug( u'...............................Verses ')181 log.debug( u'...............................Verses ')
183 s = text (u'select * FROM verse ')182 #s = text (u'select * FROM verse ')
184 log.debug( self.db.execute(s).fetchall())183 verses = self.session.query(Verse).all()
184 log.debug(verses)
185185
=== modified file 'openlp/plugins/bibles/lib/bibleHTTPimpl.py'
--- openlp/plugins/bibles/lib/bibleHTTPimpl.py 2009-07-12 15:11:57 +0000
+++ openlp/plugins/bibles/lib/bibleHTTPimpl.py 2009-07-13 20:11:36 +0000
@@ -97,7 +97,7 @@
97 """97 """
98 log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter)98 log.debug(u'get_bible_chapter %s,%s,%s,%s', version, bookid, bookname, chapter)
99 bookname = bookname.replace(u' ', '')99 bookname = bookname.replace(u' ', '')
100 urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word='+bookname+u'+'+unicode(chapter)+u'&version='+version100 urlstring = u'http://bible.crosswalk.com/OnlineStudyBible/bible.cgi?word=%s+%d&version=%s' % (bookname, chapter, version)
101 xml_string = self._get_web_text(urlstring, self.proxyurl)101 xml_string = self._get_web_text(urlstring, self.proxyurl)
102 #log.debug(u'Return data %s', xml_string)102 #log.debug(u'Return data %s', xml_string)
103 ## Strip Book Title from Heading to return it to system103 ## Strip Book Title from Heading to return it to system
@@ -207,7 +207,7 @@
207 ev = CWExtract(self.proxyurl)207 ev = CWExtract(self.proxyurl)
208 else:208 else:
209 ev = BGExtract(self.proxyurl)209 ev = BGExtract(self.proxyurl)
210
211 return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter)210 return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter)
212 except:211 except Exception, e:
213 log.error(u'Error thrown = %s', sys.exc_info()[1])212 log.error(u'Error thrown = %s', e.args[0])
213 print e
214214
=== modified file 'openlp/plugins/bibles/lib/bibleOSISimpl.py'
--- openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-07-10 15:41:08 +0000
+++ openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-07-13 20:08:43 +0000
@@ -1,6 +1,8 @@
1"""1"""
2OpenLP - Open Source Lyrics Projection2OpenLP - Open Source Lyrics Projection
3
3Copyright (c) 2008 Raoul Snyman4Copyright (c) 2008 Raoul Snyman
5
4Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley6Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley
57
6This program is free software; you can redistribute it and/or modify it under8This program is free software; you can redistribute it and/or modify it under
@@ -20,37 +22,69 @@
20import logging22import logging
21import chardet23import chardet
22import codecs24import codecs
25
26from PyQt4 import QtCore
27
23from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl28from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
24from openlp.core.lib import Receiver29from openlp.core.lib import Receiver
25from PyQt4 import QtCore
2630
27class BibleOSISImpl():31class BibleOSISImpl():
32 """
33 OSIS Bible format importer class.
34 """
28 global log35 global log
29 log = logging.getLogger(u'BibleOSISImpl')36 log = logging.getLogger(u'BibleOSISImpl')
30 log.info(u'BibleOSISImpl loaded')37 log.info(u'BibleOSISImpl loaded')
3138
32 def __init__(self, biblepath, bibledb):39 def __init__(self, biblepath, bibledb):
40 """
41 Constructor to create and set up an instance of the
42 BibleOSISImpl class.
43
44 ``biblepath``
45 This does not seem to be used.
46
47 ``bibledb``
48 A reference to a Bible database object.
49 """
33 self.bibledb = bibledb50 self.bibledb = bibledb
34 # books of the bible linked to bibleid {osis , name}51 # books of the bible linked to bibleid {osis , name}
35 self.booksOfBible = {}52 self.booksOfBible = {}
36 # books of the bible linked to bibleid {osis ,Abbrev }53 # books of the bible linked to bibleid {osis ,Abbrev }
37 self.abbrevOfBible = {}54 self.abbrevOfBible = {}
38
39 filepath = os.path.split(os.path.abspath(__file__))[0]55 filepath = os.path.split(os.path.abspath(__file__))[0]
40 filepath = os.path.abspath(os.path.join(filepath, u'..', u'resources',u'osisbooks.csv'))56 filepath = os.path.abspath(os.path.join(
57 filepath, u'..', u'resources',u'osisbooks.csv'))
41 fbibles=open(filepath, u'r')58 fbibles=open(filepath, u'r')
42 for line in fbibles:59 for line in fbibles:
43 p = line.split(u',')60 p = line.split(u',')
44 self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')61 self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')
45 self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')62 self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')
46 self.loadbible = True63 self.loadbible = True
47 QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlpstopimport'),self.stop_import)64 QtCore.QObject.connect(Receiver().get_receiver(),
65 QtCore.SIGNAL(u'openlpstopimport'), self.stop_import)
4866
49 def stop_import(self):67 def stop_import(self):
68 """
69 Stops the import of the Bible.
70 """
50 self.loadbible = False71 self.loadbible = False
5172
52 def load_data(self, osisfile_record, dialogobject=None):73 def load_data(self, osisfile_record, dialogobject=None):
53 osis = codecs.open(osisfile_record, u'r')74 """
75 Loads a Bible from file.
76
77 ``osisfile_record``
78 The file to import from.
79
80 ``dialogobject``
81 The Import dialog, so that we can increase the counter on
82 the progress bar.
83 """
84 detect_file = open(osisfile_record, u'r')
85 details = chardet.detect(detect_file.read(2048))
86 detect_file.close()
87 osis = codecs.open(osisfile_record, u'r', details['encoding'])
54 book_ptr = None88 book_ptr = None
55 id = 089 id = 0
56 count = 090 count = 0
@@ -110,8 +144,11 @@
110 if p[0] == u'Matt':144 if p[0] == u'Matt':
111 testament += 1145 testament += 1
112 book_ptr = p[0]146 book_ptr = p[0]
113 book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament)147 book = self.bibledb.create_book(
114 dialogobject.incrementProgressBar(self.booksOfBible[p[0]] )148 self.booksOfBible[p[0]],
149 self.abbrevOfBible[p[0]], testament)
150 dialogobject.incrementProgressBar(
151 self.booksOfBible[p[0]])
115 Receiver().send_message(u'openlpprocessevents')152 Receiver().send_message(u'openlpprocessevents')
116 count = 0153 count = 0
117 self.bibledb.add_verse(book.id, p[1], p[2], text)154 self.bibledb.add_verse(book.id, p[1], p[2], text)
@@ -121,10 +158,20 @@
121 Receiver().send_message(u'openlpprocessevents')158 Receiver().send_message(u'openlpprocessevents')
122 count = 0159 count = 0
123160
124 def remove_block(self, start_tag, end_tag, text):161 def remove_block(self, start_tag, end_tag, text):
125 """162 """
126 removes a block of text between two tags163 Removes a block of text between two tags::
127 <tag attrib=xvf > Some not wanted text </tag>164
165 <tag attrib="xvf">Some not wanted text</tag>
166
167 ``start_tag``
168 The XML tag to look for.
169
170 ``end_tag``
171 The ending XML tag.
172
173 ``text``
174 The string of XML to search.
128 """175 """
129 pos = text.find(start_tag)176 pos = text.find(start_tag)
130 while pos > -1:177 while pos > -1:
@@ -136,10 +183,17 @@
136 pos = text.find(start_tag)183 pos = text.find(start_tag)
137 return text184 return text
138185
139 def remove_tag(self, start_tag, text):186 def remove_tag(self, start_tag, text):
140 """187 """
141 removes a single tag188 Removes a single tag::
142 <tag attrib1=fajkdf attrib2=fajkdf attrib2=fajkdf />189
190 <tag attrib1="fajkdf" attrib2="fajkdf" attrib3="fajkdf" />
191
192 ``start_tag``
193 The XML tag to remove.
194
195 ``text``
196 The string of XML to search.
143 """197 """
144 pos = text.find(start_tag)198 pos = text.find(start_tag)
145 while pos > -1:199 while pos > -1:
146200
=== removed file 'openlp/plugins/bibles/lib/classes.py'
--- openlp/plugins/bibles/lib/classes.py 2009-02-22 07:44:08 +0000
+++ openlp/plugins/bibles/lib/classes.py 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
1# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
2"""
3OpenLP - Open Source Lyrics Projection
4Copyright (c) 2008 Raoul Snyman
5Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley
6
7This program is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free Software
9Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17Place, Suite 330, Boston, MA 02111-1307 USA
18"""
19from sqlalchemy.orm import mapper, relation
20from openlp.plugins.bibles.lib.tables import *
21
22class BaseModel(object):
23 """
24 BaseModel provides a base object with a set of generic functions
25 """
26
27 @classmethod
28 def populate(cls, **kwargs):
29 """
30 Creates an instance of a class and populates it, returning the instance
31 """
32 me = cls()
33 keys = kwargs.keys()
34 for key in keys:
35 me.__setattr__(key, kwargs[key])
36 return me
37
38class BibleMeta(BaseModel):
39 """
40 Bible Meta Data
41 """
42 pass
43
44class ONTestament(BaseModel):
45 """
46 Bible Testaments
47 """
48 pass
49
50class Book(BaseModel):
51 """
52 Song model
53 """
54 pass
55
56class Verse(BaseModel):
57 """
58 Topic model
59 """
60 pass
61
62mapper(BibleMeta, meta_table)
63mapper(ONTestament, testament_table,
64 properties={'books': relation(Book, backref='testament')})
65mapper(Book, book_table,
66 properties={'verses': relation(Verse, backref='book')})
67mapper(Verse, verse_table)
680
=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py 2009-07-09 05:15:26 +0000
+++ openlp/plugins/bibles/lib/manager.py 2009-07-13 20:08:43 +0000
@@ -2,7 +2,9 @@
2# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=42# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
3"""3"""
4OpenLP - Open Source Lyrics Projection4OpenLP - Open Source Lyrics Projection
5
5Copyright (c) 2008 Raoul Snyman6Copyright (c) 2008 Raoul Snyman
7
6Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley8Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley
79
8This program is free software; you can redistribute it and/or modify it under10This program is free software; you can redistribute it and/or modify it under
@@ -18,7 +20,7 @@
18Place, Suite 330, Boston, MA 02111-1307 USA20Place, Suite 330, Boston, MA 02111-1307 USA
19"""21"""
20import logging22import logging
21import os, os.path23import os
22import sys24import sys
2325
24from common import SearchResults26from common import SearchResults
@@ -26,72 +28,93 @@
26from bibleCSVimpl import BibleCSVImpl28from bibleCSVimpl import BibleCSVImpl
27from bibleDBimpl import BibleDBImpl29from bibleDBimpl import BibleDBImpl
28from bibleHTTPimpl import BibleHTTPImpl30from bibleHTTPimpl import BibleHTTPImpl
31
29from openlp.plugins.bibles.lib.tables import *32from openlp.plugins.bibles.lib.tables import *
30from openlp.plugins.bibles.lib.classes import *33from openlp.plugins.bibles.lib.classes import *
3134
32class BibleManager():35class BibleMode(object):
36 Full = 1
37 Partial = 2
38
39class BibleManager(object):
40 """
41 The Bible manager which holds and manages all the Bibles.
42 """
33 global log43 global log
34 log=logging.getLogger(u'BibleManager')44 log=logging.getLogger(u'BibleManager')
35 log.info(u'Bible manager loaded')45 log.info(u'Bible manager loaded')
46
36 def __init__(self, config):47 def __init__(self, config):
37 """48 """
38 Finds all the bibles defined for the system49 Finds all the bibles defined for the system and creates an
39 Creates an Interface Object for each bible containing connection information50 interface object for each bible containing connection
40 Throws Exception if no Bibles are found.51 information. Throws Exception if no Bibles are found.
4152
42 Init confirms the bible exists and stores the database path.53 Init confirms the bible exists and stores the database path.
54
55 ``config``
56 The plugin's configuration object.
43 """57 """
44 self.config = config58 self.config = config
45 log.debug(u'Bible Initialising')59 log.debug(u'Bible Initialising')
46 self.bible_db_cache = None # dict of bible database classes60 # dict of bible database objects
47 self.bible_http_cache = None # dict of bible http readers61 self.bible_db_cache = None
62 # dict of bible http readers
63 self.bible_http_cache = None
48 self.biblePath = self.config.get_data_path()64 self.biblePath = self.config.get_data_path()
49 self.proxyname = self.config.get_config(u'proxy name') #get proxy name for screen65 #get proxy name for screen
66 self.proxyname = self.config.get_config(u'proxy name')
50 self.bibleSuffix = u'sqlite'67 self.bibleSuffix = u'sqlite'
51 self.dialogobject = None68 self.dialogobject = None
52 self.reload_bibles()69 self.reload_bibles()
5370
54 def reload_bibles(self):71 def reload_bibles(self):
55 log.debug(u'Reload bibles')72 log.debug(u'Reload bibles')
56
57 files = self.config.get_files(self.bibleSuffix)73 files = self.config.get_files(self.bibleSuffix)
58 log.debug(u'Bible Files %s', files )74 log.debug(u'Bible Files %s', files )
59
60 self.bible_db_cache = {}75 self.bible_db_cache = {}
61 self.bible_http_cache = {}76 self.bible_http_cache = {}
6277 # books of the bible with testaments
63 self.book_testaments = {} # books of the bible with testaments78 self.book_testaments = {}
64 self.book_abbreviations = {} # books of the bible with abbreviation79 # books of the bible with abbreviation
80 self.book_abbreviations = {}
65 self.web_bibles_present = False81 self.web_bibles_present = False
66
67
68 for f in files:82 for f in files:
69 nme = f.split(u'.')83 nme = f.split(u'.')
70 bname = nme[0]84 bname = nme[0]
71 self.bible_db_cache[bname] = BibleDBImpl(self.biblePath, bname, self.config)85 self.bible_db_cache[bname] = BibleDBImpl(self.biblePath,
72 biblesource = self.bible_db_cache[bname].get_meta(u'WEB') # look to see if lazy load bible exists and get create getter.86 bname, self.config)
87 # look to see if lazy load bible exists and get create getter.
88 biblesource = self.bible_db_cache[bname].get_meta(u'WEB')
73 if biblesource:89 if biblesource:
74 self.web_bibles_present = True90 self.web_bibles_present = True
75 nhttp = BibleHTTPImpl()91 nhttp = BibleHTTPImpl()
76 nhttp.set_bible_source(biblesource.value) # tell The Server where to get the verses from.92 # tell The Server where to get the verses from.
93 nhttp.set_bible_source(biblesource.value)
77 self.bible_http_cache [bname] = nhttp94 self.bible_http_cache [bname] = nhttp
78 meta = self.bible_db_cache[bname].get_meta(u'proxy') # look to see if lazy load bible exists and get create getter.95 # look to see if lazy load bible exists and get create getter.
96 meta = self.bible_db_cache[bname].get_meta(u'proxy')
79 proxy = None97 proxy = None
80 if meta != None:98 if meta != None:
81 proxy = meta.value99 proxy = meta.value
82 nhttp.set_proxy(proxy) # tell The Server where to get the verses from.100 # tell The Server where to get the verses from.
83 bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value # look to see if lazy load bible exists and get create getter.101 nhttp.set_proxy(proxy)
84 nhttp.set_bibleid(bibleid) # tell The Server where to get the verses from.102 # look to see if lazy load bible exists and get create getter.
103 bibleid = self.bible_db_cache[bname].get_meta(u'bibleid').value
104 # tell The Server where to get the verses from.
105 nhttp.set_bibleid(bibleid)
85 else:106 else:
86 self.bible_http_cache [bname] = None # makes the Full / partial code easier.107 # makes the Full / partial code easier.
87108 self.bible_http_cache [bname] = None
88 if self.web_bibles_present:109 if self.web_bibles_present:
89 self.book_testaments = {} # books of the bible linked to bibleid {osis , name}110 # books of the bible linked to bibleid {osis, name}
90 self.book_abbreviations = {} # books of the bible linked to bibleid {osis ,Abbrev }111 self.book_testaments = {}
91112 # books of the bible linked to bibleid {osis, abbrev}
113 self.book_abbreviations = {}
92 filepath = os.path.split(os.path.abspath(__file__))[0]114 filepath = os.path.split(os.path.abspath(__file__))[0]
93 filepath = os.path.abspath(os.path.join(filepath, u'..', u'resources',u'httpbooks.csv'))115 filepath = os.path.abspath(os.path.join(
94 fbibles=open(filepath, 'r')116 filepath, u'..', u'resources',u'httpbooks.csv'))
117 fbibles = open(filepath, u'r')
95 for line in fbibles:118 for line in fbibles:
96 p = line.split(u',')119 p = line.split(u',')
97 self.book_abbreviations[p[0]] = p[1].replace(u'\n', '')120 self.book_abbreviations[p[0]] = p[1].replace(u'\n', '')
@@ -99,31 +122,64 @@
99 log.debug(u'Bible Initialised')122 log.debug(u'Bible Initialised')
100123
101 def process_dialog(self, dialogobject):124 def process_dialog(self, dialogobject):
125 """
126 Sets the reference to the dialog with the progress bar on it.
127
128 ``dialogobject``
129 The reference to the dialog.
130 """
102 self.dialogobject = dialogobject131 self.dialogobject = dialogobject
103132
104 def register_http_bible(self, biblename, biblesource, bibleid, proxyurl=None, proxyid=None, proxypass=None):133 def register_http_bible(self, biblename, biblesource, bibleid,
105 """134 proxyurl=None, proxyid=None, proxypass=None):
106 Return a list of bibles from a given URL.135 """
107 The selected Bible can then be registered and LazyLoaded into a database136 Return a list of bibles from a given URL. The selected Bible
108 """137 can then be registered and LazyLoaded into a database.
109 log.debug(u'register_HTTP_bible %s,%s,%s,%s,%s,%s', biblename, biblesource, bibleid, proxyurl, proxyid, proxypass)138
139 ``biblename``
140 The name of the bible to register.
141
142 ``biblesource``
143 Where this Bible stores it's verses.
144
145 ``bibleid``
146 The identifier for a Bible.
147
148 ``proxyurl``
149 Defaults to *None*. An optional URL to a proxy server.
150
151 ``proxyid``
152 Defaults to *None*. A username for logging into the proxy
153 server.
154
155 ``proxypass``
156 Defaults to *None*. The password to accompany the username.
157 """
158 log.debug(u'register_HTTP_bible %s, %s, %s, %s, %s, %s',
159 biblename, biblesource, bibleid, proxyurl, proxyid, proxypass)
110 if self._is_new_bible(biblename):160 if self._is_new_bible(biblename):
111 nbible = BibleDBImpl(self.biblePath, biblename, self.config) # Create new Bible161 # Create new Bible
112 nbible.create_tables() # Create Database162 nbible = BibleDBImpl(self.biblePath, biblename, self.config)
163 # Create Database
164 nbible.create_tables()
113 self.bible_db_cache[biblename] = nbible165 self.bible_db_cache[biblename] = nbible
114
115 nhttp = BibleHTTPImpl()166 nhttp = BibleHTTPImpl()
116 nhttp.set_bible_source(biblesource)167 nhttp.set_bible_source(biblesource)
117 self.bible_http_cache [biblename] = nhttp168 self.bible_http_cache [biblename] = nhttp
118 nbible.save_meta(u'WEB', biblesource) # register a lazy loading interest169 # register a lazy loading interest
119 nbible.save_meta(u'bibleid', bibleid) # store the we id of the bible170 nbible.save_meta(u'WEB', biblesource)
171 # store the web id of the bible
172 nbible.save_meta(u'bibleid', bibleid)
120 if proxyurl != None and proxyurl != "":173 if proxyurl != None and proxyurl != "":
121 nbible.save_meta(u'proxy', proxyurl) # store the proxy URL174 # store the proxy URL
175 nbible.save_meta(u'proxy', proxyurl)
122 nhttp.set_proxy(proxyurl)176 nhttp.set_proxy(proxyurl)
123 if proxyid != None and proxyid != "":177 if proxyid != None and proxyid != "":
124 nbible.save_meta(u'proxyid', proxyid) # store the proxy userid178 # store the proxy userid
179 nbible.save_meta(u'proxyid', proxyid)
125 if proxypass != None and proxypass != "":180 if proxypass != None and proxypass != "":
126 nbible.save_meta(u'proxypass', proxypass) # store the proxy password181 # store the proxy password
182 nbible.save_meta(u'proxypass', proxypass)
127 return True183 return True
128 else:184 else:
129 log.debug(u'register_http_file_bible %s not created already exists', biblename)185 log.debug(u'register_http_file_bible %s not created already exists', biblename)
@@ -165,21 +221,26 @@
165 log.debug(u'register_OSIS_file_bible %s , %s not created already exists', biblename, osisfile)221 log.debug(u'register_OSIS_file_bible %s , %s not created already exists', biblename, osisfile)
166 return False222 return False
167223
168 def get_bibles(self, mode=u'full'):224 def get_bibles(self, mode=BibleMode.Full):
225 """
226 Returns a list of Books of the bible. When ``mode`` is set to
227 ``BibleMode.Full`` this method returns all the Bibles for the
228 Advanced Search, and when the mode is ``BibleMode.Partial``
229 this method returns all the bibles for the Quick Search.
230
231 ``mode``
232 Defaults to ``BibleMode.Full``. The Bible mode.
233 """
169 log.debug(u'get_bibles')234 log.debug(u'get_bibles')
170 """235 bible_list = []
171 Returns a list of Books of the bible236 for bible_name, bible_object in self.bible_db_cache.iteritems():
172 Mode "Full" - Returns all the bibles for the Queck seearch237 if mode == BibleMode.Full:
173 Mode "Partial" - Returns CSV and OSIS bbles for the Advanced Search238 bible_list.append(bible_name)
174 """
175 r=[]
176 for b , o in self.bible_db_cache.iteritems():
177 if mode == u'full':
178 r.append(b)
179 else:239 else:
180 if self.bible_http_cache [b] == None: # we do not have an http bible240 if self.bible_http_cache[bible_name] is None:
181 r.append(b)241 # we do not have an http bible
182 return r242 bible_list.append(bible_name)
243 return bible_list
183244
184 def get_bible_books(self,bible):245 def get_bible_books(self,bible):
185 """246 """
@@ -192,7 +253,7 @@
192 """253 """
193 Returns the number of Chapters for a given book254 Returns the number of Chapters for a given book
194 """255 """
195 log.debug(u'get_book_chapter_count %s,%s', bible, book)256 log.debug(u'get_book_chapter_count %s, %s', bible, book)
196 return self.bible_db_cache[bible].get_max_bible_book_chapter(book)257 return self.bible_db_cache[bible].get_max_bible_book_chapter(book)
197258
198 def get_book_verse_count(self, bible, book, chapter):259 def get_book_verse_count(self, bible, book, chapter):
@@ -227,7 +288,7 @@
227 log.debug(u'get_meta %s,%s', bible, key)288 log.debug(u'get_meta %s,%s', bible, key)
228 return self.bible_db_cache[bible].get_meta(key)289 return self.bible_db_cache[bible].get_meta(key)
229290
230 def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse = 0 ):291 def get_verse_text(self, bible, bookname, schapter, echapter, sverse, everse=0):
231 """292 """
232 Returns a list of verses for a given Book, Chapter and ranges of verses.293 Returns a list of verses for a given Book, Chapter and ranges of verses.
233 If the end verse(everse) is less then the start verse(sverse)294 If the end verse(everse) is less then the start verse(sverse)
@@ -237,7 +298,7 @@
237 """298 """
238 text = []299 text = []
239 log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse)300 log.debug(u'get_verse_text %s,%s,%s,%s,%s,%s', bible, bookname, schapter, echapter, sverse, everse)
240 if not self.bible_http_cache [bible] == None:301 if not self.bible_http_cache[bible] == None:
241 # check to see if book/chapter exists302 # check to see if book/chapter exists
242 book= self.bible_db_cache[bible].get_bible_book(bookname)303 book= self.bible_db_cache[bible].get_bible_book(bookname)
243 if book == None:304 if book == None:
244305
=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py 2009-07-13 17:02:38 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py 2009-07-13 20:11:36 +0000
@@ -2,7 +2,9 @@
2# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=42# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
3"""3"""
4OpenLP - Open Source Lyrics Projection4OpenLP - Open Source Lyrics Projection
5
5Copyright (c) 2008 Raoul Snyman6Copyright (c) 2008 Raoul Snyman
7
6Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley8Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
79
8This program is free software; you can redistribute it and/or modify it under10This program is free software; you can redistribute it and/or modify it under
@@ -21,8 +23,10 @@
2123
22from PyQt4 import QtCore, QtGui24from PyQt4 import QtCore, QtGui
2325
24from openlp.core.lib import ServiceItem, MediaManagerItem, Receiver, translate, contextMenuAction, contextMenuSeparator26from openlp.core.lib import translate, ServiceItem, MediaManagerItem, \
27 Receiver, contextMenuAction, contextMenuSeparator
25from openlp.plugins.bibles.forms import BibleImportForm28from openlp.plugins.bibles.forms import BibleImportForm
29from openlp.plugins.bibles.lib.manager import BibleMode
2630
27class BibleList(QtGui.QListWidget):31class BibleList(QtGui.QListWidget):
2832
@@ -255,12 +259,12 @@
255 log.debug(u'Loading Bibles')259 log.debug(u'Loading Bibles')
256 self.QuickVersionComboBox.clear()260 self.QuickVersionComboBox.clear()
257 self.AdvancedVersionComboBox.clear()261 self.AdvancedVersionComboBox.clear()
258 bibles = self.parent.biblemanager.get_bibles(u'full')262 bibles = self.parent.biblemanager.get_bibles(BibleMode.Full)
259 # load bibles into the combo boxes263 # load bibles into the combo boxes
260 for bible in bibles:264 for bible in bibles:
261 self.QuickVersionComboBox.addItem(bible)265 self.QuickVersionComboBox.addItem(bible)
262 # Without HTT266 # Without HTTP
263 bibles = self.parent.biblemanager.get_bibles(u'partial')267 bibles = self.parent.biblemanager.get_bibles(BibleMode.Partial)
264 first = True268 first = True
265 # load bibles into the combo boxes269 # load bibles into the combo boxes
266 for bible in bibles:270 for bible in bibles:
@@ -287,8 +291,8 @@
287 self.adjustComboBox(frm, self.verses, self.AdvancedToVerse)291 self.adjustComboBox(frm, self.verses, self.AdvancedToVerse)
288292
289 def onAdvancedToChapter(self):293 def onAdvancedToChapter(self):
290 t1 = self.AdvancedFromChapter.currentText()294 t1 = self.AdvancedFromChapter.currentText()
291 t2 = self.AdvancedToChapter.currentText()295 t2 = self.AdvancedToChapter.currentText()
292 if t1 != t2:296 if t1 != t2:
293 bible = unicode(self.AdvancedVersionComboBox.currentText())297 bible = unicode(self.AdvancedVersionComboBox.currentText())
294 book = unicode(self.AdvancedBookComboBox.currentText())298 book = unicode(self.AdvancedBookComboBox.currentText())
@@ -344,12 +348,12 @@
344 bitem = self.ListView.item(item.row())348 bitem = self.ListView.item(item.row())
345 text = unicode((bitem.data(QtCore.Qt.UserRole)).toString())349 text = unicode((bitem.data(QtCore.Qt.UserRole)).toString())
346 verse = text[:text.find(u'(')]350 verse = text[:text.find(u'(')]
347 bible = text[text.find(u'(') + 1:text.find(u')')]351 bible = text[text.find(u'(') + 1:-1]
348 self.searchByReference(bible, verse)352 self.searchByReference(bible, verse)
349 book = self.search_results[0][0]353 book = self.search_results[0].book.name
350 chapter = unicode(self.search_results[0][1])354 chapter = unicode(self.search_results[0].chapter)
351 verse = unicode(self.search_results[0][2])355 verse = unicode(self.search_results[0].verse)
352 text = self.search_results[0][3]356 text = self.search_results[0].text
353 #Paragraph style force new line per verse357 #Paragraph style force new line per verse
354 if self.parent.bibles_tab.paragraph_style:358 if self.parent.bibles_tab.paragraph_style:
355 text = text + u'\n\n'359 text = text + u'\n\n'
@@ -406,8 +410,8 @@
406410
407 def initialiseChapterVerse(self, bible, book):411 def initialiseChapterVerse(self, bible, book):
408 log.debug(u'initialiseChapterVerse %s , %s', bible, book)412 log.debug(u'initialiseChapterVerse %s , %s', bible, book)
409 self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book)[0]413 self.chapters_from = self.parent.biblemanager.get_book_chapter_count(bible, book)
410 self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1)[0]414 self.verses = self.parent.biblemanager.get_book_verse_count(bible, book, 1)
411 self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)415 self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
412 self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)416 self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
413 self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)417 self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
@@ -420,10 +424,16 @@
420 combo.addItem(unicode(i))424 combo.addItem(unicode(i))
421425
422 def displayResults(self, bible):426 def displayResults(self, bible):
423 for book, chap, vse , txt in self.search_results:427 for verse in self.search_results:
424 bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible))428 #bible_text = unicode(u' %s %d:%d (%s)'%(book , chap,vse, bible))
429 #bible_verse = QtGui.QListWidgetItem(bible_text)
430 #bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text))
431 #self.ListView.addItem(bible_verse)
432 bible_text = u' %s %d:%d (%s)' % (verse.book.name,
433 verse.chapter, verse.verse, bible)
425 bible_verse = QtGui.QListWidgetItem(bible_text)434 bible_verse = QtGui.QListWidgetItem(bible_text)
426 bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text))435 bible_verse.setData(QtCore.Qt.UserRole,
436 QtCore.QVariant(bible_text))
427 self.ListView.addItem(bible_verse)437 self.ListView.addItem(bible_verse)
428438
429 def searchByReference(self, bible, search):439 def searchByReference(self, bible, search):
430440
=== renamed file 'openlp/plugins/bibles/lib/tables.py' => 'openlp/plugins/bibles/lib/models.py'
--- openlp/plugins/bibles/lib/tables.py 2009-06-16 18:21:24 +0000
+++ openlp/plugins/bibles/lib/models.py 2009-07-14 19:44:15 +0000
@@ -1,7 +1,10 @@
1# -*- coding: utf-8 -*-
1# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=42# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
2"""3"""
3OpenLP - Open Source Lyrics Projection4OpenLP - Open Source Lyrics Projection
5
4Copyright (c) 2008 Raoul Snyman6Copyright (c) 2008 Raoul Snyman
7
5Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley8Portions copyright (c) 2008 - 2009 Martin Thompson, Tim Bentley
69
7This program is free software; you can redistribute it and/or modify it under10This program is free software; you can redistribute it and/or modify it under
@@ -14,39 +17,95 @@
1417
15You should have received a copy of the GNU General Public License along with18You should have received a copy of the GNU General Public License along with
16this program; if not, write to the Free Software Foundation, Inc., 59 Temple19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17Place, Suite 330, Boston, MA 02111-1307 USA 20Place, Suite 330, Boston, MA 02111-1307 USA
18"""21"""
19import string 22import string
20from sqlalchemy import *23
21from sqlalchemy import Column, Table, MetaData, ForeignKey, schema24from sqlalchemy import Column, Table, MetaData, ForeignKey, types, \
25 create_engine
26from sqlalchemy.orm import mapper, relation, sessionmaker, scoped_session
27
28class BaseModel(object):
29 """
30 BaseModel provides a base object with a set of generic functions
31 """
32 @classmethod
33 def populate(cls, **kwargs):
34 """
35 Creates an instance of a class and populates it, returning the instance
36 """
37 me = cls()
38 keys = kwargs.keys()
39 for key in keys:
40 me.__setattr__(key, kwargs[key])
41 return me
42
43
44class BibleMeta(BaseModel):
45 """
46 Bible Meta Data
47 """
48 pass
49
50
51class ONTestament(BaseModel):
52 """
53 Bible Testaments
54 """
55 pass
56
57
58class Book(BaseModel):
59 """
60 Song model
61 """
62 pass
63
64
65class Verse(BaseModel):
66 """
67 Topic model
68 """
69 pass
70
71
72def init_models(db_url):
73 engine = create_engine(db_url)
74 metadata.bind = engine
75 session = scoped_session(sessionmaker(autoflush=True,
76 autocommit=False,
77 bind=engine))
78 # Don't think this is needed...
79 #metadata.bind.echo = False
80 #Define the tables and indexes
81 return metadata, session
82
2283
23metadata = MetaData()84metadata = MetaData()
24#Define the tables and indexes
25meta_table = Table(u'metadata', metadata,
26 Column(u'key', String(255), primary_key=True),
27 Column(u'value', String(255)),
28)
29
30testament_table = Table(u'testament', metadata,
31 Column(u'id', Integer, primary_key=True),
32 Column(u'name', String(30)),
33)
34
35book_table = Table(u'book', metadata,
36 Column(u'id', Integer, primary_key=True),
37 Column(u'testament_id', Integer, schema.ForeignKey(u'testament.id')),
38 Column(u'name', String(30)),
39 Column(u'abbreviation', String(5)),
40)
41Index(u'idx_name', book_table.c.name, book_table.c.id)
42Index(u'idx_abbrev', book_table.c.abbreviation, book_table.c.id)
43
44verse_table = Table(u'verse', metadata,
45 Column(u'id', Integer, primary_key=True),
46 Column(u'book_id', Integer , schema.ForeignKey(u'book.id')),
47 Column(u'chapter', Integer),
48 Column(u'verse', Integer),
49 Column(u'text', Text),
50)
51Index(u'idx_chapter_verse_book', verse_table.c.chapter, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id)
52Index(u'idx_chapter_verse_text', verse_table.c.text, verse_table.c.verse, verse_table.c.book_id, verse_table.c.id)
53\ No newline at end of file85\ No newline at end of file
86meta_table = Table(u'metadata', metadata,
87 Column(u'key', types.Unicode(255), primary_key=True, index=True),
88 Column(u'value', types.Unicode(255)),
89)
90testament_table = Table(u'testament', metadata,
91 Column(u'id', types.Integer, primary_key=True),
92 Column(u'name', types.Unicode(50)),
93)
94book_table = Table(u'book', metadata,
95 Column(u'id', types.Integer, primary_key=True),
96 Column(u'testament_id', types.Integer, ForeignKey(u'testament.id')),
97 Column(u'name', types.Unicode(50), index=True),
98 Column(u'abbreviation', types.Unicode(5), index=True),
99)
100verse_table = Table(u'verse', metadata,
101 Column(u'id', types.Integer, primary_key=True, index=True),
102 Column(u'book_id', types.Integer, ForeignKey(u'book.id'), index=True),
103 Column(u'chapter', types.Integer, index=True),
104 Column(u'verse', types.Integer, index=True),
105 Column(u'text', types.UnicodeText, index=True),
106)
107mapper(BibleMeta, meta_table)
108mapper(ONTestament, testament_table,
109 properties={'books': relation(Book, backref='testament')})
110mapper(Book, book_table,
111 properties={'verses': relation(Verse, backref='book')})
112mapper(Verse, verse_table)