annotate python/apps/ide.py @ 66:bcd55a341512

Added py3k check
author windel
date Sun, 07 Oct 2012 17:27:09 +0200
parents 361f7d13adea
children 99bf4f7d47f4
rev   line source
65
361f7d13adea Fixes after movage
windel
parents: 64
diff changeset
1 import sys, os
66
bcd55a341512 Added py3k check
windel
parents: 65
diff changeset
2 if sys.version_info.major != 3:
bcd55a341512 Added py3k check
windel
parents: 65
diff changeset
3 print("Needs to be run in python version 3.x")
bcd55a341512 Added py3k check
windel
parents: 65
diff changeset
4 sys.exit(1)
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 *
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
8 import base64
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
9
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
10 # Compiler imports:
66
bcd55a341512 Added py3k check
windel
parents: 65
diff changeset
11 sys.path.insert(0, os.path.join('..','libs'))
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
12 from project import Project
65
361f7d13adea Fixes after movage
windel
parents: 64
diff changeset
13 from compiler import Compiler
361f7d13adea Fixes after movage
windel
parents: 64
diff changeset
14 from widgets import CodeEdit, AstViewer
64
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
15
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
16 lcfospng = base64.decodestring(b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\n/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJEhMKBk7B678AAAA/SURBVFjD\n7dbBCQAgDATBi9h/y7EFA4Kf2QLCwH1S6XQu6sqoujublc8BAAAAAAAAAAB8B+zXT6YJAAAAAKYd\nWSgFQNUyijIAAAAASUVORK5CYII=\n')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
17
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
18 class BuildOutput(QTextEdit):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
19 """ Build output component """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
20 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
21 super(BuildOutput, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
22 self.setCurrentFont(QFont('Courier'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
23 self.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
24 self.append('Build output will appear here!')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
25
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
26 class BuildErrors(QListView):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
27 sigErrorSelected = pyqtSignal(object)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
28 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
29 super(BuildErrors, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
30 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
31 self.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
32 self.clicked.connect(self.itemSelected)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
33 def setErrorList(self, errorlist):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
34 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
35 for e in errorlist:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
36 row, col, msg = e
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
37 item = QStandardItem(str(msg))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
38 item.setData(e)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
39 model.appendRow(item)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
40 self.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
41 def itemSelected(self, index):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
42 if not index.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
43 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
44 model = self.model()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
45 item = model.itemFromIndex(index)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
46 err = item.data()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
47 self.sigErrorSelected.emit(err)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
48
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
49 class ProjectView(QWidget):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
50 sigLoadFile = pyqtSignal(str)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
51 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
52 super(ProjectView, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
53 self.treeview = QTreeView(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
54 self.treeview.setContextMenuPolicy(Qt.CustomContextMenu)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
55 l = QVBoxLayout(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
56 l.addWidget(self.treeview)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
57 pm = QPixmap()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
58 pm.loadFromData(lcfospng)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
59 self.projectIcon = QIcon(pm)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
60 # Connect signals:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
61 self.treeview.activated.connect(self.activate)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
62 self.treeview.customContextMenuRequested.connect(self.contextMenu)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
63 def setProject(self, project):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
64 self.project = project
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
65 model = QStandardItemModel()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
66 root = model.invisibleRootItem()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
67 pitem = QStandardItem(self.projectIcon, project.name)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
68 pitem.setEditable(False)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
69 pitem.setData(project)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
70 root.appendRow(pitem)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
71 for f in self.project.files:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
72 fitem = QStandardItem(f)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
73 pitem.appendRow(fitem)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
74 fitem.setEditable(False)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
75 fitem.setData(f)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
76 self.treeview.setModel(model)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
77 self.treeview.expandAll()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
78 def contextMenu(self, pos):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
79 idx = self.treeview.indexAt(pos)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
80 if not idx.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
81 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
82 item = self.treeview.model().itemFromIndex(idx)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
83 def activate(self, index):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
84 if not index.isValid():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
85 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
86 model = self.treeview.model()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
87 item = model.itemFromIndex(index)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
88 fn = item.data()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
89 if type(fn) is str:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
90 self.sigLoadFile.emit(fn)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
91
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
92 class AboutDialog(QDialog):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
93 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
94 super(AboutDialog, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
95 self.setWindowTitle('About')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
96 l = QVBoxLayout(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
97 txt = QTextEdit(self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
98 txt.setReadOnly(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
99 aboutText = """<h1>lcfOS IDE</h1>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
100 <p>An all-in-one IDE for OS development.</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
101 <p>https://www.assembla.com/spaces/lcfOS/wiki</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
102 <p>Author: Windel Bouwman</p>
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
103 """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
104 txt.append(aboutText)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
105 l.addWidget(txt)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
106 but = QPushButton('OK')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
107 but.setDefault(True)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
108 but.clicked.connect(self.close)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
109 l.addWidget(but)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
110
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
111 class ProjectOptions(QDialog):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
112 pass
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
113 # TODO: project options in here
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
114
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
115 class Ide(QMainWindow):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
116 def __init__(self, parent=None):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
117 super(Ide, self).__init__(parent)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
118 self.setWindowTitle('LCFOS IDE')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
119 icon = QPixmap()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
120 icon.loadFromData(lcfospng)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
121 self.setWindowIcon(QIcon(icon))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
122
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
123 # Create menus:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
124 self.fileMenu = self.menuBar().addMenu('File')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
125 self.viewMenu = self.menuBar().addMenu('View')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
126 self.projectMenu = self.menuBar().addMenu('Project')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
127 self.helpMenu = self.menuBar().addMenu('Help')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
128
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
129 # Create mdi area:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
130 self.mdiArea = QMdiArea()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
131 self.setCentralWidget(self.mdiArea)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
132
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
133 # Create components:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
134 self.buildOutput = BuildOutput()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
135 self.addComponent('Build output', self.buildOutput)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
136
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
137 self.astViewer = AstViewer()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
138 self.addComponent('AST viewer', self.astViewer)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
139 self.astViewer.sigNodeSelected.connect(self.nodeSelected)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
140
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
141 self.builderrors = BuildErrors()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
142 self.addComponent('Build errors', self.builderrors)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
143 self.builderrors.sigErrorSelected.connect(self.errorSelected)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
144
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
145 self.projectview = ProjectView()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
146 self.addComponent('Project', self.projectview)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
147 self.projectview.sigLoadFile.connect(self.loadFile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
148
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
149 # About dialog:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
150 self.aboutDialog = AboutDialog()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
151 self.aboutDialog.setWindowIcon(QIcon(icon))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
152 # Create actions:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
153 self.buildAction = QAction('Build!', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
154 self.buildAction.setShortcut(QKeySequence('F7'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
155 self.projectMenu.addAction(self.buildAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
156 self.buildAction.triggered.connect(self.buildFile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
157 self.openProjectAction = QAction("Open project", self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
158 self.openProjectAction.triggered.connect(self.openProject)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
159 self.projectMenu.addAction(self.openProjectAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
160 self.helpAction = QAction('Help', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
161 self.helpAction.setShortcut(QKeySequence('F1'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
162 self.helpMenu.addAction(self.helpAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
163 self.aboutAction = QAction('About', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
164 self.helpMenu.addAction(self.aboutAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
165 self.aboutAction.triggered.connect(self.aboutDialog.open)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
166
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
167 self.newFileAction = QAction("New File", self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
168 self.fileMenu.addAction(self.newFileAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
169 self.newFileAction.triggered.connect(self.newFile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
170 self.saveFileAction = QAction("Save File", self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
171 self.fileMenu.addAction(self.saveFileAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
172 self.saveFileAction.triggered.connect(self.saveFile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
173 self.closeFileAction = QAction("Close File", self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
174 self.fileMenu.addAction(self.closeFileAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
175 self.closeFileAction.triggered.connect(self.closeFile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
176
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
177 cascadeAction = QAction("Cascade windows", self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
178 cascadeAction.triggered.connect(self.mdiArea.cascadeSubWindows)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
179 self.viewMenu.addAction(cascadeAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
180 tileAction = QAction('Tile windows', self)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
181 tileAction.triggered.connect(self.mdiArea.tileSubWindows)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
182 self.viewMenu.addAction(tileAction)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
183
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
184 # Load settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
185 self.settings = QSettings('windelsoft', 'lcfoside')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
186 self.loadSettings()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
187
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
188 def addComponent(self, name, widget):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
189 dw = QDockWidget(name)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
190 dw.setWidget(widget)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
191 dw.setObjectName(name)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
192 self.addDockWidget(Qt.RightDockWidgetArea, dw)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
193 self.viewMenu.addAction(dw.toggleViewAction())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
194
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
195 # File handling:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
196 def newFile(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
197 ce = CodeEdit()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
198 w = self.mdiArea.addSubWindow(ce)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
199 ce.show()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
200
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
201 def saveFile(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
202 ac = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
203 if ac:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
204 ac.saveFile()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
205
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
206 def saveAll(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
207 pass
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
208
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
209 def openFile(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
210 # TODO
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
211 pass
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
212
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
213 def closeFile(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
214 ac = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
215 if ac:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
216 self.mdiArea.removeSubWindow(ac)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
217
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
218 def loadFile(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
219 # Find existing mdi widget:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
220 wid = self.findMdiChild(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
221 if wid:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
222 self.mdiArea.setActiveSubWindow(wid.parent())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
223 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
224
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
225 # Create a new one:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
226 ce = CodeEdit()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
227 source = self.project.loadProjectFile(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
228 ce.setSource(source)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
229 self.mdiArea.addSubWindow(ce)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
230 ce.show()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
231 return ce
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
232
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
233 # MDI:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
234 def activeMdiChild(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
235 aw = self.mdiArea.activeSubWindow()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
236 if aw:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
237 return aw.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
238 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
239 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
240
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
241 def findMdiChild(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
242 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
243 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
244 if wid.filename == filename:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
245 return wid
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
246 return None
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
247
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
248 def allChildren(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
249 c = []
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
250 for window in self.mdiArea.subWindowList():
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
251 wid = window.widget()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
252 c.append(wid)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
253 return c
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
254
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
255 # Settings:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
256 def loadSettings(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
257 if self.settings.contains('mainwindowstate'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
258 self.restoreState(self.settings.value('mainwindowstate'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
259 if self.settings.contains('mainwindowgeometry'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
260 self.restoreGeometry(self.settings.value('mainwindowgeometry'))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
261 if self.settings.contains('openedproject'):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
262 projectfile = self.settings.value('openedproject')
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
263 self.loadProject(projectfile)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
264
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
265 def closeEvent(self, ev):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
266 self.settings.setValue('mainwindowstate', self.saveState())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
267 self.settings.setValue('mainwindowgeometry', self.saveGeometry())
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
268 if self.project:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
269 self.settings.setValue('openedproject', self.project.filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
270 # TODO: ask for save of opened files
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
271 ev.accept()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
272
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
273 # Error handling:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
274 def nodeSelected(self, node):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
275 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
276 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
277 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
278 if node.location:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
279 row, col = node.location
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
280 ce.highlightErrorLocation( row, col )
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
281 else:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
282 ce.clearErrors()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
283
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
284 def errorSelected(self, err):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
285 row, col, msg = err
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
286 ce = self.activeMdiChild()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
287 if not ce:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
288 return
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
289 ce.highlightErrorLocation(row, col)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
290
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
291 # Project loading:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
292 def loadProject(self, filename):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
293 self.project = Project(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
294 self.projectview.setProject(self.project)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
295
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
296 def openProject(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
297 filename = QFileDialog.getOpenFileName(self, \
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
298 "Choose project file", "", "lcfos Project files (*.lcp)")
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
299 if filename:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
300 self.loadProject(filename)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
301
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
302 # Build recepy:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
303 def buildFile(self):
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
304 """ Build project """
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
305 self.saveAll()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
306 self.buildOutput.clear()
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
307 self.buildOutput.append(str(self.compiler))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
308 mods = self.compiler.compileProject(self.project)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
309
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
310 self.builderrors.setErrorList(self.compiler.errorlist)
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
311 self.astViewer.setAst(mods[0])
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
312 for err in self.compiler.errorlist:
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
313 self.buildOutput.append(str(err))
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
314 self.buildOutput.append("Done!")
4a27c28c7d0f File movage
windel
parents: 63
diff changeset
315
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
316
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
317 if __name__ == '__main__':
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
318 app = QApplication(sys.argv)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
319 ide = Ide()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
320 ide.compiler = Compiler()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
321 ide.show()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
322 app.exec_()
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
323