diff 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
line wrap: on
line diff
--- a/python/st-util.py	Sat Jan 19 18:16:04 2013 +0100
+++ b/python/st-util.py	Sat Jan 19 18:41:49 2013 +0100
@@ -17,6 +17,41 @@
          fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
          fl.addRow('Status:', QLabel(parent.stl.StatusString))
 
+class RegisterModel(QAbstractTableModel):
+   def __init__(self):
+      super().__init__()
+      self.regCount = 15
+      self.device = None
+   def rowCount(self, parent):
+      if parent.isValid():
+         return 0
+      if self.device:
+         return 21 # TODO make variable
+      else:
+         return 0
+   def setDevice(self, dev):
+      self.device = dev
+      self.modelReset.emit()
+   def columnCount(self, parent):
+      if parent.isValid():
+         return 0
+      return 2
+   def data(self, index, role):
+      if index.isValid():
+         row, col = index.row(), index.column()
+         if role == Qt.DisplayRole:
+            if col == 0:
+               return 'R{0}'.format(row)
+            elif col == 1:
+               v = self.device.iface.read_reg(row)
+               return '0x{0:X}'.format(v)
+
+class RegisterView(QTableView):
+   def __init__(self):
+      super().__init__()
+      self.mdl = RegisterModel()
+      self.setModel(self.mdl)
+
 class DeviceTreeModel(QAbstractItemModel):
    def __init__(self):
       super().__init__()