comparison 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
comparison
equal deleted inserted replaced
130:654093a9a1e3 131:04e45faafd1d
14 if parent.stl: 14 if parent.stl:
15 fl.addRow('ST link version:', QLabel(parent.stl.Version)) 15 fl.addRow('ST link version:', QLabel(parent.stl.Version))
16 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId))) 16 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId)))
17 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString)) 17 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
18 fl.addRow('Status:', QLabel(parent.stl.StatusString)) 18 fl.addRow('Status:', QLabel(parent.stl.StatusString))
19
20 class RegisterModel(QAbstractTableModel):
21 def __init__(self):
22 super().__init__()
23 self.regCount = 15
24 self.device = None
25 def rowCount(self, parent):
26 if parent.isValid():
27 return 0
28 if self.device:
29 return 21 # TODO make variable
30 else:
31 return 0
32 def setDevice(self, dev):
33 self.device = dev
34 self.modelReset.emit()
35 def columnCount(self, parent):
36 if parent.isValid():
37 return 0
38 return 2
39 def data(self, index, role):
40 if index.isValid():
41 row, col = index.row(), index.column()
42 if role == Qt.DisplayRole:
43 if col == 0:
44 return 'R{0}'.format(row)
45 elif col == 1:
46 v = self.device.iface.read_reg(row)
47 return '0x{0:X}'.format(v)
48
49 class RegisterView(QTableView):
50 def __init__(self):
51 super().__init__()
52 self.mdl = RegisterModel()
53 self.setModel(self.mdl)
19 54
20 class DeviceTreeModel(QAbstractItemModel): 55 class DeviceTreeModel(QAbstractItemModel):
21 def __init__(self): 56 def __init__(self):
22 super().__init__() 57 super().__init__()
23 self.chipPixmap = QPixmap('chip.png').scaled(32, 32) 58 self.chipPixmap = QPixmap('chip.png').scaled(32, 32)