annotate python/ide.py @ 95:4a37d6992bd3

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