annotate python/ide.py @ 248:b10d46e5c8dd

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