annotate python/st-util.py @ 132:205578c96a79

Moved hexview to seperate class
author Windel Bouwman
date Sun, 20 Jan 2013 17:45:45 +0100
parents 04e45faafd1d
children 9af544be5d2a
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
132
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
55 class MemoryViewer(QWidget):
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
56 pass
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
57
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
58 class FlashTool(QWidget):
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
59 def __init__(self):
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
60 super().__init__()
205578c96a79 Moved hexview to seperate class
Windel Bouwman
parents: 131
diff changeset
61
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
62 class DeviceTreeModel(QAbstractItemModel):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
63 def __init__(self):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
64 super().__init__()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
65 self.chipPixmap = QPixmap('chip.png').scaled(32, 32)
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
66 self.hardwarePixmap = QPixmap('hardware.png').scaled(32, 32)
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
67 self.refresh()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
68 def refresh(self):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
69 """ Check all usb interfaces for interfaces """
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
70 self.interfaces = devices.createInterfaces()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
71 self.devices = []
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
72 self.modelReset.emit()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
73 def addDevice(self, device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
74 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
75 print('device already open')
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
76 return
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
77 self.devices.append(device)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
78 self.modelReset.emit()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
79 def index(self, row, column, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
80 if parent.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
81 ip = parent.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
82 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
83 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
84 return self.createIndex(row, column, devs[row])
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
85 else:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
86 iface = self.interfaces[row]
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
87 return self.createIndex(row, column, iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
88 return idx
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
89 def parent(self, index):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
90 if index.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
91 ip = index.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
92 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
93 return QModelIndex()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
94 elif isinstance(ip, Device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
95 iface = ip.iface
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
96 row = self.interfaces.index(iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
97 return self.createIndex(row, 0, iface)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
98 return QModelIndex()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
99 def rowCount(self, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
100 if parent.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
101 # non-root level:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
102 ip = parent.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
103 if isinstance(ip, Interface):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
104 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
105 return len(devs)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
106 else:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
107 # root level:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
108 return len(self.interfaces)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
109 return 0
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
110 def columnCount(self, parent):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
111 return 1
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
112 def data(self, index, role):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
113 if index.isValid():
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
114 ip = index.internalPointer()
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
115 if role == Qt.DisplayRole:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
116 return str(ip)
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
117 elif role == Qt.DecorationRole:
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
118 if isinstance(ip, Interface):
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
119 return self.hardwarePixmap
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
120 if isinstance(ip, Device):
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
121 return self.chipPixmap
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
122
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
123 class DeviceExplorer(QTreeView):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
124 """ Lists all interfaces plugged in and allows selection """
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
125 deviceSelected = pyqtSignal(Device)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
126 def __init__(self):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
127 super().__init__()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
128 self.mdl = DeviceTreeModel()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
129 self.setModel(self.mdl)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
130 self.activated.connect(self.openItem)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
131 self.header().close()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
132 self.customContextMenuRequested.connect(self.openMenu)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
133 self.setContextMenuPolicy(Qt.CustomContextMenu)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
134 def openItem(self, idx):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
135 if idx.isValid():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
136 ip = idx.internalPointer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
137 if isinstance(ip, Interface):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
138 if not ip.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
139 ip.open()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
140 # Try to get a device:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
141 self.mdl.addDevice(ip.createDevice())
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
142 if isinstance(ip, Device):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
143 self.deviceSelected.emit(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
144 def openMenu(self, pt):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
145 idx = self.indexAt(pt)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
146 menu = QMenu()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
147 menu.addAction('Refresh', self.mdl.refresh)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
148 if idx.isValid():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
149 ip = idx.internalPointer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
150 if isinstance(ip, Interface):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
151 if ip.IsOpen:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
152 def closeInterface():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
153 self.mdl.closeInterface(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
154 menu.addAction('Close', closeInterface)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
155 else:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
156 def openInterface():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
157 ip.open()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
158 # Try to get a device:
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
159 self.mdl.addDevice(ip.createDevice())
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
160 menu.addAction('Open', openInterface)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
161 elif isinstance(ip, Device):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
162 def selectDevice():
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
163 self.deviceSelected.emit(ip)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
164 menu.addAction('Select', selectDevice)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
165 menu.exec(self.mapToGlobal(pt))
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
166
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
167 class StUtil(QMainWindow):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
168 connected = pyqtSignal(bool)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
169 def __init__(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
170 super().__init__()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
171 self.stl = None
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
172 def buildAction(name, callback, shortcut=None):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
173 a = QAction(name, self)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
174 a.triggered.connect(callback)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
175 if shortcut:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
176 a.setShortcut(shortcut)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
177 return a
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
178 mb = self.menuBar()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
179 fileMenu = mb.addMenu("File")
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
180 self.connectAction = buildAction('Connect', self.connect)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
181 fileMenu.addAction(self.connectAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
182 self.disconnectAction = buildAction('Disconnect', self.disconnect)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
183 fileMenu.addAction(self.disconnectAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
184
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
185 self.miscMenu = mb.addMenu("Misc")
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
186 infoAction = buildAction('Info', self.info)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
187 self.miscMenu.addAction(infoAction)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
188
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
189 sb = self.statusBar()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
190
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
191 devexplr = DeviceExplorer()
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
192 self.setCentralWidget(devexplr)
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
193 devexplr.deviceSelected.connect(self.handleDeviceSelected)
129
9e350a7dde98 Changed architecture and updated the util
Windel Bouwman
parents: 127
diff changeset
194
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
195 self.connected.connect(self.handleConnectedChange)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
196 self.connected.emit(False)
130
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
197 def handleDeviceSelected(self, dev):
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
198 self.dev = dev
654093a9a1e3 Added icons, improved device explorer
Windel Bouwman
parents: 129
diff changeset
199 self.handleConnectedChange(True)
127
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
200 def handleConnectedChange(self, state):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
201 self.miscMenu.setEnabled(state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
202 self.connectAction.setEnabled(not state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
203 self.disconnectAction.setEnabled(state)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
204 msg = 'Connected!' if state else 'Disconnected!'
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
205 self.statusBar().showMessage(msg)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
206 def info(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
207 infoDialog = InformationDialog(self)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
208 infoDialog.exec()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
209 def connect(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
210 try:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
211 self.stl = stlink.STLink()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
212 self.stl.open()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
213 except (stlink.STLinkException, usb.UsbError) as e:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
214 QMessageBox.warning(self, "Error", str(e))
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 if self.stl:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
217 self.connected.emit(True)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
218 def disconnect(self):
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
219 if self.stl:
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
220 self.stl.close()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
221 self.connected.emit(False)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
222 self.stl = None
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
223
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
224 if __name__ == '__main__':
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
225 app = QApplication(sys.argv)
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
226 stu = StUtil()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
227 stu.show()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
228 app.exec()
ec1f2cc04d95 Added st util gui start
Windel Bouwman
parents:
diff changeset
229