add possibility to switch the booknames of bibles - fix bug #822363

This commit is contained in:
Armin Köhler 2012-02-29 12:47:21 +01:00
parent 9dadcb9217
commit 3ed9dcaae3
5 changed files with 235 additions and 12 deletions

View File

@ -58,6 +58,13 @@ class DisplayStyle(object):
Curly = 2
Square = 3
class LanguageSelection(object):
"""
An enumeration for bible bookname language.
"""
Bible = 0
Application = 1
English = 2
def update_reference_separators():
"""

View File

@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, SettingsTab, translate
from openlp.core.lib.ui import UiStrings, find_and_set_in_combo_box
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
update_reference_separators, get_reference_separator
update_reference_separators, get_reference_separator, LanguageSelection
log = logging.getLogger(__name__)
@ -140,9 +140,25 @@ class BiblesTab(SettingsTab):
self.scriptureReferenceLayout.addWidget(self.endSeparatorLineEdit, 3,
1)
self.leftLayout.addWidget(self.scriptureReferenceGroupBox)
self.leftLayout.addStretch()
self.rightColumn.setSizePolicy(
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
self.languageSelectionGroupBox = QtGui.QGroupBox(self.rightColumn)
self.languageSelectionGroupBox.setObjectName(
u'languageSelectionGroupBox')
self.languageSelectionLayout = QtGui.QVBoxLayout(
self.languageSelectionGroupBox)
self.languageSelectionLabel = QtGui.QLabel(
self.languageSelectionGroupBox)
self.languageSelectionLabel.setObjectName(u'languageSelectionLabel')
self.languageSelectionComboBox = QtGui.QComboBox(
self.languageSelectionGroupBox)
self.languageSelectionComboBox.setObjectName(
u'languageSelectionComboBox')
self.languageSelectionComboBox.addItems([u'', u'', u''])
self.languageSelectionLayout.addWidget(self.languageSelectionLabel)
self.languageSelectionLayout.addWidget(self.languageSelectionComboBox)
self.rightLayout.addWidget(self.languageSelectionGroupBox)
self.leftLayout.addStretch()
self.rightLayout.addStretch()
# Signals and slots
QtCore.QObject.connect(
@ -198,6 +214,9 @@ class BiblesTab(SettingsTab):
self.onEndSeparatorLineEditFinished)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_list'), self.updateThemeList)
QtCore.QObject.connect(
self.languageSelectionComboBox, QtCore.SIGNAL(u'activated(int)'),
self.onLanguageSelectionComboBoxChanged)
def retranslateUi(self):
self.verseDisplayGroupBox.setTitle(
@ -257,6 +276,24 @@ class BiblesTab(SettingsTab):
'end marks may be defined.\nThey have to be separated by a '
'vertical bar "|".\nPlease clear this edit line to use the '
'default value.'))
self.languageSelectionGroupBox.setTitle(
translate('BiblesPlugin.BiblesTab', 'Preferred Bookname Language'))
self.languageSelectionLabel.setText(translate('BiblesPlugin.BiblesTab',
'Choose the language in which the book names of the\nbible should '
'be displayed in advanced search or on\nautocompleter in quick '
'search:'))
self.languageSelectionComboBox.setItemText(LanguageSelection.Bible,
translate('BiblesPlugin.BiblesTab', 'Bible language'))
self.languageSelectionComboBox.setItemText(
LanguageSelection.Application,
translate('BiblesPlugin.BiblesTab', 'Application language'))
self.languageSelectionComboBox.setItemText(LanguageSelection.English,
translate('BiblesPlugin.BiblesTab', 'English'))
self.languageSelectionComboBox.setToolTip(
translate('BiblesPlugin.BiblesTab', 'Multiple options:\n '
'Bible language - the language in which the bible book names '
'was imported\n Application language - the language you have '
'choosen for Openlp\n English - use always English booknames'))
def onBibleThemeComboBoxChanged(self):
self.bible_theme = self.bibleThemeComboBox.currentText()
@ -267,6 +304,9 @@ class BiblesTab(SettingsTab):
def onLayoutStyleComboBoxChanged(self):
self.layout_style = self.layoutStyleComboBox.currentIndex()
def onLanguageSelectionComboBoxChanged(self):
self.language_selection = self.languageSelectionComboBox.currentIndex()
def onNewChaptersCheckBoxChanged(self, check_state):
self.show_new_chapters = False
# We have a set value convert to True/False.
@ -448,6 +488,9 @@ class BiblesTab(SettingsTab):
self.endSeparatorLineEdit.setPalette(
self.getGreyTextPalette(False))
self.endSeparatorCheckBox.setChecked(True)
self.language_selection = settings.value(
u'bookname language', QtCore.QVariant(0)).toInt()[0]
self.languageSelectionComboBox.setCurrentIndex(self.language_selection)
settings.endGroup()
def save(self):
@ -459,6 +502,8 @@ class BiblesTab(SettingsTab):
QtCore.QVariant(self.display_style))
settings.setValue(u'verse layout style',
QtCore.QVariant(self.layout_style))
settings.setValue(u'bookname language',
QtCore.QVariant(self.language_selection))
settings.setValue(u'second bibles', QtCore.QVariant(self.second_bibles))
settings.setValue(u'bible theme', QtCore.QVariant(self.bible_theme))
if self.verseSeparatorCheckBox.isChecked():
@ -482,6 +527,7 @@ class BiblesTab(SettingsTab):
else:
settings.remove(u'end separator')
update_reference_separators()
Receiver.send_message(u'bibles_load_list')
settings.endGroup()
def updateThemeList(self, theme_list):

View File

@ -227,6 +227,19 @@ class BibleManager(object):
for book in self.db_cache[bible].get_books()
]
def get_book_by_id(self, bible, id):
"""
Returns a book object by given id.
``bible``
Unicode. The Bible to get the list of books from.
``id``
Unicode. The book_reference_id to get the book for.
"""
log.debug(u'BibleManager.get_book_by_id("%s", "%s")', bible, id)
return self.db_cache[bible].get_book_by_book_ref_id(id)
def get_chapter_count(self, bible, book):
"""
Returns the number of Chapters for a given book.

