Mercurial > lcfOS
diff python/hexviewer.py @ 105:6a303f835c6d
Removed compilers directory
author | Windel Bouwman |
---|---|
date | Mon, 31 Dec 2012 17:35:17 +0100 |
parents | ed230e947dc6 |
children | ad14c7c52589 |
line wrap: on
line diff
--- a/python/hexviewer.py Sun Dec 30 22:31:55 2012 +0100 +++ b/python/hexviewer.py Mon Dec 31 17:35:17 2012 +0100 @@ -26,16 +26,18 @@ br2 = QBrush(Qt.yellow) painter.setBrush(br2) w = self.width() - byteWidth = self.fontWidth * 16 * 3 + 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) - for r in range(1, 10): + 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) - bts = bytes(range(16)) x = addressWidth + 4 for b in bts: b = '{0:02X}'.format(b) @@ -46,8 +48,15 @@ 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.hexfile = hf self.update() class BinViewMain(QMainWindow): @@ -55,7 +64,6 @@ super().__init__() self.bv = BinViewer() self.setCentralWidget(self.bv) - self.bv.setHexFile(hexfile.HexFile('audio.hex')) mb = self.menuBar() fileMenu = mb.addMenu("File") @@ -74,5 +82,6 @@ app = QApplication(sys.argv) bv = BinViewMain() bv.show() + bv.bv.setHexFile(hexfile.HexFile('audio.hex')) app.exec_()