src/eric7/QScintilla/SpellCheckingDialog.py

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

eric ide

mercurial