This commit is contained in:
Tim Bentley 2014-03-08 22:02:34 +00:00
parent 0da1b7b5f7
commit 83abc63079
4 changed files with 189 additions and 266 deletions

View File

@ -116,20 +116,20 @@ class BiblePlugin(Plugin):
if QtGui.QMessageBox.information(self.main_window, if QtGui.QMessageBox.information(self.main_window,
translate('OpenLP', 'Information'), translate('OpenLP', 'Information'),
translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n' translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n'
'Should OpenLP upgrade now?'), 'Should OpenLP upgrade now?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \ QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)) == \
QtGui.QMessageBox.Yes: QtGui.QMessageBox.Yes:
self.on_tools_upgrade_Item_triggered() self.on_tools_upgrade_Item_triggered()
def add_import_menu_item(self, import_menu): def add_import_menu_item(self, import_menu):
self.import_bible_item = create_action(import_menu, 'importBibleItem', self.import_bible_item = create_action(import_menu, 'importBibleItem',
text=translate('BiblesPlugin', '&Bible'), visible=False, text=translate('BiblesPlugin', '&Bible'), visible=False,
triggers=self.on_bible_import_click) triggers=self.on_bible_import_click)
import_menu.addAction(self.import_bible_item) import_menu.addAction(self.import_bible_item)
def add_export_menu_Item(self, export_menu): def add_export_menu_Item(self, export_menu):
self.export_bible_item = create_action(export_menu, 'exportBibleItem', self.export_bible_item = create_action(export_menu, 'exportBibleItem',
text=translate('BiblesPlugin', '&Bible'), visible=False) text=translate('BiblesPlugin', '&Bible'), visible=False)
export_menu.addAction(self.export_bible_item) export_menu.addAction(self.export_bible_item)
def add_tools_menu_item(self, tools_menu): def add_tools_menu_item(self, tools_menu):
@ -140,7 +140,8 @@ class BiblePlugin(Plugin):
The actual **Tools** menu item, so that your actions can use it as their parent. The actual **Tools** menu item, so that your actions can use it as their parent.
""" """
log.debug('add tools menu') log.debug('add tools menu')
self.tools_upgrade_item = create_action(tools_menu, 'toolsUpgradeItem', self.tools_upgrade_item = create_action(
tools_menu, 'toolsUpgradeItem',
text=translate('BiblesPlugin', '&Upgrade older Bibles'), text=translate('BiblesPlugin', '&Upgrade older Bibles'),
statustip=translate('BiblesPlugin', 'Upgrade the Bible databases to the latest format.'), statustip=translate('BiblesPlugin', 'Upgrade the Bible databases to the latest format.'),
visible=False, triggers=self.on_tools_upgrade_Item_triggered) visible=False, triggers=self.on_tools_upgrade_Item_triggered)
@ -162,14 +163,16 @@ class BiblePlugin(Plugin):
def about(self): def about(self):
about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>' about_text = translate('BiblesPlugin', '<strong>Bible Plugin</strong>'
'<br />The Bible plugin provides the ability to display Bible ' '<br />The Bible plugin provides the ability to display Bible '
'verses from different sources during the service.') 'verses from different sources during the service.')
return about_text return about_text
def uses_theme(self, theme): def uses_theme(self, theme):
""" """
Called to find out if the bible plugin is currently using a theme. Returns ``True`` if the theme is being used, Called to find out if the bible plugin is currently using a theme. Returns ``True`` if the theme is being used,
otherwise returns ``False``. otherwise returns ``False``.
:param theme: The theme
""" """
return str(self.settings_tab.bible_theme) == theme return str(self.settings_tab.bible_theme) == theme
@ -178,11 +181,8 @@ class BiblePlugin(Plugin):
Rename the theme the bible plugin is using making the plugin use the Rename the theme the bible plugin is using making the plugin use the
new name. new name.
``old_theme`` :param old_theme: The name of the theme the plugin should stop using. Unused for this particular plugin.
The name of the theme the plugin should stop using. Unused for this particular plugin. :param new_theme: The new name the plugin should now use.
``new_theme``
The new name the plugin should now use.
""" """
self.settings_tab.bible_theme = new_theme self.settings_tab.bible_theme = new_theme
self.settings_tab.save() self.settings_tab.save()
@ -207,8 +207,7 @@ class BiblePlugin(Plugin):
'new': translate('BiblesPlugin', 'Add a new Bible.'), 'new': translate('BiblesPlugin', 'Add a new Bible.'),
'edit': translate('BiblesPlugin', 'Edit the selected Bible.'), 'edit': translate('BiblesPlugin', 'Edit the selected Bible.'),
'delete': translate('BiblesPlugin', 'Delete the selected Bible.'), 'delete': translate('BiblesPlugin', 'Delete the selected Bible.'),
'preview': translate('BiblesPlugin', 'preview': translate('BiblesPlugin', 'Preview the selected Bible.'),
'Preview the selected Bible.'),
'live': translate('BiblesPlugin', 'Send the selected Bible live.'), 'live': translate('BiblesPlugin', 'Send the selected Bible live.'),
'service': translate('BiblesPlugin', 'Add the selected Bible to the service.') 'service': translate('BiblesPlugin', 'Add the selected Bible to the service.')
} }

View File

