Tue, 10 Dec 2024 15:46:34 +0100
Updated copyright for 2025.
7998 | 1 | # -*- coding: utf-8 -*- |
2 | ||
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
3 | # Copyright (c) 2021 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
7998 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a docstring generator base class. | |
8 | """ | |
9 | ||
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10078
diff
changeset
|
10 | import contextlib |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
11 | import importlib |
7998 | 12 | import re |
13 | ||
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
14 | from PyQt6.QtCore import Qt |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
15 | from PyQt6.QtWidgets import QMenu |
7998 | 16 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
17 | from eric7 import Preferences |
9413
80c06d472826
Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
18 | from eric7.EricWidgets.EricApplication import ericApp |
7998 | 19 | |
20 | ||
21 | def getIndentStr(text): | |
22 | """ | |
23 | Function to get the indentation of a text. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
7998 | 25 | @param text text to extract indentation from |
26 | @type str | |
27 | @return indentation string | |
28 | @rtype str | |
29 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
30 | indent = "" |
7998 | 31 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
32 | ret = re.match(r"(\s*)", text) |
7998 | 33 | if ret: |
34 | indent = ret.group(1) | |
35 | ||
36 | return indent | |
37 | ||
38 | ||
8207
d359172d11be
Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
39 | class BaseDocstringGenerator: |
7998 | 40 | """ |
41 | Class implementing a docstring generator base class. | |
42 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
43 | |
7998 | 44 | def __init__(self, editor): |
45 | """ | |
46 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | |
7998 | 48 | @param editor reference to the editor widget |
49 | @type Editor | |
50 | """ | |
51 | self.editor = editor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
10069
435cc5875135
Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
53 | def isFunctionStart(self, text): # noqa: U100 |
7998 | 54 | """ |
55 | Public method to test, if a text is the start of a function or method | |
56 | definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
57 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
58 | @param text line of text to be tested (unused) |
7998 | 59 | @type str |
60 | @return flag indicating that the given text starts a function or | |
61 | method definition (always False) | |
62 | @rtype bool | |
63 | """ | |
64 | return False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | |
10069
435cc5875135
Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
66 | def hasFunctionDefinition(self, cursorPosition): # noqa: U100 |
7998 | 67 | """ |
68 | Public method to test, if the cursor is right below a function | |
69 | definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
70 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
71 | @param cursorPosition current cursor position (line and column) (unused) |
7998 | 72 | @type tuple of (int, int) |
73 | @return flag indicating cursor is right below a function definition | |
74 | @rtype bool | |
75 | """ | |
76 | return False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | |
10069
435cc5875135
Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
78 | def isDocstringIntro(self, cursorPosition): # noqa: U100 |
7998 | 79 | """ |
80 | Public function to test, if the line up to the cursor position might be | |
81 | introducing a docstring. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
83 | @param cursorPosition current cursor position (line and column) (unused) |
7998 | 84 | @type tuple of (int, int) |
85 | @return flag indicating a potential start of a docstring | |
86 | @rtype bool | |
87 | """ | |
88 | return False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | |
10069
435cc5875135
Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
90 | def insertDocstring(self, cursorPosition, fromStart=True): # noqa: U100 |
7998 | 91 | """ |
92 | Public method to insert a docstring for the function at the cursor | |
93 | position. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
95 | @param cursorPosition position of the cursor (line and index) (unused) |
7998 | 96 | @type tuple of (int, int) |
97 | @param fromStart flag indicating that the editor text cursor is placed | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
98 | on the line starting the function definition (unused) |
7998 | 99 | @type bool |
100 | """ | |
101 | # just do nothing in the base class | |
102 | return | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
103 | |
10069
435cc5875135
Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
104 | def insertDocstringFromShortcut(self, cursorPosition): # noqa: U100 |
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
|
105 | """ |
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 | 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
|
107 | position initiated via a keyboard shortcut. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
108 | |
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10665
diff
changeset
|
109 | @param cursorPosition position of the cursor (line and index) (unused) |
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
|
110 | @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
|
111 | """ |
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 | # 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
|
113 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
114 | |
7998 | 115 | def getDocstringType(self): |
116 | """ | |
117 | Public method to determine the docstring type to be generated. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | |
7998 | 119 | @return docstring type (one of 'ericdoc', 'numpydoc', 'googledoc', |
120 | 'sphinxdoc') | |
121 | @rtype str | |
122 | """ | |
123 | docstringStyle = "" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
125 | project = ericApp().getObject("Project") |
7998 | 126 | filename = self.editor.getFileName() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
127 | if filename and project.isOpen() and project.isProjectFile(filename): |
7998 | 128 | docstringStyle = project.getDocstringType().lower() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
129 | |
7998 | 130 | if docstringStyle == "": |
131 | docstringStyle = Preferences.getEditor("DocstringType") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | |
7998 | 133 | return docstringStyle |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
134 | |
7998 | 135 | def _generateDocstringList(self, functionInfo, docstringType): |
136 | """ | |
137 | Protected method to generate type specific docstrings based on the | |
138 | extracted function information. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
139 | |
7998 | 140 | @param functionInfo reference to the function info object |
141 | @type FunctionInfo | |
142 | @param docstringType kind of docstring to be generated | |
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10078
diff
changeset
|
143 | @type str |
7998 | 144 | @return list of docstring lines |
145 | @rtype str | |
146 | """ | |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
147 | generatorModuleMapping = { |
9497
8beca4047c53
Modified most of the importlib.import_module() calls to use relative imports.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9486
diff
changeset
|
148 | "ericdoc": ".EricdocGenerator", |
8beca4047c53
Modified most of the importlib.import_module() calls to use relative imports.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9486
diff
changeset
|
149 | "numpydoc": ".NumpydocGenerator", |
10665
66564661c3b5
Fixed a type in the docstring generator causing 'googledoc' type to fail.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
150 | "googledoc": ".GoogledocGenerator", |
9497
8beca4047c53
Modified most of the importlib.import_module() calls to use relative imports.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9486
diff
changeset
|
151 | "sphinxdoc": ".SphinxdocGenerator", |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
152 | } |
10431
64157aeb0312
Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10078
diff
changeset
|
153 | with contextlib.suppress(KeyError): |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
154 | mod = importlib.import_module( |
9497
8beca4047c53
Modified most of the importlib.import_module() calls to use relative imports.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9486
diff
changeset
|
155 | generatorModuleMapping[docstringType], __package__ |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
156 | ) |
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
157 | return mod.generateDoc(functionInfo, self.editor) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
158 | |
9486
5a8179763e38
Changed docstring generator imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9482
diff
changeset
|
159 | return [] |
7998 | 160 | |
161 | ||
8207
d359172d11be
Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8143
diff
changeset
|
162 | class FunctionInfo: |
7998 | 163 | """ |
164 | Class implementing an object to store function information. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
165 | |
7998 | 166 | Methods to extract the relevant information need to be implemented in |
167 | language specific subclasses. | |
168 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
169 | |
7998 | 170 | def __init__(self): |
171 | """ | |
172 | Constructor | |
173 | """ | |
174 | self.hasInfo = False | |
175 | self.funcionText = "" | |
176 | self.argumentsText = "" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
177 | |
10078
9ebe2183cf49
Improved the Python docstring generator with respect to Qt event handler methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
178 | self.functionName = "" |
9ebe2183cf49
Improved the Python docstring generator with respect to Qt event handler methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
179 | # name of the function |
7998 | 180 | self.functionIndent = "" |
181 | # indentation fo function definition | |
182 | self.argumentsList = [] | |
183 | # list of tuples with name, type and value | |
184 | self.returnTypeAnnotated = None | |
185 | # return type extracted from type annotation | |
186 | self.returnValueInBody = [] | |
187 | # return values extracted from function body | |
188 | self.raiseList = None | |
189 | # exceptions raised by function | |
190 | self.hasYield = False | |
191 | # function is a generator | |
192 | self.functionType = "" | |
193 | # function type with these values | |
194 | # classmethod, staticmethod, qtslot, constructor or empty (i.e. | |
195 | # standard) | |
196 | self.isAsync = False | |
197 | # function is an asynchronous function, i.e. async def f(): | |
198 | self.visibility = "" | |
199 | # function visibility with allowed values: | |
200 | # public, protected, private or special (i.e. starting and | |
201 | # ending with '__' | |
10078
9ebe2183cf49
Improved the Python docstring generator with respect to Qt event handler methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
202 | self.eventHandler = False |
9ebe2183cf49
Improved the Python docstring generator with respect to Qt event handler methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10069
diff
changeset
|
203 | # function is an event handler method |
7998 | 204 | |
9500
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
205 | def parseDefinition(self, text, quote, quoteReplace): |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
206 | """ |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
207 | Public method to parse the function definition text. |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
208 | |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
209 | Note: This method should be overwritten in subclasses. |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
210 | |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
211 | @param text text containing the function definition |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
212 | @type str |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
213 | @param quote quote string to be replaced |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
214 | @type str |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
215 | @param quoteReplace quote string to replace the original |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
216 | @type str |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
217 | """ |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
218 | pass |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
219 | |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
220 | def parseBody(self, text): |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
221 | """ |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
222 | Public method to parse the function body text. |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
223 | |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
224 | Note: This method should be overwritten in subclasses. |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
225 | |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
226 | @param text function body text |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
227 | @type str |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
228 | """ |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
229 | pass |
5771348ded12
Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9497
diff
changeset
|
230 | |
7998 | 231 | |
232 | class DocstringMenuForEnterOnly(QMenu): | |
233 | """ | |
234 | Class implementing a special menu reacting to the enter/return keys only. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
235 | |
7998 | 236 | If a keyboard input is not the "enter key", the menu is closed and the |
237 | input is inserted to the code editor. | |
238 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
239 | |
7998 | 240 | def __init__(self, editor): |
241 | """ | |
242 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
243 | |
7998 | 244 | @param editor reference to the editor |
245 | @type Editor | |
246 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
247 | super().__init__(editor) |
7998 | 248 | self.__editor = editor |
249 | ||
250 | def keyPressEvent(self, evt): | |
251 | """ | |
252 | Protected method to handle key press events. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
253 | |
7998 | 254 | @param evt reference to the key press event object |
255 | @type QKeyEvent | |
256 | """ | |
257 | 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
|
258 | if key not in (Qt.Key.Key_Enter, Qt.Key.Key_Return): |
7998 | 259 | self.__editor.keyPressEvent(evt) |
260 | self.close() | |
261 | else: | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8207
diff
changeset
|
262 | super().keyPressEvent(evt) |