annotate python/ide.py @ 164:e023d3ce1d63

Fix to loc of assignment
author Windel Bouwman
date Mon, 18 Mar 2013 22:15:57 +0100
parents 8104fc8b5e90
children 598d3888a11c
rev   line source
99
windel
parents: 98
diff changeset
1 #!/usr/bin/python
windel
parents: 98
diff changeset
2
69
60cc36ef5a50 Rework in compiler
windel
parents: 68
diff changeset
3 import sys, os, base64
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
4 assert sys.version_info.major == 3, "Needs to be run in python version 3.x"
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
5
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
6 from PyQt4.QtCore import *
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
7 from PyQt4.QtGui import *
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
8
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
9 # Compiler imports:
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
10 from project import Project
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 102
diff changeset
11 import ppci
100
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
12 from astviewer import AstViewer
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
13 #from codeeditor import CodeEdit
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
14 from codeedit import CodeEdit
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
15 stutil = __import__('st-util')
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
16 import testc3
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
17
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
18 lcfospng = base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEhMKBk7B678AAAA/SURBVFjD\n7dbBCQAgDATBi9h/y7EFA4Kf2QLCwH1S6XQu6sqoujublc8BAAAAAAAAAAB8B+zXT6YJAAAAAKYd\nWSgFQNUyijIAAAAASUVORK5CYII=\n')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
19
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
20 class BuildOutput(QTextEdit):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
21 """ Build output component """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
22 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
23 super(BuildOutput, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
24 self.setCurrentFont(QFont('Courier'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
25 self.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
26 self.append('Build output will appear here!')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
27
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
28 class BuildErrors(QListView):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
29 sigErrorSelected = pyqtSignal(object)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
30 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
31 super(BuildErrors, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
32 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
33 self.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
34 self.clicked.connect(self.itemSelected)
154
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
35 self.errorIcon = QIcon('error.png')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
36 def setErrorList(self, errorlist):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
37 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
38 for e in errorlist:
154
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
39 item = QStandardItem(self.errorIcon, str(e))
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
40 item.setData(e)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
41 model.appendRow(item)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
42 self.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
43 def itemSelected(self, index):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
44 if not index.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
45 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
46 model = self.model()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
47 item = model.itemFromIndex(index)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
48 err = item.data()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
49 self.sigErrorSelected.emit(err)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
50
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
51 class ProjectView(QWidget):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
52 sigLoadFile = pyqtSignal(str)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
53 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
54 super(ProjectView, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
55 self.treeview = QTreeView(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
56 self.treeview.setContextMenuPolicy(Qt.CustomContextMenu)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
57 l = QVBoxLayout(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
58 l.addWidget(self.treeview)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
59 pm = QPixmap()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
60 pm.loadFromData(lcfospng)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
61 self.projectIcon = QIcon(pm)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
62 # Connect signals:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
63 self.treeview.activated.connect(self.activate)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
64 self.treeview.customContextMenuRequested.connect(self.contextMenu)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
65 def setProject(self, project):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
66 self.project = project
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
67 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
68 root = model.invisibleRootItem()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
69 pitem = QStandardItem(self.projectIcon, project.name)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
70 pitem.setEditable(False)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
71 pitem.setData(project)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
72 root.appendRow(pitem)
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
73 for el in self.project.elements:
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
74 fitem = QStandardItem(el)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
75 pitem.appendRow(fitem)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
76 fitem.setEditable(False)
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
77 fitem.setData(el)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
78 self.treeview.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
79 self.treeview.expandAll()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
80 def contextMenu(self, pos):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
81 idx = self.treeview.indexAt(pos)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
82 if not idx.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
83 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
84 item = self.treeview.model().itemFromIndex(idx)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
85 def activate(self, index):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
86 if not index.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
87 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
88 model = self.treeview.model()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
89 item = model.itemFromIndex(index)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
90 fn = item.data()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
91 if type(fn) is str:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
92 self.sigLoadFile.emit(fn)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
93
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
94 class AboutDialog(QDialog):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
95 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
96 super(AboutDialog, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
97 self.setWindowTitle('About')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
98 l = QVBoxLayout(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
99 txt = QTextEdit(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
100 txt.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
101 aboutText = """<h1>lcfOS IDE</h1>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
102 <p>An all-in-one IDE for OS development.</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
103 <p>https://www.assembla.com/spaces/lcfOS/wiki</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
104 <p>Author: Windel Bouwman</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
105 """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
106 txt.append(aboutText)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
107 l.addWidget(txt)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
108 but = QPushButton('OK')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
109 but.setDefault(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
110 but.clicked.connect(self.close)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
111 l.addWidget(but)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
112
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
113 class ProjectOptions(QDialog):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
114 pass
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
115 # TODO: project options in here
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
116
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
117 class Ide(QMainWindow):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
118 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
119 super(Ide, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
120 self.setWindowTitle('LCFOS IDE')
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 106
diff changeset
121 self.compiler = None # TODO
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
122 icon = QPixmap()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
123 icon.loadFromData(lcfospng)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
124 self.setWindowIcon(QIcon(icon))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
125
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
126 # Create menus:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
127 mb = self.menuBar()
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
128 self.fileMenu = mb.addMenu('File')
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
129 self.projectMenu = mb.addMenu('Project')
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
130 self.viewMenu = mb.addMenu('View')
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
131 self.helpMenu = mb.addMenu('Help')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
132
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
133 # Create mdi area:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
134 self.mdiArea = QMdiArea()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
135 self.setCentralWidget(self.mdiArea)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
136
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
137 # Create components:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
138 def addComponent(name, widget):
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
139 dw = QDockWidget(name)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
140 dw.setWidget(widget)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
141 dw.setObjectName(name)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
142 self.addDockWidget(Qt.RightDockWidgetArea, dw)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
143 self.viewMenu.addAction(dw.toggleViewAction())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
144 return widget
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
145
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
146 self.buildOutput = addComponent('Build output', BuildOutput())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
147 self.astViewer = addComponent('AST viewer', AstViewer())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
148 self.astViewer.sigNodeSelected.connect(self.nodeSelected)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
149 self.builderrors = addComponent('Build errors', BuildErrors())
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
150 self.builderrors.sigErrorSelected.connect(self.errorSelected)
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
151 self.projectview = addComponent('Project explorer', ProjectView())
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
152 self.projectview.sigLoadFile.connect(self.loadFile)
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
153 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
154 self.regview = addComponent('Registers', stutil.RegisterView())
136
9af544be5d2a Added hexfile edit
Windel Bouwman
parents: 131
diff changeset
155 self.memview = addComponent('Memory', stutil.MemoryView())
137
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
156 self.ctrlToolbar = stutil.DebugToolbar()
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
157 self.addToolBar(self.ctrlToolbar)
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
158 self.ctrlToolbar.setObjectName('debugToolbar')
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
159 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice)
136
9af544be5d2a Added hexfile edit
Windel Bouwman
parents: 131
diff changeset
160 self.devxplr.deviceSelected.connect(self.memview.setDevice)
137
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
161 self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice)
143
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 137
diff changeset
162 self.ctrlToolbar.statusChange.connect(self.regview.refresh)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
163
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
164 # About dialog:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
165 self.aboutDialog = AboutDialog()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
166 self.aboutDialog.setWindowIcon(QIcon(icon))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
167 # Create actions:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
168 def addMenuEntry(name, menu, callback, shortcut=None):
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
169 a = QAction(name, self)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
170 menu.addAction(a)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
171 a.triggered.connect(callback)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
172 if shortcut:
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
173 a.setShortcut(shortcut)
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
174
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
175 addMenuEntry("New", self.projectMenu, self.newProject)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
176 addMenuEntry("Open", self.projectMenu, self.openProject)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
177 addMenuEntry("Save", self.projectMenu, self.saveProject)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
178 addMenuEntry("Close", self.projectMenu, self.closeProject)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
179 addMenuEntry("Build", self.projectMenu, self.buildProject, shortcut=QKeySequence('F7'))
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
180
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
181 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
182 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
183 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
184 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F8"))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
185
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
186 self.helpAction = QAction('Help', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
187 self.helpAction.setShortcut(QKeySequence('F1'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
188 self.helpMenu.addAction(self.helpAction)
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
189 addMenuEntry('About', self.helpMenu, self.aboutDialog.open)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
190
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
191 addMenuEntry('Cascade windows', self.viewMenu, self.mdiArea.cascadeSubWindows)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
192 addMenuEntry('Tile windows', self.viewMenu, self.mdiArea.tileSubWindows)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
193
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
194 sb = self.statusBar()
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
195
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
196 # Load settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
197 self.settings = QSettings('windelsoft', 'lcfoside')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
198 self.loadSettings()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
199
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
200 ce = self.newFile()
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
201 ce.Source = testc3.testsrc
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
202
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
203 self.diag = ppci.DiagnosticsManager()
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
204
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
205 # File handling:
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
206 def newProject(self):
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
207 filename = QFileDialog.getSaveFileName(self, \
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
208 "Select new projectfile", "", "lcfos Project files (*.lcp2)")
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
209 if filename:
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
210 self.project = Project()
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
211 self.project.filename = filename
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
212 self.project.save()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
213
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
214 def newFile(self):
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
215 ce = CodeEdit()
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
216 ce.textChanged.connect(self.buildProject)
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
217 w = self.mdiArea.addSubWindow(ce)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
218 ce.show()
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
219 w.resize(500, 700)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
220 return ce
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
221 def openFile(self):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
222 filename = QFileDialog.getOpenFileName(self, "Open K# file...", "*.ks", "K# source files (*.ks)")
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
223 if filename:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
224 self.loadFile(filename)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
225 def saveFile(self):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
226 ac = self.activeMdiChild()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
227 if ac:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
228 ac.save()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
229
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
230 def saveProject(self):
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
231 self.project.save()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
232
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
233 def closeProject(self):
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
234 ac = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
235 if ac:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
236 self.mdiArea.removeSubWindow(ac)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
237
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
238 def loadFile(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
239 # Find existing mdi widget:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
240 wid = self.findMdiChild(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
241 if wid:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
242 self.mdiArea.setActiveSubWindow(wid.parent())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
243 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
244
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
245 # Create a new one:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
246 ce = CodeEdit()
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
247
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
248 #source = self.project.loadProjectFile(filename)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
249 try:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
250 with open(filename) as f:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
251 source = f.read()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
252 ce.setSource(source)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
253 except Exception as e:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
254 print('exception opening file', e)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
255 self.mdiArea.addSubWindow(ce)
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
256 ce.setFileName(filename)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
257 ce.show()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
258 return ce
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
259
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
260 def loadProject(self, filename):
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
261 self.project = Project(filename)
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
262 self.projectview.setProject(self.project)
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
263
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
264 def openProject(self):
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
265 filename = QFileDialog.getOpenFileName(self, \
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
266 "Choose project file", "", "lcfos Project files (*.lcp2)")
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
267 if filename:
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
268 self.loadProject(filename)
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
269
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
270 # MDI:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
271 def activeMdiChild(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
272 aw = self.mdiArea.activeSubWindow()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
273 if aw:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
274 return aw.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
275 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
276 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
277
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
278 def findMdiChild(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
279 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
280 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
281 if wid.filename == filename:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
282 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
283 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
284
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
285 def allChildren(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
286 c = []
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
287 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
288 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
289 c.append(wid)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
290 return c
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
291
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
292 # Settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
293 def loadSettings(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
294 if self.settings.contains('mainwindowstate'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
295 self.restoreState(self.settings.value('mainwindowstate'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
296 if self.settings.contains('mainwindowgeometry'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
297 self.restoreGeometry(self.settings.value('mainwindowgeometry'))
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
298 if self.settings.contains('lastfile'):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
299 self.loadFile(self.settings.value('lastfile'))
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
300
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
301 def closeEvent(self, ev):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
302 self.settings.setValue('mainwindowstate', self.saveState())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
303 self.settings.setValue('mainwindowgeometry', self.saveGeometry())
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
304 #if self.project:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
305 # self.settings.setValue('openedproject', self.project.filename)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
306 # # TODO: ask for save of opened files
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
307 ac = self.activeMdiChild()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
308 if ac:
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
309 if hasattr(ac, 'filename') and ac.filename:
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
310 self.settings.setValue('lastfile', ac.filename)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
311 else:
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
312 self.settings.remove('lastfile')
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
313 else:
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
314 self.settings.remove('lastfile')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
315 ev.accept()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
316
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
317 # Error handling:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
318 def nodeSelected(self, node):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
319 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
320 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
321 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
322 if node.location:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
323 row, col = node.location
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
324 ce.highlightErrorLocation( row, col )
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
325 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
326 ce.clearErrors()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
327
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
328 def errorSelected(self, err):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
329 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
330 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
331 return
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
332 ce.setRowCol(err.loc.row, err.loc.col)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
333
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
334 # Project loading:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
335
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
336 # Build recepy:
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
337 def buildFile(self):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
338 ce = self.activeMdiChild()
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
339 print('BUILD file')
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
340 if ce:
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
341 source = ce.Source
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
342 self.buildOutput.clear()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
343 self.buildOutput.append(str(self.compiler))
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
344 ast = testc3.c3compile(source, self.diag)
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
345 #ast = self.compiler.compilesource(source)
164
e023d3ce1d63 Fix to loc of assignment
Windel Bouwman
parents: 163
diff changeset
346 print('setting ast', ast)
102
63937c8d1478 Fixes and start with ir generator
windel
parents: 101
diff changeset
347 self.astViewer.setAst(ast)
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
348 self.buildOutput.append("Done!")
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
349 def buildProject(self):
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
350 """ Build project """
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
351 print('BUILD project')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
352 self.buildOutput.clear()
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
353 self.diag.diags.clear()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
354 self.buildOutput.append(str(self.compiler))
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
355 self.buildFile()
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
356 #mods = self.compiler.compileProject(self.project)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
357
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
358 self.builderrors.setErrorList(self.diag.diags)
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
359 #self.astViewer.setAst(mods[0])
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
360 for err in self.diag.diags:
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
361 self.buildOutput.append(str(err))
154
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
362 ce = self.activeMdiChild()
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
363 if ce:
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
364 print('setting errors')
81e08e2e7777 Used error icon
Windel Bouwman
parents: 152
diff changeset
365 ce.setErrors(self.diag.diags)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
366 self.buildOutput.append("Done!")
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
367
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
368 if __name__ == '__main__':
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
369 app = QApplication(sys.argv)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
370 ide = Ide()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
371 ide.show()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
372 app.exec_()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
373