eric7/EricWidgets/EricSpellCheckedTextEdit.py

Sat, 19 Jun 2021 12:17:17 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 19 Jun 2021 12:17:17 +0200
branch
eric7
changeset 8432
074407b4c107
parent 8431
bed315a45088
child 8629
1b58dc890b87
permissions
-rw-r--r--

Extended the spellcheck text edits to add and remove words from user specific dictionaries.

8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing QTextEdit and QPlainTextEdit widgets with embedded spell
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 checking.
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
11 import contextlib
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
13 try:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
14 import enchant
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
15 import enchant.tokenize
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
16 from enchant.errors import TokenizerNotFoundError, DictNotFoundError
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
17 from enchant.utils import trim_suggestions
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
18 ENCHANT_AVAILABLE = True
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
19 except ImportError:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
20 ENCHANT_AVAILABLE = False
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 from PyQt6.QtGui import (
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 QAction, QActionGroup, QSyntaxHighlighter, QTextBlockUserData,
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 QTextCharFormat, QTextCursor
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 )
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 from PyQt6.QtWidgets import QMenu, QTextEdit, QPlainTextEdit
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
29 if ENCHANT_AVAILABLE:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
30 class SpellCheckMixin():
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
32 Class implementing the spell-check mixin for the widget classes.
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
34 # don't show more than this to keep the menu manageable
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
35 MaxSuggestions = 20
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
36
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
37 # default language to be used when no other is set
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
38 DefaultLanguage = None
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
40 # default user lists
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
41 DefaultUserWordList = None
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
42 DefaultUserExceptionList = None
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
43
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
44 def __init__(self):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
45 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
46 Constructor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
47 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
48 self.__highlighter = EnchantHighlighter(self.document())
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
49 try:
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
50 # Start with a default dictionary based on the current locale
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
51 # or the configured default language.
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
52 spellDict = enchant.DictWithPWL(
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
53 SpellCheckMixin.DefaultLanguage,
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
54 SpellCheckMixin.DefaultUserWordList,
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
55 SpellCheckMixin.DefaultUserExceptionList
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
56 )
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
57 except DictNotFoundError:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
58 # Use English dictionary if no locale dictionary is available
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
59 # or the default one could not be found.
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
60 spellDict = enchant.DictWithPWL(
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
61 "en",
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
62 SpellCheckMixin.DefaultUserWordList,
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
63 SpellCheckMixin.DefaultUserExceptionList
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
64 )
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
65 self.__highlighter.setDict(spellDict)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
66
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
67 def contextMenuEvent(self, evt):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
68 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
69 Protected method to handle context menu events to add a spelling
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
70 suggestions submenu.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
71
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
72 @param evt reference to the context menu event
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
73 @type QContextMenuEvent
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
74 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
75 menu = self.__createSpellcheckContextMenu(evt.pos())
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
76 menu.exec(evt.globalPos())
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
78 def __createSpellcheckContextMenu(self, pos):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
79 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
80 Private method to create the spell-check context menu.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
81
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
82 @param pos position of the mouse pointer
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
83 @type QPoint
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
84 @return context menu with additional spell-check entries
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
85 @rtype QMenu
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
86 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
87 menu = self.createStandardContextMenu(pos)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
88
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
89 # Add a submenu for setting the spell-check language and
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
90 # document format.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
91 menu.addSeparator()
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
92 self.__addRemoveEntry(self.__cursorForPosition(pos), menu)
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
93 menu.addMenu(self.__createLanguagesMenu(menu))
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
94 menu.addMenu(self.__createFormatsMenu(menu))
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
95
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
96 # Try to retrieve a menu of corrections for the right-clicked word
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
97 spellMenu = self.__createCorrectionsMenu(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
98 self.__cursorForMisspelling(pos), menu)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
99
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
100 if spellMenu:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
101 menu.insertSeparator(menu.actions()[0])
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
102 menu.insertMenu(menu.actions()[0], spellMenu)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
103
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
104 return menu
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
106 def __createCorrectionsMenu(self, cursor, parent=None):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
107 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
108 Private method to create a menu for corrections of the selected
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
109 word.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
110
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
111 @param cursor reference to the text cursor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
112 @type QTextCursor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
113 @param parent reference to the parent widget (defaults to None)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
114 @type QWidget (optional)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
115 @return menu with corrections
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
116 @rtype QMenu
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
117 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
118 if cursor is None:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
119 return None
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
120
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
121 text = cursor.selectedText()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
122 suggestions = trim_suggestions(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
123 text, self.__highlighter.dict().suggest(text),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
124 SpellCheckMixin.MaxSuggestions)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
125
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
126 spellMenu = QMenu(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
127 QCoreApplication.translate("SpellCheckMixin",
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
128 "Spelling Suggestions"),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
129 parent)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
130 for word in suggestions:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
131 act = spellMenu.addAction(word)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
132 act.setData((cursor, word))
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
133
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
134 if suggestions:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
135 spellMenu.addSeparator()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
136
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
137 # add management entry
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
138 act = spellMenu.addAction(QCoreApplication.translate(
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
139 "SpellCheckMixin", "Add to Dictionary"))
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
140 act.setData((cursor, text, "add"))
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
141
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
142 spellMenu.triggered.connect(self.__spellMenuTriggered)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
143 return spellMenu
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
144
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
145 def __addRemoveEntry(self, cursor, menu):
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
146 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
147 Private method to create a menu entry to remove the word at the
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
148 menu position.
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
149
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
150 @param cursor reference to the text cursor for the misspelled word
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
151 @type QTextCursor
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
152 @param menu reference to the context menu
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
153 @type QMenu
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
154 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
155 if cursor is None:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
156 return
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
157
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
158 text = cursor.selectedText()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
159 menu.addAction(QCoreApplication.translate(
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
160 "SpellCheckMixin",
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
161 "Remove '{0}' from Dictionary").format(text),
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
162 lambda: self.__addToUserDict(text, "remove"))
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
164 def __createLanguagesMenu(self, parent=None):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
165 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
166 Private method to create a menu for selecting the spell-check
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
167 language.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
168
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
169 @param parent reference to the parent widget (defaults to None)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
170 @type QWidget (optional)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
171 @return menu with spell-check languages
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
172 @rtype QMenu
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
173 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
174 curLanguage = self.__highlighter.dict().tag.lower()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
175 languageMenu = QMenu(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
176 QCoreApplication.translate("SpellCheckMixin", "Language"),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
177 parent)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
178 languageActions = QActionGroup(languageMenu)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
179
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
180 for language in sorted(enchant.list_languages()):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
181 act = QAction(language, languageActions)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
182 act.setCheckable(True)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
183 act.setChecked(language.lower() == curLanguage)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
184 act.setData(language)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
185 languageMenu.addAction(act)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
186
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
187 languageMenu.triggered.connect(self.__setLanguage)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
188 return languageMenu
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
190 def __createFormatsMenu(self, parent=None):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
191 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
192 Private method to create a menu for selecting the document format.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
193
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
194 @param parent reference to the parent widget (defaults to None)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
195 @type QWidget (optional)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
196 @return menu with document formats
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
197 @rtype QMenu
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
198 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
199 formatMenu = QMenu(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
200 QCoreApplication.translate("SpellCheckMixin", "Format"),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
201 parent)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
202 formatActions = QActionGroup(formatMenu)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
203
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
204 curFormat = self.__highlighter.chunkers()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
205 for name, chunkers in (
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
206 (QCoreApplication.translate("SpellCheckMixin", "Text"),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
207 []),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
208 (QCoreApplication.translate("SpellCheckMixin", "HTML"),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
209 [enchant.tokenize.HTMLChunker])
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
210 ):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
211 act = QAction(name, formatActions)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
212 act.setCheckable(True)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
213 act.setChecked(chunkers == curFormat)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
214 act.setData(chunkers)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
215 formatMenu.addAction(act)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
216
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
217 formatMenu.triggered.connect(self.__setFormat)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
218 return formatMenu
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
220 def __cursorForPosition(self, pos):
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
221 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
222 Private method to create a text cursor selecting the word at the
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
223 given position.
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
224
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
225 @param pos position of the misspelled word
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
226 @type QPoint
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
227 @return text cursor for the word
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
228 @rtype QTextCursor
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
229 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
230 cursor = self.cursorForPosition(pos)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
231 cursor.select(QTextCursor.SelectionType.WordUnderCursor)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
232
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
233 if cursor.hasSelection():
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
234 return cursor
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
235 else:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
236 return None
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
237
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
238 def __cursorForMisspelling(self, pos):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
239 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
240 Private method to create a text cursor selecting the misspelled
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
241 word.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
242
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
243 @param pos position of the misspelled word
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
244 @type QPoint
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
245 @return text cursor for the misspelled word
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
246 @rtype QTextCursor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
247 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
248 cursor = self.cursorForPosition(pos)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
249 misspelledWords = getattr(cursor.block().userData(),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
250 "misspelled", [])
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
251
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
252 # If the cursor is within a misspelling, select the word
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
253 for (start, end) in misspelledWords:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
254 if start <= cursor.positionInBlock() <= end:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
255 blockPosition = cursor.block().position()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
256
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
257 cursor.setPosition(blockPosition + start,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
258 QTextCursor.MoveMode.MoveAnchor)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
259 cursor.setPosition(blockPosition + end,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
260 QTextCursor.MoveMode.KeepAnchor)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
261 break
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
262
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
263 if cursor.hasSelection():
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
264 return cursor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
265 else:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
266 return None
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
268 def __correctWord(self, cursor, word):
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
269 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
270 Private method to replace some misspelled text.
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
271
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
272 @param cursor reference to the text cursor for the misspelled word
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
273 @type QTextCursor
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
274 @param word replacement text
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
275 @type str
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
276 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
277 cursor.beginEditBlock()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
278 cursor.removeSelectedText()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
279 cursor.insertText(word)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
280 cursor.endEditBlock()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
281
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
282 def __addToUserDict(self, word, command):
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
283 """
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
284 Private method to add a word to the user word or exclude list.
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
285
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
286 @param word text to be added
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
287 @type str
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
288 @param command command indicating the user dictionary type
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
289 @type str
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
290 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
291 if word:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
292 dictionary = self.__highlighter.dict()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
293 if command == "add":
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
294 dictionary.add(word)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
295 elif command == "remove":
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
296 dictionary.remove(word)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
297
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
298 self.__highlighter.rehighlight()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
299
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
300 @pyqtSlot(QAction)
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
301 def __spellMenuTriggered(self, act):
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
302 """
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
303 Private slot to handle a selection of the spell menu.
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
304
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
305 @param act reference to the selected action
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
306 @type QAction
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
307 """
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
308 data = act.data()
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
309 if len(data) == 2:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
310 # replace the misspelled word
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
311 self.__correctWord(*data)
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
312
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
313 elif len(data) == 3:
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
314 # dictionary management action
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
315 _, word, command = data
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
316 self.__addToUserDict(word, command)
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
318 @pyqtSlot(QAction)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
319 def __setLanguage(self, act):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
320 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
321 Private slot to set the selected language.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
322
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
323 @param act reference to the selected action
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
324 @type QAction
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
325 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
326 language = act.data()
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
327 self.__highlighter.setDict(enchant.Dict(
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
328 language,
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
329 SpellCheckMixin.DefaultUserWordList,
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
330 SpellCheckMixin.DefaultUserExceptionList
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
331 ))
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
333 @pyqtSlot(QAction)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
334 def __setFormat(self, act):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
335 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
336 Private slot to set the selected document format.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
337
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
338 @param act reference to the selected action
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
339 @type QAction
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
340 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
341 chunkers = act.data()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
342 self.__highlighter.setChunkers(chunkers)
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
344 def setFormat(self, formatName):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
345 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
346 Public method to set the document format.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
347
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
348 @param formatName name of the document format
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
349 @type str
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
350 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
351 self.__highlighter.setChunkers(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
352 [enchant.tokenize.HTMLChunker]
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
353 if format == "html" else
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
354 []
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
355 )
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
357 def dict(self):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
358 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
359 Public method to get a reference to the dictionary in use.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
360
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
361 @return reference to the current dictionary
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
362 @rtype enchant.Dict
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
363 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
364 return self.__highlighter.dict()
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
366 def setDict(self, spellDict):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
367 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
368 Public method to set the dictionary to be used.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
369
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
370 @param spellDict reference to the spell-check dictionary
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
371 @type emchant.Dict
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
372 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
373 self.__highlighter.setDict(spellDict)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
374
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
375 @classmethod
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
376 def setDefaultLanguage(cls, language, pwl=None, pel=None):
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
377 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
378 Class method to set the default spell-check language.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
379
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
380 @param language language to be set as default
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
381 @type str
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
382 @param pwl file name of the personal word list
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
383 @type str
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
384 @param pel file name of the personal exclude list
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
385 @type str
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
386 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
387 with contextlib.suppress(DictNotFoundError):
8431
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
388 cls.DefaultUserWordList = pwl
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
389 cls.DefaultUserExceptionList = pel
bed315a45088 Started adding support for user word lists to the spell check text edits.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8428
diff changeset
390
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
391 # set default language only, if a dictionary is available
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
392 enchant.Dict(language)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
393 cls.DefaultLanguage = language
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
394
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
395 class EnchantHighlighter(QSyntaxHighlighter):
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
397 Class implementing a QSyntaxHighlighter subclass that consults a
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
398 pyEnchant dictionary to highlight misspelled words.
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
400 TokenFilters = (enchant.tokenize.EmailFilter,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
401 enchant.tokenize.URLFilter)
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
403 # Define the spell-check style once and just assign it as necessary
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
404 ErrorFormat = QTextCharFormat()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
405 ErrorFormat.setUnderlineColor(Qt.GlobalColor.red)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
406 ErrorFormat.setUnderlineStyle(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
407 QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
408
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
409 def __init__(self, *args):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
410 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
411 Constructor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
412
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
413 @param *args list of arguments for the QSyntaxHighlighter
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
414 @type list
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
415 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
416 QSyntaxHighlighter.__init__(self, *args)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
417
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
418 self.__spellDict = None
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
419 self.__chunkers = []
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
420
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
421 def chunkers(self):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
422 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
423 Public method to get the chunkers in use.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
424
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
425 @return list of chunkers in use
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
426 @rtype list
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
427 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
428 return self.__chunkers
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
429
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
430 def setChunkers(self, chunkers):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
431 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
432 Public method to set the chunkers to be used.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
433
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
434 @param chunkers chunkers to be used
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
435 @type list
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
436 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
437 self.__chunkers = chunkers
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
438 self.setDict(self.dict())
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
439
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
440 def dict(self):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
441 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
442 Public method to get the spelling dictionary in use.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
443
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
444 @return spelling dictionary
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
445 @rtype enchant.Dict
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
446 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
447 return self.__spellDict
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
449 def setDict(self, spellDict):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
450 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
451 Public method to set the spelling dictionary to be used.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
452
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
453 @param spellDict spelling dictionary
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
454 @type enchant.Dict
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
455 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
456 try:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
457 self.__tokenizer = enchant.tokenize.get_tokenizer(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
458 spellDict.tag,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
459 chunkers=self.__chunkers,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
460 filters=EnchantHighlighter.TokenFilters)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
461 except TokenizerNotFoundError:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
462 # Fall back to the "good for most euro languages"
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
463 # English tokenizer
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
464 self.__tokenizer = enchant.tokenize.get_tokenizer(
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
465 chunkers=self.__chunkers,
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
466 filters=EnchantHighlighter.TokenFilters)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
467 self.__spellDict = spellDict
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
468
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
469 self.rehighlight()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
470
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
471 def highlightBlock(self, text):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
472 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
473 Public method to apply the text highlight.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
474
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
475 @param text text to be spell-checked
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
476 @type str
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
477 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
478 """Overridden QSyntaxHighlighter method to apply the highlight"""
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
479 if not self.__spellDict:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
480 return
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
481
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
482 # Build a list of all misspelled words and highlight them
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
483 misspellings = []
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
484 for (word, pos) in self.__tokenizer(text):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
485 if not self.__spellDict.check(word):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
486 self.setFormat(pos, len(word),
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
487 EnchantHighlighter.ErrorFormat)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
488 misspellings.append((pos, pos + len(word)))
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
489
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
490 # Store the list so the context menu can reuse this tokenization
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
491 # pass (Block-relative values so editing other blocks won't
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
492 # invalidate them)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
493 data = QTextBlockUserData()
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
494 data.misspelled = misspellings
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
495 self.setCurrentBlockUserData(data)
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
497 class EricSpellCheckedPlainTextEdit(QPlainTextEdit, SpellCheckMixin):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
498 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
499 Class implementing a QPlainTextEdit with built-in spell checker.
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
501 def __init__(self, *args):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
502 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
503 Constructor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
504
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
505 @param *args list of arguments for the QPlainTextEdit constructor.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
506 @type list
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
507 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
508 QPlainTextEdit.__init__(self, *args)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
509 SpellCheckMixin.__init__(self)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
510
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
511 class EricSpellCheckedTextEdit(QTextEdit, SpellCheckMixin):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
512 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
513 Class implementing a QTextEdit with built-in spell checker.
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 """
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
515 def __init__(self, *args):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
516 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
517 Constructor
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
518
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
519 @param *args list of arguments for the QPlainTextEdit constructor.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
520 @type list
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
521 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
522 QTextEdit.__init__(self, *args)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
523 SpellCheckMixin.__init__(self)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
524
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
525 self.setFormat("html")
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
527 def setAcceptRichText(self, accept):
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
528 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
529 Public method to set the text edit mode.
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
530
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
531 @param accept flag indicating to accept rich text
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
532 @type bool
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
533 """
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
534 QTextEdit.setAcceptRichText(self, accept)
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
535 self.setFormat("html" if accept else "text")
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
536 else:
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
537 # enchant not available
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
538 EricSpellCheckedPlainTextEdit = QPlainTextEdit
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
539 EricSpellCheckedTextEdit = QTextEdit
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 if __name__ == '__main__':
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
542 import sys
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
543 import os
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 from PyQt6.QtWidgets import QApplication
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
546 if ENCHANT_AVAILABLE:
8432
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
547 dictPath = os.path.expanduser(os.path.join("~", ".eric7", "spelling"))
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
548 SpellCheckMixin.setDefaultLanguage(
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
549 "en_US",
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
550 os.path.join(dictPath, "pwl.dic"),
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
551 os.path.join(dictPath, "pel.dic")
074407b4c107 Extended the spellcheck text edits to add and remove words from user specific dictionaries.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8431
diff changeset
552 )
8428
2deec2f8a9ab Changed some dialogs to use the new QTextEdit and QPlainTextEdit subclasses with spell checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8427
diff changeset
553
8427
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 app = QApplication(sys.argv)
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 spellEdit = EricSpellCheckedPlainTextEdit()
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 spellEdit.show()
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557
5ccf32f95805 EricWidgets: added a QTextEdit and QPlainTextEdit subclass with built-in spell-checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 sys.exit(app.exec())

eric ide

mercurial