comparison python/ide/st-util.py @ 333:dcae6574c974

Increment to qt5
author Windel Bouwman
date Sun, 09 Feb 2014 15:27:57 +0100
parents 534b94b40aa8
children
comparison
equal deleted inserted replaced
332:87feb8a23b4d 333:dcae6574c974
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import sys 3 import sys
4 from PyQt4.QtCore import * 4 from qtwrapper import QtGui, QtCore, QtWidgets, pyqtSignal, get_icon, Qt
5 from PyQt4.QtGui import *
6 import stlink, devices, stm32, usb 5 import stlink, devices, stm32, usb
7 from devices import Interface, Device 6 from devices import Interface, Device
8 from hexedit import HexEdit 7 from hexedit import HexEdit
9 8
10 9
11 class InformationDialog(QDialog): 10 class InformationDialog(QtWidgets.QDialog):
12 def __init__(self, parent): 11 def __init__(self, parent):
13 super().__init__(parent) 12 super().__init__(parent)
14 self.setWindowTitle('Info') 13 self.setWindowTitle('Info')
15 fl = QFormLayout(self) 14 fl = QFormLayout(self)
16 if parent.stl: 15 if parent.stl:
18 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId))) 17 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId)))
19 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString)) 18 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
20 fl.addRow('Status:', QLabel(parent.stl.StatusString)) 19 fl.addRow('Status:', QLabel(parent.stl.StatusString))
21 20
22 21
23 class RegisterModel(QAbstractTableModel): 22 class RegisterModel(QtCore.QAbstractTableModel):
24 def __init__(self): 23 def __init__(self):
25 super().__init__() 24 super().__init__()
26 self.regCount = 15 25 self.regCount = 15
27 self.device = None 26 self.device = None
28 27
83 fromIndex = self.index(0, 1) 82 fromIndex = self.index(0, 1)
84 toIndex = self.index(21, 1) 83 toIndex = self.index(21, 1)
85 self.dataChanged.emit(fromIndex, toIndex) 84 self.dataChanged.emit(fromIndex, toIndex)
86 85
87 86
88 class RegisterView(QTableView): 87 class RegisterView(QtWidgets.QTableView):
89 def __init__(self): 88 def __init__(self):
90 super().__init__() 89 super().__init__()
91 self.mdl = RegisterModel() 90 self.mdl = RegisterModel()
92 self.setModel(self.mdl) 91 self.setModel(self.mdl)
93 92
95 if self.mdl.device: 94 if self.mdl.device:
96 self.setEnabled(not self.mdl.device.Running) 95 self.setEnabled(not self.mdl.device.Running)
97 self.mdl.refresh() 96 self.mdl.refresh()
98 97
99 98
100 class MemoryView(QWidget): 99 class MemoryView(QtWidgets.QWidget):
101 BlockSize = 0x100 100 BlockSize = 0x100
102 def __init__(self): 101 def __init__(self):
103 super().__init__() 102 super().__init__()
104 l = QVBoxLayout(self) 103 l = QtWidgets.QVBoxLayout(self)
105 l2 = QHBoxLayout() 104 l2 = QtWidgets.QHBoxLayout()
106 l2.addWidget(QLabel('Address')) 105 l2.addWidget(QtWidgets.QLabel('Address'))
107 self.addressLine = QLineEdit() 106 self.addressLine = QtWidgets.QLineEdit()
108 self.addressLine.setInputMask('Hhhhhhhh') 107 self.addressLine.setInputMask('Hhhhhhhh')
109 l2.addWidget(self.addressLine) 108 l2.addWidget(self.addressLine)
110 upButton = QPushButton('up') 109 upButton = QtWidgets.QPushButton('up')
111 l2.addWidget(upButton) 110 l2.addWidget(upButton)
112 upButton.clicked.connect(self.doUp) 111 upButton.clicked.connect(self.doUp)
113 downButton = QPushButton('down') 112 downButton = QtWidgets.QPushButton('down')
114 downButton.clicked.connect(self.doDown) 113 downButton.clicked.connect(self.doDown)
115 l2.addWidget(downButton) 114 l2.addWidget(downButton)
116 l.addLayout(l2) 115 l.addLayout(l2)
117 self.device = None 116 self.device = None
118 self.hexEdit = HexEdit() 117 self.hexEdit = HexEdit()
146 def setDevice(self, dev): 145 def setDevice(self, dev):
147 self.device = dev 146 self.device = dev
148 self.Address = 0x8000000 147 self.Address = 0x8000000
149 148
150 149
151 class DebugToolbar(QToolBar): 150 class DebugToolbar(QtWidgets.QToolBar):
152 statusChange = pyqtSignal() 151 statusChange = pyqtSignal()
153 codePosition = pyqtSignal(int) 152 codePosition = pyqtSignal(int)
154 def __init__(self): 153
154 def __init__(self):
155 super().__init__() 155 super().__init__()
156 self.device = None 156 self.device = None
157 # generate actions: 157 # generate actions:
158 def genAction(name, callback): 158 def genAction(name, callback):
159 a = QAction(name, self) 159 a = QtWidgets.QAction(name, self)
160 a.triggered.connect(callback) 160 a.triggered.connect(callback)
161 self.addAction(a) 161 self.addAction(a)
162 return a 162 return a
163 self.stepAction = genAction('Step', self.doStep) 163 self.stepAction = genAction('Step', self.doStep)
164 self.runAction = genAction('Run', self.doRun) 164 self.runAction = genAction('Run', self.doRun)
165 self.stopAction = genAction('Stop', self.doHalt) 165 self.stopAction = genAction('Stop', self.doHalt)
166 self.resetAction = genAction('Reset', self.doReset) 166 self.resetAction = genAction('Reset', self.doReset)
167 self.enableTraceAction = genAction('Enable trace', self.doEnableTrace) 167 self.enableTraceAction = genAction('Enable trace', self.doEnableTrace)
168 self.updateEnables() 168 self.updateEnables()
169 def updateEnables(self): 169
170 def updateEnables(self):
170 if self.device: 171 if self.device:
171 self.resetAction.setEnabled(True) 172 self.resetAction.setEnabled(True)
172 self.enableTraceAction.setEnabled(True) 173 self.enableTraceAction.setEnabled(True)
173 self.runAction.setEnabled(not self.device.Running) 174 self.runAction.setEnabled(not self.device.Running)
174 self.stepAction.setEnabled(not self.device.Running) 175 self.stepAction.setEnabled(not self.device.Running)
182 self.resetAction.setEnabled(False) 183 self.resetAction.setEnabled(False)
183 self.enableTraceAction.setEnabled(False) 184 self.enableTraceAction.setEnabled(False)
184 self.runAction.setEnabled(False) 185 self.runAction.setEnabled(False)
185 self.stepAction.setEnabled(False) 186 self.stepAction.setEnabled(False)
186 self.stopAction.setEnabled(False) 187 self.stopAction.setEnabled(False)
187 def doStep(self): 188
189 def doStep(self):
188 self.device.iface.step() 190 self.device.iface.step()
189 self.updateEnables() 191 self.updateEnables()
190 def doReset(self): 192
193 def doReset(self):
191 self.device.iface.reset() 194 self.device.iface.reset()
192 self.updateEnables() 195 self.updateEnables()
193 def doRun(self): 196
197 def doRun(self):
194 self.device.iface.run() 198 self.device.iface.run()
195 self.updateEnables() 199 self.updateEnables()
196 def doHalt(self): 200
201 def doHalt(self):
197 self.device.iface.halt() 202 self.device.iface.halt()
198 self.updateEnables() 203 self.updateEnables()
199 def doEnableTrace(self): 204
205 def doEnableTrace(self):
200 self.device.iface.traceEnable() 206 self.device.iface.traceEnable()
201 self.updateEnables() 207 self.updateEnables()
202 def setDevice(self, dev): 208
209 def setDevice(self, dev):
203 self.device = dev 210 self.device = dev
204 self.updateEnables() 211 self.updateEnables()
205 212
206 213
207 class FlashTool(QWidget): 214 class FlashTool(QtWidgets.QWidget):
208 def __init__(self): 215 def __init__(self):
209 super().__init__() 216 super().__init__()
210 # TODO! 217 # TODO!
211 218
212 219
213 class DeviceTreeModel(QAbstractItemModel): 220 class DeviceTreeModel(QtCore.QAbstractItemModel):
214 def __init__(self): 221 def __init__(self):
215 super().__init__() 222 super().__init__()
216 self.chipPixmap = QPixmap('icons/chip.png').scaled(32, 32) 223 self.chipPixmap = get_icon('chip.png').scaled(32, 32)
217 self.hardwarePixmap = QPixmap('icons/hardware.png').scaled(32, 32) 224 self.hardwarePixmap = get_icon('hardware.png').scaled(32, 32)
218 self.refresh() 225 self.refresh()
219 def refresh(self): 226 def refresh(self):
220 """ Check all usb interfaces for interfaces """ 227 """ Check all usb interfaces for interfaces """
221 self.interfaces = devices.createInterfaces() 228 self.interfaces = devices.createInterfaces()
222 self.devices = [] 229 self.devices = []
269 if isinstance(ip, Interface): 276 if isinstance(ip, Interface):
270 return self.hardwarePixmap 277 return self.hardwarePixmap
271 if isinstance(ip, Device): 278 if isinstance(ip, Device):
272 return self.chipPixmap 279 return self.chipPixmap
273 280
274 class DeviceExplorer(QTreeView): 281 class DeviceExplorer(QtWidgets.QTreeView):
275 """ Lists all interfaces plugged in and allows selection """ 282 """ Lists all interfaces plugged in and allows selection """
276 deviceSelected = pyqtSignal(Device) 283 deviceSelected = pyqtSignal(Device)
277 def __init__(self): 284 def __init__(self):
278 super().__init__() 285 super().__init__()
279 self.mdl = DeviceTreeModel() 286 self.mdl = DeviceTreeModel()
318 self.deviceSelected.emit(ip) 325 self.deviceSelected.emit(ip)
319 menu.addAction('Select', selectDevice) 326 menu.addAction('Select', selectDevice)
320 menu.exec(self.mapToGlobal(pt)) 327 menu.exec(self.mapToGlobal(pt))
321 328
322 329
323 class StUtil(QMainWindow): 330 class StUtil(QtWidgets.QMainWindow):
324 connected = pyqtSignal(bool) 331 connected = pyqtSignal(bool)
325 def __init__(self): 332 def __init__(self):
326 super().__init__() 333 super().__init__()
327 self.stl = None 334 self.stl = None
328 def buildAction(name, callback, shortcut=None): 335 def buildAction(name, callback, shortcut=None):