@ -120,7 +120,7 @@ class BiblesTab(SettingsTab):
self.end_separator_line_edit = QtGui.QLineEdit(self.scripture_reference_group_box) self.end_separator_line_edit = QtGui.QLineEdit(self.scripture_reference_group_box)
self.end_separator_line_edit.setObjectName('end_separator_line_edit') self.end_separator_line_edit.setObjectName('end_separator_line_edit')
self.end_separator_line_edit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^0-9]*'), self.end_separator_line_edit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^0-9]*'),
self.end_separator_line_edit)) self.end_separator_line_edit))
self.scripture_reference_layout.addWidget(self.end_separator_line_edit, 3, 1) self.scripture_reference_layout.addWidget(self.end_separator_line_edit, 3, 1)
self.left_layout.addWidget(self.scripture_reference_group_box) self.left_layout.addWidget(self.scripture_reference_group_box)
self.right_column.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) self.right_column.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
@ -142,7 +142,7 @@ class BiblesTab(SettingsTab):
self.new_chapters_check_box.stateChanged.connect(self.on_new_chapters_check_box_changed) self.new_chapters_check_box.stateChanged.connect(self.on_new_chapters_check_box_changed)
self.display_style_combo_box.activated.connect(self.on_display_style_combo_box_changed) self.display_style_combo_box.activated.connect(self.on_display_style_combo_box_changed)
self.bible_theme_combo_box.activated.connect(self.on_bible_theme_combo_box_changed) self.bible_theme_combo_box.activated.connect(self.on_bible_theme_combo_box_changed)
self.layout_style_combo_box.activated.connect(self.on_layout_style_combo_boxChanged) self.layout_style_combo_box.activated.connect(self.on_layout_style_combo_box_changed)
self.bible_second_check_box.stateChanged.connect(self.on_bible_second_check_box) self.bible_second_check_box.stateChanged.connect(self.on_bible_second_check_box)
self.verse_separator_check_box.clicked.connect(self.on_verse_separator_check_box_clicked) self.verse_separator_check_box.clicked.connect(self.on_verse_separator_check_box_clicked)
self.verse_separator_line_edit.textEdited.connect(self.on_verse_separator_line_edit_edited) self.verse_separator_line_edit.textEdited.connect(self.on_verse_separator_line_edit_edited)
@ -170,15 +170,15 @@ class BiblesTab(SettingsTab):
self.layout_style_combo_box.setItemText(LayoutStyle.VersePerLine, UiStrings().VersePerLine) self.layout_style_combo_box.setItemText(LayoutStyle.VersePerLine, UiStrings().VersePerLine)
self.layout_style_combo_box.setItemText(LayoutStyle.Continuous, UiStrings().Continuous) self.layout_style_combo_box.setItemText(LayoutStyle.Continuous, UiStrings().Continuous)
self.display_style_combo_box.setItemText(DisplayStyle.NoBrackets, self.display_style_combo_box.setItemText(DisplayStyle.NoBrackets,
translate('BiblesPlugin.BiblesTab', 'No Brackets')) translate('BiblesPlugin.BiblesTab', 'No Brackets'))
self.display_style_combo_box.setItemText(DisplayStyle.Round, self.display_style_combo_box.setItemText(DisplayStyle.Round,
translate('BiblesPlugin.BiblesTab', '( And )')) translate('BiblesPlugin.BiblesTab', '( And )'))
self.display_style_combo_box.setItemText(DisplayStyle.Curly, self.display_style_combo_box.setItemText(DisplayStyle.Curly,
translate('BiblesPlugin.BiblesTab', '{ And }')) translate('BiblesPlugin.BiblesTab', '{ And }'))
self.display_style_combo_box.setItemText(DisplayStyle.Square, self.display_style_combo_box.setItemText(DisplayStyle.Square,
translate('BiblesPlugin.BiblesTab', '[ And ]')) translate('BiblesPlugin.BiblesTab', '[ And ]'))
self.change_note_label.setText(translate('BiblesPlugin.BiblesTab', self.change_note_label.setText(translate('BiblesPlugin.BiblesTab',
'Note:\nChanges do not affect verses already in the service.')) 'Note:\nChanges do not affect verses already in the service.'))
self.bible_second_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Display second Bible verses')) self.bible_second_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Display second Bible verses'))
self.scripture_reference_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Custom Scripture References')) self.scripture_reference_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Custom Scripture References'))
self.verse_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Verse Separator:')) self.verse_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'Verse Separator:'))
@ -186,21 +186,21 @@ class BiblesTab(SettingsTab):
self.list_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'List Separator:')) self.list_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'List Separator:'))
self.end_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'End Mark:')) self.end_separator_check_box.setText(translate('BiblesPlugin.BiblesTab', 'End Mark:'))
tip_text = translate('BiblesPlugin.BiblesTab', tip_text = translate('BiblesPlugin.BiblesTab',
'Multiple alternative verse separators may be defined.\nThey have to be separated by a vertical bar "|".' 'Multiple alternative verse separators may be defined.\nThey have to be separated by a '
'\nPlease clear this edit line to use the default value.') 'vertical bar "|".\nPlease clear this edit line to use the default value.')
self.verse_separator_line_edit.setToolTip(tip_text) self.verse_separator_line_edit.setToolTip(tip_text)
self.range_separator_line_edit.setToolTip(tip_text) self.range_separator_line_edit.setToolTip(tip_text)
self.list_separator_line_edit.setToolTip(tip_text) self.list_separator_line_edit.setToolTip(tip_text)
self.end_separator_line_edit.setToolTip(tip_text) self.end_separator_line_edit.setToolTip(tip_text)
self.language_selection_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Default Bible Language')) self.language_selection_group_box.setTitle(translate('BiblesPlugin.BiblesTab', 'Default Bible Language'))
self.language_selection_label.setText(translate('BiblesPlugin.BiblesTab', self.language_selection_label.setText(
'Book name language in search field,\nsearch results and on display:')) translate('BiblesPlugin.BiblesTab', 'Book name language in search field,\nsearch results and on display:'))
self.language_selection_combo_box.setItemText(LanguageSelection.Bible, self.language_selection_combo_box.setItemText(
translate('BiblesPlugin.BiblesTab', 'Bible Language')) LanguageSelection.Bible, translate('BiblesPlugin.BiblesTab', 'Bible Language'))
self.language_selection_combo_box.setItemText(LanguageSelection.Application, self.language_selection_combo_box.setItemText(
translate('BiblesPlugin.BiblesTab', 'Application Language')) LanguageSelection.Application, translate('BiblesPlugin.BiblesTab', 'Application Language'))
self.language_selection_combo_box.setItemText(LanguageSelection.English, self.language_selection_combo_box.setItemText(
translate('BiblesPlugin.BiblesTab', 'English')) LanguageSelection.English, translate('BiblesPlugin.BiblesTab', 'English'))
def on_bible_theme_combo_box_changed(self): def on_bible_theme_combo_box_changed(self):
self.bible_theme = self.bible_theme_combo_box.currentText() self.bible_theme = self.bible_theme_combo_box.currentText()
@ -208,7 +208,7 @@ class BiblesTab(SettingsTab):
def on_display_style_combo_box_changed(self): def on_display_style_combo_box_changed(self):
self.display_style = self.display_style_combo_box.currentIndex() self.display_style = self.display_style_combo_box.currentIndex()
def on_layout_style_combo_boxChanged(self): def on_layout_style_combo_box_changed(self):
self.layout_style = self.layout_style_combo_box.currentIndex() self.layout_style = self.layout_style_combo_box.currentIndex()
def on_language_selection_combo_box_changed(self): def on_language_selection_combo_box_changed(self):
@ -238,11 +238,11 @@ class BiblesTab(SettingsTab):
self.verse_separator_line_edit.setFocus() self.verse_separator_line_edit.setFocus()
else: else:
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default')) self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(not checked)) self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
def on_verse_separator_line_edit_edited(self, text): def on_verse_separator_line_edit_edited(self, text):
self.verse_separator_check_box.setChecked(True) self.verse_separator_check_box.setChecked(True)
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
def on_verse_separator_line_edit_finished(self): def on_verse_separator_line_edit_finished(self):
if self.verse_separator_line_edit.isModified(): if self.verse_separator_line_edit.isModified():
@ -250,18 +250,18 @@ class BiblesTab(SettingsTab):
if text == get_reference_separator('sep_v_default') or not text.replace('|', ''): if text == get_reference_separator('sep_v_default') or not text.replace('|', ''):
self.verse_separator_check_box.setChecked(False) self.verse_separator_check_box.setChecked(False)
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default')) self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
def on_range_separator_check_box_clicked(self, checked): def on_range_separator_check_box_clicked(self, checked):
if checked: if checked:
self.range_separator_line_edit.setFocus() self.range_separator_line_edit.setFocus()
else: else:
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default')) self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(not checked)) self.range_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
def on_range_separator_line_edit_edited(self, text): def on_range_separator_line_edit_edited(self, text):
self.range_separator_check_box.setChecked(True) self.range_separator_check_box.setChecked(True)
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
def on_range_separator_line_edit_finished(self): def on_range_separator_line_edit_finished(self):
if self.range_separator_line_edit.isModified(): if self.range_separator_line_edit.isModified():
@ -269,18 +269,18 @@ class BiblesTab(SettingsTab):
if text == get_reference_separator('sep_r_default') or not text.replace('|', ''): if text == get_reference_separator('sep_r_default') or not text.replace('|', ''):
self.range_separator_check_box.setChecked(False) self.range_separator_check_box.setChecked(False)
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default')) self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
def on_list_separator_check_box_clicked(self, checked): def on_list_separator_check_box_clicked(self, checked):
if checked: if checked:
self.list_separator_line_edit.setFocus() self.list_separator_line_edit.setFocus()
else: else:
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default')) self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(not checked)) self.list_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
def on_list_separator_line_edit_edited(self, text): def on_list_separator_line_edit_edited(self, text):
self.list_separator_check_box.setChecked(True) self.list_separator_check_box.setChecked(True)
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
def on_list_separator_line_edit_finished(self): def on_list_separator_line_edit_finished(self):
if self.list_separator_line_edit.isModified(): if self.list_separator_line_edit.isModified():
@ -288,18 +288,18 @@ class BiblesTab(SettingsTab):
if text == get_reference_separator('sep_l_default') or not text.replace('|', ''): if text == get_reference_separator('sep_l_default') or not text.replace('|', ''):
self.list_separator_check_box.setChecked(False) self.list_separator_check_box.setChecked(False)
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default')) self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
def on_end_separator_check_box_clicked(self, checked): def on_end_separator_check_box_clicked(self, checked):
if checked: if checked:
self.end_separator_line_edit.setFocus() self.end_separator_line_edit.setFocus()
else: else:
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default')) self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(not checked)) self.end_separator_line_edit.setPalette(self.get_grey_text_palette(not checked))
def on_end_separator_line_edit_edited(self, text): def on_end_separator_line_edit_edited(self, text):
self.end_separator_check_box.setChecked(True) self.end_separator_check_box.setChecked(True)
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
def on_end_separator_line_edit_finished(self): def on_end_separator_line_edit_finished(self):
if self.end_separator_line_edit.isModified(): if self.end_separator_line_edit.isModified():
@ -307,7 +307,7 @@ class BiblesTab(SettingsTab):
if text == get_reference_separator('sep_e_default') or not text.replace('|', ''): if text == get_reference_separator('sep_e_default') or not text.replace('|', ''):
self.end_separator_check_box.setChecked(False) self.end_separator_check_box.setChecked(False)
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default')) self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
def load(self): def load(self):
settings = Settings() settings = Settings()
@ -327,38 +327,38 @@ class BiblesTab(SettingsTab):
verse_separator = settings.value('verse separator') verse_separator = settings.value('verse separator')
if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')): if (verse_separator.strip('|') == '') or (verse_separator == get_reference_separator('sep_v_default')):
self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default')) self.verse_separator_line_edit.setText(get_reference_separator('sep_v_default'))
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(True))
self.verse_separator_check_box.setChecked(False) self.verse_separator_check_box.setChecked(False)
else: else:
self.verse_separator_line_edit.setText(verse_separator) self.verse_separator_line_edit.setText(verse_separator)
self.verse_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.verse_separator_line_edit.setPalette(self.get_grey_text_palette(False))
self.verse_separator_check_box.setChecked(True) self.verse_separator_check_box.setChecked(True)
range_separator = settings.value('range separator') range_separator = settings.value('range separator')
if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')): if (range_separator.strip('|') == '') or (range_separator == get_reference_separator('sep_r_default')):
self.range_separator_line_edit.setText(get_reference_separator('sep_r_default')) self.range_separator_line_edit.setText(get_reference_separator('sep_r_default'))
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.range_separator_line_edit.setPalette(self.get_grey_text_palette(True))
self.range_separator_check_box.setChecked(False) self.range_separator_check_box.setChecked(False)
else: else:
self.range_separator_line_edit.setText(range_separator) self.range_separator_line_edit.setText(range_separator)
self.range_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.range_separator_line_edit.setPalette(self.get_grey_text_palette(False))
self.range_separator_check_box.setChecked(True) self.range_separator_check_box.setChecked(True)
list_separator = settings.value('list separator') list_separator = settings.value('list separator')
if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')): if (list_separator.strip('|') == '') or (list_separator == get_reference_separator('sep_l_default')):
self.list_separator_line_edit.setText(get_reference_separator('sep_l_default')) self.list_separator_line_edit.setText(get_reference_separator('sep_l_default'))
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.list_separator_line_edit.setPalette(self.get_grey_text_palette(True))
self.list_separator_check_box.setChecked(False) self.list_separator_check_box.setChecked(False)
else: else:
self.list_separator_line_edit.setText(list_separator) self.list_separator_line_edit.setText(list_separator)
self.list_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.list_separator_line_edit.setPalette(self.get_grey_text_palette(False))
self.list_separator_check_box.setChecked(True) self.list_separator_check_box.setChecked(True)
end_separator = settings.value('end separator') end_separator = settings.value('end separator')
if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')): if (end_separator.strip('|') == '') or (end_separator == get_reference_separator('sep_e_default')):
self.end_separator_line_edit.setText(get_reference_separator('sep_e_default')) self.end_separator_line_edit.setText(get_reference_separator('sep_e_default'))
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(True)) self.end_separator_line_edit.setPalette(self.get_grey_text_palette(True))
self.end_separator_check_box.setChecked(False) self.end_separator_check_box.setChecked(False)
else: else:
self.end_separator_line_edit.setText(end_separator) self.end_separator_line_edit.setText(end_separator)
self.end_separator_line_edit.setPalette(self.getGreyTextPalette(False)) self.end_separator_line_edit.setPalette(self.get_grey_text_palette(False))
self.end_separator_check_box.setChecked(True) self.end_separator_check_box.setChecked(True)
self.language_selection = settings.value('book name language') self.language_selection = settings.value('book name language')
self.language_selection_combo_box.setCurrentIndex(self.language_selection) self.language_selection_combo_box.setCurrentIndex(self.language_selection)
@ -402,7 +402,7 @@ class BiblesTab(SettingsTab):
""" """
Called from ThemeManager when the Themes have changed. Called from ThemeManager when the Themes have changed.
``theme_list`` :param theme_list:
The list of available themes:: The list of available themes::
[u'Bible Theme', u'Song Theme'] [u'Bible Theme', u'Song Theme']
@ -412,7 +412,7 @@ class BiblesTab(SettingsTab):
self.bible_theme_combo_box.addItems(theme_list) self.bible_theme_combo_box.addItems(theme_list)
find_and_set_in_combo_box(self.bible_theme_combo_box, self.bible_theme) find_and_set_in_combo_box(self.bible_theme_combo_box, self.bible_theme)
def getGreyTextPalette(self, greyed): def get_grey_text_palette(self, greyed):
""" """
Returns a QPalette with greyed out text as used for placeholderText. Returns a QPalette with greyed out text as used for placeholderText.
""" """

