diff python/hexedit.py @ 137:0a540ce31cd5

Added debug toolbar and spaced hexedit
author Windel Bouwman
date Fri, 25 Jan 2013 23:47:34 +0100
parents 9af544be5d2a
children 2ec4d4332b7a
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()