forked from openlp/openlp
Implemented getting languages into combobox.
This commit is contained in:
parent
52f3695334
commit
e78a0ba0da
@ -34,6 +34,7 @@ from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
|
||||
from openlp.core.utils import get_locale_key
|
||||
from openlp.plugins.bibles.lib.manager import BibleFormat
|
||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB, clean_filename
|
||||
from openlp.plugins.bibles.lib.http import CWExtract, BGExtract, BSExtract
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -98,12 +99,13 @@ class BibleImportForm(OpenLPWizard):
|
||||
"""
|
||||
Set up the signals used in the bible importer.
|
||||
"""
|
||||
self.web_source_combo_box.currentIndexChanged.connect(self.on_web_source_combo_box_index_changed)
|
||||
self.web_language_combo_box.currentIndexChanged.connect(self.on_web_language_combo_box_index_changed)
|
||||
self.osis_browse_button.clicked.connect(self.on_osis_browse_button_clicked)
|
||||
self.csv_books_button.clicked.connect(self.on_csv_books_browse_button_clicked)
|
||||
self.csv_verses_button.clicked.connect(self.on_csv_verses_browse_button_clicked)
|
||||
self.open_song_browse_button.clicked.connect(self.on_open_song_browse_button_clicked)
|
||||
self.zefania_browse_button.clicked.connect(self.on_zefania_browse_button_clicked)
|
||||
self.web_update_button.clicked.connect(self.on_web_update_button_clicked)
|
||||
|
||||
def add_custom_pages(self):
|
||||
"""
|
||||
@ -202,20 +204,28 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.web_bible_tab.setObjectName('WebBibleTab')
|
||||
self.web_bible_layout = QtGui.QFormLayout(self.web_bible_tab)
|
||||
self.web_bible_layout.setObjectName('WebBibleLayout')
|
||||
|
||||
self.web_update_label = QtGui.QLabel(self.web_bible_tab)
|
||||
self.web_update_label.setObjectName('WebUpdateLabel')
|
||||
self.web_bible_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.web_update_label)
|
||||
self.web_update_button = QtGui.QPushButton(self.web_bible_tab)
|
||||
self.web_update_button.setObjectName('WebUpdateLabel')
|
||||
self.web_bible_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.web_update_button)
|
||||
|
||||
self.web_source_label = QtGui.QLabel(self.web_bible_tab)
|
||||
self.web_source_label.setObjectName('WebSourceLabel')
|
||||
self.web_bible_layout.setWidget(0, QtGui.QFormLayout.LabelRole, self.web_source_label)
|
||||
self.web_source_combo_box = QtGui.QComboBox(self.web_bible_tab)
|
||||
self.web_source_combo_box.setObjectName('WebSourceComboBox')
|
||||
self.web_source_combo_box.addItems(['', '', ''])
|
||||
self.web_bible_layout.setWidget(0, QtGui.QFormLayout.FieldRole, self.web_source_combo_box)
|
||||
self.web_bible_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.web_source_label)
|
||||
self.web_language_combo_box = QtGui.QComboBox(self.web_bible_tab)
|
||||
self.web_language_combo_box.setObjectName('WebSourceComboBox')
|
||||
self.web_language_combo_box.addItems(['', '', ''])
|
||||
self.web_bible_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.web_language_combo_box)
|
||||
self.web_translation_label = QtGui.QLabel(self.web_bible_tab)
|
||||
self.web_translation_label.setObjectName('web_translation_label')
|
||||
self.web_bible_layout.setWidget(1, QtGui.QFormLayout.LabelRole, self.web_translation_label)
|
||||
self.web_bible_layout.setWidget(2, QtGui.QFormLayout.LabelRole, self.web_translation_label)
|
||||
self.web_translation_combo_box = QtGui.QComboBox(self.web_bible_tab)
|
||||
self.web_translation_combo_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
|
||||
self.web_translation_combo_box.setObjectName('WebTranslationComboBox')
|
||||
self.web_bible_layout.setWidget(1, QtGui.QFormLayout.FieldRole, self.web_translation_combo_box)
|
||||
self.web_bible_layout.setWidget(2, QtGui.QFormLayout.FieldRole, self.web_translation_combo_box)
|
||||
self.web_tab_widget.addTab(self.web_bible_tab, '')
|
||||
self.web_proxy_tab = QtGui.QWidget()
|
||||
self.web_proxy_tab.setObjectName('WebProxyTab')
|
||||
@ -314,12 +324,9 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.open_song_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:'))
|
||||
self.web_source_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Location:'))
|
||||
self.zefania_file_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:'))
|
||||
self.web_source_combo_box.setItemText(WebDownload.Crosswalk, translate('BiblesPlugin.ImportWizardForm',
|
||||
'Crosswalk'))
|
||||
self.web_source_combo_box.setItemText(WebDownload.BibleGateway, translate('BiblesPlugin.ImportWizardForm',
|
||||
'BibleGateway'))
|
||||
self.web_source_combo_box.setItemText(WebDownload.Bibleserver, translate('BiblesPlugin.ImportWizardForm',
|
||||
'Bibleserver'))
|
||||
self.web_update_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Click to fetch bible list'))
|
||||
self.web_update_button.setText(translate('BiblesPlugin.ImportWizardForm', 'Fetch list'))
|
||||
#self.web_language_combo_box.setItemText(0, translate('BiblesPlugin.ImportWizardForm', 'Choose a language'))
|
||||
self.web_translation_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible:'))
|
||||
self.web_tab_widget.setTabText(self.web_tab_widget.indexOf(self.web_bible_tab),
|
||||
translate('BiblesPlugin.ImportWizardForm', 'Download Options'))
|
||||
@ -427,7 +434,7 @@ class BibleImportForm(OpenLPWizard):
|
||||
if self.currentPage() == self.progress_page:
|
||||
return True
|
||||
|
||||
def on_web_source_combo_box_index_changed(self, index):
|
||||
def on_web_language_combo_box_index_changed(self, index):
|
||||
"""
|
||||
Setup the list of Bibles when you select a different source on the web download page.
|
||||
|
||||
@ -475,6 +482,32 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.ZEF, self.zefania_file_edit,
|
||||
'last directory import')
|
||||
|
||||
def on_web_update_button_clicked(self):
|
||||
"""
|
||||
Download list of bibles from Crosswalk, BibleServer and BibleGateway, and fill data in comboboxes
|
||||
"""
|
||||
# Download from Crosswalk, BiblesGateway, BibleServer
|
||||
self.web_bible_list = {}
|
||||
for (source, extractor) in ((WebDownload.Crosswalk, CWExtract()), (WebDownload.BibleGateway, BGExtract()),
|
||||
(WebDownload.Bibleserver, BSExtract())):
|
||||
bibles = extractor.get_bibles_from_http()
|
||||
for (bible_name, bible_key, language_code) in bibles:
|
||||
if not language_code in self.web_bible_list:
|
||||
self.web_bible_list[language_code] = {}
|
||||
self.web_bible_list[language_code]['translations'] = []
|
||||
bible_language = BiblesResourcesDB.get_language(language_code)
|
||||
if bible_language:
|
||||
self.web_bible_list[language_code]['name'] = bible_language['name']
|
||||
self.web_bible_list[language_code]['native_name'] = bible_language['native_name']
|
||||
else:
|
||||
self.web_bible_list[language_code]['name'] = language_code
|
||||
self.web_bible_list[language_code]['native_name'] = language_code
|
||||
self.web_bible_list[language_code]['translations'].append((source, bible_name, bible_key))
|
||||
# Update combo box
|
||||
for key in self.web_bible_list.keys():
|
||||
self.web_language_combo_box.addItem(self.web_bible_list[key]['native_name'] + ' (' +
|
||||
self.web_bible_list[key]['name'] + ')', userData=key)
|
||||
|
||||
def register_fields(self):
|
||||
"""
|
||||
Register the bible import wizard fields.
|
||||
@ -485,7 +518,7 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.select_page.registerField('csv_versefile', self.csv_verses_edit)
|
||||
self.select_page.registerField('opensong_file', self.open_song_file_edit)
|
||||
self.select_page.registerField('zefania_file', self.zefania_file_edit)
|
||||
self.select_page.registerField('web_location', self.web_source_combo_box)
|
||||
self.select_page.registerField('web_language', self.web_language_combo_box)
|
||||
self.select_page.registerField('web_biblename', self.web_translation_combo_box)
|
||||
self.select_page.registerField('proxy_server', self.web_server_edit)
|
||||
self.select_page.registerField('proxy_username', self.web_user_edit)
|
||||
@ -509,7 +542,7 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.setField('csv_versefile', '')
|
||||
self.setField('opensong_file', '')
|
||||
self.setField('zefania_file', '')
|
||||
self.setField('web_location', WebDownload.Crosswalk)
|
||||
self.setField('web_language', 0)
|
||||
self.setField('web_biblename', self.web_translation_combo_box.currentIndex())
|
||||
self.setField('proxy_server', settings.value('proxy address'))
|
||||
self.setField('proxy_username', settings.value('proxy username'))
|
||||
@ -517,7 +550,7 @@ class BibleImportForm(OpenLPWizard):
|
||||
self.setField('license_version', self.version_name_edit.text())
|
||||
self.setField('license_copyright', self.copyright_edit.text())
|
||||
self.setField('license_permissions', self.permissions_edit.text())
|
||||
self.on_web_source_combo_box_index_changed(WebDownload.Crosswalk)
|
||||
#self.on_web_language_combo_box_index_changed(WebDownload.Crosswalk)
|
||||
settings.endGroup()
|
||||
|
||||
def load_Web_Bibles(self):
|
||||
|
@ -791,12 +791,13 @@ class BiblesResourcesDB(QtCore.QObject, Manager):
|
||||
if not isinstance(name, str):
|
||||
name = str(name)
|
||||
language = BiblesResourcesDB.run_sql(
|
||||
'SELECT id, name, code FROM language WHERE name = ? OR code = ?', (name, name.lower()))
|
||||
'SELECT id, name, code, native_name FROM language WHERE name = ? OR code = ?', (name, name.lower()))
|
||||
if language:
|
||||
return {
|
||||
'id': language[0][0],
|
||||
'name': str(language[0][1]),
|
||||
'code': str(language[0][2])
|
||||
'code': str(language[0][2]),
|
||||
'native_name': str(language[0][3])
|
||||
}
|
||||
else:
|
||||
return None
|
||||
|
@ -74,6 +74,15 @@ BIBLESERVER_LANGUAGE_CODE = {
|
||||
'fl_21': 'zh'
|
||||
}
|
||||
|
||||
CROSSWALK_LANGUAGES = {
|
||||
'Portuguese': 'pt',
|
||||
'German': 'de',
|
||||
'Italian': 'it',
|
||||
'Español': 'es',
|
||||
'French' : 'fr',
|
||||
'Dutch': 'nl'
|
||||
}
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -304,6 +313,8 @@ class BGExtract(RegistryProperties):
|
||||
def get_bibles_from_http(self):
|
||||
"""
|
||||
Load a list of bibles from BibleGateway website.
|
||||
|
||||
returns a list in the form [(biblename, biblekey, language_code)]
|
||||
"""
|
||||
log.debug('BGExtract.get_bibles_from_http')
|
||||
bible_url = 'https://legacy.biblegateway.com/versions/'
|
||||
@ -313,6 +324,7 @@ class BGExtract(RegistryProperties):
|
||||
bible_select = soup.find('select', {'class': 'translation-dropdown'})
|
||||
option_tags = bible_select.find_all('option')
|
||||
current_lang = ''
|
||||
bibles = []
|
||||
for ot in option_tags:
|
||||
tag_class = ''
|
||||
try:
|
||||
@ -321,11 +333,12 @@ class BGExtract(RegistryProperties):
|
||||
tag_class = ''
|
||||
tag_text = ot.get_text()
|
||||
if tag_class == 'lang':
|
||||
current_lang = tag_text[tag_text.find('(') + 1:tag_text.find(')') + 1].lower()
|
||||
current_lang = tag_text[tag_text.find('(') + 1:tag_text.find(')')].lower()
|
||||
elif tag_class == 'spacer':
|
||||
continue
|
||||
else:
|
||||
print('biblename: %s, bible_key: %s, class: %s' % (tag_text, ot['value'], current_lang))
|
||||
bibles.append((tag_text, ot['value'], current_lang))
|
||||
return bibles
|
||||
|
||||
|
||||
class BSExtract(RegistryProperties):
|
||||
@ -390,6 +403,8 @@ class BSExtract(RegistryProperties):
|
||||
def get_bibles_from_http(self):
|
||||
"""
|
||||
Load a list of bibles from Bibleserver website.
|
||||
|
||||
returns a list in the form [(biblename, biblekey, language_code)]
|
||||
"""
|
||||
log.debug('BSExtract.get_bibles_from_http')
|
||||
bible_url = 'http://www.bibleserver.com/index.php?language=2'
|
||||
@ -397,6 +412,7 @@ class BSExtract(RegistryProperties):
|
||||
if not soup:
|
||||
return None
|
||||
bible_links = soup.find_all('a', {'class': 'trlCell'})
|
||||
bibles = []
|
||||
for link in bible_links:
|
||||
bible_name = link.get_text()
|
||||
# Skip any audio
|
||||
@ -412,7 +428,8 @@ class BSExtract(RegistryProperties):
|
||||
language_code = BIBLESERVER_LANGUAGE_CODE[css_class]
|
||||
except KeyError:
|
||||
language_code = ''
|
||||
print('biblename: %s, bible_key: %s, class: %s' % (bible_name, bible_key, language_code))
|
||||
bibles.append((bible_name, bible_key, language_code))
|
||||
return bibles
|
||||
|
||||
|
||||
class CWExtract(RegistryProperties):
|
||||
@ -487,6 +504,7 @@ class CWExtract(RegistryProperties):
|
||||
def get_bibles_from_http(self):
|
||||
"""
|
||||
Load a list of bibles from Crosswalk website.
|
||||
returns a list in the form [(biblename, biblekey, language_code)]
|
||||
"""
|
||||
log.debug('CWExtract.get_bibles_from_http')
|
||||
bible_url = 'http://www.biblestudytools.com/search/bible-search.part/'
|
||||
@ -495,20 +513,27 @@ class CWExtract(RegistryProperties):
|
||||
return None
|
||||
bible_select = soup.find('select')
|
||||
option_tags = bible_select.find_all('option')
|
||||
bibles = []
|
||||
for ot in option_tags:
|
||||
tag_text = ot.get_text()
|
||||
tag_text = ot.get_text().strip()
|
||||
tag_value = ot['value']
|
||||
if not tag_value:
|
||||
continue
|
||||
# The names of non-english bibles has their language in parentheses at the end
|
||||
if tag_text.endswith(')'):
|
||||
language_code = ''
|
||||
language = tag_text[tag_text.rfind('(') + 1:-1]
|
||||
if language in CROSSWALK_LANGUAGES:
|
||||
language_code = CROSSWALK_LANGUAGES[language]
|
||||
tag_text = tag_text[:tag_text.rfind('(')]
|
||||
else:
|
||||
language_code = ''
|
||||
# ... except for the latin vulgate
|
||||
elif 'latin' in tag_text.lower():
|
||||
language_code = 'la'
|
||||
else:
|
||||
language_code = 'en'
|
||||
print('biblename: %s, bible_key: %s, class: %s' % (tag_text, tag_value, language_code))
|
||||
bibles.append((tag_text, tag_value, language_code))
|
||||
return bibles
|
||||
|
||||
|
||||
class HTTPBible(BibleDB, RegistryProperties):
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user