52 Constructor |
52 Constructor |
53 |
53 |
54 @param fileName name of a file to load on startup (string) |
54 @param fileName name of a file to load on startup (string) |
55 @param parent parent widget of this window (QWidget) |
55 @param parent parent widget of this window (QWidget) |
56 @param fromEric flag indicating whether it was called from within |
56 @param fromEric flag indicating whether it was called from within |
57 eric6 (boolean) |
57 eric (boolean) |
58 @param project reference to the project object (Project) |
58 @param project reference to the project object (Project) |
59 """ |
59 """ |
60 super(HexEditMainWindow, self).__init__(parent) |
60 super(HexEditMainWindow, self).__init__(parent) |
61 self.setObjectName("eric6_hex_editor") |
61 self.setObjectName("eric6_hex_editor") |
62 |
62 |
960 @rtype bool |
960 @rtype bool |
961 """ |
961 """ |
962 if self.__editor.isModified(): |
962 if self.__editor.isModified(): |
963 ret = E5MessageBox.okToClearData( |
963 ret = E5MessageBox.okToClearData( |
964 self, |
964 self, |
965 self.tr("eric6 Hex Editor"), |
965 self.tr("eric Hex Editor"), |
966 self.tr("""The loaded file has unsaved changes."""), |
966 self.tr("""The loaded file has unsaved changes."""), |
967 self.__saveHexFile) |
967 self.__saveHexFile) |
968 if not ret: |
968 if not ret: |
969 return False |
969 return False |
970 return True |
970 return True |
977 @type str |
977 @type str |
978 """ |
978 """ |
979 file = QFile(fileName) |
979 file = QFile(fileName) |
980 if not file.exists(): |
980 if not file.exists(): |
981 E5MessageBox.warning( |
981 E5MessageBox.warning( |
982 self, self.tr("eric6 Hex Editor"), |
982 self, self.tr("eric Hex Editor"), |
983 self.tr("The file '{0}' does not exist.") |
983 self.tr("The file '{0}' does not exist.") |
984 .format(fileName)) |
984 .format(fileName)) |
985 return |
985 return |
986 |
986 |
987 if not file.open(QFile.ReadOnly): |
987 if not file.open(QFile.ReadOnly): |
988 E5MessageBox.warning( |
988 E5MessageBox.warning( |
989 self, self.tr("eric6 Hex Editor"), |
989 self, self.tr("eric Hex Editor"), |
990 self.tr("Cannot read file '{0}:\n{1}.") |
990 self.tr("Cannot read file '{0}:\n{1}.") |
991 .format(fileName, file.errorString())) |
991 .format(fileName, file.errorString())) |
992 return |
992 return |
993 |
993 |
994 data = file.readAll() |
994 data = file.readAll() |
1091 @rtype bool |
1091 @rtype bool |
1092 """ |
1092 """ |
1093 file = QFile(fileName) |
1093 file = QFile(fileName) |
1094 if not file.open(QFile.WriteOnly): |
1094 if not file.open(QFile.WriteOnly): |
1095 E5MessageBox.warning( |
1095 E5MessageBox.warning( |
1096 self, self.tr("eric6 Hex Editor"), |
1096 self, self.tr("eric Hex Editor"), |
1097 self.tr("Cannot write file '{0}:\n{1}.") |
1097 self.tr("Cannot write file '{0}:\n{1}.") |
1098 .format(fileName, file.errorString())) |
1098 .format(fileName, file.errorString())) |
1099 |
1099 |
1100 self.__checkActions() |
1100 self.__checkActions() |
1101 |
1101 |
1104 res = file.write(self.__editor.data()) != -1 |
1104 res = file.write(self.__editor.data()) != -1 |
1105 file.close() |
1105 file.close() |
1106 |
1106 |
1107 if not res: |
1107 if not res: |
1108 E5MessageBox.warning( |
1108 E5MessageBox.warning( |
1109 self, self.tr("eric6 Hex Editor"), |
1109 self, self.tr("eric Hex Editor"), |
1110 self.tr("Cannot write file '{0}:\n{1}.") |
1110 self.tr("Cannot write file '{0}:\n{1}.") |
1111 .format(fileName, file.errorString())) |
1111 .format(fileName, file.errorString())) |
1112 |
1112 |
1113 self.__checkActions() |
1113 self.__checkActions() |
1114 |
1114 |
1163 return |
1163 return |
1164 |
1164 |
1165 file = QFile(fileName) |
1165 file = QFile(fileName) |
1166 if not file.open(QFile.WriteOnly): |
1166 if not file.open(QFile.WriteOnly): |
1167 E5MessageBox.warning( |
1167 E5MessageBox.warning( |
1168 self, self.tr("eric6 Hex Editor"), |
1168 self, self.tr("eric Hex Editor"), |
1169 self.tr("Cannot write file '{0}:\n{1}.") |
1169 self.tr("Cannot write file '{0}:\n{1}.") |
1170 .format(fileName, file.errorString())) |
1170 .format(fileName, file.errorString())) |
1171 return |
1171 return |
1172 |
1172 |
1173 if selectionOnly: |
1173 if selectionOnly: |
1177 res = file.write(readableData.encode("latin1")) != -1 |
1177 res = file.write(readableData.encode("latin1")) != -1 |
1178 file.close() |
1178 file.close() |
1179 |
1179 |
1180 if not res: |
1180 if not res: |
1181 E5MessageBox.warning( |
1181 E5MessageBox.warning( |
1182 self, self.tr("eric6 Hex Editor"), |
1182 self, self.tr("eric Hex Editor"), |
1183 self.tr("Cannot write file '{0}:\n{1}.") |
1183 self.tr("Cannot write file '{0}:\n{1}.") |
1184 .format(fileName, file.errorString())) |
1184 .format(fileName, file.errorString())) |
1185 return |
1185 return |
1186 |
1186 |
1187 self.__statusBar.showMessage(self.tr("File saved"), 2000) |
1187 self.__statusBar.showMessage(self.tr("File saved"), 2000) |
1280 def __about(self): |
1280 def __about(self): |
1281 """ |
1281 """ |
1282 Private slot to show a little About message. |
1282 Private slot to show a little About message. |
1283 """ |
1283 """ |
1284 E5MessageBox.about( |
1284 E5MessageBox.about( |
1285 self, self.tr("About eric6 Hex Editor"), |
1285 self, self.tr("About eric Hex Editor"), |
1286 self.tr("The eric6 Hex Editor is a simple editor component" |
1286 self.tr("The eric Hex Editor is a simple editor component" |
1287 " to edit binary files.")) |
1287 " to edit binary files.")) |
1288 |
1288 |
1289 def __aboutQt(self): |
1289 def __aboutQt(self): |
1290 """ |
1290 """ |
1291 Private slot to handle the About Qt dialog. |
1291 Private slot to handle the About Qt dialog. |
1292 """ |
1292 """ |
1293 E5MessageBox.aboutQt(self, "eric6 Hex Editor") |
1293 E5MessageBox.aboutQt(self, "eric Hex Editor") |
1294 |
1294 |
1295 def __whatsThis(self): |
1295 def __whatsThis(self): |
1296 """ |
1296 """ |
1297 Private slot called in to enter Whats This mode. |
1297 Private slot called in to enter Whats This mode. |
1298 """ |
1298 """ |