eric7/Documentation/Source/eric7.UI.PythonAstViewer.html

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

eric ide

mercurial