revert 1153

This commit is contained in:
M2j 2011-12-18 18:08:37 +01:00
parent bf3e013e9c
commit d7a5a9ae97
5 changed files with 34 additions and 169 deletions

View File

@ -30,26 +30,19 @@ plugin.
import logging import logging
import re import re
from openlp.core.lib import translate
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_reference_match(match_type): def get_reference_match(match_type):
local_separator = unicode(translate('BiblesPlugin', local_separator = unicode(u':;;\s*[:vV]\s*;;-;;\s*-\s*;;,;;\s*,\s*;;end'
':;;\\s*[:vV]\\s*;;-;;\\s*-\\s*;;,;;\\s*,\\s*;;end', ).split(u';;') # English
'Seperators for parsing references. There are 7 values separated each ' # local_separator = unicode(u',;;\s*,\s*;;-;;\s*-\s*;;.;;\.;;[Ee]nde'
'by two semicolons. Verse, range and list separators have each one ' # ).split(u';;') # German
'display symbol which appears on slides and in the GUI and a regular '
'expression for detecting this symbols.\n'
'Please ask a developer to double check your translation or make '
'yourself familar with regular experssions on: '
'http://docs.python.org/library/re.html')
).split(u';;')
separators = { separators = {
u'sep_v_display': local_separator[0], u'sep_v': local_separator[1], u'sep_v_display': local_separator[0], u'sep_v': local_separator[1],
u'sep_r_display': local_separator[2], u'sep_r': local_separator[3], u'sep_r_display': local_separator[2], u'sep_r': local_separator[3],
u'sep_l_display': local_separator[4], u'sep_l': local_separator[5], u'sep_l_display': local_separator[4], u'sep_l': local_separator[5],
u'sep_e': local_separator[6]} u'sep_e': local_separator[6]}
# verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)? # verse range match: (<chapter>:)?<verse>(-((<chapter>:)?<verse>|end)?)?
range_string = str(r'(?:(?P<from_chapter>[0-9]+)%(sep_v)s)?(?P<from_verse>' range_string = str(r'(?:(?P<from_chapter>[0-9]+)%(sep_v)s)?(?P<from_verse>'
r'[0-9]+)(?P<range_to>%(sep_r)s(?:(?:(?P<to_chapter>[0-9]+)%(sep_v)s)?' r'[0-9]+)(?P<range_to>%(sep_r)s(?:(?:(?P<to_chapter>[0-9]+)%(sep_v)s)?'
@ -138,9 +131,6 @@ def parse_reference(reference):
if match: if match:
log.debug(u'Matched reference %s' % reference) log.debug(u'Matched reference %s' % reference)
book = match.group(u'book') book = match.group(u'book')
bookname_dict = get_system_bookname_dict()
if book.lower() in bookname_dict:
book = bookname_dict[book.lower()]
ranges = match.group(u'ranges') ranges = match.group(u'ranges')
range_list = get_reference_match(u'range_separator').split(ranges) range_list = get_reference_match(u'range_separator').split(ranges)
ref_list = [] ref_list = []
@ -201,94 +191,6 @@ def parse_reference(reference):
log.debug(u'Invalid reference: %s' % reference) log.debug(u'Invalid reference: %s' % reference)
return None return None
def get_local_bookname_dict():
raw_dict = get_raw_bookname_dict()
local_bookname_dict = {}
for key in raw_dict.keys():
local_bookname_dict[key] = raw_dict[key][0]
return local_bookname_dict
def get_system_bookname_dict():
raw_dict = get_raw_bookname_dict()
system_bookname_dict = {}
for key in raw_dict.keys():
for alias in raw_dict[key]:
system_bookname_dict[alias.lower()] = key
return system_bookname_dict
def get_raw_bookname_dict():
raw_bookname_dict = {u'Genesis': translate('BiblesPlugin', 'Genesis;;Gen'),
u'Exodus': translate('BiblesPlugin', 'Exodus;;Exod'),
u'Leviticus': translate('BiblesPlugin', 'Leviticus;;Lev'),
u'Numbers': translate('BiblesPlugin', 'Numbers;;Num'),
u'Deuteronomy': translate('BiblesPlugin', 'Deuteronomy;;Deut'),
u'Joshua': translate('BiblesPlugin', 'Joshua;;Josh'),
u'Judges': translate('BiblesPlugin', 'Judges;;Judg'),
u'Ruth': translate('BiblesPlugin', 'Ruth;;Ruth'),
u'1 Samuel': translate('BiblesPlugin', '1 Samuel;;1Sam'),
u'2 Samuel': translate('BiblesPlugin', '2 Samuel;;2Sam'),
u'1 Kings': translate('BiblesPlugin', '1 Kings;;1Kgs'),
u'2 Kings': translate('BiblesPlugin', '2 Kings;;2Kgs'),
u'1 Chronicles': translate('BiblesPlugin', '1 Chronicles;;1Chr'),
u'2 Chronicles': translate('BiblesPlugin', '2 Chronicles;;2Chr'),
u'Ezra': translate('BiblesPlugin', 'Ezra;;Ezra'),
u'Nehemiah': translate('BiblesPlugin', 'Nehemiah;;Neh'),
u'Esther': translate('BiblesPlugin', 'Esther;;Esth'),
u'Job': translate('BiblesPlugin', 'Job;;Job'),
u'Psalms': translate('BiblesPlugin', 'Psalms;;Ps'),
u'Proverbs': translate('BiblesPlugin', 'Proverbs;;Prov'),
u'Ecclesiastes': translate('BiblesPlugin', 'Ecclesiastes;;Eccl'),
u'Song of Songs': translate('BiblesPlugin', 'Song of Songs;;Song'),
u'Isaiah': translate('BiblesPlugin', 'Isaiah;;Isa'),
u'Jeremiah': translate('BiblesPlugin', 'Jeremiah;;Jer'),
u'Lamentations': translate('BiblesPlugin', 'Lamentations;;Lam'),
u'Ezekiel': translate('BiblesPlugin', 'Ezekiel;;Ezek'),
u'Daniel': translate('BiblesPlugin', 'Daniel;;Dan'),
u'Hosea': translate('BiblesPlugin', 'Hosea;;Hos'),
u'Joel': translate('BiblesPlugin', 'Joel;;Joel'),
u'Amos': translate('BiblesPlugin', 'Amos;;Amos'),
u'Obad': translate('BiblesPlugin', 'Obad;;Obad'),
u'Jonah': translate('BiblesPlugin', 'Jonah;;Jonah'),
u'Micah': translate('BiblesPlugin', 'Micah;;Mic'),
u'Naham': translate('BiblesPlugin', 'Naham;;Nah'),
u'Habakkuk': translate('BiblesPlugin', 'Habakkuk;;Hab'),
u'Zephaniah': translate('BiblesPlugin', 'Zephaniah;;Zeph'),
u'Haggai': translate('BiblesPlugin', 'Haggai;;Hag'),
u'Zechariah': translate('BiblesPlugin', 'Zechariah;;Zech'),
u'Malachi': translate('BiblesPlugin', 'Malachi;;Mal'),
u'Matthew': translate('BiblesPlugin', 'Matthew;;Matt'),
u'Mark': translate('BiblesPlugin', 'Mark;;Mark'),
u'Luke': translate('BiblesPlugin', 'Luke;;Luke'),
u'John': translate('BiblesPlugin', 'John;;John'),
u'Acts': translate('BiblesPlugin', 'Acts;;Acts'),
u'Romans': translate('BiblesPlugin', 'Romans;;Rom'),
u'1 Corinthians': translate('BiblesPlugin', '1 Corinthians;;1Cor'),
u'2 Corinthians': translate('BiblesPlugin', '2 Corinthians;;2Cor'),
u'Galatians': translate('BiblesPlugin', 'Galatians;;Gal'),
u'Ephesians': translate('BiblesPlugin', 'Ephesians;;Eph'),
u'Philippians': translate('BiblesPlugin', 'Philippians;;Phil'),
u'Colossians': translate('BiblesPlugin', 'Colossians;;Col'),
u'1 Thessalonians': translate('BiblesPlugin',
'1 Thessalonians;;1Thess'),
u'2 Thessalonians': translate('BiblesPlugin',
'2 Thessalonians;;2Thess'),
u'1 Timothy': translate('BiblesPlugin', '1 Timothy;;1Tim'),
u'2 Timothy': translate('BiblesPlugin', '2 Timothy;;2Tim'),
u'Titus': translate('BiblesPlugin', 'Titus;;Titus'),
u'Philemon': translate('BiblesPlugin', 'Philemon;;Phlm'),
u'Hebrews': translate('BiblesPlugin', 'Hebrews;;Heb'),
u'James': translate('BiblesPlugin', 'James;;Jas'),
u'1 Peter': translate('BiblesPlugin', '1 Peter;;1Pet'),
u'2 Peter': translate('BiblesPlugin', '2 Peter;;2Pet'),
u'1 John': translate('BiblesPlugin', '1 John;;1John'),
u'2 John': translate('BiblesPlugin', '2 John;;2John'),
u'3 John': translate('BiblesPlugin', '3 John;;3John'),
u'Jude': translate('BiblesPlugin', 'Jude;;Jude'),
u'Revelation': translate('BiblesPlugin', 'Revelation;;Rev')}
for key in raw_bookname_dict.keys():
raw_bookname_dict[key] = unicode(raw_bookname_dict[key]).split(u';;')
return raw_bookname_dict
class SearchResults(object): class SearchResults(object):
""" """

View File

@ -190,8 +190,7 @@ class BibleDB(QtCore.QObject, Manager):
""" """
if not isinstance(old_filename, unicode): if not isinstance(old_filename, unicode):
old_filename = unicode(old_filename, u'utf-8') old_filename = unicode(old_filename, u'utf-8')
old_filename = \ old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_')
re.sub(r'[^\w]+', u'_', old_filename, re.UNICODE).strip(u'_')
return old_filename + u'.sqlite' return old_filename + u'.sqlite'
def register(self, wizard): def register(self, wizard):

View File

@ -257,14 +257,6 @@ class BibleManager(object):
- Genesis 1:1-10,2:1-10 - Genesis 1:1-10,2:1-10
""" """
log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext) log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext)
if not bible:
QtGui.QMessageBox.information(self.parent.mediaItem,
translate('BiblesPlugin.BibleManager',
'No Bibles available'),
translate('BiblesPlugin.BibleManager',
'There are no Bibles currently installed. Please use the '
'Import Wizard to install one or more Bibles.'))
return None
reflist = parse_reference(versetext) reflist = parse_reference(versetext)
if reflist: if reflist:
return self.db_cache[bible].get_verses(reflist) return self.db_cache[bible].get_verses(reflist)

