# eric7.HexEdit.HexEditWidget

Module implementing an editor for binary data.

### Global Attributes

None

### Classes

HexEditWidget | Class implementing an editor for binary data.

### Functions

None

## HexEditWidget

Class implementing an editor for binary data.

### Signals

canRedoChanged(bool)
  emitted after the redo status has changed
canUndoChanged(bool)
  emitted after the undo status has changed
currentAddressChanged(address)
  emitted to indicate the new cursor position
currentSizeChanged(size)
  emitted to indicate the new size of the data
dataChanged(modified)
  emitted to indicate a change of the data
overwriteModeChanged(state)
  emitted to indicate a change of the overwrite mode
readOnlyChanged(state)
  emitted to indicate a change of the read only state
selectionAvailable(bool)
  emitted to signal a change of the selection

### Derived from

QAbstractScrollArea

### Class Attributes

BYTES_PER_LINE
HEXCHARS_PER_LINE

### Class Methods

None

### Methods

HexEditWidget | Constructor
__adjust | Private slot to recalculate pixel positions.
__canRedoChanged | Private slot handling changes of the Redo state.
__canUndoChanged | Private slot handling changes of the Undo state.
__dataChangedPrivate | Private slot to handle data changes.
__fromHex | Private method to convert data of a Python bytearray from hex.
__initialize | Private method to do some initialization.
__readBuffers | Private method to read the buffers.
__refresh | Private slot to refresh the display.
__resetSelection | Private method to reset the selection.
__setData | Private method to set the data to show.
__setHexCursorRect | Private method to set the cursor.
__setSelection | Private method to set the selection.
__toHex | Private method to convert the data of a Python bytearray to hex.
__toReadable | Private method to convert some data into a readable format.
__updateCursor | Private slot to update the blinking cursor.
addressArea | Public method to get the address area visibility.
addressOffset | Public method to get the address offset.
addressWidth | Public method to get the width of the address area in characters.
asciiArea | Public method to get the visibility of the ASCII area.
copy | Public method to copy the selected bytes to the clipboard.
cursorBytePosition | Public method to get the cursor position in bytes.
cursorPosition | Public method to get the cursor position.
cursorPositionFromPoint | Public method to calculate a cursor position from a graphics position.
cut | Public method to cut the selected bytes and move them to the clipboard.
data | Public method to get the binary data.
dataAt | Public method to get data from a given position.
deleteByte | Public method to delete the current byte.
deleteByteBack | Public method to delete the previous byte.
deselectAll | Public method to deselect all data.
ensureVisible | Public method to ensure, that the cursor is visible.
font | Public method to get the font used to show the data.
getSelectionBegin | Public method to get the start of the selection.
getSelectionEnd | Public method to get the end of the selection.
getSelectionLength | Public method to get the length of the selection.
goto | Public method to move the cursor.
hasSelection | Public method to test for a selection.
highlighting | Public method to get the highlighting state.
indexOf | Public method to find the first occurrence of a byte array in our data.
insert | Public method to insert a byte.
insertByteArray | Public method to insert bytes.
isModified | Public method to check for any modification.
isReadOnly | Public method to test the read only state.
keyPressEvent | Protected method to handle key press events.
lastIndexOf | Public method to find the last occurrence of a byte array in our data.
mouseMoveEvent | Protected method to handle mouse moves.
mousePressEvent | Protected method to handle mouse button presses.
moveCursorToEndOfDocument | Public method to move the cursor to the end of the data.
moveCursorToEndOfLine | Public method to move the cursor to the end of the current line.
moveCursorToNextChar | Public method to move the cursor to the next byte.
moveCursorToNextLine | Public method to move the cursor to the next line.
moveCursorToNextPage | Public method to move the cursor to the next page.
moveCursorToPreviousChar | Public method to move the cursor to the previous byte.
moveCursorToPreviousLine | Public method to move the cursor to the previous line.
moveCursorToPreviousPage | Public method to move the cursor to the previous page.
moveCursorToStartOfDocument | Public method to move the cursor to the start of the data.
moveCursorToStartOfLine | Public method to move the cursor to the beginning of the current line.
overwriteMode | Public method to get the overwrite mode.
paintEvent | Protected method to handle paint events.
paste | Public method to paste bytes from the clipboard.
redo | Public slot to redo the last operation.
remove | Public method to remove bytes.
replace | Public method to replace a byte.
replaceByteArray | Public method to replace bytes.
resizeEvent | Protected method to handle resize events.
revertToUnmodified | Public slot to revert all changes.
selectAll | Public method to select all data.
selectEndOfDocument | Public method to extend the selection to the end of the data.
selectNextChar | Public method to extend the selection by one byte right.
selectNextLine | Public method to extend the selection one line down.
selectNextPage | Public method to extend the selection one page down.
selectPreviousChar | Public method to extend the selection by one byte left.
selectPreviousLine | Public method to extend the selection one line up.
selectPreviousPage | Public method to extend the selection one page up.
selectStartOfDocument | Public method to extend the selection to the start of the data.
selectToEndOfLine | Public method to extend the selection to the end of line.
selectToStartOfLine | Public method to extend the selection to the start of line.
selectionToHexString | Public method to get a hexadecimal representation of the selection.
selectionToReadableString | Public method to get a formatted representation of the selection.
setAddressArea | Public method to set the address area visibility.
setAddressOffset | Public method to set the address offset.
setAddressWidth | Public method to set the width of the address area.
setAsciiArea | Public method to set the visibility of the ASCII area.
setCursorBytePosition | Public method to set the cursor position in bytes.
setCursorPosition | Public method to set the cursor position.
setData | Public method to set the data to show.
setFont | Public method to set the font used to show the data.
setHighlighting | Public method to set the highlighting state.
setModified | Public slot to set the modified flag.
setOverwriteMode | Public method to set the overwrite mode.
setReadOnly | Public method to set the read only state.
toReadableString | Public method to get a formatted representation of our data.
undo | Public slot to undo the last operation.
undoStack | Public method to get a reference to the undo stack.
write | Public method to write data from a given position to a device.

### Static Methods

None

#### HexEditWidget (Constructor)

HexEditWidget(parent=None)

Constructor

parent (QWidget)
  refernce to the parent widget

#### HexEditWidget.__adjust

__adjust()

Private slot to recalculate pixel positions.

#### HexEditWidget.__canRedoChanged

__canRedoChanged()

Private slot handling changes of the Redo state.

#### HexEditWidget.__canUndoChanged

__canUndoChanged()

Private slot handling changes of the Undo state.

#### HexEditWidget.__dataChangedPrivate

__dataChangedPrivate(idx=0)

Private slot to handle data changes.

idx (int)
  index

#### HexEditWidget.__fromHex

__fromHex(byteArray)

Private method to convert data of a Python bytearray from hex.

byteArray (bytearray)
  byte array to be converted

Return:
  converted data

Return Type:
  bytearray

#### HexEditWidget.__initialize

__initialize()

Private method to do some initialization.

#### HexEditWidget.__readBuffers

__readBuffers()

Private method to read the buffers.

#### HexEditWidget.__refresh

__refresh()

Private slot to refresh the display.

#### HexEditWidget.__resetSelection

__resetSelection(pos=None)

Private method to reset the selection.

pos (int or None)
  position to set selection start and end to (if this is None, selection end is set to selection start)

#### HexEditWidget.__setData

__setData(ioDevice)

Private method to set the data to show.

ioDevice (QIODevice)
  device containing the data

Return:
  flag indicating success

Return Type:
  bool

#### HexEditWidget.__setHexCursorRect

__setHexCursorRect()

Private method to set the cursor.

#### HexEditWidget.__setSelection

__setSelection(pos)

Private method to set the selection.

pos (int)
  position

#### HexEditWidget.__toHex

__toHex(byteArray)

Private method to convert the data of a Python bytearray to hex.

byteArray (bytearray)
  byte array to be converted

Return:
  converted data

Return Type:
  bytearray

#### HexEditWidget.__toReadable

__toReadable(byteArray)

Private method to convert some data into a readable format.

