Mercurial > lcfOS
comparison python/ide/ide.py @ 333:dcae6574c974
Increment to qt5
author | Windel Bouwman |
---|---|
date | Sun, 09 Feb 2014 15:27:57 +0100 |
parents | ff665880a6b0 |
children | 11c5a8a70c02 |
comparison
equal
deleted
inserted
replaced
332:87feb8a23b4d | 333:dcae6574c974 |
---|---|
4 import os | 4 import os |
5 import logging | 5 import logging |
6 import traceback | 6 import traceback |
7 import io | 7 import io |
8 | 8 |
9 from PyQt4.QtCore import * | 9 from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon, abspath, Qt |
10 from PyQt4.QtGui import * | |
11 | 10 |
12 # Compiler imports: | 11 # Compiler imports: |
13 p = os.path.join(os.path.dirname(__file__), '..') | 12 p = os.path.join(os.path.dirname(__file__), '..') |
14 sys.path.insert(0, p) | 13 sys.path.insert(0, p) |
15 sys.path.insert(0, os.path.join(p, 'utils')) | 14 sys.path.insert(0, os.path.join(p, 'utils')) |
28 logging.critical(str(v)) | 27 logging.critical(str(v)) |
29 tb = traceback.format_tb(tb) | 28 tb = traceback.format_tb(tb) |
30 for i in tb: | 29 for i in tb: |
31 logging.critical(i.strip()) | 30 logging.critical(i.strip()) |
32 | 31 |
33 sys.excepthook = handle_exception | 32 # sys.excepthook = handle_exception |
34 | 33 |
35 class BuildErrors(QTreeView): | 34 class BuildErrors(QtWidgets.QTreeView): |
36 sigErrorSelected = pyqtSignal(object) | 35 sigErrorSelected = pyqtSignal(object) |
37 | 36 |
38 def __init__(self, parent=None): | 37 def __init__(self, parent=None): |
39 super(BuildErrors, self).__init__(parent) | 38 super(BuildErrors, self).__init__(parent) |
40 model = QStandardItemModel() | 39 model = QtGui.QStandardItemModel() |
41 self.setModel(model) | 40 self.setModel(model) |
42 self.clicked.connect(self.itemSelected) | 41 self.clicked.connect(self.itemSelected) |
43 self.errorIcon = QIcon('icons/error.png') | 42 self.errorIcon = get_icon('error.png') |
44 self.model = QStandardItemModel() | 43 self.model = QtGui.QStandardItemModel() |
45 self.model.setHorizontalHeaderLabels(['Message', 'Row', 'Column']) | 44 self.model.setHorizontalHeaderLabels(['Message', 'Row', 'Column']) |
46 self.header().setStretchLastSection(True) | 45 self.header().setStretchLastSection(True) |
47 self.setModel(self.model) | 46 self.setModel(self.model) |
48 | 47 |
49 def setErrorList(self, errorlist): | 48 def setErrorList(self, errorlist): |
50 c = self.model.rowCount() | 49 c = self.model.rowCount() |
51 self.model.removeRows(0, c) | 50 self.model.removeRows(0, c) |
52 for e in errorlist: | 51 for e in errorlist: |
53 item = QStandardItem(self.errorIcon, str(e.msg)) | 52 item = QtGui.QStandardItem(self.errorIcon, str(e.msg)) |
54 item.setData(e) | 53 item.setData(e) |
55 row = str(e.loc.row) if e.loc else '' | 54 row = str(e.loc.row) if e.loc else '' |
56 irow = QStandardItem(row) | 55 irow = QtGui.QStandardItem(row) |
57 irow.setData(e) | 56 irow.setData(e) |
58 col = str(e.loc.col) if e.loc else '' | 57 col = str(e.loc.col) if e.loc else '' |
59 icol = QStandardItem(col) | 58 icol = QtGui.QStandardItem(col) |
60 icol.setData(e) | 59 icol.setData(e) |
61 self.model.appendRow([item, irow, icol]) | 60 self.model.appendRow([item, irow, icol]) |
62 for i in range(3): | 61 for i in range(3): |
63 self.resizeColumnToContents(i) | 62 self.resizeColumnToContents(i) |
64 | 63 |
69 err = item.data() | 68 err = item.data() |
70 self.sigErrorSelected.emit(err) | 69 self.sigErrorSelected.emit(err) |
71 | 70 |
72 | 71 |
73 | 72 |
74 class AboutDialog(QDialog): | 73 class AboutDialog(QtWidgets.QDialog): |
75 def __init__(self, parent=None): | 74 def __init__(self, parent=None): |
76 super(AboutDialog, self).__init__(parent) | 75 super(AboutDialog, self).__init__(parent) |
77 self.setWindowTitle('About') | 76 self.setWindowTitle('About') |
78 l = QVBoxLayout(self) | 77 l = QtWidgets.QVBoxLayout(self) |
79 txt = QTextEdit(self) | 78 txt = QtWidgets.QTextEdit(self) |
80 txt.setReadOnly(True) | 79 txt.setReadOnly(True) |
81 with open(os.path.join('..', '..', 'readme.rst'), 'r') as f: | 80 with open(abspath(os.path.join('..', '..', 'readme.rst')), 'r') as f: |
82 aboutText = f.read() | 81 aboutText = f.read() |
83 txt.append(aboutText) | 82 txt.append(aboutText) |
84 l.addWidget(txt) | 83 l.addWidget(txt) |
85 but = QPushButton('OK') | 84 but = QtWidgets.QPushButton('OK') |
86 but.setDefault(True) | 85 but.setDefault(True) |
87 but.clicked.connect(self.close) | 86 but.clicked.connect(self.close) |
88 l.addWidget(but) | 87 l.addWidget(but) |
89 | 88 |
90 | 89 |
91 class Ide(QMainWindow): | 90 class Ide(QtWidgets.QMainWindow): |
92 def __init__(self, parent=None): | 91 def __init__(self, parent=None): |
93 super(Ide, self).__init__(parent) | 92 super(Ide, self).__init__(parent) |
94 self.to_open_files = [] | 93 self.to_open_files = [] |
95 self.logger = logging.getLogger('ide') | 94 self.logger = logging.getLogger('ide') |
96 | 95 |
97 self.setWindowTitle('LCFOS IDE') | 96 self.setWindowTitle('LCFOS IDE') |
98 icon = QIcon('icons/logo.png') | 97 icon = QtGui.QIcon(get_icon('logo.png')) |
99 self.setWindowIcon(icon) | 98 self.setWindowIcon(icon) |
100 | 99 |
101 # Create menus: | 100 # Create menus: |
102 mb = self.menuBar() | 101 mb = self.menuBar() |
103 self.fileMenu = mb.addMenu('File') | 102 self.fileMenu = mb.addMenu('File') |
104 self.viewMenu = mb.addMenu('View') | 103 self.viewMenu = mb.addMenu('View') |
105 self.helpMenu = mb.addMenu('Help') | 104 self.helpMenu = mb.addMenu('Help') |
106 | 105 |
107 # Create mdi area: | 106 # Create mdi area: |
108 self.mdiArea = QMdiArea() | 107 self.mdiArea = QtWidgets.QMdiArea() |
109 self.mdiArea.setViewMode(QMdiArea.TabbedView) | 108 self.mdiArea.setViewMode(QtWidgets.QMdiArea.TabbedView) |
110 self.mdiArea.setTabsClosable(True) | 109 self.mdiArea.setTabsClosable(True) |
111 self.mdiArea.setTabsMovable(True) | 110 self.mdiArea.setTabsMovable(True) |
112 self.setCentralWidget(self.mdiArea) | 111 self.setCentralWidget(self.mdiArea) |
113 | 112 |
114 # Create components: | 113 # Create components: |
115 def addComponent(name, widget): | 114 def addComponent(name, widget): |
116 dw = QDockWidget(name) | 115 dw = QtWidgets.QDockWidget(name) |
117 dw.setWidget(widget) | 116 dw.setWidget(widget) |
118 dw.setObjectName(name) | 117 dw.setObjectName(name) |
119 self.addDockWidget(Qt.RightDockWidgetArea, dw) | 118 self.addDockWidget(Qt.RightDockWidgetArea, dw) |
120 self.viewMenu.addAction(dw.toggleViewAction()) | 119 self.viewMenu.addAction(dw.toggleViewAction()) |
121 return widget | 120 return widget |
143 self.aboutDialog = AboutDialog() | 142 self.aboutDialog = AboutDialog() |
144 self.aboutDialog.setWindowIcon(icon) | 143 self.aboutDialog.setWindowIcon(icon) |
145 | 144 |
146 # Create actions: | 145 # Create actions: |
147 def addMenuEntry(name, menu, callback, shortcut=None): | 146 def addMenuEntry(name, menu, callback, shortcut=None): |
148 a = QAction(name, self) | 147 a = QtWidgets.QAction(name, self) |
149 menu.addAction(a) | 148 menu.addAction(a) |
150 a.triggered.connect(callback) | 149 a.triggered.connect(callback) |
151 if shortcut: | 150 if shortcut: |
152 a.setShortcut(shortcut) | 151 a.setShortcut(QtGui.QKeySequence(shortcut)) |
153 | 152 |
154 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) | 153 addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QtGui.QKeySequence.New) |
155 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) | 154 addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QtGui.QKeySequence.Open) |
156 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) | 155 addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QtGui.QKeySequence.Save) |
157 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F7")) | 156 addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut="F7") |
158 addMenuEntry("Build and flash", self.fileMenu, self.buildFileAndFlash, shortcut=QKeySequence("F8")) | 157 addMenuEntry("Build and flash", self.fileMenu, self.buildFileAndFlash, shortcut="F8") |
159 | 158 |
160 self.helpAction = QAction('Help', self) | 159 self.helpAction = QtWidgets.QAction('Help', self) |
161 self.helpAction.setShortcut(QKeySequence('F1')) | 160 self.helpAction.setShortcut(QtGui.QKeySequence('F1')) |
162 self.helpMenu.addAction(self.helpAction) | 161 self.helpMenu.addAction(self.helpAction) |
163 addMenuEntry('About', self.helpMenu, self.aboutDialog.open) | 162 addMenuEntry('About', self.helpMenu, self.aboutDialog.open) |
164 | 163 |
165 addMenuEntry('Cascade windows', self.viewMenu, self.mdiArea.cascadeSubWindows) | 164 addMenuEntry('Cascade windows', self.viewMenu, self.mdiArea.cascadeSubWindows) |
166 addMenuEntry('Tile windows', self.viewMenu, self.mdiArea.tileSubWindows) | 165 addMenuEntry('Tile windows', self.viewMenu, self.mdiArea.tileSubWindows) |
167 sb = self.statusBar() | 166 sb = self.statusBar() |
168 | 167 |
169 # Load settings: | 168 # Load settings: |
170 self.settings = QSettings('windelsoft', 'lcfoside') | 169 self.settings = QtCore.QSettings('windelsoft', 'lcfoside') |
171 self.loadSettings() | 170 self.loadSettings() |
172 self.diag = ppci.DiagnosticsManager() | 171 self.diag = ppci.DiagnosticsManager() |
173 | 172 |
174 # File handling: | 173 # File handling: |
175 def newFile(self): | 174 def newFile(self): |
176 self.newCodeEdit() | 175 self.newCodeEdit() |
177 | 176 |
178 def openFile(self): | 177 def openFile(self): |
179 filename = QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", | 178 filename = QtWidgets.QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", |
180 "C3 source files (*.c3)") | 179 "C3 source files (*.c3)") |
181 if filename: | 180 if filename: |
182 self.loadFile(filename) | 181 self.loadFile(filename[0]) |
183 | 182 |
184 def saveFile(self): | 183 def saveFile(self): |
185 ac = self.activeMdiChild() | 184 ac = self.activeMdiChild() |
186 if ac: | 185 if ac: |
187 ac.save() | 186 ac.save() |
191 try: | 190 try: |
192 with open(filename) as f: | 191 with open(filename) as f: |
193 ce.Source = f.read() | 192 ce.Source = f.read() |
194 ce.FileName = filename | 193 ce.FileName = filename |
195 except Exception as e: | 194 except Exception as e: |
196 print('exception opening file', e) | 195 print('exception opening file:', e) |
197 | 196 |
198 # MDI: | 197 # MDI: |
199 def newCodeEdit(self): | 198 def newCodeEdit(self): |
200 ce = CodeEdit() | 199 ce = CodeEdit() |
201 ce.textChanged.connect(self.parseFile) | 200 ce.textChanged.connect(self.parseFile) |
312 else: | 311 else: |
313 self.logger.warning('Not connected to device, skipping flash') | 312 self.logger.warning('Not connected to device, skipping flash') |
314 | 313 |
315 | 314 |
316 if __name__ == '__main__': | 315 if __name__ == '__main__': |
317 logging.basicConfig(format=zcc.logformat, level=logging.DEBUG) | 316 logging.basicConfig(format=ppci.logformat, level=logging.DEBUG) |
318 app = QApplication(sys.argv) | 317 app = QtWidgets.QApplication(sys.argv) |
319 ide = Ide() | 318 ide = Ide() |
320 ide.show() | 319 ide.show() |
321 ide.logger.info('IDE started') | 320 ide.logger.info('IDE started') |
322 app.exec_() | 321 app.exec_() |