annotate python/st-util.py @ 131:04e45faafd1d

Added register view
author Windel Bouwman
date Sat, 19 Jan 2013 18:41:49 +0100
parents 654093a9a1e3
children 205578c96a79
rev   line source
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
2
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
3 import sys
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
4 from PyQt4.QtCore import *
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
5 from PyQt4.QtGui import *
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
6 import stlink, devices, stm32
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
7 from devices import Interface, Device
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
8
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
9 class InformationDialog(QDialog):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
10 def __init__(self, parent):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
11 super().__init__(parent)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
12 self.setWindowTitle('Info')
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
13 fl = QFormLayout(self)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
14 if parent.stl:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
15 fl.addRow('ST link version:', QLabel(parent.stl.Version))
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
16 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId)))
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
17 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
18 fl.addRow('Status:', QLabel(parent.stl.StatusString))
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
19
131
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
20 class RegisterModel(QAbstractTableModel):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
21 def __init__(self):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
22 super().__init__()
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
23 self.regCount = 15
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
24 self.device = None
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
25 def rowCount(self, parent):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
26 if parent.isValid():
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
27 return 0
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
28 if self.device:
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
29 return 21 # TODO make variable
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
30 else:
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
31 return 0
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
32 def setDevice(self, dev):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
33 self.device = dev
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
34 self.modelReset.emit()
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
35 def columnCount(self, parent):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
36 if parent.isValid():
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
37 return 0
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
38 return 2
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
39 def data(self, index, role):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
40 if index.isValid():
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
41 row, col = index.row(), index.column()
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
42 if role == Qt.DisplayRole:
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
43 if col == 0:
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
44 return 'R{0}'.format(row)
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
45 elif col == 1:
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
46 v = self.device.iface.read_reg(row)
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
47 return '0x{0:X}'.format(v)
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
48
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
49 class RegisterView(QTableView):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
50 def __init__(self):
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
51 super().__init__()
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
52 self.mdl = RegisterModel()
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
53 self.setModel(self.mdl)
04e45faafd1d Added register view
Windel Bouwman
parents: 130
diff changeset
54
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
55 class DeviceTreeModel(QAbstractItemModel):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
56 def __init__(self):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
57 super().__init__()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
58 self.chipPixmap = QPixmap('chip.png').scaled(32, 32)
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
59 self.hardwarePixmap = QPixmap('hardware.png').scaled(32, 32)
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
60 self.refresh()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
61 def refresh(self):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
62 """ Check all usb interfaces for interfaces """
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
63 self.interfaces = devices.createInterfaces()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
64 self.devices = []
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
65 self.modelReset.emit()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
66 def addDevice(self, device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
67 if device.iface in [lambda d: d.iface for d in self.devices]:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
68 print('device already open')
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
69 return
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
70 self.devices.append(device)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
71 self.modelReset.emit()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
72 def index(self, row, column, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
73 if parent.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
74 ip = parent.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
75 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
76 devs = [d for d in self.devices if d.iface is ip]
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
77 return self.createIndex(row, column, devs[row])
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
78 else:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
79 iface = self.interfaces[row]
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
80 return self.createIndex(row, column, iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
81 return idx
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
82 def parent(self, index):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
83 if index.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
84 ip = index.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
85 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
86 return QModelIndex()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
87 elif isinstance(ip, Device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
88 iface = ip.iface
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
89 row = self.interfaces.index(iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
90 return self.createIndex(row, 0, iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
91 return QModelIndex()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
92 def rowCount(self, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
93 if parent.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
94 # non-root level:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
95 ip = parent.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
96 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
97 devs = [d for d in self.devices if d.iface is ip]
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
98 return len(devs)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
99 else:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
100 # root level:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
101 return len(self.interfaces)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
102 return 0
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
103 def columnCount(self, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
104 return 1
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
105 def data(self, index, role):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
106 if index.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
107 ip = index.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
108 if role == Qt.DisplayRole:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
109 return str(ip)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
110 elif role == Qt.DecorationRole:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
111 if isinstance(ip, Interface):
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
112 return self.hardwarePixmap
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
113 if isinstance(ip, Device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
114 return self.chipPixmap
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
115
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
116 class DeviceExplorer(QTreeView):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
117 """ Lists all interfaces plugged in and allows selection """
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
118 deviceSelected = pyqtSignal(Device)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
119 def __init__(self):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
120 super().__init__()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
121 self.mdl = DeviceTreeModel()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
122 self.setModel(self.mdl)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
123 self.activated.connect(self.openItem)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
124 self.header().close()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
125 self.customContextMenuRequested.connect(self.openMenu)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
126 self.setContextMenuPolicy(Qt.CustomContextMenu)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
127 def openItem(self, idx):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
128 if idx.isValid():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
129 ip = idx.internalPointer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
130 if isinstance(ip, Interface):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
131 if not ip.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
132 ip.open()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
133 # Try to get a device:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
134 self.mdl.addDevice(ip.createDevice())
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
135 if isinstance(ip, Device):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
136 self.deviceSelected.emit(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
137 def openMenu(self, pt):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
138 idx = self.indexAt(pt)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
139 menu = QMenu()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
140 menu.addAction('Refresh', self.mdl.refresh)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
141 if idx.isValid():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
142 ip = idx.internalPointer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
143 if isinstance(ip, Interface):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
144 if ip.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
145 def closeInterface():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
146 self.mdl.closeInterface(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
147 menu.addAction('Close', closeInterface)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
148 else:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
149 def openInterface():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
150 ip.open()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
151 # Try to get a device:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
152 self.mdl.addDevice(ip.createDevice())
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
153 menu.addAction('Open', openInterface)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
154 elif isinstance(ip, Device):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
155 def selectDevice():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
156 self.deviceSelected.emit(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
157 menu.addAction('Select', selectDevice)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
158 menu.exec(self.mapToGlobal(pt))
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
159
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
160 class StUtil(QMainWindow):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
161 connected = pyqtSignal(bool)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
162 def __init__(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
163 super().__init__()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
164 self.stl = None
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
165 def buildAction(name, callback, shortcut=None):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
166 a = QAction(name, self)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
167 a.triggered.connect(callback)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
168 if shortcut:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
169 a.setShortcut(shortcut)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
170 return a
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
171 mb = self.menuBar()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
172 fileMenu = mb.addMenu("File")
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
173 self.connectAction = buildAction('Connect', self.connect)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
174 fileMenu.addAction(self.connectAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
175 self.disconnectAction = buildAction('Disconnect', self.disconnect)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
176 fileMenu.addAction(self.disconnectAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
177
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
178 self.miscMenu = mb.addMenu("Misc")
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
179 infoAction = buildAction('Info', self.info)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
180 self.miscMenu.addAction(infoAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
181
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
182 sb = self.statusBar()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
183
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
184 devexplr = DeviceExplorer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
185 self.setCentralWidget(devexplr)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
186 devexplr.deviceSelected.connect(self.handleDeviceSelected)
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
187
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
188 self.connected.connect(self.handleConnectedChange)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
189 self.connected.emit(False)
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
190 def handleDeviceSelected(self, dev):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
191 self.dev = dev
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
192 self.handleConnectedChange(True)
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
193 def handleConnectedChange(self, state):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
194 self.miscMenu.setEnabled(state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
195 self.connectAction.setEnabled(not state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
196 self.disconnectAction.setEnabled(state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
197 msg = 'Connected!' if state else 'Disconnected!'
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
198 self.statusBar().showMessage(msg)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
199 def info(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
200 infoDialog = InformationDialog(self)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
201 infoDialog.exec()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
202 def connect(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
203 try:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
204 self.stl = stlink.STLink()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
205 self.stl.open()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
206 except (stlink.STLinkException, usb.UsbError) as e:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
207 QMessageBox.warning(self, "Error", str(e))
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
208 self.stl = None
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
209 if self.stl:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
210 self.connected.emit(True)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
211 def disconnect(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
212 if self.stl:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
213 self.stl.close()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
214 self.connected.emit(False)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
215 self.stl = None
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
216
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
217 if __name__ == '__main__':
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
218 app = QApplication(sys.argv)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
219 stu = StUtil()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
220 stu.show()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
221 app.exec()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
222