src/eric7/QScintilla/SpellCheckingDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2008 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the spell checking dialog.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog
12
13 from .Ui_SpellCheckingDialog import Ui_SpellCheckingDialog
14
15 import Utilities
16
17
18 class SpellCheckingDialog(QDialog, Ui_SpellCheckingDialog):
19 """
20 Class implementing the spell checking dialog.
21 """
22 def __init__(self, spellChecker, startPos, endPos, parent=None):
23 """
24 Constructor
25
26 @param spellChecker reference to the spell checker (SpellChecker)
27 @param startPos position to start spell checking (integer)
28 @param endPos end position for spell checking (integer)
29 @param parent reference to the parent widget (QWidget)
30 """
31 super().__init__(parent)
32 self.setupUi(self)
33
34 self.__spell = spellChecker
35 self.languageLabel.setText(
36 "<b>{0}</b>".format(self.__spell.getLanguage()))
37 if not self.__spell.initCheck(startPos, endPos):
38 self.__enableButtons(False)
39 else:
40 self.__advance()
41
42 def __enableButtons(self, enable):
43 """
44 Private method to set the buttons enabled state.
45
46 @param enable enable state (boolean)
47 """
48 self.addButton.setEnabled(enable)
49 self.ignoreButton.setEnabled(enable)
50 self.ignoreAllButton.setEnabled(enable)
51 self.replaceButton.setEnabled(enable)
52 self.replaceAllButton.setEnabled(enable)
53
54 def __advance(self):
55 """
56 Private method to advance to the next error.
57 """
58 try:
59 next(self.__spell)
60 except StopIteration:
61 self.__enableButtons(False)
62 self.contextLabel.setText("")
63 self.changeEdit.setText("")
64 self.suggestionsList.clear()
65 return
66
67 self.__enableButtons(True)
68 self.word, self.wordStart, self.wordEnd = self.__spell.getError()
69 lcontext, rcontext = self.__spell.getContext(
70 self.wordStart, self.wordEnd)
71 self.changeEdit.setText(self.word)
72 self.contextLabel.setText(
73 '{0}<font color="#FF0000">{1}</font>{2}'.format(
74 Utilities.html_encode(lcontext),
75 self.word,
76 Utilities.html_encode(rcontext)))
77 suggestions = self.__spell.getSuggestions(self.word)
78 self.suggestionsList.clear()
79 self.suggestionsList.addItems(suggestions)
80
81 @pyqtSlot(str)
82 def on_changeEdit_textChanged(self, text):
83 """
84 Private method to handle a change of the replacement text.
85
86 @param text contents of the line edit (string)
87 """
88 self.replaceButton.setEnabled(text != "")
89 self.replaceAllButton.setEnabled(text != "")
90
91 @pyqtSlot(str)
92 def on_suggestionsList_currentTextChanged(self, currentText):
93 """
94 Private method to handle the selection of a suggestion.
95
96 @param currentText the currently selected text (string)
97 """
98 if currentText:
99 self.changeEdit.setText(currentText)
100
101 @pyqtSlot()
102 def on_ignoreButton_clicked(self):
103 """
104 Private slot to ignore the found error.
105 """
106 self.__advance()
107
108 @pyqtSlot()
109 def on_ignoreAllButton_clicked(self):
110 """
111 Private slot to always ignore the found error.
112 """
113 self.__spell.ignoreAlways()
114 self.__advance()
115
116 @pyqtSlot()
117 def on_addButton_clicked(self):
118 """
119 Private slot to add the current word to the personal word list.
120 """
121 self.__spell.add()
122 self.__advance()
123
124 @pyqtSlot()
125 def on_replaceButton_clicked(self):
126 """
127 Private slot to replace the current word with the given replacement.
128 """
129 self.__spell.replace(self.changeEdit.text())
130 self.__advance()
131
132 @pyqtSlot()
133 def on_replaceAllButton_clicked(self):
134 """
135 Private slot to replace the current word with the given replacement.
136 """
137 self.__spell.replaceAlways(self.changeEdit.text())
138 self.__advance()

eric ide

mercurial