changeset 168:49f1ab80d040

Added awesome icons
author Windel Bouwman
date Fri, 22 Mar 2013 19:09:38 +0100
parents 0b5b2ee6b435
children ee0d30533dae
files python/astviewer.py python/c3/builder.py python/c3/typecheck.py python/functionicon.png python/ide.py python/testc3.py python/variableicon.png
diffstat 7 files changed, 30 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/python/astviewer.py	Fri Mar 22 17:40:13 2013 +0100
+++ b/python/astviewer.py	Fri Mar 22 19:09:38 2013 +0100
@@ -1,18 +1,27 @@
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
-from c3 import Visitor
+from c3 import Visitor, astnodes
 
 class AstModelBuilder:
    def __init__(self):
+      self.functionIco = QIcon(QPixmap('functionicon.png').scaled(32, 32))
+      self.variableIco = QIcon(QPixmap('variableicon.png').scaled(32, 32))
       self.visitor = Visitor(self.p1, self.p2)
+      self.model = QStandardItemModel()
    def build(self, pkg):
-      model = QStandardItemModel()
-      model.setHorizontalHeaderLabels(['Object', 'Type'])
-      self.curItem = model.invisibleRootItem()
+      self.model.clear()
+      self.model.setHorizontalHeaderLabels(['Object', 'Type'])
+      self.curItem = self.model.invisibleRootItem()
       self.visitor.visit(pkg)
-      return model
    def p1(self, node):
-      i = QStandardItem(str(node))
+      if type(node) is astnodes.Variable:
+         i = QStandardItem(self.variableIco, str(node))
+      elif type(node) is astnodes.Function:
+         i = QStandardItem(self.functionIco, str(node))
+      elif type(node) is astnodes.Package:
+         i = QStandardItem(str(node))
+      else:
+         return
       typ = str(node.typ) if hasattr(node, 'typ') else ''
       ti = QStandardItem(str(typ))
       ti.setData(node)
@@ -20,7 +29,8 @@
       self.curItem.appendRow([i, ti])
       self.curItem = i
    def p2(self, node):
-      self.curItem = self.curItem.parent()
+      if type(node) in [astnodes.Variable, astnodes.Function, astnodes.Package]:
+         self.curItem = self.curItem.parent()
 
 # The actual widget:
 class AstViewer(QTreeView):
@@ -29,13 +39,12 @@
       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 """
-      print(ast)
-      if ast:
-         self.setModel(self.modelBuilder.build(ast))
-         self.expandAll()
+      self.modelBuilder.build(ast)
+      self.expandAll()
 
    def selectHandler(self, index):
       if not index.isValid():
--- a/python/c3/builder.py	Fri Mar 22 17:40:13 2013 +0100
+++ b/python/c3/builder.py	Fri Mar 22 19:09:38 2013 +0100
@@ -17,7 +17,6 @@
       self.tc.checkPackage(self.pkg)
       ok = len(self.diag.diags) == 0
       if ok:
-         print('Generating ir-code')
          i = self.cg.gencode(self.pkg)
          return i
 
--- a/python/c3/typecheck.py	Fri Mar 22 17:40:13 2013 +0100
+++ b/python/c3/typecheck.py	Fri Mar 22 19:09:38 2013 +0100
@@ -87,7 +87,7 @@
          if not equalTypes(sym.typ, sym.value.typ):
             self.diag.error('Cannot assign {0} to {1}'.format(sym.value.typ, sym.typ), sym.loc)
          
-      elif type(sym) in [EmptyStatement, CompoundStatement, Package, Function]:
+      elif type(sym) in [EmptyStatement, CompoundStatement, Package, Function, FunctionType]:
          pass
       else:
          print('Unknown type check', sym)
Binary file python/functionicon.png has changed
--- a/python/ide.py	Fri Mar 22 17:40:13 2013 +0100
+++ b/python/ide.py	Fri Mar 22 19:09:38 2013 +0100
@@ -328,6 +328,7 @@
       if node.loc:
          row, col = node.loc.row, node.loc.col
          ce.setRowCol( row, col )
+         ce.setFocus()
       else:
          ce.clearErrors()
 
@@ -353,7 +354,6 @@
         self.buildOutput.append("Done!")
   def buildProject(self):
      """ Build project """
-     print('BUILD project')
      self.buildOutput.clear()
      self.diag.diags.clear()
      self.buildFile()
--- a/python/testc3.py	Fri Mar 22 17:40:13 2013 +0100
+++ b/python/testc3.py	Fri Mar 22 19:09:38 2013 +0100
@@ -64,7 +64,6 @@
    x86gen = x86.X86CodeGen(diag)
    ok = len(diag.diags) == 0
    if not ok:
-      print('Not generating code')
       return
    print('generating x86 code')
    x86gen.genBin(ir)
@@ -94,7 +93,9 @@
       """
       self.diag.clear()
       ir = self.builder.build(snippet)
-      print(self.diag.diags)
+      assert len(self.diag.diags) == 2
+      assert self.diag.diags[0].loc.row == 5
+      assert self.diag.diags[1].loc.row == 6
 
    def testExpressions(self):
       snippet = """
@@ -111,7 +112,11 @@
       """
       self.diag.clear()
       ir = self.builder.build(snippet)
-      print(self.diag.diags)
+      assert len(self.diag.diags) == 3
+      assert self.diag.diags[0].loc.row == 8
+      assert self.diag.diags[1].loc.row == 9
+      assert self.diag.diags[2].loc.row == 10
+      assert ir == None
 
 if __name__ == '__main__':
    do()
Binary file python/variableicon.png has changed