View File

@ -32,8 +32,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, Receiver, BaseListWithDnD, \ from openlp.core.lib import MediaManagerItem, Receiver, BaseListWithDnD, \
ItemCapabilities, translate ItemCapabilities, translate
from openlp.plugins.bibles.forms import BibleImportForm from openlp.plugins.bibles.forms import BibleImportForm
from openlp.plugins.bibles.lib import get_reference_match, \ from openlp.plugins.bibles.lib import get_reference_match
get_local_bookname_dict, get_system_bookname_dict
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -331,10 +330,6 @@ class BibleMediaItem(MediaManagerItem):
translate('BiblesPlugin.MediaItem', 'Clear')) translate('BiblesPlugin.MediaItem', 'Clear'))
self.ClearAdvancedSearchComboBox.addItem( self.ClearAdvancedSearchComboBox.addItem(
translate('BiblesPlugin.MediaItem', 'Keep')) translate('BiblesPlugin.MediaItem', 'Keep'))
self.verse_separator = get_reference_match(u'sep_v_display')
self.range_separator = get_reference_match(u'sep_r_display')
self.local_bookname = get_local_bookname_dict()
self.system_bookname = get_local_bookname_dict()
def initialise(self): def initialise(self):
log.debug(u'bible manager initialise') log.debug(u'bible manager initialise')
@ -415,12 +410,7 @@ class BibleMediaItem(MediaManagerItem):
first = True first = True
for book in book_data: for book in book_data:
row = self.AdvancedBookComboBox.count() row = self.AdvancedBookComboBox.count()
local_name = book[u'name'] self.AdvancedBookComboBox.addItem(book[u'name'])
if local_name in self.local_bookname:
local_name = self.local_bookname[local_name]
else:
log.debug(u'bookname %s not translatable', local_name)
self.AdvancedBookComboBox.addItem(local_name)
self.AdvancedBookComboBox.setItemData( self.AdvancedBookComboBox.setItemData(
row, QtCore.QVariant(book[u'chapters'])) row, QtCore.QVariant(book[u'chapters']))
if first: if first:
@ -456,12 +446,8 @@ class BibleMediaItem(MediaManagerItem):
bibles = self.parent.manager.get_bibles() bibles = self.parent.manager.get_bibles()
bible = unicode(self.QuickVersionComboBox.currentText()) bible = unicode(self.QuickVersionComboBox.currentText())
if bible: if bible:
books = [] book_data = bibles[bible].get_books()
for book in bibles[bible].get_books(): books = [book.name for book in book_data]
if book.name in self.local_bookname:
books.append(self.local_bookname[book.name])
else:
books.append(book.name)
books.sort() books.sort()
completer = QtGui.QCompleter(books) completer = QtGui.QCompleter(books)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive) completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
@ -473,12 +459,10 @@ class BibleMediaItem(MediaManagerItem):
def onAdvancedBookComboBox(self): def onAdvancedBookComboBox(self):
item = int(self.AdvancedBookComboBox.currentIndex()) item = int(self.AdvancedBookComboBox.currentIndex())
bookname = unicode(self.AdvancedBookComboBox.currentText())
if bookname in self.system_bookname:
bookname = self.system_bookname[bookname]
self.initialiseChapterVerse( self.initialiseChapterVerse(
unicode(self.AdvancedVersionComboBox.currentText()), unicode(self.AdvancedVersionComboBox.currentText()),
bookname, self.AdvancedBookComboBox.itemData(item).toInt()[0]) unicode(self.AdvancedBookComboBox.currentText()),
self.AdvancedBookComboBox.itemData(item).toInt()[0])
def onAdvancedFromVerse(self): def onAdvancedFromVerse(self):
chapter_from = int(self.AdvancedFromChapter.currentText()) chapter_from = int(self.AdvancedFromChapter.currentText())
@ -486,8 +470,6 @@ class BibleMediaItem(MediaManagerItem):
if chapter_from == chapter_to: if chapter_from == chapter_to:
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
if book in self.system_bookname:
book = self.system_bookname[book]
verse_from = int(self.AdvancedFromVerse.currentText()) verse_from = int(self.AdvancedFromVerse.currentText())
verse_count = self.parent.manager.get_verse_count(bible, book, verse_count = self.parent.manager.get_verse_count(bible, book,
chapter_to) chapter_to)
@ -497,8 +479,6 @@ class BibleMediaItem(MediaManagerItem):
def onAdvancedToChapter(self): def onAdvancedToChapter(self):
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
if book in self.system_bookname:
book = self.system_bookname[book]
chapter_from = int(self.AdvancedFromChapter.currentText()) chapter_from = int(self.AdvancedFromChapter.currentText())
chapter_to = int(self.AdvancedToChapter.currentText()) chapter_to = int(self.AdvancedToChapter.currentText())
verse_from = int(self.AdvancedFromVerse.currentText()) verse_from = int(self.AdvancedFromVerse.currentText())
@ -513,8 +493,6 @@ class BibleMediaItem(MediaManagerItem):
def onAdvancedFromChapter(self): def onAdvancedFromChapter(self):
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
if book in self.system_bookname:
book = self.system_bookname[book]
chapter_from = int(self.AdvancedFromChapter.currentText()) chapter_from = int(self.AdvancedFromChapter.currentText())
chapter_to = int(self.AdvancedToChapter.currentText()) chapter_to = int(self.AdvancedToChapter.currentText())
verse_count = self.parent.manager.get_verse_count(bible, book, verse_count = self.parent.manager.get_verse_count(bible, book,
@ -567,14 +545,14 @@ class BibleMediaItem(MediaManagerItem):
bible = unicode(self.AdvancedVersionComboBox.currentText()) bible = unicode(self.AdvancedVersionComboBox.currentText())
second_bible = unicode(self.AdvancedSecondBibleComboBox.currentText()) second_bible = unicode(self.AdvancedSecondBibleComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText()) book = unicode(self.AdvancedBookComboBox.currentText())
if book in self.system_bookname:
book = self.system_bookname[book]
chapter_from = self.AdvancedFromChapter.currentText() chapter_from = self.AdvancedFromChapter.currentText()
chapter_to = self.AdvancedToChapter.currentText() chapter_to = self.AdvancedToChapter.currentText()
verse_from = self.AdvancedFromVerse.currentText() verse_from = self.AdvancedFromVerse.currentText()
verse_to = self.AdvancedToVerse.currentText() verse_to = self.AdvancedToVerse.currentText()
verse_range = chapter_from + self.verse_separator + verse_from + \ verse_separator = get_reference_match(u'sep_v_display')
self.range_separator + chapter_to + self.verse_separator + verse_to range_separator = get_reference_match(u'sep_r_display')
verse_range = chapter_from + verse_separator + verse_from + \
range_separator + chapter_to + verse_separator + verse_to
versetext = u'%s %s' % (book, verse_range) versetext = u'%s %s' % (book, verse_range)
self.search_results = self.parent.manager.get_verses(bible, versetext) self.search_results = self.parent.manager.get_verses(bible, versetext)
if second_bible: if second_bible:
@ -670,12 +648,9 @@ class BibleMediaItem(MediaManagerItem):
second_permissions = u'' second_permissions = u''
for count, verse in enumerate(self.search_results): for count, verse in enumerate(self.search_results):
if second_bible: if second_bible:
book = verse.book.name
try: try:
if book in self.local_bookname:
book = self.local_bookname[book]
vdict = { vdict = {
'book': QtCore.QVariant(book), 'book': QtCore.QVariant(verse.book.name),
'chapter': QtCore.QVariant(verse.chapter), 'chapter': QtCore.QVariant(verse.chapter),
'verse': QtCore.QVariant(verse.verse), 'verse': QtCore.QVariant(verse.verse),
'bible': QtCore.QVariant(bible), 'bible': QtCore.QVariant(bible),
@ -694,15 +669,12 @@ class BibleMediaItem(MediaManagerItem):
} }
except IndexError: except IndexError:
break break
bible_text = u' %s %d%s%d (%s, %s)' % (book, bible_text = u' %s %d:%d (%s, %s)' % (verse.book.name,
verse.chapter, self.verse_separator, verse.verse, verse.chapter, verse.verse, version.value,
version.value, second_version.value) second_version.value)
else: else:
book = verse.book.name
if book in self.local_bookname:
book = self.local_bookname[book]
vdict = { vdict = {
'book': QtCore.QVariant(book), 'book': QtCore.QVariant(verse.book.name),
'chapter': QtCore.QVariant(verse.chapter), 'chapter': QtCore.QVariant(verse.chapter),
'verse': QtCore.QVariant(verse.verse), 'verse': QtCore.QVariant(verse.verse),
'bible': QtCore.QVariant(bible), 'bible': QtCore.QVariant(bible),
@ -716,9 +688,8 @@ class BibleMediaItem(MediaManagerItem):
'second_permissions': QtCore.QVariant(u''), 'second_permissions': QtCore.QVariant(u''),
'second_text': QtCore.QVariant(u'') 'second_text': QtCore.QVariant(u'')
} }
bible_text = u'%s %d%s%d (%s)' % (book, bible_text = u'%s %d:%d (%s)' % (verse.book.name,
verse.chapter, self.verse_separator, verse.verse, verse.chapter, verse.verse, version.value)
version.value)
bible_verse = QtGui.QListWidgetItem(bible_text) bible_verse = QtGui.QListWidgetItem(bible_text)
bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(vdict)) bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(vdict))
self.listView.addItem(bible_verse) self.listView.addItem(bible_verse)
@ -841,6 +812,8 @@ class BibleMediaItem(MediaManagerItem):
``old_item`` ``old_item``
The last item of a range. The last item of a range.
""" """
verse_separator = get_reference_match(u'sep_v_display')
range_separator = get_reference_match(u'sep_r_display')
old_bitem = self.listView.item(old_item.row()) old_bitem = self.listView.item(old_item.row())
old_chapter = self._decodeQtObject(old_bitem, 'chapter') old_chapter = self._decodeQtObject(old_bitem, 'chapter')
old_verse = self._decodeQtObject(old_bitem, 'verse') old_verse = self._decodeQtObject(old_bitem, 'verse')
@ -856,14 +829,13 @@ class BibleMediaItem(MediaManagerItem):
bibles = start_bible bibles = start_bible
if start_chapter == old_chapter: if start_chapter == old_chapter:
if start_verse == old_verse: if start_verse == old_verse:
verse_range = start_chapter + self.verse_separator + start_verse verse_range = start_chapter + verse_separator + start_verse
else: else:
verse_range = start_chapter + self.verse_separator + \ verse_range = start_chapter + verse_separator + start_verse + \
start_verse + self.range_separator + old_verse range_separator + old_verse
else: else:
verse_range = start_chapter + self.verse_separator + start_verse + \ verse_range = start_chapter + verse_separator + start_verse + \
self.range_separator + old_chapter + self.verse_separator + \ range_separator + old_chapter + verse_separator + old_verse
old_verse
title = u'%s %s (%s)' % (start_book, verse_range, bibles) title = u'%s %s (%s)' % (start_book, verse_range, bibles)
return title return title
@ -926,10 +898,10 @@ class BibleMediaItem(MediaManagerItem):
``verse`` ``verse``
The verse number (int). The verse number (int).
""" """
verse_separator = get_reference_match(u'sep_v_display')
if not self.parent.settings_tab.show_new_chapters or \ if not self.parent.settings_tab.show_new_chapters or \
old_chapter != chapter: old_chapter != chapter:
verse_text = unicode(chapter) + self.verse_separator + \ verse_text = unicode(chapter) + verse_separator + unicode(verse)
unicode(verse)
else: else:
verse_text = unicode(verse) verse_text = unicode(verse)
if self.parent.settings_tab.display_style == 1: if self.parent.settings_tab.display_style == 1:

View File

@ -43,8 +43,8 @@ Luke,Luke,Luke
John,John,John John,John,John
Acts,Acts,Acts Acts,Acts,Acts
Rom,Romans,Rom Rom,Romans,Rom
1Cor,1 Corinthians,1Cor 1Cor,1 Corinthans,1Cor
2Cor,2 Corinthians,2Cor 2Cor,2 Corinthans,2Cor
Gal,Galatians,Gal Gal,Galatians,Gal
Eph,Ephesians,Eph Eph,Ephesians,Eph
Phil,Philippians,Phil Phil,Philippians,Phil

1 Gen Genesis Gen
43 John John John
44 Acts Acts Acts
45 Rom Romans Rom
46 1Cor 1 Corinthians 1 Corinthans 1Cor
47 2Cor 2 Corinthians 2 Corinthans 2Cor
48 Gal Galatians Gal
49 Eph Ephesians Eph
50 Phil Philippians Phil