Mercurial > lcfOS
comparison python/ide.py @ 255:7416c923a02a
Added more logging
author | Windel Bouwman |
---|---|
date | Sun, 04 Aug 2013 15:10:10 +0200 |
parents | bd26dc13f270 |
children | 225f444019b1 |
comparison
equal
deleted
inserted
replaced
254:bd26dc13f270 | 255:7416c923a02a |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import sys | 3 import sys |
4 import os | 4 import os |
5 import logging | |
5 | 6 |
6 from PyQt4.QtCore import * | 7 from PyQt4.QtCore import * |
7 from PyQt4.QtGui import * | 8 from PyQt4.QtGui import * |
8 | 9 |
9 # Compiler imports: | 10 # Compiler imports: |
12 from codeedit import CodeEdit | 13 from codeedit import CodeEdit |
13 stutil = __import__('st-util') | 14 stutil = __import__('st-util') |
14 import c3 | 15 import c3 |
15 import zcc | 16 import zcc |
16 import outstream | 17 import outstream |
17 import logging | |
18 | 18 |
19 | 19 |
20 class BuildOutput(QTextEdit): | 20 class BuildOutput(QTextEdit): |
21 """ Build output component """ | 21 """ Build output component """ |
22 def __init__(self, parent=None): | 22 def __init__(self, parent=None): |
23 super(BuildOutput, self).__init__(parent) | 23 super(BuildOutput, self).__init__(parent) |
24 self.setCurrentFont(QFont('Courier')) | 24 fmt = logging.Formatter(fmt='%(asctime)s %(levelname)s %(name)s %(msg)s') |
25 self.setReadOnly(True) | 25 class MyHandler(logging.Handler): |
26 self.append('Build output will appear here!') | 26 def emit(self2, x): |
27 self.append(str(fmt.format(x))) | |
28 | |
29 logging.getLogger().addHandler(MyHandler()) | |
30 self.setCurrentFont(QFont('Courier')) | |
31 self.setReadOnly(True) | |
32 logging.info('Build output will appear here!') | |
27 | 33 |
28 | 34 |
29 class BuildErrors(QTreeView): | 35 class BuildErrors(QTreeView): |
30 sigErrorSelected = pyqtSignal(object) | 36 sigErrorSelected = pyqtSignal(object) |
31 def __init__(self, parent=None): | 37 def __init__(self, parent=None): |
79 | 85 |
80 | 86 |
81 class Ide(QMainWindow): | 87 class Ide(QMainWindow): |
82 def __init__(self, parent=None): | 88 def __init__(self, parent=None): |
83 super(Ide, self).__init__(parent) | 89 super(Ide, self).__init__(parent) |
90 | |
91 | |
84 self.setWindowTitle('LCFOS IDE') | 92 self.setWindowTitle('LCFOS IDE') |
85 icon = QIcon('icons/logo.png') | 93 icon = QIcon('icons/logo.png') |
86 self.setWindowIcon(icon) | 94 self.setWindowIcon(icon) |
87 | 95 |
88 # Create menus: | 96 # Create menus: |
106 self.viewMenu.addAction(dw.toggleViewAction()) | 114 self.viewMenu.addAction(dw.toggleViewAction()) |
107 return widget | 115 return widget |
108 | 116 |
109 self.buildOutput = addComponent('Build output', BuildOutput()) | 117 self.buildOutput = addComponent('Build output', BuildOutput()) |
110 self.astViewer = addComponent('AST viewer', AstViewer()) | 118 self.astViewer = addComponent('AST viewer', AstViewer()) |
111 self.astViewer.sigNodeSelected.connect(self.nodeSelected) | 119 self.astViewer.sigNodeSelected.connect(lambda node: self.showLoc(node.loc)) |
112 self.builderrors = addComponent('Build errors', BuildErrors()) | 120 self.builderrors = addComponent('Build errors', BuildErrors()) |
113 self.builderrors.sigErrorSelected.connect(self.errorSelected) | 121 self.builderrors.sigErrorSelected.connect(lambda err: self.showLoc(err.loc)) |
114 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) | 122 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) |
115 self.regview = addComponent('Registers', stutil.RegisterView()) | 123 self.regview = addComponent('Registers', stutil.RegisterView()) |
116 self.memview = addComponent('Memory', stutil.MemoryView()) | 124 self.memview = addComponent('Memory', stutil.MemoryView()) |
117 self.ctrlToolbar = stutil.DebugToolbar() | 125 self.ctrlToolbar = stutil.DebugToolbar() |
118 self.addToolBar(self.ctrlToolbar) | 126 self.addToolBar(self.ctrlToolbar) |
221 ev.accept() | 229 ev.accept() |
222 | 230 |
223 # Error handling: | 231 # Error handling: |
224 def nodeSelected(self, node): | 232 def nodeSelected(self, node): |
225 self.showLoc(node.loc) | 233 self.showLoc(node.loc) |
226 | |
227 def errorSelected(self, err): | |
228 self.showLoc(err.loc) | |
229 | 234 |
230 def showLoc(self, loc): | 235 def showLoc(self, loc): |
231 ce = self.activeMdiChild() | 236 ce = self.activeMdiChild() |
232 if not ce: | 237 if not ce: |
233 return | 238 return |
255 def parseFile(self): | 260 def parseFile(self): |
256 ce = self.activeMdiChild() | 261 ce = self.activeMdiChild() |
257 if not ce: | 262 if not ce: |
258 return | 263 return |
259 self.diag.clear() | 264 self.diag.clear() |
260 self.buildOutput.append('Starting parse') | |
261 pkg = self.c3front.parse(ce.Source) | 265 pkg = self.c3front.parse(ce.Source) |
262 | 266 |
263 # Set errors: | 267 # Set errors: |
264 for err in self.diag.diags: | |
265 self.buildOutput.append(str(err)) | |
266 self.builderrors.setErrorList(self.diag.diags) | 268 self.builderrors.setErrorList(self.diag.diags) |
267 ce.setErrors(self.diag.diags) | 269 ce.setErrors(self.diag.diags) |
268 self.astViewer.setAst(pkg) | 270 self.astViewer.setAst(pkg) |
269 self.buildOutput.append("Done!") | 271 logging.info('Done!') |
270 | 272 |
271 def buildFile(self): | 273 def buildFile(self): |
272 ce = self.activeMdiChild() | 274 ce = self.activeMdiChild() |
273 if not ce: | 275 if not ce: |
274 return | 276 return |
275 self.diag.clear() | 277 self.diag.clear() |
276 self.buildOutput.append('Starting build') | |
277 outs = outstream.TextOutputStream() | 278 outs = outstream.TextOutputStream() |
278 if not zcc.zcc(ce.Source, outs, self.diag): | 279 if not zcc.zcc(ce.Source, outs, self.diag): |
279 # Set errors: | 280 # Set errors: |
280 for err in self.diag.diags: | |
281 self.buildOutput.append(str(err)) | |
282 self.builderrors.setErrorList(self.diag.diags) | 281 self.builderrors.setErrorList(self.diag.diags) |
283 ce.setErrors(self.diag.diags) | 282 ce.setErrors(self.diag.diags) |
284 return | 283 return |
285 | 284 |
286 code_s = outs.getSection('code') | 285 code_s = outs.getSection('code') |
287 self.debugInfo = code_s.debugInfos() | 286 self.debugInfo = code_s.debugInfos() |
288 self.buildOutput.append("Flashing stm32f4 discovery") | |
289 if self.ctrlToolbar.device: | 287 if self.ctrlToolbar.device: |
288 logging.info('Flashing stm32f4 discovery') | |
290 bts = code_s.to_bytes() | 289 bts = code_s.to_bytes() |
291 self.ctrlToolbar.device.writeFlash(0x08000000, bts) | 290 self.ctrlToolbar.device.writeFlash(0x08000000, bts) |
292 stl = self.ctrlToolbar.device.iface | 291 stl = self.ctrlToolbar.device.iface |
293 stl.reset() | 292 stl.reset() |
294 stl.halt() | 293 stl.halt() |
295 | 294 logging.info('Done!') |
296 self.buildOutput.append("Done!") | |
297 | 295 |
298 if __name__ == '__main__': | 296 if __name__ == '__main__': |
299 logging.basicConfig(level=logging.DEBUG) | 297 logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s', level=logging.DEBUG) |
300 app = QApplication(sys.argv) | 298 app = QApplication(sys.argv) |
301 ide = Ide() | 299 ide = Ide() |
302 ide.show() | 300 ide.show() |
301 logging.info('IDE started') | |
303 app.exec_() | 302 app.exec_() |
304 | 303 |