Mercurial > lcfOS
comparison python/libs/widgets/astviewer.py @ 64:4a27c28c7d0f
File movage
author | windel |
---|---|
date | Sun, 07 Oct 2012 17:13:47 +0200 |
parents | python/apps/ide/astviewer.py@32078200cdd6 |
children |
comparison
equal
deleted
inserted
replaced
63:32078200cdd6 | 64:4a27c28c7d0f |
---|---|
1 from PyQt4.QtCore import * | |
2 from PyQt4.QtGui import * | |
3 | |
4 def astToNamedElement(astNode, parentNode): | |
5 """ Helper to convert and AST tree to NamedElement tree: """ | |
6 item = QStandardItem(str(astNode)) | |
7 item.setData(astNode) | |
8 parentNode.appendRow(item) | |
9 for c in astNode.getChildren(): | |
10 astToNamedElement(c, item) | |
11 | |
12 # The actual widget: | |
13 class AstViewer(QTreeView): | |
14 sigNodeSelected = pyqtSignal(object) | |
15 def __init__(self, parent=None): | |
16 super(AstViewer, self).__init__(parent) | |
17 self.setHeaderHidden(True) | |
18 self.clicked.connect(self.selectHandler) | |
19 | |
20 def setAst(self, ast): | |
21 """ Create a new model and add all ast elements to it """ | |
22 model = QStandardItemModel() | |
23 if ast: | |
24 astToNamedElement(ast, model.invisibleRootItem()) | |
25 self.setModel( model ) | |
26 self.expandAll() | |
27 | |
28 def selectHandler(self, index): | |
29 if not index.isValid(): | |
30 return | |
31 model = self.model() | |
32 item = model.itemFromIndex(index) | |
33 node = item.data() | |
34 self.sigNodeSelected.emit(node) | |
35 | |
36 |