Mercurial > lcfOS
comparison python/ide.py @ 152:b73bc14a3aa3
Light coupling ide and c3 frontend
author | Windel Bouwman |
---|---|
date | Sat, 02 Mar 2013 09:56:12 +0100 |
parents | 1cc59ac80950 |
children | 81e08e2e7777 |
comparison
equal
deleted
inserted
replaced
151:afc8c0207984 | 152:b73bc14a3aa3 |
---|---|
10 from project import Project | 10 from project import Project |
11 import ppci | 11 import ppci |
12 from astviewer import AstViewer | 12 from astviewer import AstViewer |
13 from codeeditor import CodeEdit | 13 from codeeditor import CodeEdit |
14 stutil = __import__('st-util') | 14 stutil = __import__('st-util') |
15 import testc3 | |
15 | 16 |
16 lcfospng = base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEhMKBk7B678AAAA/SURBVFjD\n7dbBCQAgDATBi9h/y7EFA4Kf2QLCwH1S6XQu6sqoujublc8BAAAAAAAAAAB8B+zXT6YJAAAAAKYd\nWSgFQNUyijIAAAAASUVORK5CYII=\n') | 17 lcfospng = base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEhMKBk7B678AAAA/SURBVFjD\n7dbBCQAgDATBi9h/y7EFA4Kf2QLCwH1S6XQu6sqoujublc8BAAAAAAAAAAB8B+zXT6YJAAAAAKYd\nWSgFQNUyijIAAAAASUVORK5CYII=\n') |
17 | 18 |
18 class BuildOutput(QTextEdit): | 19 class BuildOutput(QTextEdit): |
19 """ Build output component """ | 20 """ Build output component """ |
31 self.setModel(model) | 32 self.setModel(model) |
32 self.clicked.connect(self.itemSelected) | 33 self.clicked.connect(self.itemSelected) |
33 def setErrorList(self, errorlist): | 34 def setErrorList(self, errorlist): |
34 model = QStandardItemModel() | 35 model = QStandardItemModel() |
35 for e in errorlist: | 36 for e in errorlist: |
36 row, col, msg = e | 37 item = QStandardItem(str(e)) |
37 item = QStandardItem(str(msg)) | |
38 item.setData(e) | 38 item.setData(e) |
39 model.appendRow(item) | 39 model.appendRow(item) |
40 self.setModel(model) | 40 self.setModel(model) |
41 def itemSelected(self, index): | 41 def itemSelected(self, index): |
42 if not index.isValid(): | 42 if not index.isValid(): |
191 | 191 |
192 # Load settings: | 192 # Load settings: |
193 self.settings = QSettings('windelsoft', 'lcfoside') | 193 self.settings = QSettings('windelsoft', 'lcfoside') |
194 self.loadSettings() | 194 self.loadSettings() |
195 | 195 |
196 ce = self.newFile() | |
197 ce.setSource(testc3.testsrc) | |
198 | |
199 self.diag = ppci.DiagnosticsManager() | |
200 | |
196 # File handling: | 201 # File handling: |
197 def newProject(self): | 202 def newProject(self): |
198 filename = QFileDialog.getSaveFileName(self, \ | 203 filename = QFileDialog.getSaveFileName(self, \ |
199 "Select new projectfile", "", "lcfos Project files (*.lcp2)") | 204 "Select new projectfile", "", "lcfos Project files (*.lcp2)") |
200 if filename: | 205 if filename: |
201 self.project = Project() | 206 self.project = Project() |
202 self.project.filename = filename | 207 self.project.filename = filename |
203 self.project.save() | 208 self.project.save() |
204 | 209 |
205 def newFile(self): | 210 def newFile(self): |
206 self.loadFile('main.ks') | 211 ce = CodeEdit() |
212 self.mdiArea.addSubWindow(ce) | |
213 ce.show() | |
214 return ce | |
207 def openFile(self): | 215 def openFile(self): |
208 filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)") | 216 filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)") |
209 if filename: | 217 if filename: |
210 self.loadFile(filename) | 218 self.loadFile(filename) |
211 def saveFile(self): | 219 def saveFile(self): |
279 def loadSettings(self): | 287 def loadSettings(self): |
280 if self.settings.contains('mainwindowstate'): | 288 if self.settings.contains('mainwindowstate'): |
281 self.restoreState(self.settings.value('mainwindowstate')) | 289 self.restoreState(self.settings.value('mainwindowstate')) |
282 if self.settings.contains('mainwindowgeometry'): | 290 if self.settings.contains('mainwindowgeometry'): |
283 self.restoreGeometry(self.settings.value('mainwindowgeometry')) | 291 self.restoreGeometry(self.settings.value('mainwindowgeometry')) |
284 if self.settings.contains('openedproject'): | |
285 projectfile = self.settings.value('openedproject') | |
286 #self.loadProject(projectfile) | |
287 if self.settings.contains('lastfile'): | 292 if self.settings.contains('lastfile'): |
288 self.loadFile(self.settings.value('lastfile')) | 293 self.loadFile(self.settings.value('lastfile')) |
289 | 294 |
290 def closeEvent(self, ev): | 295 def closeEvent(self, ev): |
291 self.settings.setValue('mainwindowstate', self.saveState()) | 296 self.settings.setValue('mainwindowstate', self.saveState()) |
295 # # TODO: ask for save of opened files | 300 # # TODO: ask for save of opened files |
296 ac = self.activeMdiChild() | 301 ac = self.activeMdiChild() |
297 if ac: | 302 if ac: |
298 if ac.filename: | 303 if ac.filename: |
299 self.settings.setValue('lastfile', ac.filename) | 304 self.settings.setValue('lastfile', ac.filename) |
305 else: | |
306 self.settings.remove('lastfile') | |
307 else: | |
308 self.settings.remove('lastfile') | |
300 ev.accept() | 309 ev.accept() |
301 | 310 |
302 # Error handling: | 311 # Error handling: |
303 def nodeSelected(self, node): | 312 def nodeSelected(self, node): |
304 ce = self.activeMdiChild() | 313 ce = self.activeMdiChild() |
309 ce.highlightErrorLocation( row, col ) | 318 ce.highlightErrorLocation( row, col ) |
310 else: | 319 else: |
311 ce.clearErrors() | 320 ce.clearErrors() |
312 | 321 |
313 def errorSelected(self, err): | 322 def errorSelected(self, err): |
314 row, col, msg = err | |
315 ce = self.activeMdiChild() | 323 ce = self.activeMdiChild() |
316 if not ce: | 324 if not ce: |
317 return | 325 return |
318 ce.highlightErrorLocation(row, col) | 326 ce.highlightErrorLocation(err.loc.row, err.loc.col) |
319 | 327 |
320 # Project loading: | 328 # Project loading: |
321 | 329 |
322 # Build recepy: | 330 # Build recepy: |
323 def buildFile(self): | 331 def buildFile(self): |
324 ce = self.activeMdiChild() | 332 ce = self.activeMdiChild() |
333 print('BUILD file') | |
325 if ce: | 334 if ce: |
326 source = ce.source | 335 source = ce.source |
327 self.buildOutput.clear() | 336 self.buildOutput.clear() |
328 self.buildOutput.append(str(self.compiler)) | 337 self.buildOutput.append(str(self.compiler)) |
329 ast = self.compiler.compilesource(source) | 338 ast = testc3.c3compile(source, self.diag) |
339 #ast = self.compiler.compilesource(source) | |
330 self.astViewer.setAst(ast) | 340 self.astViewer.setAst(ast) |
331 self.buildOutput.append("Done!") | 341 self.buildOutput.append("Done!") |
332 def buildProject(self): | 342 def buildProject(self): |
333 """ Build project """ | 343 """ Build project """ |
344 print('BUILD project') | |
334 self.buildOutput.clear() | 345 self.buildOutput.clear() |
346 self.diag.diags.clear() | |
335 self.buildOutput.append(str(self.compiler)) | 347 self.buildOutput.append(str(self.compiler)) |
336 mods = self.compiler.compileProject(self.project) | 348 self.buildFile() |
337 | 349 #mods = self.compiler.compileProject(self.project) |
338 #self.builderrors.setErrorList(self.compiler.errorlist) | 350 |
339 self.astViewer.setAst(mods[0]) | 351 self.builderrors.setErrorList(self.diag.diags) |
340 #for err in self.compiler.errorlist: | 352 #self.astViewer.setAst(mods[0]) |
341 # self.buildOutput.append(str(err)) | 353 for err in self.diag.diags: |
354 self.buildOutput.append(str(err)) | |
342 self.buildOutput.append("Done!") | 355 self.buildOutput.append("Done!") |
343 | 356 |
344 if __name__ == '__main__': | 357 if __name__ == '__main__': |
345 app = QApplication(sys.argv) | 358 app = QApplication(sys.argv) |
346 ide = Ide() | 359 ide = Ide() |