diff python/ide.py @ 255:7416c923a02a

Added more logging
author Windel Bouwman
date Sun, 04 Aug 2013 15:10:10 +0200
parents bd26dc13f270
children 225f444019b1
line wrap: on
line diff
--- a/python/ide.py	Wed Jul 31 21:20:58 2013 +0200
+++ b/python/ide.py	Sun Aug 04 15:10:10 2013 +0200
@@ -2,6 +2,7 @@
 
 import sys
 import os
+import logging
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
@@ -14,16 +15,21 @@
 import c3
 import zcc
 import outstream
-import logging
 
 
 class BuildOutput(QTextEdit):
     """ Build output component """
     def __init__(self, parent=None):
-      super(BuildOutput, self).__init__(parent)
-      self.setCurrentFont(QFont('Courier'))
-      self.setReadOnly(True)
-      self.append('Build output will appear here!')
+        super(BuildOutput, self).__init__(parent)
+        fmt = logging.Formatter(fmt='%(asctime)s %(levelname)s %(name)s %(msg)s')
+        class MyHandler(logging.Handler):
+            def emit(self2, x):
+                self.append(str(fmt.format(x)))
+
+        logging.getLogger().addHandler(MyHandler())
+        self.setCurrentFont(QFont('Courier'))
+        self.setReadOnly(True)
+        logging.info('Build output will appear here!')
 
 
 class BuildErrors(QTreeView):
@@ -81,6 +87,8 @@
 class Ide(QMainWindow):
     def __init__(self, parent=None):
         super(Ide, self).__init__(parent)
+
+
         self.setWindowTitle('LCFOS IDE')
         icon = QIcon('icons/logo.png')
         self.setWindowIcon(icon)
@@ -108,9 +116,9 @@
 
         self.buildOutput = addComponent('Build output', BuildOutput())
         self.astViewer = addComponent('AST viewer', AstViewer())
-        self.astViewer.sigNodeSelected.connect(self.nodeSelected)
+        self.astViewer.sigNodeSelected.connect(lambda node: self.showLoc(node.loc))
         self.builderrors = addComponent('Build errors', BuildErrors())
-        self.builderrors.sigErrorSelected.connect(self.errorSelected)
+        self.builderrors.sigErrorSelected.connect(lambda err: self.showLoc(err.loc))
         self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
         self.regview = addComponent('Registers', stutil.RegisterView())
         self.memview = addComponent('Memory', stutil.MemoryView())
@@ -224,9 +232,6 @@
     def nodeSelected(self, node):
         self.showLoc(node.loc)
 
-    def errorSelected(self, err):
-        self.showLoc(err.loc)
-
     def showLoc(self, loc):
         ce = self.activeMdiChild()
         if not ce:
@@ -257,48 +262,42 @@
         if not ce:
             return
         self.diag.clear()
-        self.buildOutput.append('Starting parse')
         pkg = self.c3front.parse(ce.Source)
 
         # Set errors:
-        for err in self.diag.diags:
-            self.buildOutput.append(str(err))
         self.builderrors.setErrorList(self.diag.diags)
         ce.setErrors(self.diag.diags)
         self.astViewer.setAst(pkg)
-        self.buildOutput.append("Done!")
+        logging.info('Done!')
 
     def buildFile(self):
         ce = self.activeMdiChild()
         if not ce:
             return
         self.diag.clear()
-        self.buildOutput.append('Starting build')
         outs = outstream.TextOutputStream()
         if not zcc.zcc(ce.Source, outs, self.diag):
             # Set errors:
-            for err in self.diag.diags:
-                self.buildOutput.append(str(err))
             self.builderrors.setErrorList(self.diag.diags)
             ce.setErrors(self.diag.diags)
             return
 
         code_s = outs.getSection('code')
         self.debugInfo = code_s.debugInfos()
-        self.buildOutput.append("Flashing stm32f4 discovery")
         if self.ctrlToolbar.device:
+            logging.info('Flashing stm32f4 discovery')
             bts = code_s.to_bytes()
             self.ctrlToolbar.device.writeFlash(0x08000000, bts)
             stl = self.ctrlToolbar.device.iface
             stl.reset()
             stl.halt()
-
-        self.buildOutput.append("Done!")
+        logging.info('Done!')
 
 if __name__ == '__main__':
-    logging.basicConfig(level=logging.DEBUG)
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s', level=logging.DEBUG)
     app = QApplication(sys.argv)
     ide = Ide()
     ide.show()
+    logging.info('IDE started')
     app.exec_()