Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py

changeset 5868
c1a98c164cd3
parent 5650
4c52f07c186e
child 5870
82e04c70f969
equal deleted inserted replaced
5867:099008539886 5868:c1a98c164cd3
6 """ 6 """
7 Module implementing the Web Browser Spell Checking configuration page. 7 Module implementing the Web Browser Spell Checking configuration page.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11
12 import os
11 13
12 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QDir, QLibraryInfo, \ 14 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QDir, QLibraryInfo, \
13 QLocale 15 QLocale
14 from PyQt5.QtWidgets import QListWidgetItem 16 from PyQt5.QtWidgets import QListWidgetItem
15 17
37 self.spellCheckEnabledCheckBox.setChecked( 39 self.spellCheckEnabledCheckBox.setChecked(
38 Preferences.getWebBrowser("SpellCheckEnabled")) 40 Preferences.getWebBrowser("SpellCheckEnabled"))
39 self.on_spellCheckEnabledCheckBox_clicked() 41 self.on_spellCheckEnabledCheckBox_clicked()
40 42
41 if Globals.isMacPlatform(): 43 if Globals.isMacPlatform():
42 dictionaryDirectories = { 44 self.__dictionaryDirectories = {
43 QDir.cleanPath( 45 QDir.cleanPath(
44 QCoreApplication.applicationDirPath() + 46 QCoreApplication.applicationDirPath() +
45 "/../Resources/qtwebengine_dictionaries"), 47 "/../Resources/qtwebengine_dictionaries"),
46 QDir.cleanPath( 48 QDir.cleanPath(
47 QCoreApplication.applicationDirPath() + 49 QCoreApplication.applicationDirPath() +
48 "/../Frameworks/QtWebEngineCore.framework" 50 "/../Frameworks/QtWebEngineCore.framework"
49 "/Resources/qtwebengine_dictionaries"), 51 "/Resources/qtwebengine_dictionaries"),
50 } 52 }
51 else: 53 else:
52 dictionaryDirectories = { 54 self.__dictionaryDirectories = {
53 QDir.cleanPath( 55 QDir.cleanPath(
54 QCoreApplication.applicationDirPath() + 56 QCoreApplication.applicationDirPath() +
55 "/qtwebengine_dictionaries"), 57 "/qtwebengine_dictionaries"),
56 QDir.cleanPath( 58 QDir.cleanPath(
57 QLibraryInfo.location(QLibraryInfo.DataPath) + 59 QLibraryInfo.location(QLibraryInfo.DataPath) +
58 "/qtwebengine_dictionaries"), 60 "/qtwebengine_dictionaries"),
59 } 61 }
60 self.spellCheckDictionaryDirectoriesEdit.setPlainText( 62 self.spellCheckDictionaryDirectoriesEdit.setPlainText(
61 "\n".join(dictionaryDirectories)) 63 "\n".join(self.__dictionaryDirectories))
62 64
63 for path in dictionaryDirectories: 65 self.__writeableDirectories = []
66 for directory in self.__dictionaryDirectories:
67 if os.access(directory, os.W_OK):
68 self.__writeableDirectories.append(directory)
69 self.installButton.setEnabled(bool(self.__writeableDirectories))
70
71 self.__populateDictionariesList()
72
73 def __populateDictionariesList(self):
74 """
75 Private method to populate the spell checking dictionaries list.
76 """
77 self.spellCheckLanguagesList.clear()
78
79 for path in self.__dictionaryDirectories:
64 directory = QDir(path) 80 directory = QDir(path)
65 fileNames = directory.entryList(["*.bdic"]) 81 fileNames = directory.entryList(["*.bdic"])
66 for fileName in fileNames: 82 for fileName in fileNames:
67 lang = fileName[:-5] 83 lang = fileName[:-5]
68 langStr = self.__createLanguageString(lang) 84 langStr = self.__createLanguageString(lang)
89 itm.setCheckState(Qt.Checked) 105 itm.setCheckState(Qt.Checked)
90 topIndex += 1 106 topIndex += 1
91 107
92 if self.spellCheckLanguagesList.count(): 108 if self.spellCheckLanguagesList.count():
93 self.noLanguagesLabel.hide() 109 self.noLanguagesLabel.hide()
110 self.spellCheckLanguagesList.show()
94 else: 111 else:
112 self.noLanguagesLabel.show()
95 self.spellCheckLanguagesList.hide() 113 self.spellCheckLanguagesList.hide()
96 114
97 def save(self): 115 def save(self):
98 """ 116 """
99 Public slot to save the Help Viewers configuration. 117 Public slot to save the Help Viewers configuration.
136 154
137 country = QLocale.countryToString(loc.country()) 155 country = QLocale.countryToString(loc.country())
138 lang = QLocale.languageToString(loc.language()) 156 lang = QLocale.languageToString(loc.language())
139 languageString = "{0}/{1} [{2}]".format(lang, country, language) 157 languageString = "{0}/{1} [{2}]".format(lang, country, language)
140 return languageString 158 return languageString
159
160 @pyqtSlot()
161 def on_installButton_clicked(self):
162 """
163 Private slot to install spell checking dictionaries.
164 """
165 from WebBrowser.SpellCheck.InstallDictionariesDialog import \
166 InstallDictionariesDialog
167 dlg = InstallDictionariesDialog(self.__writeableDirectories, self)
168 dlg.exec_()
169 # TODO: Implement this dialog
170
171 self.__populateDictionariesList()
141 172
142 173
143 def create(dlg): 174 def create(dlg):
144 """ 175 """
145 Module function to create the configuration page. 176 Module function to create the configuration page.

eric ide

mercurial