# HG changeset patch # User windel # Date 1321338900 -3600 # Node ID de004f808e5638416a4ced1c3513b8fb370f7a61 # Parent 607898120eb1d6b96b2a742ceca5c4e6e804f2bd Fixup in multidocument area stuff diff -r 607898120eb1 -r de004f808e56 ide/compiler/compiler.py --- a/ide/compiler/compiler.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/compiler/compiler.py Tue Nov 15 07:35:00 2011 +0100 @@ -39,6 +39,15 @@ sym = ExportedSymbol(proc.name, proc.typ) sym.imageoffset = proc.entrypoint ast.exports.append(sym) - return ast + def compileProject(self, project): + mods = [] + for fname in project.files: + print('Compiling {0}...'.format(fname)) + source = project.loadProjectFile(fname) + mod = self.compilesource(source) + mods.append(mod) + return mods + + diff -r 607898120eb1 -r de004f808e56 ide/compiler/errors.py --- a/ide/compiler/errors.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/compiler/errors.py Tue Nov 15 07:35:00 2011 +0100 @@ -1,10 +1,11 @@ """ Error handling routines """ class CompilerException(Exception): - def __init__(self, msg, row=0, col=0): + def __init__(self, msg, row=0, col=0, filename=None): self.msg = msg self.row = row self.col = col + self.filename = filename def __repr__(self): return self.msg def __str__(self): diff -r 607898120eb1 -r de004f808e56 ide/compiler/parser.py --- a/ide/compiler/parser.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/compiler/parser.py Tue Nov 15 07:35:00 2011 +0100 @@ -37,6 +37,7 @@ def NextToken(self): self.token = self.tokens.__next__() + # TODO: store filename in location? self.location = (self.token.row, self.token.col) # Helpers to find location of the error in the code: diff -r 607898120eb1 -r de004f808e56 ide/ide/codeeditor.py --- a/ide/ide/codeeditor.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/ide/codeeditor.py Tue Nov 15 07:35:00 2011 +0100 @@ -64,13 +64,13 @@ # Syntax highlighter: self.highlighter = MySyntaxHighlighter(self.document()) - def loadFile(self, filename): + def setFileName(self, filename): self.filename = filename self.isUntitled = False - with open(filename, 'r') as f: - source = f.read() + self.setWindowTitle(filename) + def setSource(self, source): self.setPlainText(source) - self.setWindowTitle(filename) + def save(self): pass def saveAs(self): diff -r 607898120eb1 -r de004f808e56 ide/ide/ide.py --- a/ide/ide/ide.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/ide/ide.py Tue Nov 15 07:35:00 2011 +0100 @@ -74,7 +74,6 @@ if not idx.isValid(): return item = self.treeview.model().itemFromIndex(idx) - print(item) def activate(self, index): if not index.isValid(): return @@ -126,9 +125,6 @@ self.setCentralWidget(self.mdiArea) # Create components: - self.codeedit = CodeEdit() - self.mdiArea.addSubWindow(self.codeedit) - self.buildOutput = BuildOutput() self.addComponent('Build output', self.buildOutput) @@ -199,9 +195,11 @@ def saveFile(self): ac = self.activeMdiChild() if ac: - print(ac) ac.saveFile() + def saveAll(self): + pass + def openFile(self): # TODO pass @@ -212,19 +210,16 @@ self.mdiArea.removeSubWindow(ac) def loadFile(self, filename): - # Extend filename: - basedir = os.path.dirname(self.project.filename) - filename = os.path.join(basedir, filename) - # Find existing mdi widget: wid = self.findMdiChild(filename) if wid: self.mdiArea.setActiveSubWindow(wid.parent()) - return + return wid # Create a new one: ce = CodeEdit() - ce.loadFile(filename) + source = self.project.loadProjectFile(filename) + ce.setSource(source) self.mdiArea.addSubWindow(ce) ce.show() return ce @@ -243,7 +238,14 @@ if wid.filename == filename: return wid return None - + + def allChildren(self): + c = [] + for window in self.mdiArea.subWindowList(): + wid = window.widget() + c.append(wid) + return c + # Settings: def loadSettings(self): if self.settings.contains('mainwindowstate'): @@ -251,52 +253,57 @@ if self.settings.contains('mainwindowgeometry'): self.restoreGeometry(self.settings.value('mainwindowgeometry')) if self.settings.contains('openedproject'): - self.projectfile = self.settings.value('openedproject') - self.loadProject() - else: - self.projectfile = "" + projectfile = self.settings.value('openedproject') + self.loadProject(projectfile) def closeEvent(self, ev): self.settings.setValue('mainwindowstate', self.saveState()) self.settings.setValue('mainwindowgeometry', self.saveGeometry()) - self.settings.setValue('openedproject', self.projectfile) - self.codeedit.saveFile() + if self.project: + self.settings.setValue('openedproject', self.project.filename) + # TODO: ask for save of opened files ev.accept() # Error handling: def nodeSelected(self, node): + ce = self.activeMdiChild() + if not ce: + return if node.location: row, col = node.location - self.codeedit.highlightErrorLocation( row, col ) + ce.highlightErrorLocation( row, col ) else: - self.codeedit.clearErrors() + ce.clearErrors() def errorSelected(self, err): row, col, msg = err - self.codeedit.highlightErrorLocation(row, col) + ce = self.activeMdiChild() + if not ce: + return + ce.highlightErrorLocation(row, col) # Project loading: - def loadProject(self): - if self.projectfile: - self.project = Project() - self.project.load(self.projectfile) - self.projectview.setProject(self.project) + def loadProject(self, filename): + self.project = Project(filename) + self.projectview.setProject(self.project) def openProject(self): - self.projectfile = QFileDialog.getOpenFileName(self, "Choose project file", "", "lcfos Project files (*.lcp)") - self.loadProject() + filename = QFileDialog.getOpenFileName(self, \ + "Choose project file", "", "lcfos Project files (*.lcp)") + if filename: + self.loadProject(filename) # Build recepy: def buildFile(self): + """ Build project """ + self.saveAll() self.buildOutput.clear() - self.codeedit.clearErrors() - source = str(self.codeedit.toPlainText()) self.buildOutput.append(str(self.compiler)) - output = self.compiler.compilesource(source) + mods = self.compiler.compileProject(self.project) + self.builderrors.setErrorList(self.compiler.errorlist) - self.astViewer.setAst(output) - if self.compiler.errorlist: - self.buildOutput.append("error occurred") - else: - self.buildOutput.append("Done!") + self.astViewer.setAst(mods[0]) + for err in self.compiler.errorlist: + self.buildOutput.append(str(err)) + self.buildOutput.append("Done!") diff -r 607898120eb1 -r de004f808e56 ide/project.py --- a/ide/project.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/project.py Tue Nov 15 07:35:00 2011 +0100 @@ -21,12 +21,23 @@ if name == 'Files': self.inFiles = False +class ProjectFile: + def __init__(self, filename): + self.filename = filename + class Project: - def __init__(self): + def __init__(self, filename, isnew=False): self.name = "" self.files = [] self.settings = {} - self.filename = "" + self.filename = filename + + if not isnew: + """ Load the project from the XML file """ + parser = make_parser() + handler = ProjectContentHandler(self) + parser.setContentHandler(handler) + parser.parse(filename) def save(self, filename): """ Save the project in XML format """ @@ -50,14 +61,10 @@ with open(filename, 'w') as f: f.write(xml) - def load(self, filename): - """ Load the project from the XML file """ - if not os.path.exists(filename): - return - self.filename = filename - print(self.filename) - parser = make_parser() - handler = ProjectContentHandler(self) - parser.setContentHandler(handler) - parser.parse(filename) + def loadProjectFile(self, filename): + basedir = os.path.dirname(self.filename) + filename = os.path.join(basedir, filename) + with open(filename, 'r') as f: + src = f.read() + return src diff -r 607898120eb1 -r de004f808e56 ide/runbuild.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ide/runbuild.py Tue Nov 15 07:35:00 2011 +0100 @@ -0,0 +1,16 @@ +import sys + +# Compiler imports: +from compiler.compiler import Compiler +from project import Project + +if __name__ == '__main__': + if len(sys.argv) < 2: + print('Use {0} projectfile'.format(sys.argv[0])) + sys.exit(-1) + filename = sys.argv[1] + project = Project() + project.load(filename) + pc = Compiler() + pc.compileProject(project) + diff -r 607898120eb1 -r de004f808e56 ide/runtests.py --- a/ide/runtests.py Sun Nov 13 23:24:10 2011 +0100 +++ b/ide/runtests.py Tue Nov 15 07:35:00 2011 +0100 @@ -254,14 +254,13 @@ # This also works: 4D0FAFFE (another variant?? ) assert(assembler.imulreg64('r15', 'r14') == [0x4d, 0x0f, 0xaf, 0xfe]) def testProject(self): - p = Project() + p = Project('test.xml', isnew=True) p.name = "Test project" p.files.append('main.mod') p.files.append('test.mod') p.save('test.xml') - q = Project() - q.load('test.xml') + q = Project('test.xml') assert(p.name == q.name) assert(p.files == q.files)