Mercurial > lcfOS
changeset 127:ec1f2cc04d95
Added st util gui start
author | Windel Bouwman |
---|---|
date | Sun, 13 Jan 2013 13:02:29 +0100 |
parents | bbf4c9b138d4 |
children | 51cc127648e4 |
files | python/st-util.py |
diffstat | 1 files changed, 74 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/st-util.py Sun Jan 13 13:02:29 2013 +0100 @@ -0,0 +1,74 @@ +#!/usr/bin/python + +import sys +from PyQt4.QtCore import * +from PyQt4.QtGui import * +import stlink, usb + +class InformationDialog(QDialog): + def __init__(self, parent): + super().__init__(parent) + self.setWindowTitle('Info') + fl = QFormLayout(self) + if parent.stl: + fl.addRow('ST link version:', QLabel(parent.stl.Version)) + fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId))) + fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString)) + fl.addRow('Status:', QLabel(parent.stl.StatusString)) + +class StUtil(QMainWindow): + connected = pyqtSignal(bool) + def __init__(self): + super().__init__() + self.stl = None + def buildAction(name, callback, shortcut=None): + a = QAction(name, self) + a.triggered.connect(callback) + if shortcut: + a.setShortcut(shortcut) + return a + mb = self.menuBar() + fileMenu = mb.addMenu("File") + self.connectAction = buildAction('Connect', self.connect) + fileMenu.addAction(self.connectAction) + self.disconnectAction = buildAction('Disconnect', self.disconnect) + fileMenu.addAction(self.disconnectAction) + + self.miscMenu = mb.addMenu("Misc") + infoAction = buildAction('Info', self.info) + self.miscMenu.addAction(infoAction) + + sb = self.statusBar() + + self.connected.connect(self.handleConnectedChange) + self.connected.emit(False) + def handleConnectedChange(self, state): + self.miscMenu.setEnabled(state) + self.connectAction.setEnabled(not state) + self.disconnectAction.setEnabled(state) + msg = 'Connected!' if state else 'Disconnected!' + self.statusBar().showMessage(msg) + def info(self): + infoDialog = InformationDialog(self) + infoDialog.exec() + def connect(self): + try: + self.stl = stlink.STLink() + self.stl.open() + except (stlink.STLinkException, usb.UsbError) as e: + QMessageBox.warning(self, "Error", str(e)) + self.stl = None + if self.stl: + self.connected.emit(True) + def disconnect(self): + if self.stl: + self.stl.close() + self.connected.emit(False) + self.stl = None + +if __name__ == '__main__': + app = QApplication(sys.argv) + stu = StUtil() + stu.show() + app.exec() +