Mercurial > lcfOS
diff python/ide.py @ 101:af0d7913677a
Fixes and splitting into 3 stage
author | windel |
---|---|
date | Mon, 24 Dec 2012 17:55:08 +0100 |
parents | fe145e42259d |
children | 63937c8d1478 |
line wrap: on
line diff
--- a/python/ide.py Mon Dec 24 16:35:22 2012 +0100 +++ b/python/ide.py Mon Dec 24 17:55:08 2012 +0100 @@ -124,6 +124,7 @@ # Create menus: mb = self.menuBar() + self.fileMenu = mb.addMenu('File') self.projectMenu = mb.addMenu('Project') self.viewMenu = mb.addMenu('View') self.helpMenu = mb.addMenu('Help') @@ -166,6 +167,11 @@ addMenuEntry("Close", self.projectMenu, self.closeProject) addMenuEntry("Build", self.projectMenu, self.buildProject, shortcut=QKeySequence('F7')) + addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) + addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) + addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) + addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F8")) + self.helpAction = QAction('Help', self) self.helpAction.setShortcut(QKeySequence('F1')) self.helpMenu.addAction(self.helpAction) @@ -187,6 +193,17 @@ self.project.filename = filename self.project.save() + def newFile(self): + self.loadFile('main.ks') + def openFile(self): + filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)") + if filename: + self.loadFile(filename) + def saveFile(self): + ac = self.activeMdiChild() + if ac: + ac.save() + def saveProject(self): self.project.save() @@ -204,9 +221,16 @@ # Create a new one: ce = CodeEdit() - source = self.project.loadProjectFile(filename) - ce.setSource(source) + + #source = self.project.loadProjectFile(filename) + try: + with open(filename) as f: + source = f.read() + ce.setSource(source) + except Exception as e: + print('exception opening file', e) self.mdiArea.addSubWindow(ce) + ce.setFileName(filename) ce.show() return ce @@ -251,13 +275,19 @@ if self.settings.contains('openedproject'): projectfile = self.settings.value('openedproject') #self.loadProject(projectfile) + if self.settings.contains('lastfile'): + self.loadFile(self.settings.value('lastfile')) def closeEvent(self, ev): self.settings.setValue('mainwindowstate', self.saveState()) self.settings.setValue('mainwindowgeometry', self.saveGeometry()) - if self.project: - self.settings.setValue('openedproject', self.project.filename) - # TODO: ask for save of opened files + #if self.project: + # self.settings.setValue('openedproject', self.project.filename) + # # TODO: ask for save of opened files + ac = self.activeMdiChild() + if ac: + if ac.filename: + self.settings.setValue('lastfile', ac.filename) ev.accept() # Error handling: @@ -281,16 +311,25 @@ # Project loading: # Build recepy: + def buildFile(self): + ce = self.activeMdiChild() + if ce: + source = ce.source + self.buildOutput.clear() + self.buildOutput.append(str(self.compiler)) + print(source) + self.compiler.compilesource(source) + self.buildOutput.append("Done!") def buildProject(self): """ Build project """ self.buildOutput.clear() self.buildOutput.append(str(self.compiler)) mods = self.compiler.compileProject(self.project) - self.builderrors.setErrorList(self.compiler.errorlist) + #self.builderrors.setErrorList(self.compiler.errorlist) self.astViewer.setAst(mods[0]) - for err in self.compiler.errorlist: - self.buildOutput.append(str(err)) + #for err in self.compiler.errorlist: + # self.buildOutput.append(str(err)) self.buildOutput.append("Done!") if __name__ == '__main__':