Mercurial > lcfOS
comparison python/ide.py @ 247:dd8bbb963458
project remove
author | Windel Bouwman |
---|---|
date | Fri, 26 Jul 2013 10:44:26 +0200 |
parents | 6259856841a0 |
children | b10d46e5c8dd |
comparison
equal
deleted
inserted
replaced
246:f254b87258e6 | 247:dd8bbb963458 |
---|---|
10 import ppci | 10 import ppci |
11 from astviewer import AstViewer | 11 from astviewer import AstViewer |
12 #from codeeditor import CodeEdit | 12 #from codeeditor import CodeEdit |
13 from codeedit import CodeEdit | 13 from codeedit import CodeEdit |
14 stutil = __import__('st-util') | 14 stutil = __import__('st-util') |
15 import testc3 | |
16 import c3 | 15 import c3 |
17 | 16 |
18 class BuildOutput(QTextEdit): | 17 class BuildOutput(QTextEdit): |
19 """ Build output component """ | 18 """ Build output component """ |
20 def __init__(self, parent=None): | 19 def __init__(self, parent=None): |
51 return | 50 return |
52 item = self.model.itemFromIndex(index) | 51 item = self.model.itemFromIndex(index) |
53 err = item.data() | 52 err = item.data() |
54 self.sigErrorSelected.emit(err) | 53 self.sigErrorSelected.emit(err) |
55 | 54 |
56 class ProjectView(QWidget): | |
57 sigLoadFile = pyqtSignal(str) | |
58 def __init__(self, parent=None): | |
59 super(ProjectView, self).__init__(parent) | |
60 self.treeview = QTreeView(self) | |
61 self.treeview.setContextMenuPolicy(Qt.CustomContextMenu) | |
62 l = QVBoxLayout(self) | |
63 l.addWidget(self.treeview) | |
64 self.projectIcon = QIcon('icons/logo.png') | |
65 # Connect signals: | |
66 self.treeview.activated.connect(self.activate) | |
67 self.treeview.customContextMenuRequested.connect(self.contextMenu) | |
68 def setProject(self, project): | |
69 self.project = project | |
70 model = QStandardItemModel() | |
71 root = model.invisibleRootItem() | |
72 pitem = QStandardItem(self.projectIcon, project.name) | |
73 pitem.setEditable(False) | |
74 pitem.setData(project) | |
75 root.appendRow(pitem) | |
76 for el in self.project.elements: | |
77 fitem = QStandardItem(el) | |
78 pitem.appendRow(fitem) | |
79 fitem.setEditable(False) | |
80 fitem.setData(el) | |
81 self.treeview.setModel(model) | |
82 self.treeview.expandAll() | |
83 def contextMenu(self, pos): | |
84 idx = self.treeview.indexAt(pos) | |
85 if not idx.isValid(): | |
86 return | |
87 item = self.treeview.model().itemFromIndex(idx) | |
88 def activate(self, index): | |
89 if not index.isValid(): | |
90 return | |
91 model = self.treeview.model() | |
92 item = model.itemFromIndex(index) | |
93 fn = item.data() | |
94 if type(fn) is str: | |
95 self.sigLoadFile.emit(fn) | |
96 | 55 |
97 class AboutDialog(QDialog): | 56 class AboutDialog(QDialog): |
98 def __init__(self, parent=None): | 57 def __init__(self, parent=None): |
99 super(AboutDialog, self).__init__(parent) | 58 super(AboutDialog, self).__init__(parent) |
100 self.setWindowTitle('About') | 59 self.setWindowTitle('About') |
111 but = QPushButton('OK') | 70 but = QPushButton('OK') |
112 but.setDefault(True) | 71 but.setDefault(True) |
113 but.clicked.connect(self.close) | 72 but.clicked.connect(self.close) |
114 l.addWidget(but) | 73 l.addWidget(but) |
115 | 74 |
116 class ProjectOptions(QDialog): | |
117 pass | |
118 # TODO: project options in here | |
119 | |
120 class Ide(QMainWindow): | 75 class Ide(QMainWindow): |
121 def __init__(self, parent=None): | 76 def __init__(self, parent=None): |
122 super(Ide, self).__init__(parent) | 77 super(Ide, self).__init__(parent) |
123 self.setWindowTitle('LCFOS IDE') | 78 self.setWindowTitle('LCFOS IDE') |
124 self.setWindowIcon(QIcon('icons/logo.png')) | 79 icon = QIcon('icons/logo.png') |
80 self.setWindowIcon(icon) | |
125 | 81 |
126 # Create menus: | 82 # Create menus: |
127 mb = self.menuBar() | 83 mb = self.menuBar() |
128 self.fileMenu = mb.addMenu('File') | 84 self.fileMenu = mb.addMenu('File') |
129 self.projectMenu = mb.addMenu('Project') | |
130 self.viewMenu = mb.addMenu('View') | 85 self.viewMenu = mb.addMenu('View') |
131 self.helpMenu = mb.addMenu('Help') | 86 self.helpMenu = mb.addMenu('Help') |
132 | 87 |
133 # Create mdi area: | 88 # Create mdi area: |
134 self.mdiArea = QMdiArea() | 89 self.mdiArea = QMdiArea() |
146 self.buildOutput = addComponent('Build output', BuildOutput()) | 101 self.buildOutput = addComponent('Build output', BuildOutput()) |
147 self.astViewer = addComponent('AST viewer', AstViewer()) | 102 self.astViewer = addComponent('AST viewer', AstViewer()) |
148 self.astViewer.sigNodeSelected.connect(self.nodeSelected) | 103 self.astViewer.sigNodeSelected.connect(self.nodeSelected) |
149 self.builderrors = addComponent('Build errors', BuildErrors()) | 104 self.builderrors = addComponent('Build errors', BuildErrors()) |
150 self.builderrors.sigErrorSelected.connect(self.errorSelected) | 105 self.builderrors.sigErrorSelected.connect(self.errorSelected) |
151 self.projectview = addComponent('Project explorer', ProjectView()) | |
152 self.projectview.sigLoadFile.connect(self.loadFile) | |
153 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) | 106 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer()) |
154 self.regview = addComponent('Registers', stutil.RegisterView()) | 107 self.regview = addComponent('Registers', stutil.RegisterView()) |
155 self.memview = addComponent('Memory', stutil.MemoryView()) | 108 self.memview = addComponent('Memory', stutil.MemoryView()) |
156 self.ctrlToolbar = stutil.DebugToolbar() | 109 self.ctrlToolbar = stutil.DebugToolbar() |
157 self.addToolBar(self.ctrlToolbar) | 110 self.addToolBar(self.ctrlToolbar) |
159 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice) | 112 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice) |
160 self.ctrlToolbar.statusChange.connect(self.memview.refresh) | 113 self.ctrlToolbar.statusChange.connect(self.memview.refresh) |
161 self.devxplr.deviceSelected.connect(self.memview.setDevice) | 114 self.devxplr.deviceSelected.connect(self.memview.setDevice) |
162 self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice) | 115 self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice) |
163 self.ctrlToolbar.statusChange.connect(self.regview.refresh) | 116 self.ctrlToolbar.statusChange.connect(self.regview.refresh) |
117 self.ctrlToolbar.codePosition.connect(self.pointCode) | |
164 | 118 |
165 # About dialog: | 119 # About dialog: |
166 self.aboutDialog = AboutDialog() | 120 self.aboutDialog = AboutDialog() |
167 self.aboutDialog.setWindowIcon(QIcon('icons/logo.png')) | 121 self.aboutDialog.setWindowIcon(icon) |
168 # Create actions: | 122 # Create actions: |
169 def addMenuEntry(name, menu, callback, shortcut=None): | 123 def addMenuEntry(name, menu, callback, shortcut=None): |
170 a = QAction(name, self) | 124 a = QAction(name, self) |
171 menu.addAction(a) | 125 menu.addAction(a) |
172 a.triggered.connect(callback) | 126 a.triggered.connect(callback) |
174 a.setShortcut(shortcut) | 128 a.setShortcut(shortcut) |
175 | 129 |
176 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) | 130 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) |
177 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) | 131 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) |
178 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) | 132 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) |
179 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F8")) | 133 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F7")) |
180 | 134 |
181 self.helpAction = QAction('Help', self) | 135 self.helpAction = QAction('Help', self) |
182 self.helpAction.setShortcut(QKeySequence('F1')) | 136 self.helpAction.setShortcut(QKeySequence('F1')) |
183 self.helpMenu.addAction(self.helpAction) | 137 self.helpMenu.addAction(self.helpAction) |
184 addMenuEntry('About', self.helpMenu, self.aboutDialog.open) | 138 addMenuEntry('About', self.helpMenu, self.aboutDialog.open) |
191 # Load settings: | 145 # Load settings: |
192 self.settings = QSettings('windelsoft', 'lcfoside') | 146 self.settings = QSettings('windelsoft', 'lcfoside') |
193 self.loadSettings() | 147 self.loadSettings() |
194 | 148 |
195 ce = self.newFile() | 149 ce = self.newFile() |
196 ce.Source = testc3.testsrc | |
197 | |
198 self.diag = ppci.DiagnosticsManager() | 150 self.diag = ppci.DiagnosticsManager() |
199 self.c3front = c3.Builder(self.diag) | 151 self.c3front = c3.Builder(self.diag) |
200 | 152 |
201 # File handling: | 153 # File handling: |
202 def newFile(self): | 154 def newFile(self): |
203 ce = CodeEdit() | 155 ce = CodeEdit() |
204 ce.textChanged.connect(self.buildProject) | 156 ce.textChanged.connect(self.buildFile) |
205 w = self.mdiArea.addSubWindow(ce) | 157 w = self.mdiArea.addSubWindow(ce) |
206 ce.show() | 158 ce.show() |
207 w.resize(500, 700) | 159 w.resize(500, 700) |
208 return ce | 160 return ce |
161 | |
209 def openFile(self): | 162 def openFile(self): |
210 filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)") | 163 filename = QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", "C3 source files (*.ks)") |
211 if filename: | 164 if filename: |
212 self.loadFile(filename) | 165 self.loadFile(filename) |
166 | |
213 def saveFile(self): | 167 def saveFile(self): |
214 ac = self.activeMdiChild() | 168 ac = self.activeMdiChild() |
215 if ac: | 169 if ac: |
216 ac.save() | 170 ac.save() |
217 | |
218 def saveProject(self): | |
219 self.project.save() | |
220 | |
221 def closeProject(self): | |
222 ac = self.activeMdiChild() | |
223 if ac: | |
224 self.mdiArea.removeSubWindow(ac) | |
225 | 171 |
226 def loadFile(self, filename): | 172 def loadFile(self, filename): |
227 # Find existing mdi widget: | 173 # Find existing mdi widget: |
228 wid = self.findMdiChild(filename) | 174 wid = self.findMdiChild(filename) |
229 if wid: | 175 if wid: |
242 print('exception opening file', e) | 188 print('exception opening file', e) |
243 self.mdiArea.addSubWindow(ce) | 189 self.mdiArea.addSubWindow(ce) |
244 ce.setFileName(filename) | 190 ce.setFileName(filename) |
245 ce.show() | 191 ce.show() |
246 return ce | 192 return ce |
247 | |
248 def loadProject(self, filename): | |
249 self.project = Project(filename) | |
250 self.projectview.setProject(self.project) | |
251 | |
252 def openProject(self): | |
253 filename = QFileDialog.getOpenFileName(self, \ | |
254 "Choose project file", "", "lcfos Project files (*.lcp2)") | |
255 if filename: | |
256 self.loadProject(filename) | |
257 | 193 |
258 # MDI: | 194 # MDI: |
259 def activeMdiChild(self): | 195 def activeMdiChild(self): |
260 aw = self.mdiArea.activeSubWindow() | 196 aw = self.mdiArea.activeSubWindow() |
261 if aw: | 197 if aw: |
287 self.loadFile(self.settings.value('lastfile')) | 223 self.loadFile(self.settings.value('lastfile')) |
288 | 224 |
289 def closeEvent(self, ev): | 225 def closeEvent(self, ev): |
290 self.settings.setValue('mainwindowstate', self.saveState()) | 226 self.settings.setValue('mainwindowstate', self.saveState()) |
291 self.settings.setValue('mainwindowgeometry', self.saveGeometry()) | 227 self.settings.setValue('mainwindowgeometry', self.saveGeometry()) |
292 #if self.project: | |
293 # self.settings.setValue('openedproject', self.project.filename) | |
294 # # TODO: ask for save of opened files | 228 # # TODO: ask for save of opened files |
295 ac = self.activeMdiChild() | 229 ac = self.activeMdiChild() |
296 if ac: | 230 if ac: |
297 if hasattr(ac, 'filename') and ac.filename: | 231 if hasattr(ac, 'filename') and ac.filename: |
298 self.settings.setValue('lastfile', ac.filename) | 232 self.settings.setValue('lastfile', ac.filename) |
307 ce = self.activeMdiChild() | 241 ce = self.activeMdiChild() |
308 if not ce: | 242 if not ce: |
309 return | 243 return |
310 if node.loc: | 244 if node.loc: |
311 row, col = node.loc.row, node.loc.col | 245 row, col = node.loc.row, node.loc.col |
312 ce.setRowCol( row, col ) | 246 ce.setRowCol(row, col) |
313 ce.setFocus() | 247 ce.setFocus() |
314 else: | 248 else: |
315 ce.clearErrors() | 249 ce.clearErrors() |
316 | 250 |
317 def errorSelected(self, err): | 251 def errorSelected(self, err): |
319 if not ce: | 253 if not ce: |
320 return | 254 return |
321 ce.setRowCol(err.loc.row, err.loc.col) | 255 ce.setRowCol(err.loc.row, err.loc.col) |
322 ce.setFocus() | 256 ce.setFocus() |
323 | 257 |
324 # Project loading: | 258 def pointCode(self, p): |
259 print('PC', p) | |
260 | |
325 | 261 |
326 # Build recepy: | 262 # Build recepy: |
327 def buildFile(self): | 263 def buildFile(self): |
328 ce = self.activeMdiChild() | 264 ce = self.activeMdiChild() |
329 if ce: | 265 if ce: |
332 self.buildOutput.append('Starting build') | 268 self.buildOutput.append('Starting build') |
333 ir = self.c3front.build(source) | 269 ir = self.c3front.build(source) |
334 ast = self.c3front.pkg | 270 ast = self.c3front.pkg |
335 self.astViewer.setAst(ast) | 271 self.astViewer.setAst(ast) |
336 self.buildOutput.append("Done!") | 272 self.buildOutput.append("Done!") |
337 def buildProject(self): | |
338 """ Build project """ | |
339 self.buildOutput.clear() | |
340 self.diag.diags.clear() | |
341 self.buildFile() | |
342 | |
343 self.builderrors.setErrorList(self.diag.diags) | |
344 for err in self.diag.diags: | |
345 self.buildOutput.append(str(err)) | |
346 ce = self.activeMdiChild() | |
347 if ce: | |
348 ce.setErrors(self.diag.diags) | |
349 self.buildOutput.append("Done!") | |
350 | 273 |
351 if __name__ == '__main__': | 274 if __name__ == '__main__': |
352 app = QApplication(sys.argv) | 275 app = QApplication(sys.argv) |
353 ide = Ide() | 276 ide = Ide() |
354 ide.show() | 277 ide.show() |