Added smart footers to Bibles.

This commit is contained in:
Raoul Snyman 2011-03-20 22:50:19 +02:00
parent 5293683325
commit 3aa0aa23d3
3 changed files with 117 additions and 8 deletions

View File

@ -268,6 +268,7 @@ class SearchResults(object):
return len(self.verselist) > 0
from versereferencelist import VerseReferenceList
from manager import BibleManager
from biblestab import BiblesTab
from mediaitem import BibleMediaItem

View File

@ -35,7 +35,7 @@ from openlp.core.lib.ui import UiStrings, add_widget_completer, \
media_item_combo_box, critical_error_message_box
from openlp.plugins.bibles.forms import BibleImportForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
get_reference_match
VerseReferenceList, get_reference_match
log = logging.getLogger(__name__)
@ -637,6 +637,8 @@ class BibleMediaItem(MediaManagerItem):
old_chapter = -1
raw_slides = []
raw_title = []
verses = VerseReferenceList()
current = None
for item in items:
bitem = self.listView.item(item.row())
book = self._decodeQtObject(bitem, 'book')
@ -653,15 +655,16 @@ class BibleMediaItem(MediaManagerItem):
second_permissions = \
self._decodeQtObject(bitem, 'second_permissions')
second_text = self._decodeQtObject(bitem, 'second_text')
verses.add(book, chapter, verse, version, copyright, permissions)
verse_text = self.formatVerse(old_chapter, chapter, verse)
footer = u'%s (%s %s %s)' % (book, version, copyright, permissions)
if footer not in service_item.raw_footer:
service_item.raw_footer.append(footer)
#footer = u'%s (%s %s %s)' % (book, version, copyright, permissions)
#if footer not in service_item.raw_footer:
# service_item.raw_footer.append(footer)
if second_bible:
footer = u'%s (%s %s %s)' % (book, second_version,
second_copyright, second_permissions)
if footer not in service_item.raw_footer:
service_item.raw_footer.append(footer)
# footer = u'%s (%s %s %s)' % (book, second_version,
# second_copyright, second_permissions)
# if footer not in service_item.raw_footer:
# service_item.raw_footer.append(footer)
bible_text = u'%s %s\n\n%s %s' % (verse_text, text,
verse_text, second_text)
raw_slides.append(bible_text.rstrip())
@ -684,6 +687,12 @@ class BibleMediaItem(MediaManagerItem):
start_item = item
old_item = item
old_chapter = chapter
# Add footer
service_item.raw_footer.append(verses.format_verses())
if second_bible:
verses.add_version(second_version, second_copyright,
second_permissions)
service_item.raw_footer.append(verses.format_versions())
raw_title.append(self.formatTitle(start_item, item))
# If there are no more items we check whether we have to add bible_text.
if bible_text:

View File

@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Meinert Jordan, Armin Köhler, Andreas Preikschat, #
# Christian Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon #
# Tibble, Carsten Tinggaard, Frode Woldsund #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A 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 #
###############################################################################
class VerseReferenceList(object):
"""
The VerseReferenceList class encapsulates a list of verse references, but
maintains the order in which they were added.
"""
def __init__(self):
self.verse_list = []
self.version_list = []
self.current_index = -1
def add(self, book, chapter, verse, version, copyright, permission):
self.add_version(version, copyright, permission)
if not self.verse_list or \
self.verse_list[self.current_index][u'book'] != book:
self.verse_list.append({u'version': version, u'book': book,
u'chapter': chapter, u'start': verse, u'end': verse})
self.current_index += 1
elif self.verse_list[self.current_index][u'chapter'] != chapter:
self.verse_list.append({u'version': version, u'book': book,
u'chapter': chapter, u'start': verse, u'end': verse})
self.current_index += 1
elif (self.verse_list[self.current_index][u'end'] + 1) == verse:
self.verse_list[self.current_index][u'end'] = verse
else:
self.verse_list.append({u'version': version, u'book': book,
u'chapter': chapter, u'start': verse, u'end': verse})
self.current_index += 1
def add_version(self, version, copyright, permission):
for bible_version in self.version_list:
if bible_version[u'version'] == version:
return
self.version_list.append({u'version': version, u'copyright': copyright,
u'permission': permission})
def format_verses(self):
result = u''
for index, verse in enumerate(self.verse_list):
if index == 0:
result = u'%s %s:%s' % (verse[u'book'], verse[u'chapter'],
verse[u'start'])
if verse[u'start'] != verse[u'end']:
result = u'%s-%s' % (result, verse[u'end'])
continue
prev = index - 1
if self.verse_list[prev][u'version'] != verse[u'version']:
result = u'%s (%s)' % (result, verse[u'version'])
result = result + u', '
if self.verse_list[prev][u'book'] != verse[u'book']:
result = u'%s%s %s:' % (result, verse[u'book'],
verse[u'chapter'])
elif self.verse_list[prev][u'chapter'] != verse[u'chapter']:
result = u'%s%s:' % (result, verse[u'chapter'])
result = result + str(verse[u'start'])
if verse[u'start'] != verse[u'end']:
result = u'%s-%s' % (result, verse[u'end'])
if len(self.version_list) > 1:
result = u'%s (%s)' % (result, verse[u'version'])
return result
def format_versions(self):
result = u''
for index, version in enumerate(self.version_list):
if index > 0:
if result[-1] not in [u';', u',', u'.']:
result = result + u';'
result = result + u' '
result = u'%s%s, %s' % (result, version[u'version'],
version[u'copyright'])
if version[u'permission'].strip():
result = result + u', ' + version[u'permission']
return result