Mercurial > lcfOS
diff python/hexedit.py @ 134:1a50d6db24ed
Changes on hexedit
author | Windel Bouwman |
---|---|
date | Mon, 21 Jan 2013 20:24:40 +0100 |
parents | a816c683c1c0 |
children | 01d88140dc03 |
line wrap: on
line diff
--- 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)