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