byteArray (bytearray or QByteArray)
  data to be converted

Return:
  readable data

Return Type:
  str

#### HexEditWidget.__updateCursor

__updateCursor()

Private slot to update the blinking cursor.

#### HexEditWidget.addressArea

addressArea()

Public method to get the address area visibility.

Return:
  flag indicating the address area visibility

Return Type:
  bool

#### HexEditWidget.addressOffset

addressOffset()

Public method to get the address offset.

Return:
  address offset

Return Type:
  int

#### HexEditWidget.addressWidth

addressWidth()

Public method to get the width of the address area in characters.

Note: The address area width is always a multiple of four.

Return:
  minimum width of the address area

Return Type:
  int

#### HexEditWidget.asciiArea

asciiArea()

Public method to get the visibility of the ASCII area.

Return:
  visibility of the ASCII area

Return Type:
  bool

#### HexEditWidget.copy

copy()

Public method to copy the selected bytes to the clipboard.

#### HexEditWidget.cursorBytePosition

cursorBytePosition()

Public method to get the cursor position in bytes.

Return:
  cursor position in bytes

Return Type:
  int

#### HexEditWidget.cursorPosition

cursorPosition()

Public method to get the cursor position.

Return:
  cursor position

Return Type:
  int

#### HexEditWidget.cursorPositionFromPoint

cursorPositionFromPoint(point)

Public method to calculate a cursor position from a graphics position.

point (QPoint)
  graphics position

Return:
  cursor position

Return Type:
  int

#### HexEditWidget.cut

cut()

Public method to cut the selected bytes and move them to the clipboard.

#### HexEditWidget.data

data()

Public method to get the binary data.

Return:
  binary data

Return Type:
  bytearray

#### HexEditWidget.dataAt

dataAt(pos, count=-1)

Public method to get data from a given position.

pos (int)
  position to get data from
count (int)
  amount of bytes to get

Return:
  requested data

Return Type:
  bytearray

#### HexEditWidget.deleteByte

deleteByte()

Public method to delete the current byte.

#### HexEditWidget.deleteByteBack

deleteByteBack()

Public method to delete the previous byte.

#### HexEditWidget.deselectAll

deselectAll()

Public method to deselect all data.

#### HexEditWidget.ensureVisible

ensureVisible()

Public method to ensure, that the cursor is visible.

#### HexEditWidget.font

font()

Public method to get the font used to show the data.

Return:
  font used to show the data

Return Type:
  QFont

#### HexEditWidget.getSelectionBegin

getSelectionBegin()

Public method to get the start of the selection.

Return:
  selection start

Return Type:
  int

#### HexEditWidget.getSelectionEnd

getSelectionEnd()

Public method to get the end of the selection.

Return:
  selection end

Return Type:
  int

#### HexEditWidget.getSelectionLength

getSelectionLength()

Public method to get the length of the selection.

Return:
  selection length

Return Type:
  int

#### HexEditWidget.goto

goto(offset, fromCursor=False, backwards=False, extendSelection=False)

Public method to move the cursor.

offset (int)
  offset to move to
fromCursor (bool)
  flag indicating a move relative to the current cursor
backwards (bool)
  flag indicating a backwards move
extendSelection (bool)
  flag indicating to extend the selection

#### HexEditWidget.hasSelection

hasSelection()

Public method to test for a selection.

Return:
  flag indicating the presence of a selection

Return Type:
  bool

#### HexEditWidget.highlighting

highlighting()

Public method to get the highlighting state.

Return:
  highlighting state

Return Type:
  bool

#### HexEditWidget.indexOf

indexOf(byteArray, start)

Public method to find the first occurrence of a byte array in our data.

byteArray (bytearray or QByteArray)
  data to search for
start (int)
  start position of the search

Return:
  position of match (or -1 if not found)

Return Type:
  int

#### HexEditWidget.insert

insert(pos, ch)

Public method to insert a byte.

pos (int)
  position to insert the byte at
ch (int in the range 0x00 to 0xff)
  byte to insert

#### HexEditWidget.insertByteArray

insertByteArray(pos, byteArray)

Public method to insert bytes.

