diff python/astviewer.py @ 256:225f444019b1

Added build and flash menu option
author Windel Bouwman
date Sun, 04 Aug 2013 18:32:04 +0200
parents 57c032c5e753
children
line wrap: on
line diff
--- a/python/astviewer.py	Sun Aug 04 15:10:10 2013 +0200
+++ b/python/astviewer.py	Sun Aug 04 18:32:04 2013 +0200
@@ -3,19 +3,22 @@
 from c3 import Visitor, astnodes
 
 class AstModelBuilder:
-   def __init__(self):
+    def __init__(self):
       self.functionIco = QIcon(QPixmap('icons/functionicon.png').scaled(32, 32))
       self.variableIco = QIcon(QPixmap('icons/variableicon.png').scaled(32, 32))
       self.model = QStandardItemModel()
       self.model.setHorizontalHeaderLabels(['Object', 'Type'])
-   def build(self, pkg):
-      #self.model.clear()
-      c = self.model.rowCount()
-      self.model.removeRows(0, c)
-      self.curItem = self.model.invisibleRootItem()
-      visitor = Visitor()
-      visitor.visit(pkg, self.p1, self.p2)
-   def p1(self, node):
+
+    def build(self, pkg):
+        #self.model.clear()
+        c = self.model.rowCount()
+        self.model.removeRows(0, c)
+        self.curItem = self.model.invisibleRootItem()
+        if pkg:
+            visitor = Visitor()
+            visitor.visit(pkg, self.p1, self.p2)
+
+    def p1(self, node):
       if type(node) is astnodes.Variable:
          i = QStandardItem(self.variableIco, str(node))
       elif type(node) is astnodes.Function:
@@ -30,25 +33,26 @@
       i.setData(node)
       self.curItem.appendRow([i, ti])
       self.curItem = i
-   def p2(self, node):
+
+    def p2(self, node):
       if type(node) in [astnodes.Variable, astnodes.Function, astnodes.Package]:
          self.curItem = self.curItem.parent()
 
 # The actual widget:
 class AstViewer(QTreeView):
-   sigNodeSelected = pyqtSignal(object)
-   def __init__(self, parent=None):
+    sigNodeSelected = pyqtSignal(object)
+    def __init__(self, parent=None):
       super(AstViewer, self).__init__(parent)
       self.clicked.connect(self.selectHandler)
       self.modelBuilder = AstModelBuilder()
       self.setModel(self.modelBuilder.model)
 
-   def setAst(self, ast):
-      """ Create a new model and add all ast elements to it """
-      self.modelBuilder.build(ast)
-      self.expandAll()
+    def setAst(self, ast):
+        """ Create a new model and add all ast elements to it """
+        self.modelBuilder.build(ast)
+        self.expandAll()
 
-   def selectHandler(self, index):
+    def selectHandler(self, index):
       if not index.isValid():
          return
       model = self.model()