View File

@ -38,7 +38,9 @@ from openlp.core.lib.ui import UiStrings, add_widget_completer, \
find_and_set_in_combo_box, build_icon
from openlp.plugins.bibles.forms import BibleImportForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
VerseReferenceList, get_reference_separator
VerseReferenceList, get_reference_separator, LanguageSelection
from openlp.plugins.bibles.lib.ui import BibleStrings
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)
@ -424,20 +426,37 @@ class BibleMediaItem(MediaManagerItem):
book_data = book_data_temp
self.advancedBookComboBox.clear()
first = True
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
for book in book_data:
row = self.advancedBookComboBox.count()
self.advancedBookComboBox.addItem(book[u'name'])
if language_selection == LanguageSelection.Bible:
self.advancedBookComboBox.addItem(book[u'name'])
elif language_selection == LanguageSelection.Application:
data = BiblesResourcesDB.get_book_by_id(
book[u'book_reference_id'])
abbr = data[u'abbreviation'].replace(u'1', u'First').\
replace(u'2', u'Second').replace(u'3', u'Third').\
replace(u'4', u'Fourth')
self.advancedBookComboBox.addItem(getattr(BibleStrings, abbr))
elif language_selection == LanguageSelection.English:
data = BiblesResourcesDB.get_book_by_id(
book[u'book_reference_id'])
self.advancedBookComboBox.addItem(data[u'name'])
self.advancedBookComboBox.setItemData(
row, QtCore.QVariant(book[u'chapters']))
row, QtCore.QVariant(book[u'book_reference_id']))
if first:
first = False
self.initialiseChapterVerse(bible, book[u'name'],
book[u'chapters'])
book[u'book_reference_id'])
def initialiseChapterVerse(self, bible, book, chapter_count):
log.debug(u'initialiseChapterVerse %s, %s', bible, book)
self.chapter_count = chapter_count
verse_count = self.plugin.manager.get_verse_count(bible, book, 1)
def initialiseChapterVerse(self, bible, book, book_ref_id):
log.debug(u'initialiseChapterVerse %s, %s, %s', bible, book,
book_ref_id)
book = self.plugin.manager.get_book_by_id(bible, book_ref_id)
self.chapter_count = self.plugin.manager.get_chapter_count(bible, book)
verse_count = self.plugin.manager.get_verse_count(bible, book.name, 1)
if verse_count == 0:
self.advancedSearchButton.setEnabled(False)
critical_error_message_box(
@ -480,7 +499,24 @@ class BibleMediaItem(MediaManagerItem):
secondbook.book_reference_id:
book_data_temp.append(book)
book_data = book_data_temp
books = [book.name + u' ' for book in book_data]
language_selection = QtCore.QSettings().value(
self.settingsSection + u'/bookname language',
QtCore.QVariant(0)).toInt()[0]
if language_selection == LanguageSelection.Bible:
books = [book.name + u' ' for book in book_data]
elif language_selection == LanguageSelection.Application:
for book in book_data:
data = BiblesResourcesDB.get_book_by_id(
book.book_reference_id)
abbr = data[u'abbreviation'].replace(u'1', u'First').\
replace(u'2', u'Second').replace(u'3', u'Third').\
replace(u'4', u'Fourth')
books.append(getattr(BibleStrings, abbr) + u' ')
elif language_selection == LanguageSelection.English:
for book in book_data:
data = BiblesResourcesDB.get_book_by_id(
book.book_reference_id)
books.append(data[u'name'] + u' ')
books.sort(cmp=locale.strcoll)
add_widget_completer(books, self.quickSearchEdit)
@ -547,7 +583,7 @@ class BibleMediaItem(MediaManagerItem):
self.initialiseChapterVerse(
unicode(self.advancedVersionComboBox.currentText()),
unicode(self.advancedBookComboBox.currentText()),
self.advancedBookComboBox.itemData(item).toInt()[0])
unicode(self.advancedBookComboBox.itemData(item).toString()))
def onAdvancedFromVerse(self):
chapter_from = int(self.advancedFromChapter.currentText())

