92 self.__selectionPen = QPen() |
92 self.__selectionPen = QPen() |
93 # background and pen of selected text |
93 # background and pen of selected text |
94 self.__readOnly = False |
94 self.__readOnly = False |
95 # set read only mode on/off |
95 # set read only mode on/off |
96 self.__cursorPosition = 0 |
96 self.__cursorPosition = 0 |
97 # absolute positioin of cursor, 1 Byte == 2 tics |
97 # absolute position of cursor, 1 Byte == 2 tics |
98 |
98 |
99 self.__addrDigits = 0 |
99 self.__addrDigits = 0 |
100 self.__blink = True |
100 self.__blink = True |
101 self.__bData = QBuffer() |
101 self.__bData = QBuffer() |
102 self.__cursorRect = QRect() |
102 self.__cursorRect = QRect() |
730 Public method to get a formatted representation of the selection. |
730 Public method to get a formatted representation of the selection. |
731 |
731 |
732 @return formatted representation of the selection |
732 @return formatted representation of the selection |
733 @rtype str |
733 @rtype str |
734 """ |
734 """ |
735 byteArray = self.__chunks.data(self.__getSelectionBegin(), |
735 byteArray = self.__chunks.data(self.getSelectionBegin(), |
736 self.__getSelectionLength()) |
736 self.__getSelectionLength()) |
737 return self.__toReadable(byteArray) |
737 return self.__toReadable(byteArray) |
738 |
738 |
739 def toReadableString(self): |
739 def toReadableString(self): |
740 """ |
740 """ |
1037 """ |
1037 """ |
1038 Public method to cut the selected bytes and move them to the clipboard. |
1038 Public method to cut the selected bytes and move them to the clipboard. |
1039 """ |
1039 """ |
1040 if not self.__readOnly: |
1040 if not self.__readOnly: |
1041 byteArray = self.__toHex(self.__chunks.data( |
1041 byteArray = self.__toHex(self.__chunks.data( |
1042 self.__getSelectionBegin(), self.__getSelectionLength())) |
1042 self.getSelectionBegin(), self.__getSelectionLength())) |
1043 idx = 32 |
1043 idx = 32 |
1044 while idx < len(byteArray): |
1044 while idx < len(byteArray): |
1045 byteArray.insert(idx, "\n") |
1045 byteArray.insert(idx, "\n") |
1046 idx += 33 |
1046 idx += 33 |
1047 cb = QApplication.clipboard() |
1047 cb = QApplication.clipboard() |
1048 cb.setText(byteArray.decode(encoding="latin1")) |
1048 cb.setText(byteArray.decode(encoding="latin1")) |
1049 if self.__overwriteMode: |
1049 if self.__overwriteMode: |
1050 length = self.__getSelectionLength() |
1050 length = self.__getSelectionLength() |
1051 self.replaceByteArray(self.__getSelectionBegin(), length, |
1051 self.replaceByteArray(self.getSelectionBegin(), length, |
1052 bytearray(length)) |
1052 bytearray(length)) |
1053 else: |
1053 else: |
1054 self.remove(self.__getSelectionBegin(), |
1054 self.remove(self.getSelectionBegin(), |
1055 self.__getSelectionLength()) |
1055 self.__getSelectionLength()) |
1056 self.setCursorPosition(2 * self.__getSelectionBegin()) |
1056 self.setCursorPosition(2 * self.getSelectionBegin()) |
1057 self.__resetSelection(2 * self.__getSelectionBegin()) |
1057 self.__resetSelection(2 * self.getSelectionBegin()) |
1058 |
1058 |
1059 def copy(self): |
1059 def copy(self): |
1060 """ |
1060 """ |
1061 Public method to copy the selected bytes to the clipboard. |
1061 Public method to copy the selected bytes to the clipboard. |
1062 """ |
1062 """ |
1063 byteArray = self.__toHex(self.__chunks.data( |
1063 byteArray = self.__toHex(self.__chunks.data( |
1064 self.__getSelectionBegin(), self.__getSelectionLength())) |
1064 self.getSelectionBegin(), self.__getSelectionLength())) |
1065 idx = 32 |
1065 idx = 32 |
1066 while idx < len(byteArray): |
1066 while idx < len(byteArray): |
1067 byteArray.insert(idx, "\n") |
1067 byteArray.insert(idx, "\n") |
1068 idx += 33 |
1068 idx += 33 |
1069 cb = QApplication.clipboard() |
1069 cb = QApplication.clipboard() |
1081 byteArray) |
1081 byteArray) |
1082 else: |
1082 else: |
1083 self.insertByteArray(self.__bPosCurrent, byteArray) |
1083 self.insertByteArray(self.__bPosCurrent, byteArray) |
1084 self.setCursorPosition( |
1084 self.setCursorPosition( |
1085 self.__cursorPosition + 2 * len(byteArray)) |
1085 self.__cursorPosition + 2 * len(byteArray)) |
1086 self.__resetSelection(2 * self.__getSelectionBegin()) |
1086 self.__resetSelection(2 * self.getSelectionBegin()) |
1087 |
1087 |
1088 def deleteByte(self): |
1088 def deleteByte(self): |
1089 """ |
1089 """ |
1090 Public method to delete the current byte. |
1090 Public method to delete the current byte. |
1091 """ |
1091 """ |
1092 if not self.__readOnly: |
1092 if not self.__readOnly: |
1093 if self.hasSelection(): |
1093 if self.hasSelection(): |
1094 self.__bPosCurrent = self.__getSelectionBegin() |
1094 self.__bPosCurrent = self.getSelectionBegin() |
1095 if self.__overwriteMode: |
1095 if self.__overwriteMode: |
1096 byteArray = bytearray(self.__getSelectionLength()) |
1096 byteArray = bytearray(self.__getSelectionLength()) |
1097 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1097 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1098 byteArray) |
1098 byteArray) |
1099 else: |
1099 else: |
1111 """ |
1111 """ |
1112 Public method to delete the previous byte. |
1112 Public method to delete the previous byte. |
1113 """ |
1113 """ |
1114 if not self.__readOnly: |
1114 if not self.__readOnly: |
1115 if self.hasSelection(): |
1115 if self.hasSelection(): |
1116 self.__bPosCurrent = self.__getSelectionBegin() |
1116 self.__bPosCurrent = self.getSelectionBegin() |
1117 self.setCursorPosition(2 * self.__bPosCurrent) |
1117 self.setCursorPosition(2 * self.__bPosCurrent) |
1118 if self.__overwriteMode: |
1118 if self.__overwriteMode: |
1119 byteArray = bytearray(self.__getSelectionLength()) |
1119 byteArray = bytearray(self.__getSelectionLength()) |
1120 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1120 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1121 byteArray) |
1121 byteArray) |
1220 if key and key in "0123456789abcdef": |
1220 if key and key in "0123456789abcdef": |
1221 if self.hasSelection(): |
1221 if self.hasSelection(): |
1222 if self.__overwriteMode: |
1222 if self.__overwriteMode: |
1223 length = self.__getSelectionLength() |
1223 length = self.__getSelectionLength() |
1224 self.replaceByteArray( |
1224 self.replaceByteArray( |
1225 self.__getSelectionBegin(), length, |
1225 self.getSelectionBegin(), length, |
1226 bytearray(length)) |
1226 bytearray(length)) |
1227 else: |
1227 else: |
1228 self.remove(self.__getSelectionBegin(), |
1228 self.remove(self.getSelectionBegin(), |
1229 self.__getSelectionLength()) |
1229 self.__getSelectionLength()) |
1230 self.__bPosCurrent = self.__getSelectionBegin() |
1230 self.__bPosCurrent = self.getSelectionBegin() |
1231 self.setCursorPosition(2 * self.__bPosCurrent) |
1231 self.setCursorPosition(2 * self.__bPosCurrent) |
1232 self.__resetSelection(2 * self.__bPosCurrent) |
1232 self.__resetSelection(2 * self.__bPosCurrent) |
1233 |
1233 |
1234 # if in insert mode, insert a byte |
1234 # if in insert mode, insert a byte |
1235 if not self.__overwriteMode: |
1235 if not self.__overwriteMode: |
1347 colIdx < self.BYTES_PER_LINE: |
1347 colIdx < self.BYTES_PER_LINE: |
1348 c = self.viewport().palette().color(QPalette.Base) |
1348 c = self.viewport().palette().color(QPalette.Base) |
1349 painter.setPen(colStandard) |
1349 painter.setPen(colStandard) |
1350 |
1350 |
1351 posBa = self.__bPosFirst + bPosLine + colIdx |
1351 posBa = self.__bPosFirst + bPosLine + colIdx |
1352 if self.__getSelectionBegin() <= posBa and \ |
1352 if self.getSelectionBegin() <= posBa and \ |
1353 self.__getSelectionEnd() > posBa: |
1353 self.getSelectionEnd() > posBa: |
1354 c = self.__selectionBrush.color() |
1354 c = self.__selectionBrush.color() |
1355 painter.setPen(self.__selectionPen) |
1355 painter.setPen(self.__selectionPen) |
1356 elif self.__highlighting: |
1356 elif self.__highlighting: |
1357 if self.__markedShown and self.__markedShown[ |
1357 if self.__markedShown and self.__markedShown[ |
1358 posBa - self.__bPosFirst]: |
1358 posBa - self.__bPosFirst]: |
1476 self.__bSelectionBegin = pos |
1476 self.__bSelectionBegin = pos |
1477 self.__bSelectionEnd = self.__bSelectionInit |
1477 self.__bSelectionEnd = self.__bSelectionInit |
1478 |
1478 |
1479 self.selectionAvailable.emit(True) |
1479 self.selectionAvailable.emit(True) |
1480 |
1480 |
1481 def __getSelectionBegin(self): |
1481 def getSelectionBegin(self): |
1482 """ |
1482 """ |
1483 Private method to get the start of the selection. |
1483 Public method to get the start of the selection. |
1484 |
1484 |
1485 @return selection start |
1485 @return selection start |
1486 @rtype int |
1486 @rtype int |
1487 """ |
1487 """ |
1488 return self.__bSelectionBegin |
1488 return self.__bSelectionBegin |
1489 |
1489 |
1490 def __getSelectionEnd(self): |
1490 def getSelectionEnd(self): |
1491 """ |
1491 """ |
1492 Private method to get the end of the selection. |
1492 Public method to get the end of the selection. |
1493 |
1493 |
1494 @return selection end |
1494 @return selection end |
1495 @rtype int |
1495 @rtype int |
1496 """ |
1496 """ |
1497 return self.__bSelectionEnd |
1497 return self.__bSelectionEnd |