eric6/QScintilla/DocstringGenerator/BaseDocstringGenerator.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 8000
47b15df088e4
child 8207
d359172d11be
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

7998
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a docstring generator base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import re
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtCore import Qt
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtWidgets import QMenu
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui.E5Application import e5App
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Preferences
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def getIndentStr(text):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Function to get the indentation of a text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param text text to extract indentation from
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @type str
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @return indentation string
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @rtype str
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 indent = ''
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 ret = re.match(r'(\s*)', text)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 if ret:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 indent = ret.group(1)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 return indent
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 class BaseDocstringGenerator(object):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Class implementing a docstring generator base class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 def __init__(self, editor):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Constructor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param editor reference to the editor widget
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @type Editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.editor = editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 def isFunctionStart(self, text):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Public method to test, if a text is the start of a function or method
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @param text line of text to be tested
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @type str
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @return flag indicating that the given text starts a function or
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 method definition (always False)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @rtype bool
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 return False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def hasFunctionDefinition(self, cursorPosition):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Public method to test, if the cursor is right below a function
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param cursorPosition current cursor position (line and column)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @type tuple of (int, int)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @return flag indicating cursor is right below a function definition
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @rtype bool
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 def isDocstringIntro(self, cursorPosition):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Public function to test, if the line up to the cursor position might be
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 introducing a docstring.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @param cursorPosition current cursor position (line and column)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @type tuple of (int, int)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @return flag indicating a potential start of a docstring
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @rtype bool
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 return False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 def insertDocstring(self, cursorPosition, fromStart=True):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Public method to insert a docstring for the function at the cursor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 position.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @param cursorPosition position of the cursor (line and index)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @type tuple of (int, int)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 @param fromStart flag indicating that the editor text cursor is placed
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 on the line starting the function definition
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @type bool
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 # just do nothing in the base class
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return
8000
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
101
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
102 def insertDocstringFromShortcut(self, cursorPosition):
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
103 """
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
104 Public method to insert a docstring for the function at the cursor
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
105 position initiated via a keyboard shortcut.
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
106
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
107 @param cursorPosition position of the cursor (line and index)
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
108 @type tuple of (int, int)
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
109 """
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
110 # just do nothing in the base class
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
111 return
47b15df088e4 Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7998
diff changeset
112
7998
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 def getDocstringType(self):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 Public method to determine the docstring type to be generated.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @return docstring type (one of 'ericdoc', 'numpydoc', 'googledoc',
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 'sphinxdoc')
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @rtype str
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 docstringStyle = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 project = e5App().getObject("Project")
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 filename = self.editor.getFileName()
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 if (
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 filename and
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 project.isOpen() and
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 project.isProjectFile(filename)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 ):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 docstringStyle = project.getDocstringType().lower()
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 if docstringStyle == "":
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 docstringStyle = Preferences.getEditor("DocstringType")
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 return docstringStyle
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 def _generateDocstringList(self, functionInfo, docstringType):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 Protected method to generate type specific docstrings based on the
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 extracted function information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 @param functionInfo reference to the function info object
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 @type FunctionInfo
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @param docstringType kind of docstring to be generated
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @return list of docstring lines
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @rtype str
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 if docstringType == "ericdoc":
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 from .EricdocGenerator import generateEricDoc
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return generateEricDoc(functionInfo)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 elif docstringType == "numpydoc":
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 from .NumpydocGenerator import generateNumpyDoc
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 return generateNumpyDoc(functionInfo)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 elif docstringType == "googledoc":
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 from .GoogledocGenerator import generateGoogleDoc
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 return generateGoogleDoc(functionInfo, self.editor)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 elif docstringType == "sphinxdoc":
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 from .SphinxdocGenerator import generateSphinxDoc
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 return generateSphinxDoc(functionInfo)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 else:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 return []
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 class FunctionInfo(object):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Class implementing an object to store function information.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Methods to extract the relevant information need to be implemented in
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 language specific subclasses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 def __init__(self):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 Constructor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.hasInfo = False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.funcionText = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.argumentsText = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.functionIndent = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 # indentation fo function definition
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.argumentsList = []
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 # list of tuples with name, type and value
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.returnTypeAnnotated = None
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 # return type extracted from type annotation
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.returnValueInBody = []
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 # return values extracted from function body
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.raiseList = None
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 # exceptions raised by function
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.hasYield = False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 # function is a generator
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.functionType = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 # function type with these values
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 # classmethod, staticmethod, qtslot, constructor or empty (i.e.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 # standard)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.isAsync = False
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 # function is an asynchronous function, i.e. async def f():
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.visibility = ""
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 # function visibility with allowed values:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 # public, protected, private or special (i.e. starting and
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 # ending with '__'
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 class DocstringMenuForEnterOnly(QMenu):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 Class implementing a special menu reacting to the enter/return keys only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 If a keyboard input is not the "enter key", the menu is closed and the
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 input is inserted to the code editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 def __init__(self, editor):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Constructor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @param editor reference to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 @type Editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 super(DocstringMenuForEnterOnly, self).__init__(editor)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 self.__editor = editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 def keyPressEvent(self, evt):
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 Protected method to handle key press events.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 @param evt reference to the key press event object
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 @type QKeyEvent
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 """
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 key = evt.key()
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8000
diff changeset
228 if key not in (Qt.Key.Key_Enter, Qt.Key.Key_Return):
7998
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 self.__editor.keyPressEvent(evt)
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 self.close()
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 else:
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 super(DocstringMenuForEnterOnly, self).keyPressEvent(evt)

eric ide

mercurial