eric7/Preferences/ConfigurationPages/EditorSpellCheckingPage.py

Sat, 22 May 2021 19:58:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 22 May 2021 19:58:24 +0200
branch
eric7
changeset 8358
144a6b854f70
parent 8356
68ec9c3d4de5
child 8881
54e42bc2437a
permissions
-rw-r--r--

Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).

# -*- coding: utf-8 -*-

# Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Editor Spellchecking configuration page.
"""

from EricWidgets.EricPathPicker import EricPathPickerModes

from .ConfigurationPageBase import ConfigurationPageBase
from .Ui_EditorSpellCheckingPage import Ui_EditorSpellCheckingPage

import Preferences


class EditorSpellCheckingPage(ConfigurationPageBase,
                              Ui_EditorSpellCheckingPage):
    """
    Class implementing the Editor Spellchecking configuration page.
    """
    def __init__(self):
        """
        Constructor
        """
        super().__init__()
        self.setupUi(self)
        self.setObjectName("EditorSpellCheckingPage")
        
        self.pwlPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
        self.pwlPicker.setFilters(self.tr(
            "Dictionary File (*.dic);;All Files (*)"))
        
        self.pelPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
        self.pelPicker.setFilters(self.tr(
            "Dictionary File (*.dic);;All Files (*)"))
        
        from QScintilla.SpellChecker import SpellChecker
        languages = sorted(SpellChecker.getAvailableLanguages())
        self.defaultLanguageCombo.addItems(languages)
        if languages:
            self.errorLabel.hide()
        else:
            self.spellingFrame.setEnabled(False)
        
        # set initial values
        self.checkingEnabledCheckBox.setChecked(
            Preferences.getEditor("SpellCheckingEnabled"))
        
        self.defaultLanguageCombo.setCurrentIndex(
            self.defaultLanguageCombo.findText(
                Preferences.getEditor("SpellCheckingDefaultLanguage")))
        
        self.stringsOnlyCheckBox.setChecked(
            Preferences.getEditor("SpellCheckStringsOnly"))
        self.fullCheckUnknownCheckBox.setChecked(
            Preferences.getEditor("FullSpellCheckUnknown"))
        self.minimumWordSizeSlider.setValue(
            Preferences.getEditor("SpellCheckingMinWordSize"))
        self.spellCheckTextFilesLineEdit.setText(
            " ".join(Preferences.getEditor("FullSpellCheckExtensions")))
        
        self.initColour(
            "SpellingMarkers", self.spellingMarkerButton,
            Preferences.getEditorColour, hasAlpha=True)
        
        self.pwlPicker.setText(
            Preferences.getEditor("SpellCheckingPersonalWordList"))
        self.pelPicker.setText(
            Preferences.getEditor("SpellCheckingPersonalExcludeList"))
        
        if self.spellingFrame.isEnabled():
            self.enabledCheckBox.setChecked(
                Preferences.getEditor("AutoSpellCheckingEnabled"))
        else:
            self.enabledCheckBox.setChecked(False)  # not available
        self.chunkSizeSpinBox.setValue(
            Preferences.getEditor("AutoSpellCheckChunkSize"))
        
    def save(self):
        """
        Public slot to save the Editor Search configuration.
        """
        Preferences.setEditor(
            "SpellCheckingEnabled", self.checkingEnabledCheckBox.isChecked())
        
        Preferences.setEditor(
            "SpellCheckingDefaultLanguage",
            self.defaultLanguageCombo.currentText())
        
        Preferences.setEditor(
            "SpellCheckStringsOnly", self.stringsOnlyCheckBox.isChecked())
        Preferences.setEditor(
            "FullSpellCheckUnknown",
            self.fullCheckUnknownCheckBox.isChecked())
        Preferences.setEditor(
            "SpellCheckingMinWordSize", self.minimumWordSizeSlider.value())
        Preferences.setEditor(
            "FullSpellCheckExtensions",
            [ext.strip() for ext in
             self.spellCheckTextFilesLineEdit.text().split()])
        
        self.saveColours(Preferences.setEditorColour)
        
        Preferences.setEditor(
            "SpellCheckingPersonalWordList", self.pwlPicker.text())
        Preferences.setEditor(
            "SpellCheckingPersonalExcludeList", self.pelPicker.text())
        
        Preferences.setEditor(
            "AutoSpellCheckingEnabled", self.enabledCheckBox.isChecked())
        Preferences.setEditor(
            "AutoSpellCheckChunkSize", self.chunkSizeSpinBox.value())


def create(dlg):
    """
    Module function to create the configuration page.
    
    @param dlg reference to the configuration dialog
    @return reference to the instantiated page (ConfigurationPageBase)
    """
    page = EditorSpellCheckingPage()
    return page

eric ide

mercurial