Debian Codegraph @

lib/spellcheck.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 from PyQt5 import QtGui
21
22 # TODO Enchant supports OpenOffice dictionaries, make it easy to use them on Windows
23 # TODO custom words
24 # TODO integrate into the text editor's context menu
25
26
27 class SpellCheckHighlighter(QtGui.QSyntaxHighlighter):
28
29 def __init__(self, document, checker):
30 QtGui.QSyntaxHighlighter.__init__(self, document)
31 self.checker = checker
32 self.format = QtGui.QTextCharFormat()
33 self.format.setUnderlineColor(QtGui.QColor('red'))
34 self.format.setUnderlineStyle(QtGui.QTextCharFormat.SpellCheckUnderline)
35
36 def highlightBlock(self, text):
37 for index, length in self.checker.check(str(text)):
38 self.setFormat(index, length, self.format)
39
40
41 class DummySpellChecker(object):
42
43 def __init__(self, language):
44 pass
45
46 def check(self, text):
47 return []
48
49 def suggest(self, text):
50 return []
51
52 @classmethod
53 def list_languages(cls):
54 return []
55
56
57 try:
58 from breezy.plugins.qbrz.lib.spellcheck_enchant import EnchantSpellChecker as SpellChecker
59 except ImportError:
60 SpellChecker = DummySpellChecker