756 |
756 |
757 @return hexadecimal representation of the selection |
757 @return hexadecimal representation of the selection |
758 @rtype str |
758 @rtype str |
759 """ |
759 """ |
760 byteArray = self.__chunks.data(self.getSelectionBegin(), |
760 byteArray = self.__chunks.data(self.getSelectionBegin(), |
761 self.__getSelectionLength()) |
761 self.getSelectionLength()) |
762 return self.__toHex(byteArray).decode(encoding="ascii") |
762 return self.__toHex(byteArray).decode(encoding="ascii") |
763 |
763 |
764 def selectionToReadableString(self): |
764 def selectionToReadableString(self): |
765 """ |
765 """ |
766 Public method to get a formatted representation of the selection. |
766 Public method to get a formatted representation of the selection. |
767 |
767 |
768 @return formatted representation of the selection |
768 @return formatted representation of the selection |
769 @rtype str |
769 @rtype str |
770 """ |
770 """ |
771 byteArray = self.__chunks.data(self.getSelectionBegin(), |
771 byteArray = self.__chunks.data(self.getSelectionBegin(), |
772 self.__getSelectionLength()) |
772 self.getSelectionLength()) |
773 return self.__toReadable(byteArray) |
773 return self.__toReadable(byteArray) |
774 |
774 |
775 def toReadableString(self): |
775 def toReadableString(self): |
776 """ |
776 """ |
777 Public method to get a formatted representation of our data. |
777 Public method to get a formatted representation of our data. |
1073 """ |
1073 """ |
1074 Public method to cut the selected bytes and move them to the clipboard. |
1074 Public method to cut the selected bytes and move them to the clipboard. |
1075 """ |
1075 """ |
1076 if not self.__readOnly: |
1076 if not self.__readOnly: |
1077 byteArray = self.__toHex(self.__chunks.data( |
1077 byteArray = self.__toHex(self.__chunks.data( |
1078 self.getSelectionBegin(), self.__getSelectionLength())) |
1078 self.getSelectionBegin(), self.getSelectionLength())) |
1079 idx = 32 |
1079 idx = 32 |
1080 while idx < len(byteArray): |
1080 while idx < len(byteArray): |
1081 byteArray.insert(idx, "\n") |
1081 byteArray.insert(idx, "\n") |
1082 idx += 33 |
1082 idx += 33 |
1083 cb = QApplication.clipboard() |
1083 cb = QApplication.clipboard() |
1084 cb.setText(byteArray.decode(encoding="latin1")) |
1084 cb.setText(byteArray.decode(encoding="latin1")) |
1085 if self.__overwriteMode: |
1085 if self.__overwriteMode: |
1086 length = self.__getSelectionLength() |
1086 length = self.getSelectionLength() |
1087 self.replaceByteArray(self.getSelectionBegin(), length, |
1087 self.replaceByteArray(self.getSelectionBegin(), length, |
1088 bytearray(length)) |
1088 bytearray(length)) |
1089 else: |
1089 else: |
1090 self.remove(self.getSelectionBegin(), |
1090 self.remove(self.getSelectionBegin(), |
1091 self.__getSelectionLength()) |
1091 self.getSelectionLength()) |
1092 self.setCursorPosition(2 * self.getSelectionBegin()) |
1092 self.setCursorPosition(2 * self.getSelectionBegin()) |
1093 self.__resetSelection(2 * self.getSelectionBegin()) |
1093 self.__resetSelection(2 * self.getSelectionBegin()) |
1094 |
1094 |
1095 def copy(self): |
1095 def copy(self): |
1096 """ |
1096 """ |
1097 Public method to copy the selected bytes to the clipboard. |
1097 Public method to copy the selected bytes to the clipboard. |
1098 """ |
1098 """ |
1099 byteArray = self.__toHex(self.__chunks.data( |
1099 byteArray = self.__toHex(self.__chunks.data( |
1100 self.getSelectionBegin(), self.__getSelectionLength())) |
1100 self.getSelectionBegin(), self.getSelectionLength())) |
1101 idx = 32 |
1101 idx = 32 |
1102 while idx < len(byteArray): |
1102 while idx < len(byteArray): |
1103 byteArray.insert(idx, "\n") |
1103 byteArray.insert(idx, "\n") |
1104 idx += 33 |
1104 idx += 33 |
1105 cb = QApplication.clipboard() |
1105 cb = QApplication.clipboard() |
1127 """ |
1127 """ |
1128 if not self.__readOnly: |
1128 if not self.__readOnly: |
1129 if self.hasSelection(): |
1129 if self.hasSelection(): |
1130 self.__bPosCurrent = self.getSelectionBegin() |
1130 self.__bPosCurrent = self.getSelectionBegin() |
1131 if self.__overwriteMode: |
1131 if self.__overwriteMode: |
1132 byteArray = bytearray(self.__getSelectionLength()) |
1132 byteArray = bytearray(self.getSelectionLength()) |
1133 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1133 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1134 byteArray) |
1134 byteArray) |
1135 else: |
1135 else: |
1136 self.remove(self.__bPosCurrent, |
1136 self.remove(self.__bPosCurrent, |
1137 self.__getSelectionLength()) |
1137 self.getSelectionLength()) |
1138 else: |
1138 else: |
1139 if self.__overwriteMode: |
1139 if self.__overwriteMode: |
1140 self.replace(self.__bPosCurrent, 0) |
1140 self.replace(self.__bPosCurrent, 0) |
1141 else: |
1141 else: |
1142 self.remove(self.__bPosCurrent, 1) |
1142 self.remove(self.__bPosCurrent, 1) |
1150 if not self.__readOnly: |
1150 if not self.__readOnly: |
1151 if self.hasSelection(): |
1151 if self.hasSelection(): |
1152 self.__bPosCurrent = self.getSelectionBegin() |
1152 self.__bPosCurrent = self.getSelectionBegin() |
1153 self.setCursorPosition(2 * self.__bPosCurrent) |
1153 self.setCursorPosition(2 * self.__bPosCurrent) |
1154 if self.__overwriteMode: |
1154 if self.__overwriteMode: |
1155 byteArray = bytearray(self.__getSelectionLength()) |
1155 byteArray = bytearray(self.getSelectionLength()) |
1156 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1156 self.replaceByteArray(self.__bPosCurrent, len(byteArray), |
1157 byteArray) |
1157 byteArray) |
1158 else: |
1158 else: |
1159 self.remove(self.__bPosCurrent, |
1159 self.remove(self.__bPosCurrent, |
1160 self.__getSelectionLength()) |
1160 self.getSelectionLength()) |
1161 else: |
1161 else: |
1162 self.__bPosCurrent -= 1 |
1162 self.__bPosCurrent -= 1 |
1163 if self.__overwriteMode: |
1163 if self.__overwriteMode: |
1164 self.replace(self.__bPosCurrent, 0) |
1164 self.replace(self.__bPosCurrent, 0) |
1165 else: |
1165 else: |
1254 # some hex input |
1254 # some hex input |
1255 key = evt.text() |
1255 key = evt.text() |
1256 if key and key in "0123456789abcdef": |
1256 if key and key in "0123456789abcdef": |
1257 if self.hasSelection(): |
1257 if self.hasSelection(): |
1258 if self.__overwriteMode: |
1258 if self.__overwriteMode: |
1259 length = self.__getSelectionLength() |
1259 length = self.getSelectionLength() |
1260 self.replaceByteArray( |
1260 self.replaceByteArray( |
1261 self.getSelectionBegin(), length, |
1261 self.getSelectionBegin(), length, |
1262 bytearray(length)) |
1262 bytearray(length)) |
1263 else: |
1263 else: |
1264 self.remove(self.getSelectionBegin(), |
1264 self.remove(self.getSelectionBegin(), |
1265 self.__getSelectionLength()) |
1265 self.getSelectionLength()) |
1266 self.__bPosCurrent = self.getSelectionBegin() |
1266 self.__bPosCurrent = self.getSelectionBegin() |
1267 self.setCursorPosition(2 * self.__bPosCurrent) |
1267 self.setCursorPosition(2 * self.__bPosCurrent) |
1268 self.__resetSelection(2 * self.__bPosCurrent) |
1268 self.__resetSelection(2 * self.__bPosCurrent) |
1269 |
1269 |
1270 # if in insert mode, insert a byte |
1270 # if in insert mode, insert a byte |
1538 @return selection end |
1538 @return selection end |
1539 @rtype int |
1539 @rtype int |
1540 """ |
1540 """ |
1541 return self.__bSelectionEnd |
1541 return self.__bSelectionEnd |
1542 |
1542 |
1543 def __getSelectionLength(self): |
1543 def getSelectionLength(self): |
1544 """ |
1544 """ |
1545 Private method to get the length of the selection. |
1545 Public method to get the length of the selection. |
1546 |
1546 |
1547 @return selection length |
1547 @return selection length |
1548 @rtype int |
1548 @rtype int |
1549 """ |
1549 """ |
1550 return self.__bSelectionEnd - self.__bSelectionBegin |
1550 return self.__bSelectionEnd - self.__bSelectionBegin |