comparison 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
comparison
equal deleted inserted replaced
100:fe145e42259d 101:af0d7913677a
122 icon.loadFromData(lcfospng) 122 icon.loadFromData(lcfospng)
123 self.setWindowIcon(QIcon(icon)) 123 self.setWindowIcon(QIcon(icon))
124 124
125 # Create menus: 125 # Create menus:
126 mb = self.menuBar() 126 mb = self.menuBar()
127 self.fileMenu = mb.addMenu('File')
127 self.projectMenu = mb.addMenu('Project') 128 self.projectMenu = mb.addMenu('Project')
128 self.viewMenu = mb.addMenu('View') 129 self.viewMenu = mb.addMenu('View')
129 self.helpMenu = mb.addMenu('Help') 130 self.helpMenu = mb.addMenu('Help')
130 131
131 # Create mdi area: 132 # Create mdi area:
164 addMenuEntry("Open", self.projectMenu, self.openProject) 165 addMenuEntry("Open", self.projectMenu, self.openProject)
165 addMenuEntry("Save", self.projectMenu, self.saveProject) 166 addMenuEntry("Save", self.projectMenu, self.saveProject)
166 addMenuEntry("Close", self.projectMenu, self.closeProject) 167 addMenuEntry("Close", self.projectMenu, self.closeProject)
167 addMenuEntry("Build", self.projectMenu, self.buildProject, shortcut=QKeySequence('F7')) 168 addMenuEntry("Build", self.projectMenu, self.buildProject, shortcut=QKeySequence('F7'))
168 169
170 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New))
171 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open))
172 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save))
173 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F8"))
174
169 self.helpAction = QAction('Help', self) 175 self.helpAction = QAction('Help', self)
170 self.helpAction.setShortcut(QKeySequence('F1')) 176 self.helpAction.setShortcut(QKeySequence('F1'))
171 self.helpMenu.addAction(self.helpAction) 177 self.helpMenu.addAction(self.helpAction)
172 addMenuEntry('About', self.helpMenu, self.aboutDialog.open) 178 addMenuEntry('About', self.helpMenu, self.aboutDialog.open)
173 179
184 "Select new projectfile", "", "lcfos Project files (*.lcp2)") 190 "Select new projectfile", "", "lcfos Project files (*.lcp2)")
185 if filename: 191 if filename:
186 self.project = Project() 192 self.project = Project()
187 self.project.filename = filename 193 self.project.filename = filename
188 self.project.save() 194 self.project.save()
195
196 def newFile(self):
197 self.loadFile('main.ks')
198 def openFile(self):
199 filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)")
200 if filename:
201 self.loadFile(filename)
202 def saveFile(self):
203 ac = self.activeMdiChild()
204 if ac:
205 ac.save()
189 206
190 def saveProject(self): 207 def saveProject(self):
191 self.project.save() 208 self.project.save()
192 209
193 def closeProject(self): 210 def closeProject(self):
202 self.mdiArea.setActiveSubWindow(wid.parent()) 219 self.mdiArea.setActiveSubWindow(wid.parent())
203 return wid 220 return wid
204 221
205 # Create a new one: 222 # Create a new one:
206 ce = CodeEdit() 223 ce = CodeEdit()
207 source = self.project.loadProjectFile(filename) 224
208 ce.setSource(source) 225 #source = self.project.loadProjectFile(filename)
226 try:
227 with open(filename) as f:
228 source = f.read()
229 ce.setSource(source)
230 except Exception as e:
231 print('exception opening file', e)
209 self.mdiArea.addSubWindow(ce) 232 self.mdiArea.addSubWindow(ce)
233 ce.setFileName(filename)
210 ce.show() 234 ce.show()
211 return ce 235 return ce
212 236
213 def loadProject(self, filename): 237 def loadProject(self, filename):
214 self.project = Project(filename) 238 self.project = Project(filename)
249 if self.settings.contains('mainwindowgeometry'): 273 if self.settings.contains('mainwindowgeometry'):
250 self.restoreGeometry(self.settings.value('mainwindowgeometry')) 274 self.restoreGeometry(self.settings.value('mainwindowgeometry'))
251 if self.settings.contains('openedproject'): 275 if self.settings.contains('openedproject'):
252 projectfile = self.settings.value('openedproject') 276 projectfile = self.settings.value('openedproject')
253 #self.loadProject(projectfile) 277 #self.loadProject(projectfile)
278 if self.settings.contains('lastfile'):
279 self.loadFile(self.settings.value('lastfile'))
254 280
255 def closeEvent(self, ev): 281 def closeEvent(self, ev):
256 self.settings.setValue('mainwindowstate', self.saveState()) 282 self.settings.setValue('mainwindowstate', self.saveState())
257 self.settings.setValue('mainwindowgeometry', self.saveGeometry()) 283 self.settings.setValue('mainwindowgeometry', self.saveGeometry())
258 if self.project: 284 #if self.project:
259 self.settings.setValue('openedproject', self.project.filename) 285 # self.settings.setValue('openedproject', self.project.filename)
260 # TODO: ask for save of opened files 286 # # TODO: ask for save of opened files
287 ac = self.activeMdiChild()
288 if ac:
289 if ac.filename:
290 self.settings.setValue('lastfile', ac.filename)
261 ev.accept() 291 ev.accept()
262 292
263 # Error handling: 293 # Error handling:
264 def nodeSelected(self, node): 294 def nodeSelected(self, node):
265 ce = self.activeMdiChild() 295 ce = self.activeMdiChild()
279 ce.highlightErrorLocation(row, col) 309 ce.highlightErrorLocation(row, col)
280 310
281 # Project loading: 311 # Project loading:
282 312
283 # Build recepy: 313 # Build recepy:
314 def buildFile(self):
315 ce = self.activeMdiChild()
316 if ce:
317 source = ce.source
318 self.buildOutput.clear()
319 self.buildOutput.append(str(self.compiler))
320 print(source)
321 self.compiler.compilesource(source)
322 self.buildOutput.append("Done!")
284 def buildProject(self): 323 def buildProject(self):
285 """ Build project """ 324 """ Build project """
286 self.buildOutput.clear() 325 self.buildOutput.clear()
287 self.buildOutput.append(str(self.compiler)) 326 self.buildOutput.append(str(self.compiler))
288 mods = self.compiler.compileProject(self.project) 327 mods = self.compiler.compileProject(self.project)
289 328
290 self.builderrors.setErrorList(self.compiler.errorlist) 329 #self.builderrors.setErrorList(self.compiler.errorlist)
291 self.astViewer.setAst(mods[0]) 330 self.astViewer.setAst(mods[0])
292 for err in self.compiler.errorlist: 331 #for err in self.compiler.errorlist:
293 self.buildOutput.append(str(err)) 332 # self.buildOutput.append(str(err))
294 self.buildOutput.append("Done!") 333 self.buildOutput.append("Done!")
295 334
296 if __name__ == '__main__': 335 if __name__ == '__main__':
297 app = QApplication(sys.argv) 336 app = QApplication(sys.argv)
298 ide = Ide() 337 ide = Ide()