annotate python/ide.py @ 247:dd8bbb963458

project remove
author Windel Bouwman
date Fri, 26 Jul 2013 10:44:26 +0200
parents 6259856841a0
children b10d46e5c8dd
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:
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 102
diff changeset
10 import ppci
100
fe145e42259d Fixes after movage
windel
parents: 99
diff changeset
11 from astviewer import AstViewer
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
12 #from codeeditor import CodeEdit
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
13 from codeedit import CodeEdit
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
14 stutil = __import__('st-util')
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
15 import c3
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
16
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
17 class BuildOutput(QTextEdit):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
18 """ Build output component """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
19 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
20 super(BuildOutput, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
21 self.setCurrentFont(QFont('Courier'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
22 self.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
23 self.append('Build output will appear here!')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
24
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
25 class BuildErrors(QTreeView):
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
26 sigErrorSelected = pyqtSignal(object)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
27 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
28 super(BuildErrors, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
29 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
30 self.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
31 self.clicked.connect(self.itemSelected)
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 169
diff changeset
32 self.errorIcon = QIcon('icons/error.png')
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
33 self.model = QStandardItemModel()
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
34 self.model.setHorizontalHeaderLabels(['Message', 'Row', 'Column'])
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
35 self.setModel(self.model)
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
36
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
37 def setErrorList(self, errorlist):
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
38 c = self.model.rowCount()
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
39 self.model.removeRows(0, c)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
40 for e in errorlist:
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
41 item = QStandardItem(self.errorIcon, str(e.msg))
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
42 item.setData(e)
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
43 irow = QStandardItem(str(e.loc.row))
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
44 irow.setData(e)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
45 icol = QStandardItem(str(e.loc.col))
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
46 icol.setData(e)
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
47 self.model.appendRow([item, irow, icol])
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
48 def itemSelected(self, index):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
49 if not index.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
50 return
169
ee0d30533dae Added more tests and improved the diagnostic update
Windel Bouwman
parents: 168
diff changeset
51 item = self.model.itemFromIndex(index)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
52 err = item.data()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
53 self.sigErrorSelected.emit(err)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
54
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
55
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
56 class AboutDialog(QDialog):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
57 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
58 super(AboutDialog, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
59 self.setWindowTitle('About')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
60 l = QVBoxLayout(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
61 txt = QTextEdit(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
62 txt.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
63 aboutText = """<h1>lcfOS IDE</h1>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
64 <p>An all-in-one IDE for OS development.</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
65 <p>https://www.assembla.com/spaces/lcfOS/wiki</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
66 <p>Author: Windel Bouwman</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
67 """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
68 txt.append(aboutText)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
69 l.addWidget(txt)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
70 but = QPushButton('OK')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
71 but.setDefault(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
72 but.clicked.connect(self.close)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
73 l.addWidget(but)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
74
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
75 class Ide(QMainWindow):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
76 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
77 super(Ide, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
78 self.setWindowTitle('LCFOS IDE')
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
79 icon = QIcon('icons/logo.png')
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
80 self.setWindowIcon(icon)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
81
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
82 # Create menus:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
83 mb = self.menuBar()
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
84 self.fileMenu = mb.addMenu('File')
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
85 self.viewMenu = mb.addMenu('View')
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
86 self.helpMenu = mb.addMenu('Help')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
87
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
88 # Create mdi area:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
89 self.mdiArea = QMdiArea()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
90 self.setCentralWidget(self.mdiArea)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
91
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
92 # Create components:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
93 def addComponent(name, widget):
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
94 dw = QDockWidget(name)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
95 dw.setWidget(widget)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
96 dw.setObjectName(name)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
97 self.addDockWidget(Qt.RightDockWidgetArea, dw)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
98 self.viewMenu.addAction(dw.toggleViewAction())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
99 return widget
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
100
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
101 self.buildOutput = addComponent('Build output', BuildOutput())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
102 self.astViewer = addComponent('AST viewer', AstViewer())
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
103 self.astViewer.sigNodeSelected.connect(self.nodeSelected)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
104 self.builderrors = addComponent('Build errors', BuildErrors())
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
105 self.builderrors.sigErrorSelected.connect(self.errorSelected)
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
106 self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
107 self.regview = addComponent('Registers', stutil.RegisterView())
136
9af544be5d2a Added hexfile edit
Windel Bouwman
parents: 131
diff changeset
108 self.memview = addComponent('Memory', stutil.MemoryView())
137
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
109 self.ctrlToolbar = stutil.DebugToolbar()
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
110 self.addToolBar(self.ctrlToolbar)
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
111 self.ctrlToolbar.setObjectName('debugToolbar')
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
112 self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice)
240
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
113 self.ctrlToolbar.statusChange.connect(self.memview.refresh)
136
9af544be5d2a Added hexfile edit
Windel Bouwman
parents: 131
diff changeset
114 self.devxplr.deviceSelected.connect(self.memview.setDevice)
137
0a540ce31cd5 Added debug toolbar and spaced hexedit
Windel Bouwman
parents: 136
diff changeset
115 self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice)
143
1cc59ac80950 Fixed halt button
Windel Bouwman
parents: 137
diff changeset
116 self.ctrlToolbar.statusChange.connect(self.regview.refresh)
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
117 self.ctrlToolbar.codePosition.connect(self.pointCode)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
118
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
119 # About dialog:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
120 self.aboutDialog = AboutDialog()
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
121 self.aboutDialog.setWindowIcon(icon)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
122 # Create actions:
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
123 def addMenuEntry(name, menu, callback, shortcut=None):
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
124 a = QAction(name, self)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
125 menu.addAction(a)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
126 a.triggered.connect(callback)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
127 if shortcut:
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
128 a.setShortcut(shortcut)
67
99bf4f7d47f4 Changed project storage
windel
parents: 66
diff changeset
129
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
130 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
131 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open))
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
132 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save))
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
133 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F7"))
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
134
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
135 self.helpAction = QAction('Help', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
136 self.helpAction.setShortcut(QKeySequence('F1'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
137 self.helpMenu.addAction(self.helpAction)
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
138 addMenuEntry('About', self.helpMenu, self.aboutDialog.open)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
139
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
140 addMenuEntry('Cascade windows', self.viewMenu, self.mdiArea.cascadeSubWindows)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
141 addMenuEntry('Tile windows', self.viewMenu, self.mdiArea.tileSubWindows)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
142
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
143 sb = self.statusBar()
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
144
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
145 # Load settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
146 self.settings = QSettings('windelsoft', 'lcfoside')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
147 self.loadSettings()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
148
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
149 ce = self.newFile()
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
150 self.diag = ppci.DiagnosticsManager()
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
151 self.c3front = c3.Builder(self.diag)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
152
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
153 # File handling:
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
154 def newFile(self):
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
155 ce = CodeEdit()
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
156 ce.textChanged.connect(self.buildFile)
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
157 w = self.mdiArea.addSubWindow(ce)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
158 ce.show()
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
159 w.resize(500, 700)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
160 return ce
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
161
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
162 def openFile(self):
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
163 filename = QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", "C3 source files (*.ks)")
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
164 if filename:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
165 self.loadFile(filename)
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
166
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
167 def saveFile(self):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
168 ac = self.activeMdiChild()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
169 if ac:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
170 ac.save()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
171
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
172 def loadFile(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
173 # Find existing mdi widget:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
174 wid = self.findMdiChild(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
175 if wid:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
176 self.mdiArea.setActiveSubWindow(wid.parent())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
177 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
178
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
179 # Create a new one:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
180 ce = CodeEdit()
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
181
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
182 #source = self.project.loadProjectFile(filename)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
183 try:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
184 with open(filename) as f:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
185 source = f.read()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
186 ce.setSource(source)
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
187 except Exception as e:
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
188 print('exception opening file', e)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
189 self.mdiArea.addSubWindow(ce)
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
190 ce.setFileName(filename)
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
191 ce.show()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
192 return ce
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
193
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
194 # MDI:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
195 def activeMdiChild(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
196 aw = self.mdiArea.activeSubWindow()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
197 if aw:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
198 return aw.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
199 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
200 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
201
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
202 def findMdiChild(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
203 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
204 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
205 if wid.filename == filename:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
206 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
207 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
208
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
209 def allChildren(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
210 c = []
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
211 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
212 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
213 c.append(wid)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
214 return c
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
215
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
216 # Settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
217 def loadSettings(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
218 if self.settings.contains('mainwindowstate'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
219 self.restoreState(self.settings.value('mainwindowstate'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
220 if self.settings.contains('mainwindowgeometry'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
221 self.restoreGeometry(self.settings.value('mainwindowgeometry'))
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
222 if self.settings.contains('lastfile'):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
223 self.loadFile(self.settings.value('lastfile'))
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
224
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
225 def closeEvent(self, ev):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
226 self.settings.setValue('mainwindowstate', self.saveState())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
227 self.settings.setValue('mainwindowgeometry', self.saveGeometry())
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
228 # # TODO: ask for save of opened files
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
229 ac = self.activeMdiChild()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
230 if ac:
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
231 if hasattr(ac, 'filename') and ac.filename:
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
232 self.settings.setValue('lastfile', ac.filename)
152
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
233 else:
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
234 self.settings.remove('lastfile')
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
235 else:
b73bc14a3aa3 Light coupling ide and c3 frontend
Windel Bouwman
parents: 143
diff changeset
236 self.settings.remove('lastfile')
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
237 ev.accept()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
238
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
239 # Error handling:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
240 def nodeSelected(self, node):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
241 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
242 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
243 return
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
244 if node.loc:
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
245 row, col = node.loc.row, node.loc.col
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
246 ce.setRowCol(row, col)
168
49f1ab80d040 Added awesome icons
Windel Bouwman
parents: 167
diff changeset
247 ce.setFocus()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
248 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
249 ce.clearErrors()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
250
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
251 def errorSelected(self, err):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
252 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
253 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
254 return
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 162
diff changeset
255 ce.setRowCol(err.loc.row, err.loc.col)
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 165
diff changeset
256 ce.setFocus()
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
257
247
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
258 def pointCode(self, p):
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
259 print('PC', p)
dd8bbb963458 project remove
Windel Bouwman
parents: 240
diff changeset
260
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
261
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
262 # Build recepy:
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
263 def buildFile(self):
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
264 ce = self.activeMdiChild()
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
265 if ce:
162
d8c735dc31f9 Used new editor in ide
Windel Bouwman
parents: 154
diff changeset
266 source = ce.Source
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
267 self.buildOutput.clear()
165
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
268 self.buildOutput.append('Starting build')
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
269 ir = self.c3front.build(source)
598d3888a11c Added front class and fided AST view
Windel Bouwman
parents: 164
diff changeset
270 ast = self.c3front.pkg
102
63937c8d1478 Fixes and start with ir generator
windel
parents: 101
diff changeset
271 self.astViewer.setAst(ast)
101
af0d7913677a Fixes and splitting into 3 stage
windel
parents: 100
diff changeset
272 self.buildOutput.append("Done!")
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
273
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
274 if __name__ == '__main__':
240
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
275 app = QApplication(sys.argv)
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
276 ide = Ide()
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
277 ide.show()
6259856841a0 Remove project
Windel Bouwman
parents: 207
diff changeset
278 app.exec_()
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
279