# HG changeset patch # User windel # Date 1350051091 -7200 # Node ID 99bf4f7d47f4fa9832cdde5ea69850cb1dad56b0 # Parent bcd55a3415120e4a82a06c296bda6ae360c4dd51 Changed project storage diff -r bcd55a341512 -r 99bf4f7d47f4 python/apps/ide.py --- a/python/apps/ide.py Sun Oct 07 17:27:09 2012 +0200 +++ b/python/apps/ide.py Fri Oct 12 16:11:31 2012 +0200 @@ -68,11 +68,11 @@ pitem.setEditable(False) pitem.setData(project) root.appendRow(pitem) - for f in self.project.files: - fitem = QStandardItem(f) + for el in self.project.elements: + fitem = QStandardItem(el) pitem.appendRow(fitem) fitem.setEditable(False) - fitem.setData(f) + fitem.setData(el) self.treeview.setModel(model) self.treeview.expandAll() def contextMenu(self, pos): @@ -121,9 +121,8 @@ self.setWindowIcon(QIcon(icon)) # Create menus: - self.fileMenu = self.menuBar().addMenu('File') + self.projectMenu = self.menuBar().addMenu('Project') self.viewMenu = self.menuBar().addMenu('View') - self.projectMenu = self.menuBar().addMenu('Project') self.helpMenu = self.menuBar().addMenu('Help') # Create mdi area: @@ -143,20 +142,32 @@ self.builderrors.sigErrorSelected.connect(self.errorSelected) self.projectview = ProjectView() - self.addComponent('Project', self.projectview) + self.addComponent('Project explorer', self.projectview) self.projectview.sigLoadFile.connect(self.loadFile) # About dialog: self.aboutDialog = AboutDialog() self.aboutDialog.setWindowIcon(QIcon(icon)) # Create actions: - self.buildAction = QAction('Build!', self) + self.newFileAction = QAction("New", self) + self.projectMenu.addAction(self.newFileAction) + self.newFileAction.triggered.connect(self.newProject) + + self.openAction = QAction("Open", self) + self.openAction.triggered.connect(self.openProject) + self.projectMenu.addAction(self.openAction) + + self.saveAction = QAction("Save", self) + self.projectMenu.addAction(self.saveAction) + self.saveAction.triggered.connect(self.saveProject) + self.closeAction = QAction("Close", self) + self.projectMenu.addAction(self.closeAction) + self.closeAction.triggered.connect(self.closeProject) + self.buildAction = QAction('Build', self) self.buildAction.setShortcut(QKeySequence('F7')) self.projectMenu.addAction(self.buildAction) - self.buildAction.triggered.connect(self.buildFile) - self.openProjectAction = QAction("Open project", self) - self.openProjectAction.triggered.connect(self.openProject) - self.projectMenu.addAction(self.openProjectAction) + self.buildAction.triggered.connect(self.buildProject) + self.helpAction = QAction('Help', self) self.helpAction.setShortcut(QKeySequence('F1')) self.helpMenu.addAction(self.helpAction) @@ -164,15 +175,6 @@ self.helpMenu.addAction(self.aboutAction) self.aboutAction.triggered.connect(self.aboutDialog.open) - self.newFileAction = QAction("New File", self) - self.fileMenu.addAction(self.newFileAction) - self.newFileAction.triggered.connect(self.newFile) - self.saveFileAction = QAction("Save File", self) - self.fileMenu.addAction(self.saveFileAction) - self.saveFileAction.triggered.connect(self.saveFile) - self.closeFileAction = QAction("Close File", self) - self.fileMenu.addAction(self.closeFileAction) - self.closeFileAction.triggered.connect(self.closeFile) cascadeAction = QAction("Cascade windows", self) cascadeAction.triggered.connect(self.mdiArea.cascadeSubWindows) @@ -193,24 +195,18 @@ self.viewMenu.addAction(dw.toggleViewAction()) # File handling: - def newFile(self): - ce = CodeEdit() - w = self.mdiArea.addSubWindow(ce) - ce.show() + def newProject(self): + filename = QFileDialog.getSaveFileName(self, \ + "Select new projectfile", "", "lcfos Project files (*.lcp2)") + if filename: + self.project = Project() + self.project.filename = filename + self.project.save() - def saveFile(self): - ac = self.activeMdiChild() - if ac: - ac.saveFile() + def saveProject(self): + self.project.save() - def saveAll(self): - pass - - def openFile(self): - # TODO - pass - - def closeFile(self): + def closeProject(self): ac = self.activeMdiChild() if ac: self.mdiArea.removeSubWindow(ac) @@ -230,6 +226,16 @@ ce.show() return ce + def loadProject(self, filename): + self.project = Project(filename) + self.projectview.setProject(self.project) + + def openProject(self): + filename = QFileDialog.getOpenFileName(self, \ + "Choose project file", "", "lcfos Project files (*.lcp2)") + if filename: + self.loadProject(filename) + # MDI: def activeMdiChild(self): aw = self.mdiArea.activeSubWindow() @@ -260,7 +266,7 @@ self.restoreGeometry(self.settings.value('mainwindowgeometry')) if self.settings.contains('openedproject'): projectfile = self.settings.value('openedproject') - self.loadProject(projectfile) + #self.loadProject(projectfile) def closeEvent(self, ev): self.settings.setValue('mainwindowstate', self.saveState()) @@ -289,18 +295,9 @@ ce.highlightErrorLocation(row, col) # Project loading: - def loadProject(self, filename): - self.project = Project(filename) - self.projectview.setProject(self.project) - - def openProject(self): - filename = QFileDialog.getOpenFileName(self, \ - "Choose project file", "", "lcfos Project files (*.lcp)") - if filename: - self.loadProject(filename) # Build recepy: - def buildFile(self): + def buildProject(self): """ Build project """ self.saveAll() self.buildOutput.clear() diff -r bcd55a341512 -r 99bf4f7d47f4 python/libs/compiler/compiler.py --- a/python/libs/compiler/compiler.py Sun Oct 07 17:27:09 2012 +0200 +++ b/python/libs/compiler/compiler.py Fri Oct 12 16:11:31 2012 +0200 @@ -50,4 +50,3 @@ mods.append(mod) return mods - diff -r bcd55a341512 -r 99bf4f7d47f4 python/libs/project.py --- a/python/libs/project.py Sun Oct 07 17:27:09 2012 +0200 +++ b/python/libs/project.py Fri Oct 12 16:11:31 2012 +0200 @@ -1,70 +1,32 @@ """ - Project that can be stored to and loaded from XML. + source project + contains: + - modules + - primitives like functions, types and variables + - other modules + """ -from xml.sax import ContentHandler, make_parser -import xml.dom.minidom as md -import os.path - -class ProjectContentHandler(ContentHandler): - def __init__(self, project): - self.project = project - self.inFiles = False - def startElement(self, name, attrs): - if name == 'Project': - self.project.name = attrs['name'] - if name == 'Files': - self.inFiles = True - if name == 'File' and self.inFiles: - self.project.files.append(attrs['Filename']) - def endElement(self, name): - if name == 'Files': - self.inFiles = False - -class ProjectFile: - def __init__(self, filename): - self.filename = filename +import json class Project: - def __init__(self, filename, isnew=False): + def __init__(self, filename=None): self.name = "" - self.files = [] + self.modules = [] + self.elements = [] self.settings = {} self.filename = filename - if not isnew: + if self.filename: """ 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 """ - # Create document: - doc = md.Document() - # Add project: - project = doc.createElement("Project") - project.setAttribute("name", self.name) - doc.appendChild(project) + with open(self.filename, 'r') as f: + d = json.load(f) + self.elements = d['elements'] - # Add project files: - filesNode = doc.createElement("Files") - project.appendChild(filesNode) - for f in self.files: - fe = doc.createElement("File") - fe.setAttribute("Filename", f) - filesNode.appendChild(fe) + def save(self): + if self.filename: + d = {'elements': self.elements} + print(d) + with open(self.filename, 'w') as f: + json.dump(d, f) - # Write the XML file: - xml = doc.toprettyxml() - with open(filename, 'w') as f: - f.write(xml) - - 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 bcd55a341512 -r 99bf4f7d47f4 python/libs/widgets/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/libs/widgets/__init__.py Fri Oct 12 16:11:31 2012 +0200 @@ -0,0 +1,5 @@ +# File to make this directory a package. + +from .codeeditor import CodeEdit +from .astviewer import AstViewer +