|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.UI.PythonAstViewer</title> |
|
4 <meta charset="UTF-8"> |
|
5 <link rel="stylesheet" href="styles.css"> |
|
6 </head> |
|
7 <body> |
|
8 <a NAME="top" ID="top"></a> |
|
9 <h1>eric7.UI.PythonAstViewer</h1> |
|
10 |
|
11 <p> |
|
12 Module implementing a widget to visualize the Python AST for some Python |
|
13 sources. |
|
14 </p> |
|
15 <h3>Global Attributes</h3> |
|
16 |
|
17 <table> |
|
18 <tr><td>None</td></tr> |
|
19 </table> |
|
20 <h3>Classes</h3> |
|
21 |
|
22 <table> |
|
23 |
|
24 <tr> |
|
25 <td><a href="#PythonAstViewer">PythonAstViewer</a></td> |
|
26 <td>Class implementing a widget to visualize the Python AST for some Python sources.</td> |
|
27 </tr> |
|
28 </table> |
|
29 <h3>Functions</h3> |
|
30 |
|
31 <table> |
|
32 <tr><td>None</td></tr> |
|
33 </table> |
|
34 <hr /> |
|
35 <hr /> |
|
36 <a NAME="PythonAstViewer" ID="PythonAstViewer"></a> |
|
37 <h2>PythonAstViewer</h2> |
|
38 |
|
39 <p> |
|
40 Class implementing a widget to visualize the Python AST for some Python |
|
41 sources. |
|
42 </p> |
|
43 <h3>Derived from</h3> |
|
44 QWidget |
|
45 <h3>Class Attributes</h3> |
|
46 |
|
47 <table> |
|
48 <tr><td>EndIndexRole</td></tr><tr><td>EndLineRole</td></tr><tr><td>StartIndexRole</td></tr><tr><td>StartLineRole</td></tr> |
|
49 </table> |
|
50 <h3>Class Methods</h3> |
|
51 |
|
52 <table> |
|
53 <tr><td>None</td></tr> |
|
54 </table> |
|
55 <h3>Methods</h3> |
|
56 |
|
57 <table> |
|
58 |
|
59 <tr> |
|
60 <td><a href="#PythonAstViewer.__init__">PythonAstViewer</a></td> |
|
61 <td>Constructor</td> |
|
62 </tr> |
|
63 <tr> |
|
64 <td><a href="#PythonAstViewer.__astItemClicked">__astItemClicked</a></td> |
|
65 <td>Private slot handling a user click on an AST node item.</td> |
|
66 </tr> |
|
67 <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> |
|
71 <tr> |
|
72 <td><a href="#PythonAstViewer.__clearSelection">__clearSelection</a></td> |
|
73 <td>Private method to clear all selected items.</td> |
|
74 </tr> |
|
75 <tr> |
|
76 <td><a href="#PythonAstViewer.__createErrorItem">__createErrorItem</a></td> |
|
77 <td>Private method to create a top level error item.</td> |
|
78 </tr> |
|
79 <tr> |
|
80 <td><a href="#PythonAstViewer.__editorChanged">__editorChanged</a></td> |
|
81 <td>Private slot to handle a change of the current editor.</td> |
|
82 </tr> |
|
83 <tr> |
|
84 <td><a href="#PythonAstViewer.__editorDoubleClicked">__editorDoubleClicked</a></td> |
|
85 <td>Private slot to handle a mouse button double click in the editor.</td> |
|
86 </tr> |
|
87 <tr> |
|
88 <td><a href="#PythonAstViewer.__editorLanguageChanged">__editorLanguageChanged</a></td> |
|
89 <td>Private slot to handle a change of the editor language.</td> |
|
90 </tr> |
|
91 <tr> |
|
92 <td><a href="#PythonAstViewer.__editorSaved">__editorSaved</a></td> |
|
93 <td>Private slot to reload the AST after the connected editor was saved.</td> |
|
94 </tr> |
|
95 <tr> |
|
96 <td><a href="#PythonAstViewer.__findClosestContainingItem">__findClosestContainingItem</a></td> |
|
97 <td>Private method to search for the tree item that contains a range closest.</td> |
|
98 </tr> |
|
99 <tr> |
|
100 <td><a href="#PythonAstViewer.__findClosestContainingNode">__findClosestContainingNode</a></td> |
|
101 <td>Private method to search for the AST node that contains a range closest.</td> |
|
102 </tr> |
|
103 <tr> |
|
104 <td><a href="#PythonAstViewer.__grabFocus">__grabFocus</a></td> |
|
105 <td>Private method to grab the input focus.</td> |
|
106 </tr> |
|
107 <tr> |
|
108 <td><a href="#PythonAstViewer.__lastEditorClosed">__lastEditorClosed</a></td> |
|
109 <td>Private slot to handle the last editor closed signal of the view manager.</td> |
|
110 </tr> |
|
111 <tr> |
|
112 <td><a href="#PythonAstViewer.__loadAST">__loadAST</a></td> |
|
113 <td>Private method to generate the AST from the source of the current editor and visualize it.</td> |
|
114 </tr> |
|
115 <tr> |
|
116 <td><a href="#PythonAstViewer.__markTextRanges">__markTextRanges</a></td> |
|
117 <td>Private method to modify the AST nodes with end_lineno and end_col_offset information.</td> |
|
118 </tr> |
|
119 <tr> |
|
120 <td><a href="#PythonAstViewer.__populateNode">__populateNode</a></td> |
|
121 <td>Private method to populate the tree view with a node.</td> |
|
122 </tr> |
|
123 <tr> |
|
124 <td><a href="#PythonAstViewer.__rangeContainsSmaller">__rangeContainsSmaller</a></td> |
|
125 <td>Private method to check, if second is contained in first.</td> |
|
126 </tr> |
|
127 <tr> |
|
128 <td><a href="#PythonAstViewer.__rangeContainsSmallerOrEqual">__rangeContainsSmallerOrEqual</a></td> |
|
129 <td>Private method to check, if second is contained in or equal to first.</td> |
|
130 </tr> |
|
131 <tr> |
|
132 <td><a href="#PythonAstViewer.__resizeColumns">__resizeColumns</a></td> |
|
133 <td>Private method to resize the columns to suitable values.</td> |
|
134 </tr> |
|
135 <tr> |
|
136 <td><a href="#PythonAstViewer.__selectItemForEditorSelection">__selectItemForEditorSelection</a></td> |
|
137 <td>Private slot to select the item corresponding to an editor selection.</td> |
|
138 </tr> |
|
139 <tr> |
|
140 <td><a href="#PythonAstViewer.hide">hide</a></td> |
|
141 <td>Public slot to hide the AST viewer.</td> |
|
142 </tr> |
|
143 <tr> |
|
144 <td><a href="#PythonAstViewer.preferencesChanged">preferencesChanged</a></td> |
|
145 <td>Public slot handling changes of the AST viewer settings.</td> |
|
146 </tr> |
|
147 <tr> |
|
148 <td><a href="#PythonAstViewer.resizeEvent">resizeEvent</a></td> |
|
149 <td>Protected method to handle resize events.</td> |
|
150 </tr> |
|
151 <tr> |
|
152 <td><a href="#PythonAstViewer.show">show</a></td> |
|
153 <td>Public slot to show the AST viewer.</td> |
|
154 </tr> |
|
155 <tr> |
|
156 <td><a href="#PythonAstViewer.shutdown">shutdown</a></td> |
|
157 <td>Public method to perform shutdown actions.</td> |
|
158 </tr> |
|
159 </table> |
|
160 <h3>Static Methods</h3> |
|
161 |
|
162 <table> |
|
163 <tr><td>None</td></tr> |
|
164 </table> |
|
165 |
|
166 <a NAME="PythonAstViewer.__init__" ID="PythonAstViewer.__init__"></a> |
|
167 <h4>PythonAstViewer (Constructor)</h4> |
|
168 <b>PythonAstViewer</b>(<i>viewmanager, parent=None</i>) |
|
169 |
|
170 <p> |
|
171 Constructor |
|
172 </p> |
|
173 <dl> |
|
174 |
|
175 <dt><i>viewmanager</i> (ViewManager)</dt> |
|
176 <dd> |
|
177 reference to the viewmanager object |
|
178 </dd> |
|
179 <dt><i>parent</i> (QWidget)</dt> |
|
180 <dd> |
|
181 reference to the parent widget |
|
182 </dd> |
|
183 </dl> |
|
184 <a NAME="PythonAstViewer.__astItemClicked" ID="PythonAstViewer.__astItemClicked"></a> |
|
185 <h4>PythonAstViewer.__astItemClicked</h4> |
|
186 <b>__astItemClicked</b>(<i>itm, column</i>) |
|
187 |
|
188 <p> |
|
189 Private slot handling a user click on an AST node item. |
|
190 </p> |
|
191 <dl> |
|
192 |
|
193 <dt><i>itm</i> (QTreeWidgetItem)</dt> |
|
194 <dd> |
|
195 reference to the clicked item |
|
196 </dd> |
|
197 <dt><i>column</i> (int)</dt> |
|
198 <dd> |
|
199 column number of the click |
|
200 </dd> |
|
201 </dl> |
|
202 <a NAME="PythonAstViewer.__astViewerStateChanged" ID="PythonAstViewer.__astViewerStateChanged"></a> |
|
203 <h4>PythonAstViewer.__astViewerStateChanged</h4> |
|
204 <b>__astViewerStateChanged</b>(<i>on</i>) |
|
205 |
|
206 <p> |
|
207 Private slot to toggle the display of the AST viewer. |
|
208 </p> |
|
209 <dl> |
|
210 |
|
211 <dt><i>on</i> (bool)</dt> |
|
212 <dd> |
|
213 flag indicating to show the AST |
|
214 </dd> |
|
215 </dl> |
|
216 <a NAME="PythonAstViewer.__clearSelection" ID="PythonAstViewer.__clearSelection"></a> |
|
217 <h4>PythonAstViewer.__clearSelection</h4> |
|
218 <b>__clearSelection</b>(<i></i>) |
|
219 |
|
220 <p> |
|
221 Private method to clear all selected items. |
|
222 </p> |
|
223 <a NAME="PythonAstViewer.__createErrorItem" ID="PythonAstViewer.__createErrorItem"></a> |
|
224 <h4>PythonAstViewer.__createErrorItem</h4> |
|
225 <b>__createErrorItem</b>(<i>error</i>) |
|
226 |
|
227 <p> |
|
228 Private method to create a top level error item. |
|
229 </p> |
|
230 <dl> |
|
231 |
|
232 <dt><i>error</i> (str)</dt> |
|
233 <dd> |
|
234 error message |
|
235 </dd> |
|
236 </dl> |
|
237 <dl> |
|
238 <dt>Return:</dt> |
|
239 <dd> |
|
240 generated item |
|
241 </dd> |
|
242 </dl> |
|
243 <dl> |
|
244 <dt>Return Type:</dt> |
|
245 <dd> |
|
246 QTreeWidgetItem |
|
247 </dd> |
|
248 </dl> |
|
249 <a NAME="PythonAstViewer.__editorChanged" ID="PythonAstViewer.__editorChanged"></a> |
|
250 <h4>PythonAstViewer.__editorChanged</h4> |
|
251 <b>__editorChanged</b>(<i>editor</i>) |
|
252 |
|
253 <p> |
|
254 Private slot to handle a change of the current editor. |
|
255 </p> |
|
256 <dl> |
|
257 |
|
258 <dt><i>editor</i> (Editor)</dt> |
|
259 <dd> |
|
260 reference to the current editor |
|
261 </dd> |
|
262 </dl> |
|
263 <a NAME="PythonAstViewer.__editorDoubleClicked" ID="PythonAstViewer.__editorDoubleClicked"></a> |
|
264 <h4>PythonAstViewer.__editorDoubleClicked</h4> |
|
265 <b>__editorDoubleClicked</b>(<i>editor, pos, buttons</i>) |
|
266 |
|
267 <p> |
|
268 Private slot to handle a mouse button double click in the editor. |
|
269 </p> |
|
270 <dl> |
|
271 |
|
272 <dt><i>editor</i> (Editor)</dt> |
|
273 <dd> |
|
274 reference to the editor, that emitted the signal |
|
275 </dd> |
|
276 <dt><i>pos</i> (QPoint)</dt> |
|
277 <dd> |
|
278 position of the double click |
|
279 </dd> |
|
280 <dt><i>buttons</i> (Qt.MouseButtons)</dt> |
|
281 <dd> |
|
282 mouse buttons that were double clicked |
|
283 </dd> |
|
284 </dl> |
|
285 <a NAME="PythonAstViewer.__editorLanguageChanged" ID="PythonAstViewer.__editorLanguageChanged"></a> |
|
286 <h4>PythonAstViewer.__editorLanguageChanged</h4> |
|
287 <b>__editorLanguageChanged</b>(<i>editor</i>) |
|
288 |
|
289 <p> |
|
290 Private slot to handle a change of the editor language. |
|
291 </p> |
|
292 <dl> |
|
293 |
|
294 <dt><i>editor</i> (Editor)</dt> |
|
295 <dd> |
|
296 reference to the editor which changed language |
|
297 </dd> |
|
298 </dl> |
|
299 <a NAME="PythonAstViewer.__editorSaved" ID="PythonAstViewer.__editorSaved"></a> |
|
300 <h4>PythonAstViewer.__editorSaved</h4> |
|
301 <b>__editorSaved</b>(<i>editor</i>) |
|
302 |
|
303 <p> |
|
304 Private slot to reload the AST after the connected editor was saved. |
|
305 </p> |
|
306 <dl> |
|
307 |
|
308 <dt><i>editor</i> (Editor)</dt> |
|
309 <dd> |
|
310 reference to the editor that performed a save action |
|
311 </dd> |
|
312 </dl> |
|
313 <a NAME="PythonAstViewer.__findClosestContainingItem" ID="PythonAstViewer.__findClosestContainingItem"></a> |
|
314 <h4>PythonAstViewer.__findClosestContainingItem</h4> |
|
315 <b>__findClosestContainingItem</b>(<i>itm, textRange</i>) |
|
316 |
|
317 <p> |
|
318 Private method to search for the tree item that contains a range |
|
319 closest. |
|
320 </p> |
|
321 <dl> |
|
322 |
|
323 <dt><i>itm</i> (QTreeWidgetItem)</dt> |
|
324 <dd> |
|
325 tree item to start searching at |
|
326 </dd> |
|
327 <dt><i>textRange</i> (tuple of (int, int, int, int))</dt> |
|
328 <dd> |
|
329 tuple giving the start and end positions |
|
330 </dd> |
|
331 </dl> |
|
332 <dl> |
|
333 <dt>Return:</dt> |
|
334 <dd> |
|
335 best matching tree item |
|
336 </dd> |
|
337 </dl> |
|
338 <dl> |
|
339 <dt>Return Type:</dt> |
|
340 <dd> |
|
341 QTreeWidgetItem |
|
342 </dd> |
|
343 </dl> |
|
344 <a NAME="PythonAstViewer.__findClosestContainingNode" ID="PythonAstViewer.__findClosestContainingNode"></a> |
|
345 <h4>PythonAstViewer.__findClosestContainingNode</h4> |
|
346 <b>__findClosestContainingNode</b>(<i>node, textRange</i>) |
|
347 |
|
348 <p> |
|
349 Private method to search for the AST node that contains a range |
|
350 closest. |
|
351 </p> |
|
352 <dl> |
|
353 |
|
354 <dt><i>node</i> (ast.AST)</dt> |
|
355 <dd> |
|
356 AST node to start searching at |
|
357 </dd> |
|
358 <dt><i>textRange</i> (tuple of (int, int, int, int))</dt> |
|
359 <dd> |
|
360 tuple giving the start and end positions |
|
361 </dd> |
|
362 </dl> |
|
363 <dl> |
|
364 <dt>Return:</dt> |
|
365 <dd> |
|
366 best matching node |
|
367 </dd> |
|
368 </dl> |
|
369 <dl> |
|
370 <dt>Return Type:</dt> |
|
371 <dd> |
|
372 ast.AST |
|
373 </dd> |
|
374 </dl> |
|
375 <a NAME="PythonAstViewer.__grabFocus" ID="PythonAstViewer.__grabFocus"></a> |
|
376 <h4>PythonAstViewer.__grabFocus</h4> |
|
377 <b>__grabFocus</b>(<i></i>) |
|
378 |
|
379 <p> |
|
380 Private method to grab the input focus. |
|
381 </p> |
|
382 <a NAME="PythonAstViewer.__lastEditorClosed" ID="PythonAstViewer.__lastEditorClosed"></a> |
|
383 <h4>PythonAstViewer.__lastEditorClosed</h4> |
|
384 <b>__lastEditorClosed</b>(<i></i>) |
|
385 |
|
386 <p> |
|
387 Private slot to handle the last editor closed signal of the view |
|
388 manager. |
|
389 </p> |
|
390 <a NAME="PythonAstViewer.__loadAST" ID="PythonAstViewer.__loadAST"></a> |
|
391 <h4>PythonAstViewer.__loadAST</h4> |
|
392 <b>__loadAST</b>(<i></i>) |
|
393 |
|
394 <p> |
|
395 Private method to generate the AST from the source of the current |
|
396 editor and visualize it. |
|
397 </p> |
|
398 <a NAME="PythonAstViewer.__markTextRanges" ID="PythonAstViewer.__markTextRanges"></a> |
|
399 <h4>PythonAstViewer.__markTextRanges</h4> |
|
400 <b>__markTextRanges</b>(<i>tree, source</i>) |
|
401 |
|
402 <p> |
|
403 Private method to modify the AST nodes with end_lineno and |
|
404 end_col_offset information. |
|
405 </p> |
|
406 <p> |
|
407 Note: The modifications are only done for nodes containing lineno and |
|
408 col_offset attributes. |
|
409 </p> |
|
410 <dl> |
|
411 |
|
412 <dt><i>tree</i> (ast.AST)</dt> |
|
413 <dd> |
|
414 reference to the AST to be modified |
|
415 </dd> |
|
416 <dt><i>source</i> (str)</dt> |
|
417 <dd> |
|
418 source code the AST was created from |
|
419 </dd> |
|
420 </dl> |
|
421 <a NAME="PythonAstViewer.__populateNode" ID="PythonAstViewer.__populateNode"></a> |
|
422 <h4>PythonAstViewer.__populateNode</h4> |
|
423 <b>__populateNode</b>(<i>name, nodeOrFields, parent</i>) |
|
424 |
|
425 <p> |
|
426 Private method to populate the tree view with a node. |
|
427 </p> |
|
428 <dl> |
|
429 |
|
430 <dt><i>name</i> (str)</dt> |
|
431 <dd> |
|
432 name of the node |
|
433 </dd> |
|
434 <dt><i>nodeOrFields</i> (ast.AST or list)</dt> |
|
435 <dd> |
|
436 reference to the node or a list node fields |
|
437 </dd> |
|
438 <dt><i>parent</i> (QTreeWidget or QTreeWidgetItem)</dt> |
|
439 <dd> |
|
440 reference to the parent item |
|
441 </dd> |
|
442 </dl> |
|
443 <a NAME="PythonAstViewer.__rangeContainsSmaller" ID="PythonAstViewer.__rangeContainsSmaller"></a> |
|
444 <h4>PythonAstViewer.__rangeContainsSmaller</h4> |
|
445 <b>__rangeContainsSmaller</b>(<i>first, second</i>) |
|
446 |
|
447 <p> |
|
448 Private method to check, if second is contained in first. |
|
449 </p> |
|
450 <dl> |
|
451 |
|
452 <dt><i>first</i> (tuple of (int, int, int, int))</dt> |
|
453 <dd> |
|
454 text range to check against |
|
455 </dd> |
|
456 <dt><i>second</i> (tuple of (int, int, int, int))</dt> |
|
457 <dd> |
|
458 text range to check for |
|
459 </dd> |
|
460 </dl> |
|
461 <dl> |
|
462 <dt>Return:</dt> |
|
463 <dd> |
|
464 flag indicating second is contained in first |
|
465 </dd> |
|
466 </dl> |
|
467 <dl> |
|
468 <dt>Return Type:</dt> |
|
469 <dd> |
|
470 bool |
|
471 </dd> |
|
472 </dl> |
|
473 <a NAME="PythonAstViewer.__rangeContainsSmallerOrEqual" ID="PythonAstViewer.__rangeContainsSmallerOrEqual"></a> |
|
474 <h4>PythonAstViewer.__rangeContainsSmallerOrEqual</h4> |
|
475 <b>__rangeContainsSmallerOrEqual</b>(<i>first, second</i>) |
|
476 |
|
477 <p> |
|
478 Private method to check, if second is contained in or equal to first. |
|
479 </p> |
|
480 <dl> |
|
481 |
|
482 <dt><i>first</i> (tuple of (int, int, int, int))</dt> |
|
483 <dd> |
|
484 text range to check against |
|
485 </dd> |
|
486 <dt><i>second</i> (tuple of (int, int, int, int))</dt> |
|
487 <dd> |
|
488 text range to check for |
|
489 </dd> |
|
490 </dl> |
|
491 <dl> |
|
492 <dt>Return:</dt> |
|
493 <dd> |
|
494 flag indicating second is contained in or equal to first |
|
495 </dd> |
|
496 </dl> |
|
497 <dl> |
|
498 <dt>Return Type:</dt> |
|
499 <dd> |
|
500 bool |
|
501 </dd> |
|
502 </dl> |
|
503 <a NAME="PythonAstViewer.__resizeColumns" ID="PythonAstViewer.__resizeColumns"></a> |
|
504 <h4>PythonAstViewer.__resizeColumns</h4> |
|
505 <b>__resizeColumns</b>(<i></i>) |
|
506 |
|
507 <p> |
|
508 Private method to resize the columns to suitable values. |
|
509 </p> |
|
510 <a NAME="PythonAstViewer.__selectItemForEditorSelection" ID="PythonAstViewer.__selectItemForEditorSelection"></a> |
|
511 <h4>PythonAstViewer.__selectItemForEditorSelection</h4> |
|
512 <b>__selectItemForEditorSelection</b>(<i></i>) |
|
513 |
|
514 <p> |
|
515 Private slot to select the item corresponding to an editor selection. |
|
516 </p> |
|
517 <a NAME="PythonAstViewer.hide" ID="PythonAstViewer.hide"></a> |
|
518 <h4>PythonAstViewer.hide</h4> |
|
519 <b>hide</b>(<i></i>) |
|
520 |
|
521 <p> |
|
522 Public slot to hide the AST viewer. |
|
523 </p> |
|
524 <a NAME="PythonAstViewer.preferencesChanged" ID="PythonAstViewer.preferencesChanged"></a> |
|
525 <h4>PythonAstViewer.preferencesChanged</h4> |
|
526 <b>preferencesChanged</b>(<i></i>) |
|
527 |
|
528 <p> |
|
529 Public slot handling changes of the AST viewer settings. |
|
530 </p> |
|
531 <a NAME="PythonAstViewer.resizeEvent" ID="PythonAstViewer.resizeEvent"></a> |
|
532 <h4>PythonAstViewer.resizeEvent</h4> |
|
533 <b>resizeEvent</b>(<i>evt</i>) |
|
534 |
|
535 <p> |
|
536 Protected method to handle resize events. |
|
537 </p> |
|
538 <dl> |
|
539 |
|
540 <dt><i>evt</i> (QResizeEvent)</dt> |
|
541 <dd> |
|
542 resize event |
|
543 </dd> |
|
544 </dl> |
|
545 <a NAME="PythonAstViewer.show" ID="PythonAstViewer.show"></a> |
|
546 <h4>PythonAstViewer.show</h4> |
|
547 <b>show</b>(<i></i>) |
|
548 |
|
549 <p> |
|
550 Public slot to show the AST viewer. |
|
551 </p> |
|
552 <a NAME="PythonAstViewer.shutdown" ID="PythonAstViewer.shutdown"></a> |
|
553 <h4>PythonAstViewer.shutdown</h4> |
|
554 <b>shutdown</b>(<i></i>) |
|
555 |
|
556 <p> |
|
557 Public method to perform shutdown actions. |
|
558 </p> |
|
559 <div align="right"><a href="#top">Up</a></div> |
|
560 <hr /> |
|
561 </body></html> |