src/eric7/QScintilla/TypingCompleters/CompleterBase.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a base class for all typing completers.
8
9 Typing completers are classes that implement some convenience actions,
10 that are performed while the user is typing (e.g. insert ')' when the
11 user types '(').
12 """
13
14 from PyQt6.QtCore import QObject
15
16
17 class CompleterBase(QObject):
18 """
19 Class implementing the base class for all completers.
20 """
21 def __init__(self, editor, parent=None):
22 """
23 Constructor
24
25 @param editor reference to the editor object (QScintilla.Editor)
26 @param parent reference to the parent object (QObject)
27 If parent is None, we set the editor as the parent.
28 """
29 if parent is None:
30 parent = editor
31
32 super().__init__(parent)
33
34 self.editor = editor
35 self.enabled = False
36
37 def setEnabled(self, enable):
38 """
39 Public slot to set the enabled state.
40
41 @param enable flag indicating the new enabled state (boolean)
42 """
43 if enable:
44 if not self.enabled:
45 self.editor.SCN_CHARADDED.connect(self.charAdded)
46 else:
47 if self.enabled:
48 self.editor.SCN_CHARADDED.disconnect(self.charAdded)
49 self.enabled = enable
50
51 def isEnabled(self):
52 """
53 Public method to get the enabled state.
54
55 @return enabled state (boolean)
56 """
57 return self.enabled
58
59 def charAdded(self, charNumber):
60 """
61 Public slot called to handle the user entering a character.
62
63 Note 1: this slot must be overridden by subclasses implementing the
64 specific behavior for the language.
65
66 Note 2: charNumber can be greater than 255 because the editor is
67 in UTF-8 mode by default.
68
69 @param charNumber value of the character entered (integer)
70 """
71 pass # just do nothing
72
73 def readSettings(self):
74 """
75 Public slot called to reread the configuration parameters.
76
77 Note: this slot should be overridden by subclasses having
78 configurable parameters.
79 """
80 pass # just do nothing

eric ide

mercurial