Mercurial > lcfOS
diff python/ide/hexedit.py @ 343:11c5a8a70c02 devel
Fix ide
author | Windel Bouwman |
---|---|
date | Sat, 01 Mar 2014 16:27:52 +0100 |
parents | dcae6574c974 |
children |
line wrap: on
line diff
--- a/python/ide/hexedit.py Sat Mar 01 15:40:31 2014 +0100 +++ b/python/ide/hexedit.py Sat Mar 01 16:27:52 2014 +0100 @@ -1,20 +1,19 @@ #!/usr/bin/python import sys -import os -from qtwrapper import QtGui, QtCore, QtWidgets, Qt +from qtwrapper import QtGui, QtCore, QtWidgets, Qt, abspath, uic BYTES_PER_LINE, GAP = 8, 12 def clamp(minimum, x, maximum): - return max(minimum, min(x, maximum)) + return max(minimum, min(x, maximum)) def asciiChar(v): - if v < 0x20 or v > 0x7e: - return '.' - else: - return chr(v) + if v < 0x20 or v > 0x7e: + return '.' + else: + return chr(v) class BinViewer(QtWidgets.QWidget): """ The view has an address, hex byte and ascii column """ @@ -99,18 +98,18 @@ painter.fillRect(self.cursorX, self.cursorY + chh - 2, chw, 2, Qt.black) def keyPressEvent(self, event): - if event.matches(QKeySequence.MoveToNextChar): + if event.matches(QtGui.QKeySequence.MoveToNextChar): self.CursorPosition += 1 - if event.matches(QKeySequence.MoveToPreviousChar): + if event.matches(QtGui.QKeySequence.MoveToPreviousChar): self.CursorPosition -= 1 - if event.matches(QKeySequence.MoveToNextLine): + if event.matches(QtGui.QKeySequence.MoveToNextLine): self.CursorPosition += 2 * BYTES_PER_LINE - if event.matches(QKeySequence.MoveToPreviousLine): + if event.matches(QtGui.QKeySequence.MoveToPreviousLine): self.CursorPosition -= 2 * BYTES_PER_LINE - if event.matches(QKeySequence.MoveToNextPage): + if event.matches(QtGui.QKeySequence.MoveToNextPage): rows = int(self.scrollArea.viewport().height() / self.charHeight) self.CursorPosition += (rows - 1) * 2 * BYTES_PER_LINE - if event.matches(QKeySequence.MoveToPreviousPage): + if event.matches(QtGui.QKeySequence.MoveToPreviousPage): rows = int(self.scrollArea.viewport().height() / self.charHeight) self.CursorPosition -= (rows - 1) * 2 * BYTES_PER_LINE char = event.text().lower() @@ -177,10 +176,9 @@ class HexEditor(QtWidgets.QMainWindow): - def __init__(self): + def __init__(self): super().__init__() - basedir = os.path.dirname(__file__) - uic.loadUi(os.path.join(basedir, 'hexeditor.ui'), baseinstance=self) + uic.loadUi(abspath('hexeditor.ui'), baseinstance=self) self.he = HexEdit() self.setCentralWidget(self.he) self.actionOpen.triggered.connect(self.doOpen) @@ -188,20 +186,24 @@ self.actionSaveAs.triggered.connect(self.doSaveAs) self.fileName = None self.updateControls() - def updateControls(self): + + def updateControls(self): s = True if self.fileName else False self.actionSave.setEnabled(s) self.actionSaveAs.setEnabled(s) - def doOpen(self): - filename = QFileDialog.getOpenFileName(self) + + def doOpen(self): + filename = QtWidgets.QFileDialog.getOpenFileName(self) if filename: with open(filename, 'rb') as f: self.he.bv.Data = f.read() self.fileName = filename self.updateControls() - def doSave(self): + + def doSave(self): self.updateControls() - def doSaveAs(self): + + def doSaveAs(self): filename = QFileDialog.getSaveFileName(self) if filename: with open(filename, 'wb') as f: @@ -211,8 +213,8 @@ if __name__ == '__main__': - app = QApplication(sys.argv) - he = HexEditor() - he.show() - #he.bv.Data = bytearray(range(100)) * 8 + b'x' - app.exec() + app = QtWidgets.QApplication(sys.argv) + he = HexEditor() + he.show() + #he.bv.Data = bytearray(range(100)) * 8 + b'x' + app.exec()