eric6/QScintilla/TypingCompleters/CompleterBase.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2019 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 __future__ import unicode_literals
15
16 from PyQt5.QtCore import QObject
17
18
19 class CompleterBase(QObject):
20 """
21 Class implementing the base class for all completers.
22 """
23 def __init__(self, editor, parent=None):
24 """
25 Constructor
26
27 @param editor reference to the editor object (QScintilla.Editor)
28 @param parent reference to the parent object (QObject)
29 If parent is None, we set the editor as the parent.
30 """
31 if parent is None:
32 parent = editor
33
34 super(CompleterBase, self).__init__(parent)
35
36 self.editor = editor
37 self.enabled = False
38
39 def setEnabled(self, enable):
40 """
41 Public slot to set the enabled state.
42
43 @param enable flag indicating the new enabled state (boolean)
44 """
45 if enable:
46 if not self.enabled:
47 self.editor.SCN_CHARADDED.connect(self.charAdded)
48 else:
49 if self.enabled:
50 self.editor.SCN_CHARADDED.disconnect(self.charAdded)
51 self.enabled = enable
52
53 def isEnabled(self):
54 """
55 Public method to get the enabled state.
56
57 @return enabled state (boolean)
58 """
59 return self.enabled
60
61 def charAdded(self, charNumber):
62 """
63 Public slot called to handle the user entering a character.
64
65 Note 1: this slot must be overridden by subclasses implementing the
66 specific behavior for the language.
67
68 Note 2: charNumber can be greater than 255 because the editor is
69 in UTF-8 mode by default.
70
71 @param charNumber value of the character entered (integer)
72 """
73 pass # just do nothing
74
75 def readSettings(self):
76 """
77 Public slot called to reread the configuration parameters.
78
79 Note: this slot should be overridden by subclasses having
80 configurable parameters.
81 """
82 pass # just do nothing

eric ide

mercurial