View File

@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) Second008-2012 Raoul Snyman #
# Portions copyright (c) Second008-2012 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, 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 Second 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 #
###############################################################################
"""
The :mod:`openlp.plugins.bibles.lib.ui` module provides standard UI components
for the bibles plugin.
"""
from openlp.core.lib import translate
class BibleStrings(object):
"""
Provide standard strings for use throughout the bibles plugin.
"""
# These strings should need a good reason to be retranslated elsewhere.
Gen = translate('OpenLP.Ui','Genesis')
Exod = translate('OpenLP.Ui','Exodus')
Lev = translate('OpenLP.Ui','Leviticus')
Num = translate('OpenLP.Ui','Numbers')
Deut = translate('OpenLP.Ui','Deuteronomy')
Josh = translate('OpenLP.Ui','Joshua')
Judg = translate('OpenLP.Ui','Judges')
Ruth = translate('OpenLP.Ui','Ruth')
FirstSam = translate('OpenLP.Ui','1 Samuel')
SecondSam = translate('OpenLP.Ui','2 Samuel')
FirstKgs = translate('OpenLP.Ui','1 Kings')
SecondKgs = translate('OpenLP.Ui','2 Kings')
FirstChr = translate('OpenLP.Ui','1 Chronicles')
SecondChr = translate('OpenLP.Ui','2 Chronicles')
Esra = translate('OpenLP.Ui','Ezra')
Neh = translate('OpenLP.Ui','Nehemiah')
Esth = translate('OpenLP.Ui','Esther')
Job = translate('OpenLP.Ui','Job')
Ps = translate('OpenLP.Ui','Psalms')
Prov = translate('OpenLP.Ui','Proverbs')
Eccl = translate('OpenLP.Ui','Ecclesiastes')
Song = translate('OpenLP.Ui','Song of Solomon')
Isa = translate('OpenLP.Ui','Isaiah')
Jer = translate('OpenLP.Ui','Jeremiah')
Lam = translate('OpenLP.Ui','Lamentations')
Ezek = translate('OpenLP.Ui','Ezekiel')
Dan = translate('OpenLP.Ui','Daniel')
Hos = translate('OpenLP.Ui','Hosea')
Joel = translate('OpenLP.Ui','Joel')
Amos= translate('OpenLP.Ui','Amos')
Obad = translate('OpenLP.Ui','Obadiah')
Jonah = translate('OpenLP.Ui','Jonah')
Mic = translate('OpenLP.Ui','Micah')
Nah = translate('OpenLP.Ui','Nahum')
Hab = translate('OpenLP.Ui','Habakkuk')
Zeph = translate('OpenLP.Ui','Zephaniah')
Hag = translate('OpenLP.Ui','Haggai')
Zech = translate('OpenLP.Ui','Zechariah')
Mal = translate('OpenLP.Ui','Malachi')
Matt = translate('OpenLP.Ui','Matthew')
Mark = translate('OpenLP.Ui','Mark')
Luke = translate('OpenLP.Ui','Luke')
John = translate('OpenLP.Ui','John')
Acts = translate('OpenLP.Ui','Acts')
Rom = translate('OpenLP.Ui','Romans')
FirstCor = translate('OpenLP.Ui','1 Corinthians')
SecondCor = translate('OpenLP.Ui','2 Corinthians')
Gal = translate('OpenLP.Ui','Galatians')
Eph = translate('OpenLP.Ui','Ephesians')
Phil = translate('OpenLP.Ui','Philippians')
Col = translate('OpenLP.Ui','Colossians')
FirstThess = translate('OpenLP.Ui','1 Thessalonians')
SecondThess = translate('OpenLP.Ui','2 Thessalonians')
FirstTim = translate('OpenLP.Ui','1 Timothy')
SecondTim = translate('OpenLP.Ui','2 Timothy')
Titus = translate('OpenLP.Ui','Titus')
Phlm = translate('OpenLP.Ui','Philemon')
Heb = translate('OpenLP.Ui','Hebrews')
Jas = translate('OpenLP.Ui','James')
FirstPet = translate('OpenLP.Ui','1 Peter')
SecondPet = translate('OpenLP.Ui','2 Peter')
FirstJohn = translate('OpenLP.Ui','1 John')
SecondJohn = translate('OpenLP.Ui','2 John')
ThirdJohn = translate('OpenLP.Ui','3 John')
Jude = translate('OpenLP.Ui','Jude')
Rev = translate('OpenLP.Ui','Revelation')
Jdt = translate('OpenLP.Ui','Judith')
Wis = translate('OpenLP.Ui','Wisdom')
Tob = translate('OpenLP.Ui','Tobit')
Sir = translate('OpenLP.Ui','Sirach')
Bar = translate('OpenLP.Ui','Baruch')
FirstMacc = translate('OpenLP.Ui','1 Maccabees')
SecondMacc = translate('OpenLP.Ui','2 Maccabees')
ThirdMacc = translate('OpenLP.Ui','3 Maccabees')
FourthMacc = translate('OpenLP.Ui','4 Maccabees')
AddDan = translate('OpenLP.Ui','Rest of Daniel')
AddEsth = translate('OpenLP.Ui','Rest of Esther')
PrMan = translate('OpenLP.Ui','Prayer of Manasses')
LetJer = translate('OpenLP.Ui','Letter of Jeremiah')
PrAza = translate('OpenLP.Ui','Prayer of Azariah')
Sus = translate('OpenLP.Ui','Susanna')
Bel = translate('OpenLP.Ui','Bel')
FirstEsdr = translate('OpenLP.Ui','1 Esdras')
SecondEsdr = translate('OpenLP.Ui','2 Esdras')