pos (int)
  position to insert the bytes at
byteArray (bytearray or QByteArray)
  bytes to be insert

#### HexEditWidget.isModified

isModified()

Public method to check for any modification.

Return:
  flag indicating a modified state

Return Type:
  bool

#### HexEditWidget.isReadOnly

isReadOnly()

Public method to test the read only state.

Return:
  flag indicating the read only state

Return Type:
  bool

#### HexEditWidget.keyPressEvent

keyPressEvent(evt)

Protected method to handle key press events.

evt (QKeyEvent)
  reference to the key event

#### HexEditWidget.lastIndexOf

lastIndexOf(byteArray, start)

Public method to find the last occurrence of a byte array in our data.

byteArray (bytearray or QByteArray)
  data to search for
start (int)
  start position of the search

Return:
  position of match (or -1 if not found)

Return Type:
  int

#### HexEditWidget.mouseMoveEvent

mouseMoveEvent(evt)

Protected method to handle mouse moves.

evt (QMouseEvent)
  reference to the mouse event

#### HexEditWidget.mousePressEvent

mousePressEvent(evt)

Protected method to handle mouse button presses.

evt (QMouseEvent)
  reference to the mouse event

#### HexEditWidget.moveCursorToEndOfDocument

moveCursorToEndOfDocument()

Public method to move the cursor to the end of the data.

#### HexEditWidget.moveCursorToEndOfLine

moveCursorToEndOfLine()

Public method to move the cursor to the end of the current line.

#### HexEditWidget.moveCursorToNextChar

moveCursorToNextChar()

Public method to move the cursor to the next byte.

#### HexEditWidget.moveCursorToNextLine

moveCursorToNextLine()

Public method to move the cursor to the next line.

#### HexEditWidget.moveCursorToNextPage

moveCursorToNextPage()

Public method to move the cursor to the next page.

#### HexEditWidget.moveCursorToPreviousChar

moveCursorToPreviousChar()

Public method to move the cursor to the previous byte.

#### HexEditWidget.moveCursorToPreviousLine

moveCursorToPreviousLine()

Public method to move the cursor to the previous line.

#### HexEditWidget.moveCursorToPreviousPage

moveCursorToPreviousPage()

Public method to move the cursor to the previous page.

#### HexEditWidget.moveCursorToStartOfDocument

moveCursorToStartOfDocument()

Public method to move the cursor to the start of the data.

#### HexEditWidget.moveCursorToStartOfLine

moveCursorToStartOfLine()

Public method to move the cursor to the beginning of the current line.

#### HexEditWidget.overwriteMode

overwriteMode()

Public method to get the overwrite mode.

Return:
  overwrite mode

Return Type:
  bool

#### HexEditWidget.paintEvent

paintEvent(evt)

Protected method to handle paint events.

evt (QPaintEvent)
  reference to the paint event

#### HexEditWidget.paste

paste()

Public method to paste bytes from the clipboard.

#### HexEditWidget.redo

redo()

Public slot to redo the last operation.

#### HexEditWidget.remove

remove(pos, length=1)

Public method to remove bytes.

pos (int)
  position to remove bytes from
length (int)
  amount of bytes to remove

#### HexEditWidget.replace

replace(pos, ch)

Public method to replace a byte.

pos (int)
  position to replace the byte at
ch (int in the range 0x00 to 0xff)
  byte to replace with

#### HexEditWidget.replaceByteArray

replaceByteArray(pos, length, byteArray)

Public method to replace bytes.

pos (int)
  position to replace the bytes at
length (int)
  amount of bytes to replace
byteArray (bytearray or QByteArray)
  bytes to replace with

#### HexEditWidget.resizeEvent

resizeEvent(evt)

Protected method to handle resize events.

evt (QResizeEvent)
  reference to the resize event

#### HexEditWidget.revertToUnmodified

revertToUnmodified()

Public slot to revert all changes.

#### HexEditWidget.selectAll

selectAll()

Public method to select all data.

#### HexEditWidget.selectEndOfDocument

selectEndOfDocument()

Public method to extend the selection to the end of the data.

