changeset 132:205578c96a79

Moved hexview to seperate class
author Windel Bouwman
date Sun, 20 Jan 2013 17:45:45 +0100
parents 04e45faafd1d
children a816c683c1c0
files python/hexedit.py python/hexviewer.py python/st-util.py python/stlink.py
diffstat 4 files changed, 75 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/hexedit.py	Sun Jan 20 17:45:45 2013 +0100
@@ -0,0 +1,61 @@
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+class HexEdit(QScrollArea):
+   def __init__(self):
+      super().__init__()
+
+class BinViewer(QWidget):
+   """
+      The binviewer consists of a hex view, a ascii view
+      and perhaps others..
+   """
+   def __init__(self):
+      super().__init__()
+      self.setFont(QFont('Courier'))
+      self.fontHeight = self.fontMetrics().height()
+      self.fontWidth = self.fontMetrics().width('x')
+      self.hexfile = hexfile.HexFile()
+   def paintEvent(self, event):
+      painter = QPainter(self)
+      br = QBrush(Qt.lightGray)
+      painter.setBrush(br)
+      h = self.height()
+      addressWidth = self.fontWidth * 8
+      painter.drawRect(2, 2, addressWidth, h)
+      br2 = QBrush(Qt.yellow)
+      painter.setBrush(br2)
+      w = self.width()
+      byteWidth = self.fontWidth * (16 * 3 - 1)
+      painter.drawRect(addressWidth + 4, 2, byteWidth, h)
+      asciiWidth = self.fontWidth * 16
+      br2 = QBrush(Qt.gray)
+      painter.setBrush(br2)
+      painter.drawRect(addressWidth + byteWidth + 4, 2, asciiWidth, h)
+      rows = int(h / self.fontHeight) + 1
+      offset = 0
+      for r in range(1, rows):
+         bts = self.getBytes(offset + r - 1)
+         addr = '{0:08X}'.format(r << 16)
+         painter.drawText(2, 2 + self.fontHeight * r, addr)
+         x = addressWidth + 4
+         for b in bts:
+            b = '{0:02X}'.format(b)
+            painter.drawText(x, 2 + self.fontHeight * r, b)
+            x += 3 * self.fontWidth
+         x = addressWidth + byteWidth + 4
+         for b in bts:
+            b = '{0}'.format(chr(b))
+            painter.drawText(x, 2 + self.fontHeight * r, b)
+            x += 1 * self.fontWidth
+   def getBytes(self, offset):
+      if self.hexfile.regions:
+         r = self.hexfile.regions[0]
+         chunks = [r.data[p:p+16] for p in range(0, len(r.data), 16)]
+         if len(chunks) > offset:
+            return chunks[offset]
+      return bytes()
+   def setHexFile(self, hf):
+      self.hexfile = hf
+      self.update()
--- a/python/hexviewer.py	Sat Jan 19 18:41:49 2013 +0100
+++ b/python/hexviewer.py	Sun Jan 20 17:45:45 2013 +0100
@@ -6,59 +6,6 @@
 import sys
 import hexfile
 
-class BinViewer(QWidget):
-   """
-      The binviewer consists of a hex view, a ascii view
-      and perhaps others..
-   """
-   def __init__(self):
-      super().__init__()
-      self.setFont(QFont('Courier'))
-      self.fontHeight = self.fontMetrics().height()
-      self.fontWidth = self.fontMetrics().width('x')
-      self.hexfile = hexfile.HexFile()
-   def paintEvent(self, event):
-      painter = QPainter(self)
-      br = QBrush(Qt.lightGray)
-      painter.setBrush(br)
-      h = self.height()
-      addressWidth = self.fontWidth * 8
-      painter.drawRect(2, 2, addressWidth, h)
-      br2 = QBrush(Qt.yellow)
-      painter.setBrush(br2)
-      w = self.width()
-      byteWidth = self.fontWidth * (16 * 3 - 1)
-      painter.drawRect(addressWidth + 4, 2, byteWidth, h)
-      asciiWidth = self.fontWidth * 16
-      br2 = QBrush(Qt.gray)
-      painter.setBrush(br2)
-      painter.drawRect(addressWidth + byteWidth + 4, 2, asciiWidth, h)
-      rows = int(h / self.fontHeight) + 1
-      offset = 0
-      for r in range(1, rows):
-         bts = self.getBytes(offset + r - 1)
-         addr = '{0:08X}'.format(r << 16)
-         painter.drawText(2, 2 + self.fontHeight * r, addr)
-         x = addressWidth + 4
-         for b in bts:
-            b = '{0:02X}'.format(b)
-            painter.drawText(x, 2 + self.fontHeight * r, b)
-            x += 3 * self.fontWidth
-         x = addressWidth + byteWidth + 4
-         for b in bts:
-            b = '{0}'.format(chr(b))
-            painter.drawText(x, 2 + self.fontHeight * r, b)
-            x += 1 * self.fontWidth
-   def getBytes(self, offset):
-      if self.hexfile.regions:
-         r = self.hexfile.regions[0]
-         chunks = [r.data[p:p+16] for p in range(0, len(r.data), 16)]
-         if len(chunks) > offset:
-            return chunks[offset]
-      return bytes()
-   def setHexFile(self, hf):
-      self.hexfile = hf
-      self.update()
 
 class HexFileModel(QAbstractTableModel):
    def __init__(self):
@@ -136,12 +83,15 @@
 if __name__ == '__main__':
    app = QApplication(sys.argv)
    bv = BinViewMain()
-   bv.show()
+   #bv.show()
    hf = hexfile.HexFile('audio.hex')
    #bv.bv.setHexFile(
    bv.hfm.HexFile = hf
    qpv = QtPropertyViewer()
    qpv.propertyModel.InspectedWidget = bv
    #qpv.show()
+   bv = BinViewer()
+   bv.show()
+   bv.setHexFile(hf)
    app.exec_()
 
--- a/python/st-util.py	Sat Jan 19 18:41:49 2013 +0100
+++ b/python/st-util.py	Sun Jan 20 17:45:45 2013 +0100
@@ -52,6 +52,13 @@
       self.mdl = RegisterModel()
       self.setModel(self.mdl)
 
+class MemoryViewer(QWidget):
+   pass
+
+class FlashTool(QWidget):
+   def __init__(self):
+      super().__init__()
+
 class DeviceTreeModel(QAbstractItemModel):
    def __init__(self):
       super().__init__()
--- a/python/stlink.py	Sat Jan 19 18:41:49 2013 +0100
+++ b/python/stlink.py	Sun Jan 20 17:45:45 2013 +0100
@@ -80,7 +80,7 @@
          self.exitDfuMode()
       if self.CurrentMode != DEBUG_MODE:
          self.enterSwdMode()
-      self.reset()
+      #self.reset()
    def close(self):
       if self.IsOpen:
          self.devHandle.close()
@@ -151,6 +151,7 @@
       statii = {CORE_RUNNING: 'CORE RUNNING', CORE_HALTED: 'CORE HALTED'}
       if s in statii:
          return statii[s]
+      return 'Unknown status'
 
    def reset(self):
       cmd = bytearray(16)
@@ -224,6 +225,7 @@
    # Test program
    sl = STLink2()
    sl.open()
+   sl.reset()
    print('version:', sl.Version)
    print('mode before doing anything:', sl.CurrentModeString)
    if sl.CurrentMode == DFU_MODE: