# HG changeset patch # User Windel Bouwman # Date 1358700345 -3600 # Node ID 205578c96a79608936712c091e219cecdeffc2b5 # Parent 04e45faafd1d1885e8f8c93747e919d175b8d3de Moved hexview to seperate class diff -r 04e45faafd1d -r 205578c96a79 python/hexedit.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/hexedit.py Sun Jan 20 17:45:45 2013 +0100 @@ -0,0 +1,61 @@ + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +class HexEdit(QScrollArea): + def __init__(self): + super().__init__() + +class BinViewer(QWidget): + """ + The binviewer consists of a hex view, a ascii view + and perhaps others.. + """ + def __init__(self): + super().__init__() + self.setFont(QFont('Courier')) + self.fontHeight = self.fontMetrics().height() + self.fontWidth = self.fontMetrics().width('x') + self.hexfile = hexfile.HexFile() + def paintEvent(self, event): + painter = QPainter(self) + br = QBrush(Qt.lightGray) + painter.setBrush(br) + h = self.height() + addressWidth = self.fontWidth * 8 + painter.drawRect(2, 2, addressWidth, h) + br2 = QBrush(Qt.yellow) + painter.setBrush(br2) + w = self.width() + 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) + 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) + x = addressWidth + 4 + for b in bts: + b = '{0:02X}'.format(b) + painter.drawText(x, 2 + self.fontHeight * r, b) + x += 3 * self.fontWidth + x = addressWidth + byteWidth + 4 + for b in bts: + 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.update() diff -r 04e45faafd1d -r 205578c96a79 python/hexviewer.py --- a/python/hexviewer.py Sat Jan 19 18:41:49 2013 +0100 +++ b/python/hexviewer.py Sun Jan 20 17:45:45 2013 +0100 @@ -6,59 +6,6 @@ import sys import hexfile -class BinViewer(QWidget): - """ - The binviewer consists of a hex view, a ascii view - and perhaps others.. - """ - def __init__(self): - super().__init__() - self.setFont(QFont('Courier')) - self.fontHeight = self.fontMetrics().height() - self.fontWidth = self.fontMetrics().width('x') - self.hexfile = hexfile.HexFile() - def paintEvent(self, event): - painter = QPainter(self) - br = QBrush(Qt.lightGray) - painter.setBrush(br) - h = self.height() - addressWidth = self.fontWidth * 8 - painter.drawRect(2, 2, addressWidth, h) - br2 = QBrush(Qt.yellow) - painter.setBrush(br2) - w = self.width() - 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) - 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) - x = addressWidth + 4 - for b in bts: - b = '{0:02X}'.format(b) - painter.drawText(x, 2 + self.fontHeight * r, b) - x += 3 * self.fontWidth - x = addressWidth + byteWidth + 4 - for b in bts: - 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.update() class HexFileModel(QAbstractTableModel): def __init__(self): @@ -136,12 +83,15 @@ if __name__ == '__main__': app = QApplication(sys.argv) bv = BinViewMain() - bv.show() + #bv.show() hf = hexfile.HexFile('audio.hex') #bv.bv.setHexFile( bv.hfm.HexFile = hf qpv = QtPropertyViewer() qpv.propertyModel.InspectedWidget = bv #qpv.show() + bv = BinViewer() + bv.show() + bv.setHexFile(hf) app.exec_() diff -r 04e45faafd1d -r 205578c96a79 python/st-util.py --- a/python/st-util.py Sat Jan 19 18:41:49 2013 +0100 +++ b/python/st-util.py Sun Jan 20 17:45:45 2013 +0100 @@ -52,6 +52,13 @@ self.mdl = RegisterModel() self.setModel(self.mdl) +class MemoryViewer(QWidget): + pass + +class FlashTool(QWidget): + def __init__(self): + super().__init__() + class DeviceTreeModel(QAbstractItemModel): def __init__(self): super().__init__() diff -r 04e45faafd1d -r 205578c96a79 python/stlink.py --- a/python/stlink.py Sat Jan 19 18:41:49 2013 +0100 +++ b/python/stlink.py Sun Jan 20 17:45:45 2013 +0100 @@ -80,7 +80,7 @@ self.exitDfuMode() if self.CurrentMode != DEBUG_MODE: self.enterSwdMode() - self.reset() + #self.reset() def close(self): if self.IsOpen: self.devHandle.close() @@ -151,6 +151,7 @@ statii = {CORE_RUNNING: 'CORE RUNNING', CORE_HALTED: 'CORE HALTED'} if s in statii: return statii[s] + return 'Unknown status' def reset(self): cmd = bytearray(16) @@ -224,6 +225,7 @@ # Test program sl = STLink2() sl.open() + sl.reset() print('version:', sl.Version) print('mode before doing anything:', sl.CurrentModeString) if sl.CurrentMode == DFU_MODE: