src/eric7/Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/Preferences/ConfigurationPages/WebBrowserSpellCheckingPage.py	Wed Jul 13 14:55:47 2022 +0200
@@ -10,9 +10,7 @@
 import os
 import contextlib
 
-from PyQt6.QtCore import (
-    pyqtSlot, Qt, QCoreApplication, QDir, QLibraryInfo, QLocale
-)
+from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication, QDir, QLibraryInfo, QLocale
 from PyQt6.QtWidgets import QListWidgetItem
 
 from .ConfigurationPageBase import ConfigurationPageBase
@@ -22,11 +20,13 @@
 import Globals
 
 
-class WebBrowserSpellCheckingPage(ConfigurationPageBase,
-                                  Ui_WebBrowserSpellCheckingPage):
+class WebBrowserSpellCheckingPage(
+    ConfigurationPageBase, Ui_WebBrowserSpellCheckingPage
+):
     """
     Class implementing the Web Browser Spell Checking page.
     """
+
     def __init__(self):
         """
         Constructor
@@ -34,56 +34,58 @@
         super().__init__()
         self.setupUi(self)
         self.setObjectName("WebBrowserSpellCheckingPage")
-        
+
         # set initial values
         self.spellCheckEnabledCheckBox.setChecked(
-            Preferences.getWebBrowser("SpellCheckEnabled"))
+            Preferences.getWebBrowser("SpellCheckEnabled")
+        )
         self.on_spellCheckEnabledCheckBox_clicked()
-        
+
         if Globals.isMacPlatform():
             self.__dictionaryDirectories = {
                 QDir.cleanPath(
-                    QCoreApplication.applicationDirPath() +
-                    "/../Resources/qtwebengine_dictionaries"),
+                    QCoreApplication.applicationDirPath()
+                    + "/../Resources/qtwebengine_dictionaries"
+                ),
                 QDir.cleanPath(
-                    QCoreApplication.applicationDirPath() +
-                    "/../Frameworks/QtWebEngineCore.framework"
-                    "/Resources/qtwebengine_dictionaries"),
+                    QCoreApplication.applicationDirPath()
+                    + "/../Frameworks/QtWebEngineCore.framework"
+                    "/Resources/qtwebengine_dictionaries"
+                ),
             }
         else:
             self.__dictionaryDirectories = {
                 QDir.cleanPath(
-                    QCoreApplication.applicationDirPath() +
-                    "/qtwebengine_dictionaries"),
+                    QCoreApplication.applicationDirPath() + "/qtwebengine_dictionaries"
+                ),
                 QDir.cleanPath(
-                    QLibraryInfo.path(
-                        QLibraryInfo.LibraryPath.DataPath) +
-                    "/qtwebengine_dictionaries"
+                    QLibraryInfo.path(QLibraryInfo.LibraryPath.DataPath)
+                    + "/qtwebengine_dictionaries"
                 ),
             }
         self.spellCheckDictionaryDirectoriesEdit.setPlainText(
-            "\n".join(self.__dictionaryDirectories))
+            "\n".join(self.__dictionaryDirectories)
+        )
         # try to create these directories, if they don't exist
         for directory in self.__dictionaryDirectories:
             if not os.path.exists(directory):
                 with contextlib.suppress(os.error):
                     os.makedirs(directory)
-        
+
         self.__writeableDirectories = []
         for directory in self.__dictionaryDirectories:
             if os.access(directory, os.W_OK):
                 self.__writeableDirectories.append(directory)
-        self.manageDictionariesButton.setEnabled(
-            bool(self.__writeableDirectories))
-        
+        self.manageDictionariesButton.setEnabled(bool(self.__writeableDirectories))
+
         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"])
@@ -94,26 +96,28 @@
                     langStr, Qt.MatchFlag.MatchExactly
                 ):
                     continue
-                
+
                 itm = QListWidgetItem(langStr, self.spellCheckLanguagesList)
                 itm.setData(Qt.ItemDataRole.UserRole, lang)
                 itm.setFlags(itm.flags() | Qt.ItemFlag.ItemIsUserCheckable)
                 itm.setCheckState(Qt.CheckState.Unchecked)
         self.spellCheckLanguagesList.sortItems(Qt.SortOrder.AscendingOrder)
-        
+
         spellCheckLanguages = Preferences.getWebBrowser("SpellCheckLanguages")
         topIndex = 0
         for lang in spellCheckLanguages:
             items = self.spellCheckLanguagesList.findItems(
-                self.__createLanguageString(lang), Qt.MatchFlag.MatchExactly)
+                self.__createLanguageString(lang), Qt.MatchFlag.MatchExactly
+            )
             if items:
                 itm = items[0]
                 self.spellCheckLanguagesList.takeItem(
-                    self.spellCheckLanguagesList.row(itm))
+                    self.spellCheckLanguagesList.row(itm)
+                )
                 self.spellCheckLanguagesList.insertItem(topIndex, itm)
                 itm.setCheckState(Qt.CheckState.Checked)
                 topIndex += 1
-        
+
         if self.spellCheckLanguagesList.count():
             self.noLanguagesLabel.hide()
             self.spellCheckLanguagesList.show()
@@ -122,7 +126,7 @@
             self.noLanguagesLabel.show()
             self.spellCheckLanguagesList.hide()
             self.spellCheckEnabledCheckBox.setChecked(False)
-    
+
     def save(self):
         """
         Public slot to save the Help Viewers configuration.
@@ -132,14 +136,12 @@
             itm = self.spellCheckLanguagesList.item(row)
             if itm.checkState() == Qt.CheckState.Checked:
                 languages.append(itm.data(Qt.ItemDataRole.UserRole))
-        
+
         Preferences.setWebBrowser(
-            "SpellCheckEnabled",
-            self.spellCheckEnabledCheckBox.isChecked())
-        Preferences.setWebBrowser(
-            "SpellCheckLanguages",
-            languages)
-    
+            "SpellCheckEnabled", self.spellCheckEnabledCheckBox.isChecked()
+        )
+        Preferences.setWebBrowser("SpellCheckLanguages", languages)
+
     @pyqtSlot()
     def on_spellCheckEnabledCheckBox_clicked(self):
         """
@@ -148,44 +150,45 @@
         enable = self.spellCheckEnabledCheckBox.isChecked()
         self.noLanguagesLabel.setEnabled(enable)
         self.spellCheckLanguagesList.setEnabled(enable)
-    
+
     def __createLanguageString(self, language):
         """
         Private method to create a language string given a language identifier.
-        
+
         @param language language identifier
         @type str
         @return language string
         @rtype str
         """
         loc = QLocale(language)
-        
+
         if loc.language() == QLocale.Language.C:
             return language
-        
+
         country = QLocale.countryToString(loc.country())
         lang = QLocale.languageToString(loc.language())
         languageString = "{0}/{1} [{2}]".format(lang, country, language)
         return languageString
-    
+
     @pyqtSlot()
     def on_manageDictionariesButton_clicked(self):
         """
         Private slot to manage spell checking dictionaries.
         """
         from WebBrowser.SpellCheck.ManageDictionariesDialog import (
-            ManageDictionariesDialog
+            ManageDictionariesDialog,
         )
+
         dlg = ManageDictionariesDialog(self.__writeableDirectories, self)
         dlg.exec()
-        
+
         self.__populateDictionariesList()
 
 
 def create(dlg):
     """
     Module function to create the configuration page.
-    
+
     @param dlg reference to the configuration dialog
     @type Configuration
     @return reference to the instantiated page

eric ide

mercurial