changeset 137:0a540ce31cd5

Added debug toolbar and spaced hexedit
author Windel Bouwman
date Fri, 25 Jan 2013 23:47:34 +0100
parents 9af544be5d2a
children 14e739ed03ab
files python/hexedit.py python/ide.py python/st-util.py
diffstat 3 files changed, 52 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/python/hexedit.py	Wed Jan 23 21:54:14 2013 +0100
+++ b/python/hexedit.py	Fri Jan 25 23:47:34 2013 +0100
@@ -37,8 +37,10 @@
       position = clamp(0, int(position), len(self.Data) * 2 - 1)
       self.cursorPosition = position
       x = position % (2 * BYTES_PER_LINE)
+      x = x + int(x / 2) # Create a gap between hex values
       self.cursorX = self.xposHex + x * self.charWidth
-      self.cursorY = int(position / (2 * BYTES_PER_LINE)) * self.charHeight + 2
+      y = int(position / (2 * BYTES_PER_LINE))
+      self.cursorY = y * self.charHeight + 2
       self.blinkcursor = True
       self.update()
    def getCursorPosition(self):
@@ -79,7 +81,7 @@
                b = self.Data[index + colIndex]
                painter.drawText(xpos, ypos, '{0:02X}'.format(b))
                painter.drawText(xposAscii, ypos, asciiChar(b))
-               xpos += 2 * chw
+               xpos += 3 * chw
                xposAscii += chw
          ypos += chh
       # cursor
@@ -111,7 +113,7 @@
          else:
             self.data[i] = (self.data[i] & 0xF0) | v
          self.CursorPosition += 1
-      self.scrollArea.ensureVisible(self.cursorX, self.cursorY, self.charWidth, self.charHeight + 2)
+      self.scrollArea.ensureVisible(self.cursorX, self.cursorY + self.charHeight / 2, 4, self.charHeight / 2 + 4)
       self.update()
    def cursorPositionAt(self, pos):
       """ Calculate cursor position at a certain point """
@@ -128,7 +130,7 @@
       self.charWidth = self.fontMetrics().width('x')
       self.xposAddr = GAP
       self.xposHex = self.xposAddr + 8 * self.charWidth + GAP
-      self.xposAscii = self.xposHex + BYTES_PER_LINE * 2 * self.charWidth + GAP
+      self.xposAscii = self.xposHex + (BYTES_PER_LINE * 3 - 1) * self.charWidth + GAP
       self.xposEnd = self.xposAscii + self.charWidth * BYTES_PER_LINE + GAP
       self.setMinimumWidth(self.xposEnd)
       sbw = self.scrollArea.verticalScrollBar().width()
--- a/python/ide.py	Wed Jan 23 21:54:14 2013 +0100
+++ b/python/ide.py	Fri Jan 25 23:47:34 2013 +0100
@@ -151,8 +151,12 @@
     self.devxplr = addComponent('Device explorer', stutil.DeviceExplorer())
     self.regview = addComponent('Registers', stutil.RegisterView())
     self.memview = addComponent('Memory', stutil.MemoryView())
+    self.ctrlToolbar = stutil.DebugToolbar()
+    self.addToolBar(self.ctrlToolbar)
+    self.ctrlToolbar.setObjectName('debugToolbar')
     self.devxplr.deviceSelected.connect(self.regview.mdl.setDevice)
     self.devxplr.deviceSelected.connect(self.memview.setDevice)
+    self.devxplr.deviceSelected.connect(self.ctrlToolbar.setDevice)
 
     # About dialog:
     self.aboutDialog = AboutDialog()
--- a/python/st-util.py	Wed Jan 23 21:54:14 2013 +0100
+++ b/python/st-util.py	Fri Jan 25 23:47:34 2013 +0100
@@ -84,9 +84,51 @@
       self.device = dev
       self.loadAddress(0x8000000)
 
+class DebugToolbar(QToolBar):
+   def __init__(self):
+      super().__init__()
+      self.device = None
+      # generate actions:
+      def genAction(name, callback):
+         a = QAction(name, self)
+         a.triggered.connect(callback)
+         self.addAction(a)
+         return a
+      self.stepAction = genAction('Step', self.doStep)
+      self.runAction = genAction('Run', self.doRun)
+      self.stopAction = genAction('Stop', self.doStop)
+      self.resetAction = genAction('Reset', self.doReset)
+      self.updateEnables()
+   def updateEnables(self):
+      if self.device:
+         self.resetAction.setEnabled(True)
+         if running:
+            self.runAction.setEnabled(False)
+            self.stepAction.setEnabled(False)
+         else:
+            self.runAction.setEnabled(True)
+            self.stepAction.setEnabled(True)
+      else:
+         self.resetAction.setEnabled(False)
+         self.runAction.setEnabled(True)
+         self.stepAction.setEnabled(False)
+   def doStep(self):
+      self.device.iface.step()
+   def doReset(self):
+      self.device.iface.reset()
+   def doRun(self):
+      self.device.iface.run()
+   def doStop(self):
+      pass
+      # TODO: self.device.iface.halt()
+   def setDevice(self, dev):
+      self.device = dev
+      self.updateEnables()
+
 class FlashTool(QWidget):
    def __init__(self):
       super().__init__()
+      # TODO!
 
 class DeviceTreeModel(QAbstractItemModel):
    def __init__(self):