Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- a/python/ide/ide.py Fri Feb 07 12:51:55 2014 +0100 +++ b/python/ide/ide.py Sun Feb 09 15:27:57 2014 +0100 @@ -6,8 +6,7 @@ import traceback import io -from PyQt4.QtCore import * -from PyQt4.QtGui import * +from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon, abspath, Qt # Compiler imports: p = os.path.join(os.path.dirname(__file__), '..') @@ -30,18 +29,18 @@ for i in tb: logging.critical(i.strip()) -sys.excepthook = handle_exception +# sys.excepthook = handle_exception -class BuildErrors(QTreeView): +class BuildErrors(QtWidgets.QTreeView): sigErrorSelected = pyqtSignal(object) def __init__(self, parent=None): super(BuildErrors, self).__init__(parent) - model = QStandardItemModel() + model = QtGui.QStandardItemModel() self.setModel(model) self.clicked.connect(self.itemSelected) - self.errorIcon = QIcon('icons/error.png') - self.model = QStandardItemModel() + self.errorIcon = get_icon('error.png') + self.model = QtGui.QStandardItemModel() self.model.setHorizontalHeaderLabels(['Message', 'Row', 'Column']) self.header().setStretchLastSection(True) self.setModel(self.model) @@ -50,13 +49,13 @@ c = self.model.rowCount() self.model.removeRows(0, c) for e in errorlist: - item = QStandardItem(self.errorIcon, str(e.msg)) + item = QtGui.QStandardItem(self.errorIcon, str(e.msg)) item.setData(e) row = str(e.loc.row) if e.loc else '' - irow = QStandardItem(row) + irow = QtGui.QStandardItem(row) irow.setData(e) col = str(e.loc.col) if e.loc else '' - icol = QStandardItem(col) + icol = QtGui.QStandardItem(col) icol.setData(e) self.model.appendRow([item, irow, icol]) for i in range(3): @@ -71,31 +70,31 @@ -class AboutDialog(QDialog): +class AboutDialog(QtWidgets.QDialog): def __init__(self, parent=None): super(AboutDialog, self).__init__(parent) self.setWindowTitle('About') - l = QVBoxLayout(self) - txt = QTextEdit(self) + l = QtWidgets.QVBoxLayout(self) + txt = QtWidgets.QTextEdit(self) txt.setReadOnly(True) - with open(os.path.join('..', '..', 'readme.rst'), 'r') as f: + with open(abspath(os.path.join('..', '..', 'readme.rst')), 'r') as f: aboutText = f.read() txt.append(aboutText) l.addWidget(txt) - but = QPushButton('OK') + but = QtWidgets.QPushButton('OK') but.setDefault(True) but.clicked.connect(self.close) l.addWidget(but) -class Ide(QMainWindow): +class Ide(QtWidgets.QMainWindow): def __init__(self, parent=None): super(Ide, self).__init__(parent) self.to_open_files = [] self.logger = logging.getLogger('ide') self.setWindowTitle('LCFOS IDE') - icon = QIcon('icons/logo.png') + icon = QtGui.QIcon(get_icon('logo.png')) self.setWindowIcon(icon) # Create menus: @@ -105,15 +104,15 @@ self.helpMenu = mb.addMenu('Help') # Create mdi area: - self.mdiArea = QMdiArea() - self.mdiArea.setViewMode(QMdiArea.TabbedView) + self.mdiArea = QtWidgets.QMdiArea() + self.mdiArea.setViewMode(QtWidgets.QMdiArea.TabbedView) self.mdiArea.setTabsClosable(True) self.mdiArea.setTabsMovable(True) self.setCentralWidget(self.mdiArea) # Create components: def addComponent(name, widget): - dw = QDockWidget(name) + dw = QtWidgets.QDockWidget(name) dw.setWidget(widget) dw.setObjectName(name) self.addDockWidget(Qt.RightDockWidgetArea, dw) @@ -145,20 +144,20 @@ # Create actions: def addMenuEntry(name, menu, callback, shortcut=None): - a = QAction(name, self) + a = QtWidgets.QAction(name, self) menu.addAction(a) a.triggered.connect(callback) if shortcut: - a.setShortcut(shortcut) + a.setShortcut(QtGui.QKeySequence(shortcut)) - addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QKeySequence(QKeySequence.New)) - addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QKeySequence(QKeySequence.Open)) - addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QKeySequence(QKeySequence.Save)) - addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut=QKeySequence("F7")) - addMenuEntry("Build and flash", self.fileMenu, self.buildFileAndFlash, shortcut=QKeySequence("F8")) + addMenuEntry("New", self.fileMenu, self.newFile, shortcut=QtGui.QKeySequence.New) + addMenuEntry("Open", self.fileMenu, self.openFile, shortcut=QtGui.QKeySequence.Open) + addMenuEntry("Save", self.fileMenu, self.saveFile, shortcut=QtGui.QKeySequence.Save) + addMenuEntry("Build", self.fileMenu, self.buildFile, shortcut="F7") + addMenuEntry("Build and flash", self.fileMenu, self.buildFileAndFlash, shortcut="F8") - self.helpAction = QAction('Help', self) - self.helpAction.setShortcut(QKeySequence('F1')) + self.helpAction = QtWidgets.QAction('Help', self) + self.helpAction.setShortcut(QtGui.QKeySequence('F1')) self.helpMenu.addAction(self.helpAction) addMenuEntry('About', self.helpMenu, self.aboutDialog.open) @@ -167,7 +166,7 @@ sb = self.statusBar() # Load settings: - self.settings = QSettings('windelsoft', 'lcfoside') + self.settings = QtCore.QSettings('windelsoft', 'lcfoside') self.loadSettings() self.diag = ppci.DiagnosticsManager() @@ -176,10 +175,10 @@ self.newCodeEdit() def openFile(self): - filename = QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", + filename = QtWidgets.QFileDialog.getOpenFileName(self, "Open C3 file...", "*.c3", "C3 source files (*.c3)") if filename: - self.loadFile(filename) + self.loadFile(filename[0]) def saveFile(self): ac = self.activeMdiChild() @@ -193,7 +192,7 @@ ce.Source = f.read() ce.FileName = filename except Exception as e: - print('exception opening file', e) + print('exception opening file:', e) # MDI: def newCodeEdit(self): @@ -314,8 +313,8 @@ if __name__ == '__main__': - logging.basicConfig(format=zcc.logformat, level=logging.DEBUG) - app = QApplication(sys.argv) + logging.basicConfig(format=ppci.logformat, level=logging.DEBUG) + app = QtWidgets.QApplication(sys.argv) ide = Ide() ide.show() ide.logger.info('IDE started')