View File

@ -80,8 +80,8 @@ class CSVBible(BibleDB):
""" """
log.info(self.__class__.__name__) log.info(self.__class__.__name__)
BibleDB.__init__(self, parent, **kwargs) BibleDB.__init__(self, parent, **kwargs)
self.booksfile = kwargs['booksfile'] self.books_file = kwargs['books_file']
self.versesfile = kwargs['versefile'] self.verses_file = kwargs['versefile']
def do_import(self, bible_name=None): def do_import(self, bible_name=None):
""" """
@ -99,8 +99,8 @@ class CSVBible(BibleDB):
book_list = {} book_list = {}
# Populate the Tables # Populate the Tables
try: try:
details = get_file_encoding(self.booksfile) details = get_file_encoding(self.books_file)
books_file = open(self.booksfile, 'r') books_file = open(self.books_file, 'r')
if not books_file.read(3) == '\xEF\xBB\xBF': if not books_file.read(3) == '\xEF\xBB\xBF':
# no BOM was found # no BOM was found
books_file.seek(0) books_file.seek(0)
@ -109,10 +109,10 @@ class CSVBible(BibleDB):
if self.stop_import_flag: if self.stop_import_flag:
break break
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', 'Importing books... %s') % self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', 'Importing books... %s') %
str(line[2], details['encoding'])) str(line[2], details['encoding']))
book_ref_id = self.get_book_ref_id_by_name(str(line[2], details['encoding']), 67, language_id) book_ref_id = self.get_book_ref_id_by_name(str(line[2], details['encoding']), 67, language_id)
if not book_ref_id: if not book_ref_id:
log.error('Importing books from "%s" failed' % self.booksfile) log.error('Importing books from "%s" failed' % self.books_file)
return False return False
book_details = BiblesResourcesDB.get_book_by_id(book_ref_id) book_details = BiblesResourcesDB.get_book_by_id(book_ref_id)
self.create_book(str(line[2], details['encoding']), book_ref_id, book_details['testament_id']) self.create_book(str(line[2], details['encoding']), book_ref_id, book_details['testament_id'])
@ -131,8 +131,8 @@ class CSVBible(BibleDB):
verse_file = None verse_file = None
try: try:
book_ptr = None book_ptr = None
details = get_file_encoding(self.versesfile) details = get_file_encoding(self.verses_file)
verse_file = open(self.versesfile, 'rb') verse_file = open(self.verses_file, 'rb')
if not verse_file.read(3) == '\xEF\xBB\xBF': if not verse_file.read(3) == '\xEF\xBB\xBF':
# no BOM was found # no BOM was found
verse_file.seek(0) verse_file.seek(0)
@ -147,8 +147,9 @@ class CSVBible(BibleDB):
if book_ptr != line_book: if book_ptr != line_book:
book = self.get_book(line_book) book = self.get_book(line_book)
book_ptr = book.name book_ptr = book.name
self.wizard.increment_progress_bar(translate('BiblesPlugin.CSVBible', self.wizard.increment_progress_bar(
'Importing verses from %s... Importing verses from <book name>...') % book.name) translate('BiblesPlugin.CSVBible',
'Importing verses from %s... Importing verses from <book name>...') % book.name)
self.session.commit() self.session.commit()
try: try:
verse_text = str(line[3], details['encoding']) verse_text = str(line[3], details['encoding'])
@ -169,6 +170,7 @@ class CSVBible(BibleDB):
else: else:
return success return success
def get_file_encoding(filename): def get_file_encoding(filename):
""" """
Utility function to get the file encoding. Utility function to get the file encoding.

