mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: When adding dictionaries allow directly a LibreOffice adding the dictionary just by choosing the language
Cleanup previous PR that implement this functionality
This commit is contained in:
parent
a44bb42eda
commit
4d20e70ea1
@ -12,10 +12,10 @@ from itertools import chain
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QT_VERSION_STR, QAbstractItemView, QAbstractTableModel, QAction, QApplication,
|
QT_VERSION_STR, QAbstractItemView, QAbstractTableModel, QAction, QApplication,
|
||||||
QCheckBox, QComboBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QGridLayout,
|
QCheckBox, QComboBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QGridLayout,
|
||||||
QHBoxLayout, QIcon, QInputDialog, QKeySequence, QLabel, QLineEdit,
|
QHBoxLayout, QIcon, QInputDialog, QKeySequence, QLabel, QLineEdit, QListWidget,
|
||||||
QListWidget,QListWidgetItem, QMenu, QModelIndex, QPlainTextEdit, QPushButton,
|
QListWidgetItem, QMenu, QModelIndex, QPlainTextEdit, QPushButton, QSize,
|
||||||
QSize, QStackedLayout, Qt, QTableView, QTimer, QToolButton, QTreeWidget,
|
QStackedLayout, Qt, QTableView, QTabWidget, QTimer, QToolButton, QTreeWidget,
|
||||||
QTabWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal,
|
QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal,
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -33,6 +33,7 @@ from calibre.gui2.tweak_book import (
|
|||||||
current_container, dictionaries, editors, set_book_locale, tprefs,
|
current_container, dictionaries, editors, set_book_locale, tprefs,
|
||||||
)
|
)
|
||||||
from calibre.gui2.tweak_book.widgets import Dialog
|
from calibre.gui2.tweak_book.widgets import Dialog
|
||||||
|
from calibre.gui2.widgets import BusyCursor
|
||||||
from calibre.gui2.widgets2 import FlowLayout
|
from calibre.gui2.widgets2 import FlowLayout
|
||||||
from calibre.spell import DictionaryLocale
|
from calibre.spell import DictionaryLocale
|
||||||
from calibre.spell.break_iterator import split_into_words
|
from calibre.spell.break_iterator import split_into_words
|
||||||
@ -40,7 +41,7 @@ from calibre.spell.dictionary import (
|
|||||||
best_locale_for_language, builtin_dictionaries, catalog_online_dictionaries,
|
best_locale_for_language, builtin_dictionaries, catalog_online_dictionaries,
|
||||||
custom_dictionaries, dprefs, get_dictionary, remove_dictionary, rename_dictionary,
|
custom_dictionaries, dprefs, get_dictionary, remove_dictionary, rename_dictionary,
|
||||||
)
|
)
|
||||||
from calibre.spell.import_from import import_from_oxt, import_from_online
|
from calibre.spell.import_from import import_from_online, import_from_oxt
|
||||||
from calibre.startup import connect_lambda
|
from calibre.startup import connect_lambda
|
||||||
from calibre.utils.icu import contains, primary_contains, primary_sort_key, sort_key
|
from calibre.utils.icu import contains, primary_contains, primary_sort_key, sort_key
|
||||||
from calibre.utils.localization import (
|
from calibre.utils.localization import (
|
||||||
@ -90,8 +91,8 @@ class AddDictionary(QDialog): # {{{
|
|||||||
|
|
||||||
self.web_download = QWidget(self)
|
self.web_download = QWidget(self)
|
||||||
self.oxt_import = QWidget(self)
|
self.oxt_import = QWidget(self)
|
||||||
tabs.addTab(self.web_download, _('Download online'))
|
tabs.setTabIcon(tabs.addTab(self.web_download, _('&Download')), QIcon.ic('download-metadata.png'))
|
||||||
tabs.addTab(self.oxt_import, _('Import from OXT file'))
|
tabs.setTabIcon(tabs.addTab(self.oxt_import, _('&Import from OXT file')), QIcon.ic('unpack-book.png'))
|
||||||
tabs.currentChanged.connect(self.tab_changed)
|
tabs.currentChanged.connect(self.tab_changed)
|
||||||
|
|
||||||
# Download online tab
|
# Download online tab
|
||||||
@ -100,16 +101,16 @@ class AddDictionary(QDialog): # {{{
|
|||||||
self.web_download.setLayout(l)
|
self.web_download.setLayout(l)
|
||||||
|
|
||||||
la = QLabel('<p>' + _(
|
la = QLabel('<p>' + _(
|
||||||
'''{0} supports the use of LibreOffice dictionaries for spell checking. You can
|
'''{0} supports the use of LibreOffice dictionaries for spell checking. Choose the language you
|
||||||
download some of them from <a href="{1}">the LibreOffice dictionaries repository</a>.'''
|
want below and click OK to download the dictionary from the <a href="{1}">LibreOffice dictionaries repository</a>.'''
|
||||||
).format(__appname__, 'https://github.com/LibreOffice/dictionaries')+'<p>') # noqa
|
).format(__appname__, 'https://github.com/LibreOffice/dictionaries')+'<p>')
|
||||||
la.setWordWrap(True)
|
la.setWordWrap(True)
|
||||||
la.setOpenExternalLinks(True)
|
la.setOpenExternalLinks(True)
|
||||||
la.setMinimumWidth(450)
|
la.setMinimumWidth(450)
|
||||||
l.addRow(la)
|
l.addRow(la)
|
||||||
|
|
||||||
self.combobox_online = c = QComboBox(self)
|
self.combobox_online = c = QComboBox(self)
|
||||||
l.addRow(_('Langue to download:'), c)
|
l.addRow(_('&Language to download:'), c)
|
||||||
|
|
||||||
c.addItem('', None)
|
c.addItem('', None)
|
||||||
languages = current_languages_dictionaries(reread=False)
|
languages = current_languages_dictionaries(reread=False)
|
||||||
@ -218,7 +219,8 @@ class AddDictionary(QDialog): # {{{
|
|||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
idx = self.tabs.currentIndex()
|
idx = self.tabs.currentIndex()
|
||||||
if idx== 0:
|
if idx == 0:
|
||||||
|
with BusyCursor():
|
||||||
self._process_online_download()
|
self._process_online_download()
|
||||||
elif idx == 1:
|
elif idx == 1:
|
||||||
self._process_oxt_import()
|
self._process_oxt_import()
|
||||||
@ -1603,7 +1605,8 @@ def find_next_error(current_editor, current_editor_name, gui_parent, show_editor
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication([])
|
from calibre.gui2 import Application
|
||||||
|
app = Application([])
|
||||||
dictionaries.initialize()
|
dictionaries.initialize()
|
||||||
ManageDictionaries.test()
|
ManageDictionaries.test()
|
||||||
del app
|
del app
|
||||||
|
@ -137,6 +137,7 @@ def _import_from_virtual_directory(read_file_func, name, dest_dir=None, prefix='
|
|||||||
num += 1
|
num += 1
|
||||||
return num
|
return num
|
||||||
|
|
||||||
|
|
||||||
def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
||||||
with ZipFile(source_path) as zf:
|
with ZipFile(source_path) as zf:
|
||||||
def read_file(key):
|
def read_file(key):
|
||||||
@ -153,13 +154,15 @@ def import_from_oxt(source_path, name, dest_dir=None, prefix='dic-'):
|
|||||||
|
|
||||||
return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)
|
return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)
|
||||||
|
|
||||||
|
|
||||||
def import_from_online(directory, name, dest_dir=None, prefix='dic-'):
|
def import_from_online(directory, name, dest_dir=None, prefix='dic-'):
|
||||||
br = browser()
|
br = browser(timeout=30)
|
||||||
def read_file(key):
|
def read_file(key):
|
||||||
rp = br.open('/'.join([ONLINE_DICTIONARY_BASE_URL, directory, key]))
|
rp = br.open('/'.join((ONLINE_DICTIONARY_BASE_URL, directory, key)))
|
||||||
return rp.read()
|
return rp.read()
|
||||||
|
|
||||||
return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)
|
return _import_from_virtual_directory(read_file, name, dest_dir=dest_dir, prefix=prefix)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import_from_libreoffice_source_tree(sys.argv[-1])
|
import_from_libreoffice_source_tree(sys.argv[-1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user