# HG changeset patch # User Windel Bouwman # Date 1358796280 -3600 # Node ID 1a50d6db24ed986336523eca003f8a36d3d0e522 # Parent a816c683c1c03b731282ec344ad64c7d4689ceab Changes on hexedit diff -r a816c683c1c0 -r 1a50d6db24ed python/hexedit.py --- a/python/hexedit.py Sun Jan 20 21:48:41 2013 +0100 +++ b/python/hexedit.py Mon Jan 21 20:24:40 2013 +0100 @@ -7,18 +7,19 @@ class BinViewer(QWidget): """ The view has an address, hex byte and ascii column """ - def __init__(self): + def __init__(self, scrollArea): super().__init__() self.setFont(QFont('Courier', 10)) self.setFocusPolicy(Qt.StrongFocus) self.blinkcursor = False + self.cursorX = 0 + self.cursorY = 0 + self.scrollArea = scrollArea self.Data = bytearray() t = QTimer(self) t.timeout.connect(self.updateCursor) t.setInterval(500) t.start() - self.cursorX = 0 - self.cursorY = 0 def updateCursor(self): self.blinkcursor = not self.blinkcursor self.update(self.cursorX, self.cursorY, self.charWidth, self.charHeight) @@ -51,6 +52,8 @@ ypos = yposStart for index in range(firstIndex, lastIndex, BYTES_PER_LINE): + painter.drawText(self.xposAddr, ypos, '{0:08X}'.format(index)) + xpos = self.xposHex for colIndex in range(BYTES_PER_LINE): if index + colIndex < len(self.Data): @@ -64,14 +67,17 @@ painter.fillRect(self.cursorX, self.cursorY + self.charHeight - 2, self.charWidth, 2, Qt.blue) def keyPressEvent(self, event): if event.matches(QKeySequence.MoveToNextChar): - self.setCursorPosition(self.cursorPosition + 1) + self.setCursorPosition(self.cursorPosition + 1) if event.matches(QKeySequence.MoveToPreviousChar): - self.setCursorPosition(self.cursorPosition - 1) + self.setCursorPosition(self.cursorPosition - 1) if event.matches(QKeySequence.MoveToNextLine): - self.setCursorPosition(self.cursorPosition + 2 * BYTES_PER_LINE) + self.setCursorPosition(self.cursorPosition + 2 * BYTES_PER_LINE) if event.matches(QKeySequence.MoveToPreviousLine): - self.setCursorPosition(self.cursorPosition - 2 * BYTES_PER_LINE) - + self.setCursorPosition(self.cursorPosition - 2 * BYTES_PER_LINE) + self.ensureVisible() + self.update() + def ensureVisible(self): + self.scrollArea.ensureVisible(self.cursorX, self.cursorY + self.charHeight, 3, self.charHeight / 2 + 2) def adjust(self): self.charHeight = self.fontMetrics().height() self.charWidth = self.fontMetrics().width('x') @@ -98,7 +104,7 @@ def __init__(self): super().__init__() self.setWidgetResizable(True) - self.bv = BinViewer() + self.bv = BinViewer(self) self.setWidget(self.bv) self.setFocusPolicy(Qt.NoFocus)