QScintilla/SpellCheckingDialog.py

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

eric ide

mercurial