#### HexEditWidget.selectNextChar

selectNextChar()

Public method to extend the selection by one byte right.

#### HexEditWidget.selectNextLine

selectNextLine()

Public method to extend the selection one line down.

#### HexEditWidget.selectNextPage

selectNextPage()

Public method to extend the selection one page down.

#### HexEditWidget.selectPreviousChar

selectPreviousChar()

Public method to extend the selection by one byte left.

#### HexEditWidget.selectPreviousLine

selectPreviousLine()

Public method to extend the selection one line up.

#### HexEditWidget.selectPreviousPage

selectPreviousPage()

Public method to extend the selection one page up.

#### HexEditWidget.selectStartOfDocument

selectStartOfDocument()

Public method to extend the selection to the start of the data.

#### HexEditWidget.selectToEndOfLine

selectToEndOfLine()

Public method to extend the selection to the end of line.

#### HexEditWidget.selectToStartOfLine

selectToStartOfLine()

Public method to extend the selection to the start of line.

#### HexEditWidget.selectionToHexString

selectionToHexString()

Public method to get a hexadecimal representation of the selection.

Return:
  hexadecimal representation of the selection

Return Type:
  str

#### HexEditWidget.selectionToReadableString

selectionToReadableString()

Public method to get a formatted representation of the selection.

Return:
  formatted representation of the selection

Return Type:
  str

#### HexEditWidget.setAddressArea

setAddressArea(on)

Public method to set the address area visibility.

on (bool)
  flag indicating the address area visibility

#### HexEditWidget.setAddressOffset

setAddressOffset(offset)

Public method to set the address offset.

offset (int)
  address offset

#### HexEditWidget.setAddressWidth

setAddressWidth(width)

Public method to set the width of the address area.

Note: The address area width is always a multiple of four. The given value will be adjusted as required.

width (int)
  width of the address area in characters

#### HexEditWidget.setAsciiArea

setAsciiArea(on)

Public method to set the visibility of the ASCII area.

on (bool)
  flag indicating the visibility of the ASCII area

#### HexEditWidget.setCursorBytePosition

setCursorBytePosition(pos)

Public method to set the cursor position in bytes.

pos (int)
  cursor position in bytes

#### HexEditWidget.setCursorPosition

setCursorPosition(pos)

Public method to set the cursor position.

pos (int)
  cursor position

#### HexEditWidget.setData

setData(dataOrDevice)

Public method to set the data to show.

dataOrDevice (bytearray, QByteArray or QIODevice)
  byte array or device containing the data

Return:
  flag indicating success

Return Type:
  bool

Raises TypeError:
  raised to indicate a wrong parameter type

#### HexEditWidget.setFont

setFont(font)

Public method to set the font used to show the data.

font (QFont)
  font used to show the data

#### HexEditWidget.setHighlighting

setHighlighting(on)

Public method to set the highlighting state.

on (bool)
  new highlighting state

#### HexEditWidget.setModified

setModified(modified, setCleanState=False)

Public slot to set the modified flag.

modified (bool)
  flag indicating the new modification status
setCleanState (bool)
  flag indicating to set the undo stack to clean

#### HexEditWidget.setOverwriteMode

setOverwriteMode(on)

Public method to set the overwrite mode.

on (bool)
  flag indicating the new overwrite mode

#### HexEditWidget.setReadOnly

setReadOnly(on)

Public method to set the read only state.

on (bool)
  new read only state

#### HexEditWidget.toReadableString

toReadableString()

Public method to get a formatted representation of our data.

Return:
  formatted representation of our data

Return Type:
  str

#### HexEditWidget.undo

undo()

Public slot to undo the last operation.

#### HexEditWidget.undoStack

undoStack()

Public method to get a reference to the undo stack.

Return:
  reference to the undo stack

Return Type:
  HexEditUndoStack

#### HexEditWidget.write

write(device, pos=0, count=-1)

Public method to write data from a given position to a device.

device (QIODevice)
  device to write to
pos (int)
  position to start the write at
count (int)
  amount of bytes to write

Return:
  flag indicating success

Return Type:
  bool

Up