Documentation/Source/eric6.UI.PythonAstViewer.html

changeset 6935
71627b93aebc
equal deleted inserted replaced
6934:eae7d1d9cc7b 6935:71627b93aebc
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.UI.PythonAstViewer</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body><a NAME="top" ID="top"></a>
22 <h1>eric6.UI.PythonAstViewer</h1>
23 <p>
24 Module implementing a widget to visualize the Python AST for some Python
25 sources.
26 </p>
27 <h3>Global Attributes</h3>
28 <table>
29 <tr><td>None</td></tr>
30 </table>
31 <h3>Classes</h3>
32 <table>
33 <tr>
34 <td><a href="#PythonAstViewer">PythonAstViewer</a></td>
35 <td>Class implementing a widget to visualize the Python AST for some Python sources.</td>
36 </tr>
37 </table>
38 <h3>Functions</h3>
39 <table>
40 <tr><td>None</td></tr>
41 </table>
42 <hr /><hr />
43 <a NAME="PythonAstViewer" ID="PythonAstViewer"></a>
44 <h2>PythonAstViewer</h2>
45 <p>
46 Class implementing a widget to visualize the Python AST for some Python
47 sources.
48 </p>
49 <h3>Derived from</h3>
50 QWidget
51 <h3>Class Attributes</h3>
52 <table>
53 <tr><td>EndIndexRole</td></tr><tr><td>EndLineRole</td></tr><tr><td>StartIndexRole</td></tr><tr><td>StartLineRole</td></tr>
54 </table>
55 <h3>Class Methods</h3>
56 <table>
57 <tr><td>None</td></tr>
58 </table>
59 <h3>Methods</h3>
60 <table>
61 <tr>
62 <td><a href="#PythonAstViewer.__init__">PythonAstViewer</a></td>
63 <td>Constructor</td>
64 </tr><tr>
65 <td><a href="#PythonAstViewer.__astItemClicked">__astItemClicked</a></td>
66 <td>Private slot handling a user click on an AST node item.</td>
67 </tr><tr>
68 <td><a href="#PythonAstViewer.__astViewerStateChanged">__astViewerStateChanged</a></td>
69 <td>Private slot to toggle the display of the AST viewer.</td>
70 </tr><tr>
71 <td><a href="#PythonAstViewer.__clearSelection">__clearSelection</a></td>
72 <td>Private method to clear all selected items.</td>
73 </tr><tr>
74 <td><a href="#PythonAstViewer.__createErrorItem">__createErrorItem</a></td>
75 <td>Private method to create a top level error item.</td>
76 </tr><tr>
77 <td><a href="#PythonAstViewer.__editorChanged">__editorChanged</a></td>
78 <td>Private slot to handle a change of the current editor.</td>
79 </tr><tr>
80 <td><a href="#PythonAstViewer.__editorDoubleClicked">__editorDoubleClicked</a></td>
81 <td>Private slot to handle a mouse button double click in the editor.</td>
82 </tr><tr>
83 <td><a href="#PythonAstViewer.__editorSaved">__editorSaved</a></td>
84 <td>Private slot to reload the AST after the connected editor was saved.</td>
85 </tr><tr>
86 <td><a href="#PythonAstViewer.__findClosestContainingItem">__findClosestContainingItem</a></td>
87 <td>Private method to search for the tree item that contains a range closest.</td>
88 </tr><tr>
89 <td><a href="#PythonAstViewer.__findClosestContainingNode">__findClosestContainingNode</a></td>
90 <td>Private method to search for the AST node that contains a range closest.</td>
91 </tr><tr>
92 <td><a href="#PythonAstViewer.__grabFocus">__grabFocus</a></td>
93 <td>Private method to grab the input focus.</td>
94 </tr><tr>
95 <td><a href="#PythonAstViewer.__lastEditorClosed">__lastEditorClosed</a></td>
96 <td>Private slot to handle the last editor closed signal of the view manager.</td>
97 </tr><tr>
98 <td><a href="#PythonAstViewer.__loadAST">__loadAST</a></td>
99 <td>Private method to generate the AST from the source of the current editor and visualize it.</td>
100 </tr><tr>
101 <td><a href="#PythonAstViewer.__markTextRanges">__markTextRanges</a></td>
102 <td>Private method to modify the AST nodes with end_lineno and end_col_offset information.</td>
103 </tr><tr>
104 <td><a href="#PythonAstViewer.__populateNode">__populateNode</a></td>
105 <td>Private method to populate the tree view with a node.</td>
106 </tr><tr>
107 <td><a href="#PythonAstViewer.__rangeContainsSmaller">__rangeContainsSmaller</a></td>
108 <td>Private method to check, if second is contained in first.</td>
109 </tr><tr>
110 <td><a href="#PythonAstViewer.__rangeContainsSmallerOrEqual">__rangeContainsSmallerOrEqual</a></td>
111 <td>Private method to check, if second is contained in or equal to first.</td>
112 </tr><tr>
113 <td><a href="#PythonAstViewer.__resizeColumns">__resizeColumns</a></td>
114 <td>Private method to resize the columns to suitable values.</td>
115 </tr><tr>
116 <td><a href="#PythonAstViewer.__selectItemForEditorSelection">__selectItemForEditorSelection</a></td>
117 <td>Private slot to select the item corresponding to an editor selection.</td>
118 </tr><tr>
119 <td><a href="#PythonAstViewer.hide">hide</a></td>
120 <td>Public slot to hide the AST viewer.</td>
121 </tr><tr>
122 <td><a href="#PythonAstViewer.resizeEvent">resizeEvent</a></td>
123 <td>Protected method to handle resize events.</td>
124 </tr><tr>
125 <td><a href="#PythonAstViewer.show">show</a></td>
126 <td>Public slot to show the AST viewer.</td>
127 </tr><tr>
128 <td><a href="#PythonAstViewer.shutdown">shutdown</a></td>
129 <td>Public method to perform shutdown actions.</td>
130 </tr>
131 </table>
132 <h3>Static Methods</h3>
133 <table>
134 <tr><td>None</td></tr>
135 </table>
136 <a NAME="PythonAstViewer.__init__" ID="PythonAstViewer.__init__"></a>
137 <h4>PythonAstViewer (Constructor)</h4>
138 <b>PythonAstViewer</b>(<i>viewmanager, parent=None</i>)
139 <p>
140 Constructor
141 </p><dl>
142 <dt><i>viewmanager</i> (ViewManager)</dt>
143 <dd>
144 reference to the viewmanager object
145 </dd><dt><i>parent</i> (QWidget)</dt>
146 <dd>
147 reference to the parent widget
148 </dd>
149 </dl><a NAME="PythonAstViewer.__astItemClicked" ID="PythonAstViewer.__astItemClicked"></a>
150 <h4>PythonAstViewer.__astItemClicked</h4>
151 <b>__astItemClicked</b>(<i>itm, column</i>)
152 <p>
153 Private slot handling a user click on an AST node item.
154 </p><dl>
155 <dt><i>itm</i> (QTreeWidgetItem)</dt>
156 <dd>
157 reference to the clicked item
158 </dd><dt><i>column</i> (int)</dt>
159 <dd>
160 column number of the click
161 </dd>
162 </dl><a NAME="PythonAstViewer.__astViewerStateChanged" ID="PythonAstViewer.__astViewerStateChanged"></a>
163 <h4>PythonAstViewer.__astViewerStateChanged</h4>
164 <b>__astViewerStateChanged</b>(<i>on</i>)
165 <p>
166 Private slot to toggle the display of the AST viewer.
167 </p><dl>
168 <dt><i>on</i> (bool)</dt>
169 <dd>
170 flag indicating to show the AST
171 </dd>
172 </dl><a NAME="PythonAstViewer.__clearSelection" ID="PythonAstViewer.__clearSelection"></a>
173 <h4>PythonAstViewer.__clearSelection</h4>
174 <b>__clearSelection</b>(<i></i>)
175 <p>
176 Private method to clear all selected items.
177 </p><a NAME="PythonAstViewer.__createErrorItem" ID="PythonAstViewer.__createErrorItem"></a>
178 <h4>PythonAstViewer.__createErrorItem</h4>
179 <b>__createErrorItem</b>(<i>error</i>)
180 <p>
181 Private method to create a top level error item.
182 </p><dl>
183 <dt><i>error</i> (str)</dt>
184 <dd>
185 error message
186 </dd>
187 </dl><dl>
188 <dt>Returns:</dt>
189 <dd>
190 generated item
191 </dd>
192 </dl><dl>
193 <dt>Return Type:</dt>
194 <dd>
195 QTreeWidgetItem
196 </dd>
197 </dl><a NAME="PythonAstViewer.__editorChanged" ID="PythonAstViewer.__editorChanged"></a>
198 <h4>PythonAstViewer.__editorChanged</h4>
199 <b>__editorChanged</b>(<i>editor</i>)
200 <p>
201 Private slot to handle a change of the current editor.
202 </p><dl>
203 <dt><i>editor</i> (Editor)</dt>
204 <dd>
205 reference to the current editor
206 </dd>
207 </dl><a NAME="PythonAstViewer.__editorDoubleClicked" ID="PythonAstViewer.__editorDoubleClicked"></a>
208 <h4>PythonAstViewer.__editorDoubleClicked</h4>
209 <b>__editorDoubleClicked</b>(<i>editor, pos, buttons</i>)
210 <p>
211 Private slot to handle a mouse button double click in the editor.
212 </p><dl>
213 <dt><i>editor</i> (Editor)</dt>
214 <dd>
215 reference to the editor, that emitted the signal
216 </dd><dt><i>pos</i> (QPoint)</dt>
217 <dd>
218 position of the double click
219 </dd><dt><i>buttons</i> (Qt.MouseButtons)</dt>
220 <dd>
221 mouse buttons that were double clicked
222 </dd>
223 </dl><a NAME="PythonAstViewer.__editorSaved" ID="PythonAstViewer.__editorSaved"></a>
224 <h4>PythonAstViewer.__editorSaved</h4>
225 <b>__editorSaved</b>(<i>editor</i>)
226 <p>
227 Private slot to reload the AST after the connected editor was saved.
228 </p><dl>
229 <dt><i>editor</i> (Editor)</dt>
230 <dd>
231 reference to the editor that performed a save action
232 </dd>
233 </dl><a NAME="PythonAstViewer.__findClosestContainingItem" ID="PythonAstViewer.__findClosestContainingItem"></a>
234 <h4>PythonAstViewer.__findClosestContainingItem</h4>
235 <b>__findClosestContainingItem</b>(<i>itm, textRange</i>)
236 <p>
237 Private method to search for the tree item that contains a range
238 closest.
239 </p><dl>
240 <dt><i>itm</i> (QTreeWidgetItem)</dt>
241 <dd>
242 tree item to start searching at
243 </dd><dt><i>textRange</i> (tuple of (int, int, int, int))</dt>
244 <dd>
245 tuple giving the start and end positions
246 </dd>
247 </dl><dl>
248 <dt>Returns:</dt>
249 <dd>
250 best matching tree item
251 </dd>
252 </dl><dl>
253 <dt>Return Type:</dt>
254 <dd>
255 QTreeWidgetItem
256 </dd>
257 </dl><a NAME="PythonAstViewer.__findClosestContainingNode" ID="PythonAstViewer.__findClosestContainingNode"></a>
258 <h4>PythonAstViewer.__findClosestContainingNode</h4>
259 <b>__findClosestContainingNode</b>(<i>node, textRange</i>)
260 <p>
261 Private method to search for the AST node that contains a range
262 closest.
263 </p><dl>
264 <dt><i>node</i> (ast.AST)</dt>
265 <dd>
266 AST node to start searching at
267 </dd><dt><i>textRange</i> (tuple of (int, int, int, int))</dt>
268 <dd>
269 tuple giving the start and end positions
270 </dd>
271 </dl><dl>
272 <dt>Returns:</dt>
273 <dd>
274 best matching node
275 </dd>
276 </dl><dl>
277 <dt>Return Type:</dt>
278 <dd>
279 ast.AST
280 </dd>
281 </dl><a NAME="PythonAstViewer.__grabFocus" ID="PythonAstViewer.__grabFocus"></a>
282 <h4>PythonAstViewer.__grabFocus</h4>
283 <b>__grabFocus</b>(<i></i>)
284 <p>
285 Private method to grab the input focus.
286 </p><a NAME="PythonAstViewer.__lastEditorClosed" ID="PythonAstViewer.__lastEditorClosed"></a>
287 <h4>PythonAstViewer.__lastEditorClosed</h4>
288 <b>__lastEditorClosed</b>(<i></i>)
289 <p>
290 Private slot to handle the last editor closed signal of the view
291 manager.
292 </p><a NAME="PythonAstViewer.__loadAST" ID="PythonAstViewer.__loadAST"></a>
293 <h4>PythonAstViewer.__loadAST</h4>
294 <b>__loadAST</b>(<i></i>)
295 <p>
296 Private method to generate the AST from the source of the current
297 editor and visualize it.
298 </p><a NAME="PythonAstViewer.__markTextRanges" ID="PythonAstViewer.__markTextRanges"></a>
299 <h4>PythonAstViewer.__markTextRanges</h4>
300 <b>__markTextRanges</b>(<i>tree, source</i>)
301 <p>
302 Private method to modify the AST nodes with end_lineno and
303 end_col_offset information.
304 </p><p>
305 Note: The modifications are only done for nodes containing lineno and
306 col_offset attributes.
307 </p><dl>
308 <dt><i>tree</i> (ast.AST)</dt>
309 <dd>
310 reference to the AST to be modified
311 </dd><dt><i>source</i> (str)</dt>
312 <dd>
313 source code the AST was created from
314 </dd>
315 </dl><a NAME="PythonAstViewer.__populateNode" ID="PythonAstViewer.__populateNode"></a>
316 <h4>PythonAstViewer.__populateNode</h4>
317 <b>__populateNode</b>(<i>name, nodeOrFields, parent</i>)
318 <p>
319 Private method to populate the tree view with a node.
320 </p><dl>
321 <dt><i>name</i> (str)</dt>
322 <dd>
323 name of the node
324 </dd><dt><i>nodeOrFields</i> (ast.AST or list)</dt>
325 <dd>
326 reference to the node or a list node fields
327 </dd><dt><i>parent</i> (QTreeWidget or QTreeWidgetItem)</dt>
328 <dd>
329 reference to the parent item
330 </dd>
331 </dl><a NAME="PythonAstViewer.__rangeContainsSmaller" ID="PythonAstViewer.__rangeContainsSmaller"></a>
332 <h4>PythonAstViewer.__rangeContainsSmaller</h4>
333 <b>__rangeContainsSmaller</b>(<i>first, second</i>)
334 <p>
335 Private method to check, if second is contained in first.
336 </p><dl>
337 <dt><i>first</i> (tuple of (int, int, int, int))</dt>
338 <dd>
339 text range to check against
340 </dd><dt><i>second</i> (tuple of (int, int, int, int))</dt>
341 <dd>
342 text range to check for
343 </dd>
344 </dl><dl>
345 <dt>Returns:</dt>
346 <dd>
347 flag indicating second is contained in first
348 </dd>
349 </dl><dl>
350 <dt>Return Type:</dt>
351 <dd>
352 bool
353 </dd>
354 </dl><a NAME="PythonAstViewer.__rangeContainsSmallerOrEqual" ID="PythonAstViewer.__rangeContainsSmallerOrEqual"></a>
355 <h4>PythonAstViewer.__rangeContainsSmallerOrEqual</h4>
356 <b>__rangeContainsSmallerOrEqual</b>(<i>first, second</i>)
357 <p>
358 Private method to check, if second is contained in or equal to first.
359 </p><dl>
360 <dt><i>first</i> (tuple of (int, int, int, int))</dt>
361 <dd>
362 text range to check against
363 </dd><dt><i>second</i> (tuple of (int, int, int, int))</dt>
364 <dd>
365 text range to check for
366 </dd>
367 </dl><dl>
368 <dt>Returns:</dt>
369 <dd>
370 flag indicating second is contained in or equal to first
371 </dd>
372 </dl><dl>
373 <dt>Return Type:</dt>
374 <dd>
375 bool
376 </dd>
377 </dl><a NAME="PythonAstViewer.__resizeColumns" ID="PythonAstViewer.__resizeColumns"></a>
378 <h4>PythonAstViewer.__resizeColumns</h4>
379 <b>__resizeColumns</b>(<i></i>)
380 <p>
381 Private method to resize the columns to suitable values.
382 </p><a NAME="PythonAstViewer.__selectItemForEditorSelection" ID="PythonAstViewer.__selectItemForEditorSelection"></a>
383 <h4>PythonAstViewer.__selectItemForEditorSelection</h4>
384 <b>__selectItemForEditorSelection</b>(<i></i>)
385 <p>
386 Private slot to select the item corresponding to an editor selection.
387 </p><a NAME="PythonAstViewer.hide" ID="PythonAstViewer.hide"></a>
388 <h4>PythonAstViewer.hide</h4>
389 <b>hide</b>(<i></i>)
390 <p>
391 Public slot to hide the AST viewer.
392 </p><a NAME="PythonAstViewer.resizeEvent" ID="PythonAstViewer.resizeEvent"></a>
393 <h4>PythonAstViewer.resizeEvent</h4>
394 <b>resizeEvent</b>(<i>evt</i>)
395 <p>
396 Protected method to handle resize events.
397 </p><dl>
398 <dt><i>evt</i> (QResizeEvent)</dt>
399 <dd>
400 resize event
401 </dd>
402 </dl><a NAME="PythonAstViewer.show" ID="PythonAstViewer.show"></a>
403 <h4>PythonAstViewer.show</h4>
404 <b>show</b>(<i></i>)
405 <p>
406 Public slot to show the AST viewer.
407 </p><a NAME="PythonAstViewer.shutdown" ID="PythonAstViewer.shutdown"></a>
408 <h4>PythonAstViewer.shutdown</h4>
409 <b>shutdown</b>(<i></i>)
410 <p>
411 Public method to perform shutdown actions.
412 </p>
413 <div align="right"><a href="#top">Up</a></div>
414 <hr />
415 </body></html>

eric ide

mercurial