View File

@ -79,23 +79,23 @@ def init_schema(url):
session, metadata = init_db(url) session, metadata = init_db(url)
meta_table = Table('metadata', metadata, meta_table = Table('metadata', metadata,
Column('key', types.Unicode(255), primary_key=True, index=True), Column('key', types.Unicode(255), primary_key=True, index=True),
Column('value', types.Unicode(255)), Column('value', types.Unicode(255)),
) )
book_table = Table('book', metadata, book_table = Table('book', metadata,
Column('id', types.Integer, primary_key=True), Column('id', types.Integer, primary_key=True),
Column('book_reference_id', types.Integer, index=True), Column('book_reference_id', types.Integer, index=True),
Column('testament_reference_id', types.Integer), Column('testament_reference_id', types.Integer),
Column('name', types.Unicode(50), index=True), Column('name', types.Unicode(50), index=True),
) )
verse_table = Table('verse', metadata, verse_table = Table('verse', metadata,
Column('id', types.Integer, primary_key=True, index=True), Column('id', types.Integer, primary_key=True, index=True),
Column('book_id', types.Integer, ForeignKey( Column('book_id', types.Integer, ForeignKey(
'book.id'), index=True), 'book.id'), index=True),
Column('chapter', types.Integer, index=True), Column('chapter', types.Integer, index=True),
Column('verse', types.Integer, index=True), Column('verse', types.Integer, index=True),
Column('text', types.UnicodeText, index=True), Column('text', types.UnicodeText, index=True),
) )
try: try:
@ -105,8 +105,7 @@ def init_schema(url):
try: try:
class_mapper(Book) class_mapper(Book)
except UnmappedClassError: except UnmappedClassError:
mapper(Book, book_table, mapper(Book, book_table, properties={'verses': relation(Verse, backref='book')})
properties={'verses': relation(Verse, backref='book')})
try: try:
class_mapper(Verse) class_mapper(Verse)
except UnmappedClassError: except UnmappedClassError:
@ -184,8 +183,7 @@ class BibleDB(QtCore.QObject, Manager):
may want to override this method to supply their own custom may want to override this method to supply their own custom
initialisation as well. initialisation as well.
``wizard`` :param wizard: The actual Qt wizard form.
The actual Qt wizard form.
""" """
self.wizard = wizard self.wizard = wizard
return self.name return self.name
@ -194,14 +192,9 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Add a book to the database. Add a book to the database.
``name`` :param name: The name of the book.
The name of the book. :param bk_ref_id: The book_reference_id from bibles_resources.sqlite of the book.
:param testament: *Defaults to 1.* The testament_reference_id from
``bk_ref_id``
The book_reference_id from bibles_resources.sqlite of the book.
``testament``
*Defaults to 1.* The testament_reference_id from
bibles_resources.sqlite of the testament this book belongs to. bibles_resources.sqlite of the testament this book belongs to.
""" """
log.debug('BibleDB.create_book("%s", "%s")', name, bk_ref_id) log.debug('BibleDB.create_book("%s", "%s")', name, bk_ref_id)
@ -213,8 +206,7 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Update a book in the database. Update a book in the database.
``book`` :param book: The book object
The book object
""" """
log.debug('BibleDB.update_book("%s")', book.name) log.debug('BibleDB.update_book("%s")', book.name)
return self.save_object(book) return self.save_object(book)
@ -223,31 +215,24 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Delete a book from the database. Delete a book from the database.
``db_book`` :param db_book: The book object.
The book object.
""" """
log.debug('BibleDB.delete_book("%s")', db_book.name) log.debug('BibleDB.delete_book("%s")', db_book.name)
if self.delete_object(Book, db_book.id): if self.delete_object(Book, db_book.id):
return True return True
return False return False
def create_chapter(self, book_id, chapter, textlist): def create_chapter(self, book_id, chapter, text_list):
""" """
Add a chapter and its verses to a book. Add a chapter and its verses to a book.
``book_id`` :param book_id: The id of the book being appended.
The id of the book being appended. :param chapter: The chapter number.
:param text_list: A dict of the verses to be inserted. The key is the verse number, and the value is the verse text.
``chapter``
The chapter number.
``textlist``
A dict of the verses to be inserted. The key is the verse number,
and the value is the verse text.
""" """
log.debug('BibleDBcreate_chapter("%s", "%s")', book_id, chapter) log.debug('BibleDBcreate_chapter("%s", "%s")', book_id, chapter)
# Text list has book and chapter as first two elements of the array. # Text list has book and chapter as first two elements of the array.
for verse_number, verse_text in textlist.items(): for verse_number, verse_text in text_list.items():
verse = Verse.populate( verse = Verse.populate(
book_id=book_id, book_id=book_id,
chapter=chapter, chapter=chapter,
@ -261,17 +246,10 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Add a single verse to a chapter. Add a single verse to a chapter.
``book_id`` :param book_id: The id of the book being appended.
The id of the book being appended. :param chapter: The chapter number.
:param verse: The verse number.
``chapter`` :param text: The verse text.
The chapter number.
``verse``
The verse number.
``text``
The verse text.
""" """
if not isinstance(text, str): if not isinstance(text, str):
details = chardet.detect(text) details = chardet.detect(text)
@ -289,11 +267,8 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Utility method to save or update BibleMeta objects in a Bible database. Utility method to save or update BibleMeta objects in a Bible database.
``key`` :param key: The key for this instance.
The key for this instance. :param value: The value for this instance.
``value``
The value for this instance.
""" """
if not isinstance(value, str): if not isinstance(value, str):
value = str(value) value = str(value)
@ -309,8 +284,7 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Return a book object from the database. Return a book object from the database.
``book`` :param book: The name of the book to return.
The name of the book to return.
""" """
log.debug('BibleDB.get_book("%s")', book) log.debug('BibleDB.get_book("%s")', book)
return self.get_object_filtered(Book, Book.name.like(book + '%')) return self.get_object_filtered(Book, Book.name.like(book + '%'))
@ -327,8 +301,7 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Return a book object from the database. Return a book object from the database.
``id`` :param id: The reference id of the book to return.
The reference id of the book to return.
""" """
log.debug('BibleDB.get_book_by_book_ref_id("%s")', id) log.debug('BibleDB.get_book_by_book_ref_id("%s")', id)
return self.get_object_filtered(Book, Book.book_reference_id.like(id)) return self.get_object_filtered(Book, Book.book_reference_id.like(id))
@ -357,11 +330,8 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Return the id of a named book. Return the id of a named book.
``book`` :param book: The name of the book, according to the selected language.
The name of the book, according to the selected language. :param language_selection: The language selection the user has chosen in the settings section of the Bible.
``language_selection``
The language selection the user has chosen in the settings section of the Bible.
""" """
log.debug('get_book_ref_id_by_localised_name("%s", "%s")', book, language_selection) log.debug('get_book_ref_id_by_localised_name("%s", "%s")', book, language_selection)
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
@ -398,8 +368,7 @@ class BibleDB(QtCore.QObject, Manager):
This is probably the most used function. It retrieves the list of This is probably the most used function. It retrieves the list of
verses based on the user's query. verses based on the user's query.
``reference_list`` :param reference_list: This is the list of references the media manager item wants. It is
This is the list of references the media manager item wants. It is
a list of tuples, with the following format:: a list of tuples, with the following format::
(book_reference_id, chapter, start_verse, end_verse) (book_reference_id, chapter, start_verse, end_verse)
@ -410,6 +379,7 @@ class BibleDB(QtCore.QObject, Manager):
list of ``Verse`` objects. For example:: list of ``Verse`` objects. For example::
[(u'35', 1, 1, 1), (u'35', 2, 2, 3)] [(u'35', 1, 1, 1), (u'35', 2, 2, 3)]
:param show_error:
""" """
log.debug('BibleDB.get_verses("%s")', reference_list) log.debug('BibleDB.get_verses("%s")', reference_list)
verse_list = [] verse_list = []
@ -436,14 +406,14 @@ class BibleDB(QtCore.QObject, Manager):
critical_error_message_box( critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'), translate('BiblesPlugin', 'No Book Found'),
translate('BiblesPlugin', 'No matching book ' translate('BiblesPlugin', 'No matching book '
'could be found in this Bible. Check that you have spelled the name of the book correctly.')) 'could be found in this Bible. Check that you have spelled the name of the book correctly.'))
return verse_list return verse_list
def verse_search(self, text): def verse_search(self, text):
""" """
Search for verses containing text ``text``. Search for verses containing text ``text``.
``text`` :param text:
The text to search for. If the text contains commas, it will be The text to search for. If the text contains commas, it will be
split apart and OR'd on the list of values. If the text just split apart and OR'd on the list of values. If the text just
contains spaces, it will split apart and AND'd on the list of contains spaces, it will split apart and AND'd on the list of
@ -468,8 +438,7 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Return the number of chapters in a book. Return the number of chapters in a book.
``book`` :param book: The book object to get the chapter count for.
The book object to get the chapter count for.
""" """
log.debug('BibleDB.get_chapter_count("%s")', book.name) log.debug('BibleDB.get_chapter_count("%s")', book.name)
count = self.session.query(func.max(Verse.chapter)).join(Book).filter( count = self.session.query(func.max(Verse.chapter)).join(Book).filter(
@ -482,11 +451,8 @@ class BibleDB(QtCore.QObject, Manager):
""" """
Return the number of verses in a chapter. Return the number of verses in a chapter.
``book_ref_id`` :param book_ref_id: The book reference id.
The book reference id. :param chapter: The chapter to get the verse count for.
``chapter``
The chapter to get the verse count for.
""" """
log.debug('BibleDB.get_verse_count("%s", "%s")', book_ref_id, chapter) log.debug('BibleDB.get_verse_count("%s", "%s")', book_ref_id, chapter)
count = self.session.query(func.max(Verse.verse)).join(Book) \ count = self.session.query(func.max(Verse.verse)).join(Book) \
@ -499,12 +465,10 @@ class BibleDB(QtCore.QObject, Manager):
def get_language(self, bible_name=None): def get_language(self, bible_name=None):
""" """
If no language is given it calls a dialog window where the user could If no language is given it calls a dialog window where the user could select the bible language.
select the bible language.
Return the language id of a bible. Return the language id of a bible.
``book`` :param bible_name: The language the bible is.
The language the bible is.
""" """
log.debug('BibleDB.get_language()') log.debug('BibleDB.get_language()')
from openlp.plugins.bibles.forms import LanguageForm from openlp.plugins.bibles.forms import LanguageForm
@ -521,8 +485,7 @@ class BibleDB(QtCore.QObject, Manager):
def is_old_database(self): def is_old_database(self):
""" """
Returns ``True`` if it is a bible database, which has been created Returns ``True`` if it is a bible database, which has been created prior to 1.9.6.
prior to 1.9.6.
""" """
try: try:
self.session.query(Book).all() self.session.query(Book).all()
@ -576,9 +539,9 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
Return the cursor object. Instantiate one if it doesn't exist yet. Return the cursor object. Instantiate one if it doesn't exist yet.
""" """
if BiblesResourcesDB.cursor is None: if BiblesResourcesDB.cursor is None:
filepath = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir), file_path = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir),
'bibles', 'resources', 'bibles_resources.sqlite') 'bibles', 'resources', 'bibles_resources.sqlite')
conn = sqlite3.connect(filepath) conn = sqlite3.connect(file_path)
BiblesResourcesDB.cursor = conn.cursor() BiblesResourcesDB.cursor = conn.cursor()
return BiblesResourcesDB.cursor return BiblesResourcesDB.cursor
@ -603,8 +566,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
Return a list of all the books of the Bible. Return a list of all the books of the Bible.
""" """
log.debug('BiblesResourcesDB.get_books()') log.debug('BiblesResourcesDB.get_books()')
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(
'abbreviation, chapters FROM book_reference ORDER BY id') 'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference ORDER BY id')
return [{ return [{
'id': book[0], 'id': book[0],
'testament_id': book[1], 'testament_id': book[1],
@ -618,24 +581,20 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return a book by name or abbreviation. Return a book by name or abbreviation.
``name`` :param name: The name or abbreviation of the book.
The name or abbreviation of the book. :param lower: True if the comparsion should be only lowercase
``lower``
True if the comparsion should be only lowercase
""" """
log.debug('BiblesResourcesDB.get_book("%s")', name) log.debug('BiblesResourcesDB.get_book("%s")', name)
if not isinstance(name, str): if not isinstance(name, str):
name = str(name) name = str(name)
if lower: if lower:
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(
'abbreviation, chapters FROM book_reference WHERE ' 'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE '
'LOWER(name) = ? OR LOWER(abbreviation) = ?', 'LOWER(name) = ? OR LOWER(abbreviation) = ?', (name.lower(), name.lower()))
(name.lower(), name.lower()))
else: else:
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(
'abbreviation, chapters FROM book_reference WHERE name = ?' 'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE name = ?'
' OR abbreviation = ?', (name, name)) ' OR abbreviation = ?', (name, name))
if books: if books:
return { return {
'id': books[0][0], 'id': books[0][0],
@ -652,16 +611,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the books which include string. Return the books which include string.
``string`` :param string: The string to search for in the book names or abbreviations.
The string to search for in the book names or abbreviations.
""" """
log.debug('BiblesResourcesDB.get_book_like("%s")', string) log.debug('BiblesResourcesDB.get_book_like("%s")', string)
if not isinstance(string, str): if not isinstance(string, str):
name = str(string) name = str(string)
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(
'abbreviation, chapters FROM book_reference WHERE ' 'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE '
'LOWER(name) LIKE ? OR LOWER(abbreviation) LIKE ?', 'LOWER(name) LIKE ? OR LOWER(abbreviation) LIKE ?',
('%' + string.lower() + '%', '%' + string.lower() + '%')) ('%' + string.lower() + '%', '%' + string.lower() + '%'))
if books: if books:
return [{ return [{
'id': book[0], 'id': book[0],
@ -678,14 +636,13 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return a book by id. Return a book by id.
``id`` :param id: The id of the book.
The id of the book.
""" """
log.debug('BiblesResourcesDB.get_book_by_id("%s")', id) log.debug('BiblesResourcesDB.get_book_by_id("%s")', id)
if not isinstance(id, int): if not isinstance(id, int):
id = int(id) id = int(id)
books = BiblesResourcesDB.run_sql('SELECT id, testament_id, name, ' books = BiblesResourcesDB.run_sql(
'abbreviation, chapters FROM book_reference WHERE id = ?', (id, )) 'SELECT id, testament_id, name, abbreviation, chapters FROM book_reference WHERE id = ?', (id, ))
if books: if books:
return { return {
'id': books[0][0], 'id': books[0][0],
@ -702,16 +659,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the chapter details for a specific chapter of a book. Return the chapter details for a specific chapter of a book.
``book_ref_id`` :param book_ref_id: The id of a book.
The id of a book. :param chapter: The chapter number.
``chapter``
The chapter number.
""" """
log.debug('BiblesResourcesDB.get_chapter("%s", "%s")', book_ref_id, chapter) log.debug('BiblesResourcesDB.get_chapter("%s", "%s")', book_ref_id, chapter)
if not isinstance(chapter, int): if not isinstance(chapter, int):
chapter = int(chapter) chapter = int(chapter)
chapters = BiblesResourcesDB.run_sql('SELECT id, book_reference_id, ' chapters = BiblesResourcesDB.run_sql(
'SELECT id, book_reference_id, '
'chapter, verse_count FROM chapters WHERE book_reference_id = ?', (book_ref_id,)) 'chapter, verse_count FROM chapters WHERE book_reference_id = ?', (book_ref_id,))
try: try:
return { return {
@ -728,8 +683,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the number of chapters in a book. Return the number of chapters in a book.
``book_ref_id`` :param book_ref_id: The id of the book.
The id of the book.
""" """
log.debug('BiblesResourcesDB.get_chapter_count("%s")', book_ref_id) log.debug('BiblesResourcesDB.get_chapter_count("%s")', book_ref_id)
details = BiblesResourcesDB.get_book_by_id(book_ref_id) details = BiblesResourcesDB.get_book_by_id(book_ref_id)
@ -742,11 +696,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the number of verses in a chapter. Return the number of verses in a chapter.
``book`` :param book_ref_id: The id of the book.
The id of the book. :param chapter: The number of the chapter.
``chapter``
The number of the chapter.
""" """
log.debug('BiblesResourcesDB.get_verse_count("%s", "%s")', book_ref_id, chapter) log.debug('BiblesResourcesDB.get_verse_count("%s", "%s")', book_ref_id, chapter)
details = BiblesResourcesDB.get_chapter(book_ref_id, chapter) details = BiblesResourcesDB.get_chapter(book_ref_id, chapter)
@ -759,15 +710,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return a download_source_id by source. Return a download_source_id by source.
``name`` :param source: The name or abbreviation of the book.
The name or abbreviation of the book.
""" """
log.debug('BiblesResourcesDB.get_download_source("%s")', source) log.debug('BiblesResourcesDB.get_download_source("%s")', source)
if not isinstance(source, str): if not isinstance(source, str):
source = str(source) source = str(source)
source = source.title() source = source.title()
dl_source = BiblesResourcesDB.run_sql('SELECT id, source FROM ' dl_source = BiblesResourcesDB.run_sql(
'download_source WHERE source = ?', (source.lower(),)) 'SELECT id, source FROM download_source WHERE source = ?', (source.lower(),))
if dl_source: if dl_source:
return { return {
'id': dl_source[0][0], 'id': dl_source[0][0],
@ -781,8 +731,7 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the bibles a webbible provide for download. Return the bibles a webbible provide for download.
``source`` :param source: The source of the webbible.
The source of the webbible.
""" """
log.debug('BiblesResourcesDB.get_webbibles("%s")', source) log.debug('BiblesResourcesDB.get_webbibles("%s")', source)
if not isinstance(source, str): if not isinstance(source, str):
@ -806,11 +755,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return the bibles a webbible provide for download. Return the bibles a webbible provide for download.
``abbreviation`` :param abbreviation: The abbreviation of the webbible.
The abbreviation of the webbible. :param source: The source of the webbible.
``source``
The source of the webbible.
""" """
log.debug('BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation, source) log.debug('BiblesResourcesDB.get_webbibles("%s", "%s")', abbreviation, source)
if not isinstance(abbreviation, str): if not isinstance(abbreviation, str):
@ -818,8 +764,8 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
if not isinstance(source, str): if not isinstance(source, str):
source = str(source) source = str(source)
source = BiblesResourcesDB.get_download_source(source) source = BiblesResourcesDB.get_download_source(source)
bible = BiblesResourcesDB.run_sql('SELECT id, name, abbreviation, ' bible = BiblesResourcesDB.run_sql(
'language_id, download_source_id FROM webbibles WHERE ' 'SELECT id, name, abbreviation, language_id, download_source_id FROM webbibles WHERE '
'download_source_id = ? AND abbreviation = ?', (source['id'], abbreviation)) 'download_source_id = ? AND abbreviation = ?', (source['id'], abbreviation))
try: try:
return { return {
@ -837,16 +783,14 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
""" """
Return a book_reference_id if the name matches. Return a book_reference_id if the name matches.
``name`` :param name: The name to search the id.
The name to search the id. :param language_id: The language_id for which language should be searched
``language_id``
The language_id for which language should be searched
""" """
log.debug('BiblesResourcesDB.get_alternative_book_name("%s", "%s")', name, language_id) log.debug('BiblesResourcesDB.get_alternative_book_name("%s", "%s")', name, language_id)
if language_id: if language_id:
books = BiblesResourcesDB.run_sql('SELECT book_reference_id, name ' books = BiblesResourcesDB.run_sql(
'FROM alternative_book_names WHERE language_id = ? ORDER BY id', (language_id, )) 'SELECT book_reference_id, name FROM alternative_book_names WHERE language_id = ? ORDER BY id',
(language_id, ))
else: else:
books = BiblesResourcesDB.run_sql('SELECT book_reference_id, name FROM alternative_book_names ORDER BY id') books = BiblesResourcesDB.run_sql('SELECT book_reference_id, name FROM alternative_book_names ORDER BY id')
for book in books: for book in books:
@ -857,17 +801,15 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
@staticmethod @staticmethod
def get_language(name): def get_language(name):
""" """
Return a dict containing the language id, name and code by name or Return a dict containing the language id, name and code by name or abbreviation.
abbreviation.
``name`` :param name: The name or abbreviation of the language.
The name or abbreviation of the language.
""" """
log.debug('BiblesResourcesDB.get_language("%s")', name) log.debug('BiblesResourcesDB.get_language("%s")', name)
if not isinstance(name, str): if not isinstance(name, str):
name = str(name) name = str(name)
language = BiblesResourcesDB.run_sql('SELECT id, name, code FROM ' language = BiblesResourcesDB.run_sql(
'language WHERE name = ? OR code = ?', (name, name.lower())) 'SELECT id, name, code FROM language WHERE name = ? OR code = ?', (name, name.lower()))
if language: if language:
return { return {
'id': language[0][0], 'id': language[0][0],
@ -920,22 +862,20 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
def get_cursor(): def get_cursor():
""" """
Return the cursor object. Instantiate one if it doesn't exist yet. Return the cursor object. Instantiate one if it doesn't exist yet.
If necessary loads up the database and creates the tables if the If necessary loads up the database and creates the tables if the database doesn't exist.
database doesn't exist.
""" """
if AlternativeBookNamesDB.cursor is None: if AlternativeBookNamesDB.cursor is None:
filepath = os.path.join( file_path = os.path.join(
AppLocation.get_directory(AppLocation.DataDir), 'bibles', 'alternative_book_names.sqlite') AppLocation.get_directory(AppLocation.DataDir), 'bibles', 'alternative_book_names.sqlite')
if not os.path.exists(filepath): if not os.path.exists(file_path):
#create new DB, create table alternative_book_names #create new DB, create table alternative_book_names
AlternativeBookNamesDB.conn = sqlite3.connect(filepath) AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
AlternativeBookNamesDB.conn.execute('CREATE TABLE ' AlternativeBookNamesDB.conn.execute(
'alternative_book_names(id INTEGER NOT NULL, ' 'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '
'book_reference_id INTEGER, language_id INTEGER, name ' 'book_reference_id INTEGER, language_id INTEGER, name VARCHAR(50), PRIMARY KEY (id))')
'VARCHAR(50), PRIMARY KEY (id))')
else: else:
#use existing DB #use existing DB
AlternativeBookNamesDB.conn = sqlite3.connect(filepath) AlternativeBookNamesDB.conn = sqlite3.connect(file_path)
AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor() AlternativeBookNamesDB.cursor = AlternativeBookNamesDB.conn.cursor()
return AlternativeBookNamesDB.cursor return AlternativeBookNamesDB.cursor
@ -944,14 +884,9 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
""" """
Run an SQL query on the database, returning the results. Run an SQL query on the database, returning the results.
``query`` :param query: The actual SQL query to run.
The actual SQL query to run. :param parameters: Any variable parameters to add to the query
:param commit: If a commit statement is necessary this should be True.
``parameters``
Any variable parameters to add to the query
``commit``
If a commit statement is necessary this should be True.
""" """
cursor = AlternativeBookNamesDB.get_cursor() cursor = AlternativeBookNamesDB.get_cursor()
cursor.execute(query, parameters) cursor.execute(query, parameters)
@ -964,19 +899,16 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
""" """
Return a book_reference_id if the name matches. Return a book_reference_id if the name matches.
``name`` :param name: The name to search the id.
The name to search the id. :param language_id: The language_id for which language should be searched
``language_id``
The language_id for which language should be searched
""" """
log.debug('AlternativeBookNamesDB.get_book_reference_id("%s", "%s")', name, language_id) log.debug('AlternativeBookNamesDB.get_book_reference_id("%s", "%s")', name, language_id)
if language_id: if language_id:
books = AlternativeBookNamesDB.run_sql('SELECT book_reference_id, ' books = AlternativeBookNamesDB.run_sql(
'name FROM alternative_book_names WHERE language_id = ?', (language_id, )) 'SELECT book_reference_id, name FROM alternative_book_names WHERE language_id = ?', (language_id, ))
else: else:
books = AlternativeBookNamesDB.run_sql('SELECT book_reference_id, ' books = AlternativeBookNamesDB.run_sql(
'name FROM alternative_book_names') 'SELECT book_reference_id, name FROM alternative_book_names')
for book in books: for book in books:
if book[1].lower() == name.lower(): if book[1].lower() == name.lower():
return book[0] return book[0]
@ -987,19 +919,14 @@ class AlternativeBookNamesDB(QtCore.QObject, Manager):
""" """
Add an alternative book name to the database. Add an alternative book name to the database.
``name`` :param name: The name of the alternative book name.
The name of the alternative book name. :param book_reference_id: The book_reference_id of the book.
:param language_id: The language to which the alternative book name belong.
``book_reference_id``
The book_reference_id of the book.
``language_id``
The language to which the alternative book name belong.
""" """
log.debug('AlternativeBookNamesDB.create_alternative_book_name("%s", ' log.debug('AlternativeBookNamesDB.create_alternative_book_name("%s", "%s", "%s")',
'"%s", "%s"', name, book_reference_id, language_id) name, book_reference_id, language_id)
return AlternativeBookNamesDB.run_sql('INSERT INTO ' return AlternativeBookNamesDB.run_sql(
'alternative_book_names(book_reference_id, language_id, name) ' 'INSERT INTO alternative_book_names(book_reference_id, language_id, name) '
'VALUES (?, ?, ?)', (book_reference_id, language_id, name), True) 'VALUES (?, ?, ?)', (book_reference_id, language_id, name), True)
@ -1012,8 +939,7 @@ class OldBibleDB(QtCore.QObject, Manager):
def __init__(self, parent, **kwargs): def __init__(self, parent, **kwargs):
""" """
The constructor loads up the database and creates and initialises the The constructor loads up the database and creates and initialises the tables if the database doesn't exist.
tables if the database doesn't exist.
**Required keyword arguments:** **Required keyword arguments:**
@ -1021,8 +947,7 @@ class OldBibleDB(QtCore.QObject, Manager):
The path to the bible database file. The path to the bible database file.
``name`` ``name``
The name of the database. This is also used as the file name for The name of the database. This is also used as the file name for SQLite databases.
SQLite databases.
""" """
log.info('OldBibleDB loaded') log.info('OldBibleDB loaded')
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
@ -1040,8 +965,8 @@ class OldBibleDB(QtCore.QObject, Manager):
Return the cursor object. Instantiate one if it doesn't exist yet. Return the cursor object. Instantiate one if it doesn't exist yet.
""" """
if self.cursor is None: if self.cursor is None:
filepath = os.path.join(self.path, self.file) file_path = os.path.join(self.path, self.file)
self.connection = sqlite3.connect(filepath) self.connection = sqlite3.connect(file_path)
self.cursor = self.connection.cursor() self.cursor = self.connection.cursor()
return self.cursor return self.cursor
@ -1049,11 +974,8 @@ class OldBibleDB(QtCore.QObject, Manager):
""" """
Run an SQL query on the database, returning the results. Run an SQL query on the database, returning the results.
``query`` :param query: The actual SQL query to run.
The actual SQL query to run. :param parameters: Any variable parameters to add to the query.
``parameters``
Any variable parameters to add to the query.
""" """
cursor = self.get_cursor() cursor = self.get_cursor()
cursor.execute(query, parameters) cursor.execute(query, parameters)
@ -1092,9 +1014,9 @@ class OldBibleDB(QtCore.QObject, Manager):
""" """
if not isinstance(name, str): if not isinstance(name, str):
name = str(name) name = str(name)
books = self.run_sql('SELECT id, testament_id, name, ' books = self.run_sql(
'abbreviation FROM book WHERE LOWER(name) = ? OR ' 'SELECT id, testament_id, name, abbreviation FROM book WHERE LOWER(name) = ? OR '
'LOWER(abbreviation) = ?', (name.lower(), name.lower())) 'LOWER(abbreviation) = ?', (name.lower(), name.lower()))
if books: if books:
return { return {
'id': books[0][0], 'id': books[0][0],
@ -1122,8 +1044,8 @@ class OldBibleDB(QtCore.QObject, Manager):
""" """
Returns the verses of the Bible. Returns the verses of the Bible.
""" """
verses = self.run_sql('SELECT book_id, chapter, verse, text FROM ' verses = self.run_sql(
'verse WHERE book_id = ? ORDER BY id', (book_id, )) 'SELECT book_id, chapter, verse, text FROM verse WHERE book_id = ? ORDER BY id', (book_id, ))
if verses: if verses:
return [{ return [{
'book_id': int(verse[0]), 'book_id': int(verse[0]),