--- a/Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py Sat Sep 02 19:05:28 2017 +0200 +++ b/Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py Sat Sep 02 20:00:57 2017 +0200 @@ -9,6 +9,8 @@ from __future__ import unicode_literals +import os + from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QDir, QLibraryInfo, \ QLocale from PyQt5.QtWidgets import QListWidgetItem @@ -39,7 +41,7 @@ self.on_spellCheckEnabledCheckBox_clicked() if Globals.isMacPlatform(): - dictionaryDirectories = { + self.__dictionaryDirectories = { QDir.cleanPath( QCoreApplication.applicationDirPath() + "/../Resources/qtwebengine_dictionaries"), @@ -49,7 +51,7 @@ "/Resources/qtwebengine_dictionaries"), } else: - dictionaryDirectories = { + self.__dictionaryDirectories = { QDir.cleanPath( QCoreApplication.applicationDirPath() + "/qtwebengine_dictionaries"), @@ -58,9 +60,23 @@ "/qtwebengine_dictionaries"), } self.spellCheckDictionaryDirectoriesEdit.setPlainText( - "\n".join(dictionaryDirectories)) + "\n".join(self.__dictionaryDirectories)) + + self.__writeableDirectories = [] + for directory in self.__dictionaryDirectories: + if os.access(directory, os.W_OK): + self.__writeableDirectories.append(directory) + self.installButton.setEnabled(bool(self.__writeableDirectories)) - for path in dictionaryDirectories: + self.__populateDictionariesList() + + def __populateDictionariesList(self): + """ + Private method to populate the spell checking dictionaries list. + """ + self.spellCheckLanguagesList.clear() + + for path in self.__dictionaryDirectories: directory = QDir(path) fileNames = directory.entryList(["*.bdic"]) for fileName in fileNames: @@ -91,7 +107,9 @@ if self.spellCheckLanguagesList.count(): self.noLanguagesLabel.hide() + self.spellCheckLanguagesList.show() else: + self.noLanguagesLabel.show() self.spellCheckLanguagesList.hide() def save(self): @@ -138,6 +156,19 @@ lang = QLocale.languageToString(loc.language()) languageString = "{0}/{1} [{2}]".format(lang, country, language) return languageString + + @pyqtSlot() + def on_installButton_clicked(self): + """ + Private slot to install spell checking dictionaries. + """ + from WebBrowser.SpellCheck.InstallDictionariesDialog import \ + InstallDictionariesDialog + dlg = InstallDictionariesDialog(self.__writeableDirectories, self) + dlg.exec_() + # TODO: Implement this dialog + + self.__populateDictionariesList() def create(dlg):