eric6/HexEdit/HexEditWidget.py

Sat, 21 Sep 2019 17:41:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 21 Sep 2019 17:41:22 +0200
changeset 7254
f00d825fbdb3
parent 7229
53054eb5b15a
child 7360
9190402e4505
permissions
-rw-r--r--

Continued to resolve code style issue M841.

4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2016 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an editor for binary data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
10 import math
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
11
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 from PyQt5.QtCore import (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 pyqtSignal, pyqtSlot, Qt, QByteArray, QTimer, QRect, QBuffer, QIODevice
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 )
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 from PyQt5.QtGui import (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
16 QBrush, QPen, QColor, QFont, QPalette, QKeySequence, QPainter
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from PyQt5.QtWidgets import QAbstractScrollArea, QApplication
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from .HexEditChunks import HexEditChunks
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from .HexEditUndoStack import HexEditUndoStack
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 import Globals
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 class HexEditWidget(QAbstractScrollArea):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Class implementing an editor for binary data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @signal currentAddressChanged(address) emitted to indicate the new
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 cursor position
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @signal currentSizeChanged(size) emitted to indicate the new size of
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @signal dataChanged(modified) emitted to indicate a change of the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @signal overwriteModeChanged(state) emitted to indicate a change of
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 the overwrite mode
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @signal readOnlyChanged(state) emitted to indicate a change of the
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 read only state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @signal canRedoChanged(bool) emitted after the redo status has changed
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @signal canUndoChanged(bool) emitted after the undo status has changed
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @signal selectionAvailable(bool) emitted to signal a change of the
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 selection
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 currentAddressChanged = pyqtSignal(int)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 currentSizeChanged = pyqtSignal(int)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 dataChanged = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 overwriteModeChanged = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 readOnlyChanged = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 canRedoChanged = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 canUndoChanged = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 selectionAvailable = pyqtSignal(bool)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 HEXCHARS_PER_LINE = 47
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 BYTES_PER_LINE = 16
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
4688
fe866d2674fc Corrected the hex editor keyboard handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4686
diff changeset
56 def __init__(self, parent=None):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 Constructor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @param parent refernce to the parent widget
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @type QWidget
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 super(HexEditWidget, self).__init__(parent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 # Properties
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__addressArea = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 # switch the address area on/off
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
68 self.__addressAreaBrush = QBrush()
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
69 self.__addressAreaPen = QPen()
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
70 # background and pen of the address area
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__addressOffset = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 # offset into the shown address range
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__addressWidth = 4
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 # address area width in characters
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__asciiArea = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 # switch the ASCII area on/off
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__data = bytearray()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 # contents of the hex editor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__highlighting = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 # switch the highlighting feature on/off
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__highlightingBrush = QBrush()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__highlightingPen = QPen()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 # background and pen of highlighted text
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.__overwriteMode = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 # set overwrite mode on/off
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__selectionBrush = QBrush()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__selectionPen = QPen()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 # background and pen of selected text
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__readOnly = False
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 # set read only mode on/off
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__cursorPosition = 0
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
92 # absolute position of cursor, 1 Byte == 2 tics
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__addrDigits = 0
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
95 self.__addrSeparators = 0
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.__blink = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__bData = QBuffer()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__cursorRect = QRect()
4656
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
99 self.__cursorRectAscii = QRect()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__dataShown = bytearray()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__hexDataShown = bytearray()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__lastEventSize = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__markedShown = bytearray()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.__modified = False
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.__rowsShown = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 # pixel related attributes (starting with __px)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.__pxCharWidth = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__pxCharHeight = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__pxPosHexX = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__pxPosAdrX = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.__pxPosAsciiX = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 self.__pxGapAdr = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.__pxGapAdrHex = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.__pxGapHexAscii = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.__pxSelectionSub = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.__pxCursorWidth = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.__pxCursorX = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__pxCursorY = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 # absolute byte position related attributes (starting with __b)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.__bSelectionBegin = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.__bSelectionEnd = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__bSelectionInit = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__bPosFirst = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__bPosLast = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.__bPosCurrent = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.__chunks = HexEditChunks()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.__undoStack = HexEditUndoStack(self.__chunks, self)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 if Globals.isWindowsPlatform():
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.setFont(QFont("Courier", 10))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.setFont(QFont("Monospace", 10))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
136 self.setAddressAreaColors(
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
137 self.palette().color(QPalette.WindowText),
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
138 self.palette().alternateBase().color())
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
139 self.setHighlightColors(
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
140 self.palette().color(QPalette.WindowText),
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
141 QColor(0xff, 0xff, 0x99, 0xff))
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
142 self.setSelectionColors(
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
143 self.palette().highlightedText().color(),
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
144 self.palette().highlight().color())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 self.__cursorTimer = QTimer()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.__cursorTimer.timeout.connect(self.__updateCursor)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.verticalScrollBar().valueChanged.connect(self.__adjust)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.__undoStack.indexChanged.connect(self.__dataChangedPrivate)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self.__undoStack.canRedoChanged.connect(self.__canRedoChanged)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.__undoStack.canUndoChanged.connect(self.__canUndoChanged)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.readOnlyChanged.connect(self.__canRedoChanged)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.readOnlyChanged.connect(self.__canUndoChanged)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__cursorTimer.setInterval(500)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.__cursorTimer.start()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.setAddressWidth(4)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.setAddressArea(True)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.setAsciiArea(True)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.setOverwriteMode(True)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.setHighlighting(True)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.setReadOnly(False)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.__initialize()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 def undoStack(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 Public method to get a reference to the undo stack.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 @return reference to the undo stack
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @rtype HexEditUndoStack
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 return self.__undoStack
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @pyqtSlot()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 def __canRedoChanged(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 Private slot handling changes of the Redo state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self.canRedoChanged.emit(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.__undoStack.canRedo() and not self.__readOnly)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @pyqtSlot()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 def __canUndoChanged(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 Private slot handling changes of the Undo state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 self.canUndoChanged.emit(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.__undoStack.canUndo() and not self.__readOnly)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 def addressArea(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 Public method to get the address area visibility.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 @return flag indicating the address area visibility
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 return self.__addressArea
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 def setAddressArea(self, on):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 Public method to set the address area visibility.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 @param on flag indicating the address area visibility
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 self.__addressArea = on
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 self.__adjust()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 self.setCursorPosition(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
216 def addressAreaColors(self):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
218 Public method to get the address area colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
220 @return address area foreground and background colors
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
221 @rtype tuple of 2 QColor
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
223 return self.__addressAreaPen.color(), self.__addressAreaBrush.color()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
225 def setAddressAreaColors(self, foreground, background):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
227 Public method to set the address area colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
229 @param foreground address area foreground color
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
230 @type QColor
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
231 @param background address area background color
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 @type QColor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
234 self.__addressAreaPen = QPen(foreground)
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
235 self.__addressAreaBrush = QBrush(background)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 def addressOffset(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 Public method to get the address offset.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @return address offset
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 return self.__addressOffset
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 def setAddressOffset(self, offset):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 Public method to set the address offset.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 @param offset address offset
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 self.__addressOffset = offset
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 self.__adjust()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 self.setCursorPosition(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 def addressWidth(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
261 Public method to get the width of the address area in
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 characters.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
264 Note: The address area width is always a multiple of four.
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
265
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 @return minimum width of the address area
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 size = self.__chunks.size()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 n = 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 if size > 0x100000000:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 n += 8
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 size //= 0x100000000
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 if size > 0x10000:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 n += 4
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 size //= 0x10000
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 if size > 0x100:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 n += 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 size //= 0x100
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 if size > 0x10:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 n += 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 size //= 0x10
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
283 n = int(math.ceil(n / 4)) * 4
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if n > self.__addressWidth:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 return n
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 return self.__addressWidth
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 def setAddressWidth(self, width):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 Public method to set the width of the address area.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
294 Note: The address area width is always a multiple of four.
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
295 The given value will be adjusted as required.
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
296
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 @param width width of the address area in characters
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 """
4686
5f8a5c568230 Improved the display of addresses and sizes in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4673
diff changeset
300 self.__addressWidth = int(math.ceil(width / 4)) * 4
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 self.__adjust()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 self.setCursorPosition(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 def asciiArea(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 Public method to get the visibility of the ASCII area.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 @return visibility of the ASCII area
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 return self.__asciiArea
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 def setAsciiArea(self, on):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 Public method to set the visibility of the ASCII area.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 @param on flag indicating the visibility of the ASCII area
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.__asciiArea = on
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 def cursorPosition(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 Public method to get the cursor position.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 @return cursor position
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 return self.__cursorPosition
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 def setCursorPosition(self, pos):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 Public method to set the cursor position.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 @param pos cursor position
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 # step 1: delete old cursor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 self.__blink = False
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 self.viewport().update(self.__cursorRect)
4656
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
343 if self.__asciiArea:
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
344 self.viewport().update(self.__cursorRectAscii)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 # step 2: check, if cursor is in range
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 if self.__overwriteMode and pos > (self.__chunks.size() * 2 - 1):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 pos = self.__chunks.size() * 2 - 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if (not self.__overwriteMode) and pos > (self.__chunks.size() * 2):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 pos = self.__chunks.size() * 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 if pos < 0:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 pos = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 # step 3: calculate new position of cursor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 self.__cursorPosition = pos
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 self.__bPosCurrent = pos // 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 self.__pxCursorY = (
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 ((pos // 2 - self.__bPosFirst) // self.BYTES_PER_LINE + 1) *
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 self.__pxCharHeight)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 x = (pos % (2 * self.BYTES_PER_LINE))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 self.__pxCursorX = (
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 (((x // 2) * 3) + (x % 2)) * self.__pxCharWidth + self.__pxPosHexX)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363
4673
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
364 self.__setHexCursorRect()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365
4656
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
366 # step 4: calculate position of ASCII cursor
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
367 x = self.__bPosCurrent % self.BYTES_PER_LINE
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
368 self.__cursorRectAscii = QRect(
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
369 self.__pxPosAsciiX + x * self.__pxCharWidth - 1,
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
370 self.__pxCursorY - self.__pxCharHeight + 4,
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
371 self.__pxCharWidth + 1, self.__pxCharHeight + 1)
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
372
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
373 # step 5: draw new cursors
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.__blink = True
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 self.viewport().update(self.__cursorRect)
4656
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
376 if self.__asciiArea:
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
377 self.viewport().update(self.__cursorRectAscii)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 self.currentAddressChanged.emit(self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379
4673
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
380 def __setHexCursorRect(self):
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
381 """
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
382 Private method to set the cursor.
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
383 """
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
384 if self.__overwriteMode:
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
385 self.__cursorRect = QRect(
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
386 self.__pxCursorX, self.__pxCursorY + self.__pxCursorWidth,
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
387 self.__pxCharWidth, self.__pxCursorWidth)
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
388 else:
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
389 self.__cursorRect = QRect(
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
390 self.__pxCursorX, self.__pxCursorY - self.__pxCharHeight + 4,
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
391 self.__pxCursorWidth, self.__pxCharHeight)
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
392
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
393 def cursorBytePosition(self):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
394 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
395 Public method to get the cursor position in bytes.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
396
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
397 @return cursor position in bytes
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
398 @rtype int
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
399 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
400 return self.__bPosCurrent
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
401
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
402 def setCursorBytePosition(self, pos):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
403 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
404 Public method to set the cursor position in bytes.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
405
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
406 @param pos cursor position in bytes
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
407 @type int
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
408 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
409 self.setCursorPosition(pos * 2)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
410
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
411 def goto(self, offset, fromCursor=False, backwards=False,
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
412 extendSelection=False):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
413 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
414 Public method to move the cursor.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
415
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
416 @param offset offset to move to
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
417 @type int
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
418 @param fromCursor flag indicating a move relative to the current cursor
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
419 @type bool
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
420 @param backwards flag indicating a backwards move
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
421 @type bool
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
422 @param extendSelection flag indicating to extend the selection
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
423 @type bool
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
424 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
425 if fromCursor:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
426 if backwards:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
427 newPos = self.cursorBytePosition() - offset
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
428 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
429 newPos = self.cursorBytePosition() + offset
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
430 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
431 if backwards:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
432 newPos = self.__chunks.size() - offset
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
433 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
434 newPos = offset
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
435
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
436 self.setCursorBytePosition(newPos)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
437 if extendSelection:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
438 self.__setSelection(self.__cursorPosition)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
439 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
440 self.__resetSelection(self.__cursorPosition)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
441
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
442 self.__refresh()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4669
diff changeset
443
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 def data(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 Public method to get the binary data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 @return binary data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 @rtype bytearray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 return self.__chunks.data(0, -1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 def setData(self, dataOrDevice):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 Public method to set the data to show.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 @param dataOrDevice byte array or device containing the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 @type bytearray, QByteArray or QIODevice
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 @return flag indicating success
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 @exception TypeError raised to indicate a wrong parameter type
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 if isinstance(dataOrDevice, (bytearray, QByteArray)):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 self.__data = bytearray(dataOrDevice)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 self.__bData.setData(self.__data)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 return self.__setData(self.__bData)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 elif isinstance(dataOrDevice, QIODevice):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 return self.__setData(dataOrDevice)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 raise TypeError(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 "setData: parameter must be bytearray, "
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 "QByteArray or QIODevice")
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 def __setData(self, ioDevice):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 Private method to set the data to show.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 @param ioDevice device containing the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 @type QIODevice
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480 @return flag indicating success
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 ok = self.__chunks.setIODevice(ioDevice)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 self.__initialize()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 self.__dataChangedPrivate()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 return ok
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 def highlighting(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 Public method to get the highlighting state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 @return highlighting state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 return self.__highlighting
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 def setHighlighting(self, on):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 Public method to set the highlighting state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 @param on new highlighting state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 self.__highlighting = on
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
507 def highlightColors(self):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
509 Public method to get the highlight colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
511 @return highlight foreground and background colors
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
512 @rtype tuple of 2 QColor
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
514 return self.__highlightingPen.color(), self.__highlightingBrush.color()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
516 def setHighlightColors(self, foreground, background):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
518 Public method to set the highlight colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
520 @param foreground highlight foreground color
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
521 @type QColor
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
522 @param background highlight background color
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 @type QColor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
525 self.__highlightingPen = QPen(foreground)
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
526 self.__highlightingBrush = QBrush(background)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 def overwriteMode(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 Public method to get the overwrite mode.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 @return overwrite mode
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
536 return self.__overwriteMode
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 def setOverwriteMode(self, on):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 Public method to set the overwrite mode.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 @param on flag indicating the new overwrite mode
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 self.__overwriteMode = on
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 self.overwriteModeChanged.emit(self.__overwriteMode)
4673
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
547
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
548 # step 1: delete old cursor
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
549 self.__blink = False
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
550 self.viewport().update(self.__cursorRect)
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
551 # step 2: change the cursor rectangle
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
552 self.__setHexCursorRect()
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
553 # step 3: draw new cursors
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
554 self.__blink = True
6fa2418f010c Finalized the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
555 self.viewport().update(self.__cursorRect)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
557 def selectionColors(self):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
559 Public method to get the selection colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
561 @return selection foreground and background colors
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
562 @rtype tuple of 2 QColor
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
564 return self.__selectionPen.color(), self.__selectionBrush.color()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
566 def setSelectionColors(self, foreground, background):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
568 Public method to set the selection colors.
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
570 @param foreground selection foreground color
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
571 @type QColor
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
572 @param background selection background color
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 @type QColor
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 """
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
575 self.__selectionPen = QPen(foreground)
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
576 self.__selectionBrush = QBrush(background)
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
578
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
579 def isReadOnly(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
580 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581 Public method to test the read only state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
582
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 @return flag indicating the read only state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 return self.__readOnly
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 def setReadOnly(self, on):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 Public method to set the read only state.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 @param on new read only state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 self.__readOnly = on
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 self.readOnlyChanged.emit(self.__readOnly)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
598 def font(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 Public method to get the font used to show the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 @return font used to show the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
603 @rtype QFont
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
605 return super(HexEditWidget, self).font()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
607 def setFont(self, font):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
608 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609 Public method to set the font used to show the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 @param font font used to show the data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612 @type QFont
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 super(HexEditWidget, self).setFont(font)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 self.__pxCharWidth = self.fontMetrics().width("2")
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 self.__pxCharHeight = self.fontMetrics().height()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617 self.__pxGapAdr = self.__pxCharWidth // 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 self.__pxGapAdrHex = self.__pxCharWidth
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
619 self.__pxGapHexAscii = 2 * self.__pxCharWidth
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 self.__pxCursorWidth = self.__pxCharHeight // 7
4656
ec546bd4ec56 Added a cursor to the ASCII area of the hex edit widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4652
diff changeset
621 self.__pxSelectionSub = self.fontMetrics().descent()
4658
d760763dcc4a Created a configuration page for the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
622 self.__adjust()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
625 def dataAt(self, pos, count=-1):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 Public method to get data from a given position.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 @param pos position to get data from
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 @param count amount of bytes to get
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 @return requested data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 @rtype bytearray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 return bytearray(self.__chunks.data(pos, count))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638 def write(self, device, pos=0, count=-1):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 Public method to write data from a given position to a device.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642 @param device device to write to
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 @type QIODevice
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 @param pos position to start the write at
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
646 @param count amount of bytes to write
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
647 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 @return flag indicating success
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
651 return self.__chunks.write(device, pos, count)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
653 def insert(self, pos, ch):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
655 Public method to insert a byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657 @param pos position to insert the byte at
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
659 @param ch byte to insert
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660 @type int in the range 0x00 to 0xff
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 assert ch in range(0, 256)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 self.__undoStack.insert(pos, ch)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667 def remove(self, pos, length=1):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
668 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669 Public method to remove bytes.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
670
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
671 @param pos position to remove bytes from
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 @param length amount of bytes to remove
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
676 self.__undoStack.removeAt(pos, length)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
678
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
679 def replace(self, pos, ch):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
681 Public method to replace a byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
682
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
683 @param pos position to replace the byte at
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 @param ch byte to replace with
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 @type int in the range 0x00 to 0xff
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 assert ch in range(0, 256)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 self.__undoStack.overwrite(pos, ch)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 def insertByteArray(self, pos, byteArray):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 Public method to insert bytes.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 @param pos position to insert the bytes at
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
699 @param byteArray bytes to be insert
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700 @type bytearray or QByteArray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 self.__undoStack.insertByteArray(pos, bytearray(byteArray))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
704
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
705 def replaceByteArray(self, pos, length, byteArray):
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
706 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
707 Public method to replace bytes.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
708
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
709 @param pos position to replace the bytes at
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
710 @type int
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
711 @param length amount of bytes to replace
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
712 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
713 @param byteArray bytes to replace with
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
714 @type bytearray or QByteArray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
715 """
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
716 self.__undoStack.overwriteByteArray(pos, length, bytearray(byteArray))
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
717 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
718
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
719 def cursorPositionFromPoint(self, point):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
720 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
721 Public method to calculate a cursor position from a graphics position.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
722
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
723 @param point graphics position
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
724 @type QPoint
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
725 @return cursor position
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
726 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
727 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728 result = -1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
729 if (point.x() >= self.__pxPosHexX) and (
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
730 point.x() < (self.__pxPosHexX + (1 + self.HEXCHARS_PER_LINE) *
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
731 self.__pxCharWidth)):
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
732 x = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
733 (point.x() - self.__pxPosHexX - self.__pxCharWidth // 2) //
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 self.__pxCharWidth
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
735 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736 x = (x // 3) * 2 + x % 3
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
737 y = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
738 ((point.y() - 3) // self.__pxCharHeight) * 2 *
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 self.BYTES_PER_LINE
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
740 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
741 result = self.__bPosFirst * 2 + x + y
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
742 return result
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
743
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
744 def ensureVisible(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
746 Public method to ensure, that the cursor is visible.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
748 if self.__cursorPosition < 2 * self.__bPosFirst:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 self.verticalScrollBar().setValue(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
750 self.__cursorPosition // 2 // self.BYTES_PER_LINE)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
751 if self.__cursorPosition > (
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
752 (self.__bPosFirst + (self.__rowsShown - 1) *
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
753 self.BYTES_PER_LINE) * 2):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 self.verticalScrollBar().setValue(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
755 self.__cursorPosition // 2 // self.BYTES_PER_LINE -
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
756 self.__rowsShown + 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757 self.viewport().update()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
759 def indexOf(self, byteArray, start):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761 Public method to find the first occurrence of a byte array in our data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 @param byteArray data to search for
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 @type bytearray or QByteArray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
765 @param start start position of the search
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
766 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
767 @return position of match (or -1 if not found)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
768 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
769 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
770 byteArray = bytearray(byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
771 pos = self.__chunks.indexOf(byteArray, start)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
772 if pos > -1:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 curPos = pos * 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774 self.setCursorPosition(curPos + len(byteArray) * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775 self.__resetSelection(curPos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
776 self.__setSelection(curPos + len(byteArray) * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 self.ensureVisible()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
778 return pos
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
779
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
780 def lastIndexOf(self, byteArray, start):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
782 Public method to find the last occurrence of a byte array in our data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784 @param byteArray data to search for
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
785 @type bytearray or QByteArray
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
786 @param start start position of the search
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 @type int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 @return position of match (or -1 if not found)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
789 @rtype int
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
790 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 byteArray = bytearray(byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
792 pos = self.__chunks.lastIndexOf(byteArray, start)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 if pos > -1:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 curPos = pos * 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 self.setCursorPosition(curPos - 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
796 self.__resetSelection(curPos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797 self.__setSelection(curPos + len(byteArray) * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
798 self.ensureVisible()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
799 return pos
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
800
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801 def isModified(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803 Public method to check for any modification.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 @return flag indicating a modified state
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806 @rtype bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
807 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
808 return self.__modified
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
809
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 def setModified(self, modified, setCleanState=False):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
811 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
812 Public slot to set the modified flag.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
813
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
814 @param modified flag indicating the new modification status
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
815 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
816 @param setCleanState flag indicating to set the undo stack to clean
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 @type bool
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
819 self.__modified = modified
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
820 self.dataChanged.emit(modified)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
821
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
822 if not modified and setCleanState:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
823 self.__undoStack.setClean()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
824
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
825 def selectionToHexString(self):
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
826 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
827 Public method to get a hexadecimal representation of the selection.
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
828
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
829 @return hexadecimal representation of the selection
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
830 @rtype str
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
831 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
832 byteArray = self.__chunks.data(self.getSelectionBegin(),
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
833 self.getSelectionLength())
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
834 return self.__toHex(byteArray).decode(encoding="ascii")
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4658
diff changeset
835
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
836 def selectionToReadableString(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
837 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
838 Public method to get a formatted representation of the selection.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
839
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840 @return formatted representation of the selection
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
841 @rtype str
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
842 """
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
843 byteArray = self.__chunks.data(self.getSelectionBegin(),
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
844 self.getSelectionLength())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
845 return self.__toReadable(byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
846
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
847 def toReadableString(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
848 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
849 Public method to get a formatted representation of our data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
850
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
851 @return formatted representation of our data
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
852 @rtype str
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
854 byteArray = self.__chunks.data()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855 return self.__toReadable(byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
857 @pyqtSlot()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 def redo(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
859 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
860 Public slot to redo the last operation.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
861 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
862 self.__undoStack.redo()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
863 self.setCursorPosition(self.__chunks.pos() * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
864 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
865
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
866 @pyqtSlot()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
867 def undo(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
868 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
869 Public slot to undo the last operation.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
870 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871 self.__undoStack.undo()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
872 self.setCursorPosition(self.__chunks.pos() * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
873 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
875 @pyqtSlot()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876 def revertToUnmodified(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
877 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878 Public slot to revert all changes.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880 cleanIndex = self.__undoStack.cleanIndex()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 if cleanIndex >= 0:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 self.__undoStack.setIndex(cleanIndex)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
883 self.setCursorPosition(self.__chunks.pos() * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
887 ## Cursor movement commands
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 def moveCursorToNextChar(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892 Public method to move the cursor to the next byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
894 self.setCursorPosition(self.__cursorPosition + 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
896
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 def moveCursorToPreviousChar(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
898 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
899 Public method to move the cursor to the previous byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
900 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
901 self.setCursorPosition(self.__cursorPosition - 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
902 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
903
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
904 def moveCursorToEndOfLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
905 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
906 Public method to move the cursor to the end of the current line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
907 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
908 self.setCursorPosition(self.__cursorPosition |
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
909 (2 * self.BYTES_PER_LINE - 1))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
910 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
911
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
912 def moveCursorToStartOfLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
913 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
914 Public method to move the cursor to the beginning of the current line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
915 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
916 self.setCursorPosition(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
917 self.__cursorPosition -
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
918 (self.__cursorPosition % (2 * self.BYTES_PER_LINE)))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
920
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 def moveCursorToPreviousLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923 Public method to move the cursor to the previous line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
924 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
925 self.setCursorPosition(self.__cursorPosition - 2 * self.BYTES_PER_LINE)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
926 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
927
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
928 def moveCursorToNextLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
929 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
930 Public method to move the cursor to the next line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
931 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
932 self.setCursorPosition(self.__cursorPosition + 2 * self.BYTES_PER_LINE)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
933 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
934
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
935 def moveCursorToNextPage(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
936 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
937 Public method to move the cursor to the next page.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
938 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
939 self.setCursorPosition(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
940 self.__cursorPosition +
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
941 (self.__rowsShown - 1) * 2 * self.BYTES_PER_LINE)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
942 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
943
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
944 def moveCursorToPreviousPage(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
945 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
946 Public method to move the cursor to the previous page.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
947 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
948 self.setCursorPosition(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
949 self.__cursorPosition -
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
950 (self.__rowsShown - 1) * 2 * self.BYTES_PER_LINE)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
951 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
952
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
953 def moveCursorToEndOfDocument(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
954 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
955 Public method to move the cursor to the end of the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
956 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
957 self.setCursorPosition(self.__chunks.size() * 2)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
958 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
959
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
960 def moveCursorToStartOfDocument(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
961 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
962 Public method to move the cursor to the start of the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
963 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
964 self.setCursorPosition(0)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
965 self.__resetSelection(self.__cursorPosition)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
966
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
967 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
968 ## Selection commands
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
969 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
970
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
971 def deselectAll(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
972 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
973 Public method to deselect all data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
974 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
975 self.__resetSelection(0)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
976 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
977
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
978 def selectAll(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
979 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
980 Public method to select all data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
981 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
982 self.__resetSelection(0)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
983 self.__setSelection(2 * self.__chunks.size() + 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
984 self.__refresh()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
985
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
986 def selectNextChar(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
987 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
988 Public method to extend the selection by one byte right.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
989 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
990 pos = self.__cursorPosition + 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
991 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
992 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
993
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
994 def selectPreviousChar(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
995 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
996 Public method to extend the selection by one byte left.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
997 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
998 pos = self.__cursorPosition - 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
999 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1000 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1001
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1002 def selectToEndOfLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1003 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1004 Public method to extend the selection to the end of line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1005 """
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1006 pos = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1007 self.__cursorPosition -
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1008 (self.__cursorPosition % (2 * self.BYTES_PER_LINE)) +
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1009 2 * self.BYTES_PER_LINE
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1010 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1011 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1012 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1013
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1014 def selectToStartOfLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1015 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1016 Public method to extend the selection to the start of line.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1017 """
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1018 pos = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1019 self.__cursorPosition -
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1020 (self.__cursorPosition % (2 * self.BYTES_PER_LINE))
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1021 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1022 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1023 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1024
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1025 def selectPreviousLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1026 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1027 Public method to extend the selection one line up.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1028 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1029 pos = self.__cursorPosition - 2 * self.BYTES_PER_LINE
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1030 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1031 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1032
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1033 def selectNextLine(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1034 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1035 Public method to extend the selection one line down.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1036 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1037 pos = self.__cursorPosition + 2 * self.BYTES_PER_LINE
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1038 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1039 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1040
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1041 def selectNextPage(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1042 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1043 Public method to extend the selection one page down.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1044 """
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1045 pos = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1046 self.__cursorPosition +
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1047 ((self.viewport().height() // self.__pxCharHeight) - 1) *
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1048 2 * self.BYTES_PER_LINE
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1049 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1050 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1051 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1052
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1053 def selectPreviousPage(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1054 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1055 Public method to extend the selection one page up.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1056 """
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1057 pos = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1058 self.__cursorPosition -
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1059 ((self.viewport().height() // self.__pxCharHeight) - 1) *
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1060 2 * self.BYTES_PER_LINE
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
1061 )
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1062 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1063 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1064
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1065 def selectEndOfDocument(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1066 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1067 Public method to extend the selection to the end of the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1068 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1069 pos = self.__chunks.size() * 2
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1070 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1071 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1072
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1073 def selectStartOfDocument(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1074 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1075 Public method to extend the selection to the start of the data.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1076 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1077 pos = 0
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1078 self.setCursorPosition(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1079 self.__setSelection(pos)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1080
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1081 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1082 ## Edit commands
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1083 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1084
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1085 def cut(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1086 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1087 Public method to cut the selected bytes and move them to the clipboard.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1088 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1089 if not self.__readOnly:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1090 byteArray = self.__toHex(self.__chunks.data(
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1091 self.getSelectionBegin(), self.getSelectionLength()))
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1092 idx = 32
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1093 while idx < len(byteArray):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1094 byteArray.insert(idx, "\n")
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1095 idx += 33
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1096 cb = QApplication.clipboard()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1097 cb.setText(byteArray.decode(encoding="latin1"))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1098 if self.__overwriteMode:
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1099 length = self.getSelectionLength()
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1100 self.replaceByteArray(self.getSelectionBegin(), length,
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1101 bytearray(length))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1102 else:
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1103 self.remove(self.getSelectionBegin(),
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1104 self.getSelectionLength())
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1105 self.setCursorPosition(2 * self.getSelectionBegin())
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1106 self.__resetSelection(2 * self.getSelectionBegin())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1107
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1108 def copy(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1109 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1110 Public method to copy the selected bytes to the clipboard.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1111 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1112 byteArray = self.__toHex(self.__chunks.data(
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1113 self.getSelectionBegin(), self.getSelectionLength()))
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1114 idx = 32
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1115 while idx < len(byteArray):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1116 byteArray.insert(idx, "\n")
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1117 idx += 33
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1118 cb = QApplication.clipboard()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1119 cb.setText(byteArray.decode(encoding="latin1"))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1120
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1121 def paste(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1122 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1123 Public method to paste bytes from the clipboard.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1124 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1125 if not self.__readOnly:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1126 cb = QApplication.clipboard()
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1127 byteArray = self.__fromHex(cb.text().encode(encoding="latin1"))
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1128 if self.__overwriteMode:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1129 self.replaceByteArray(self.__bPosCurrent, len(byteArray),
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1130 byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1131 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1132 self.insertByteArray(self.__bPosCurrent, byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1133 self.setCursorPosition(
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1134 self.__cursorPosition + 2 * len(byteArray))
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1135 self.__resetSelection(2 * self.getSelectionBegin())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1136
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1137 def deleteByte(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1138 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1139 Public method to delete the current byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1140 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1141 if not self.__readOnly:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1142 if self.hasSelection():
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1143 self.__bPosCurrent = self.getSelectionBegin()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1144 if self.__overwriteMode:
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1145 byteArray = bytearray(self.getSelectionLength())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1146 self.replaceByteArray(self.__bPosCurrent, len(byteArray),
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1147 byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1148 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1149 self.remove(self.__bPosCurrent,
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1150 self.getSelectionLength())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1151 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1152 if self.__overwriteMode:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1153 self.replace(self.__bPosCurrent, 0)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1154 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1155 self.remove(self.__bPosCurrent, 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1156 self.setCursorPosition(2 * self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1157 self.__resetSelection(2 * self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1158
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1159 def deleteByteBack(self):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1160 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1161 Public method to delete the previous byte.
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1162 """
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1163 if not self.__readOnly:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1164 if self.hasSelection():
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4650
diff changeset
1165 self.__bPosCurrent = self.getSelectionBegin()
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1166 self.setCursorPosition(2 * self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1167 if self.__overwriteMode:
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1168 byteArray = bytearray(self.getSelectionLength())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1169 self.replaceByteArray(self.__bPosCurrent, len(byteArray),
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1170 byteArray)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1171 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1172 self.remove(self.__bPosCurrent,
4669
d37bfc9ca3b9 Added selection information to the statusbar of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4664
diff changeset
1173 self.getSelectionLength())
4650
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1174 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1175 self.__bPosCurrent -= 1
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1176 if self.__overwriteMode:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1177 self.replace(self.__bPosCurrent, 0)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1178 else:
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1179 self.remove(self.__bPosCurrent, 1)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1180 self.setCursorPosition(2 * self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1181 self.__resetSelection(2 * self.__bPosCurrent)
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1182
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1183 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1184 ## Event handling methods
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1185 ####################################################
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1186
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1187 def keyPressEvent(self, evt):
b1ca3bcde70b First commit for the new hex editor tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1188 """