eric6/HexEdit/HexEditMainWindow.py

changeset 8259
2bbec88047dd
parent 8240
93b8a353c4bf
child 8265
0090cfa83159
equal deleted inserted replaced
8258:82b608e352ec 8259:2bbec88047dd
1043 Private method to save a binary file. 1043 Private method to save a binary file.
1044 1044
1045 @return flag indicating success 1045 @return flag indicating success
1046 @rtype bool 1046 @rtype bool
1047 """ 1047 """
1048 if not self.__fileName: 1048 ok = (
1049 ok = self.__saveHexFileAs() 1049 self.__saveHexDataFile(self.__fileName)
1050 else: 1050 if self.__fileName else
1051 ok = self.__saveHexDataFile(self.__fileName) 1051 self.__saveHexFileAs()
1052 )
1052 1053
1053 if ok: 1054 if ok:
1054 self.__editor.undoStack().setClean() 1055 self.__editor.undoStack().setClean()
1055 1056
1056 return ok 1057 return ok
1184 self, self.tr("eric Hex Editor"), 1185 self, self.tr("eric Hex Editor"),
1185 self.tr("Cannot write file '{0}:\n{1}.") 1186 self.tr("Cannot write file '{0}:\n{1}.")
1186 .format(fileName, file.errorString())) 1187 .format(fileName, file.errorString()))
1187 return 1188 return
1188 1189
1189 if selectionOnly: 1190 readableData = (
1190 readableData = self.__editor.selectionToReadableString() 1191 self.__editor.selectionToReadableString()
1191 else: 1192 if selectionOnly else
1192 readableData = self.__editor.toReadableString() 1193 self.__editor.toReadableString()
1194 )
1193 res = file.write(readableData.encode("latin1")) != -1 1195 res = file.write(readableData.encode("latin1")) != -1
1194 file.close() 1196 file.close()
1195 1197
1196 if not res: 1198 if not res:
1197 E5MessageBox.warning( 1199 E5MessageBox.warning(
1233 """ 1235 """
1234 self.__fileName = fileName 1236 self.__fileName = fileName
1235 # insert filename into list of recently opened files 1237 # insert filename into list of recently opened files
1236 self.__addToRecentList(fileName) 1238 self.__addToRecentList(fileName)
1237 1239
1238 if not self.__fileName: 1240 shownName = (
1239 shownName = self.tr("Untitled") 1241 self.tr("Untitled")
1240 else: 1242 if not self.__fileName else
1241 shownName = self.__strippedName(self.__fileName) 1243 self.__strippedName(self.__fileName)
1244 )
1242 1245
1243 self.setWindowTitle(self.tr("{0}[*] - {1}") 1246 self.setWindowTitle(self.tr("{0}[*] - {1}")
1244 .format(shownName, self.tr("Hex Editor"))) 1247 .format(shownName, self.tr("Hex Editor")))
1245 1248
1246 self.setWindowModified(self.__editor.isModified()) 1249 self.setWindowModified(self.__editor.isModified())
1318 """ 1321 """
1319 Private method to handle the search action. 1322 Private method to handle the search action.
1320 """ 1323 """
1321 self.__replaceWidget.hide() 1324 self.__replaceWidget.hide()
1322 self.__gotoWidget.hide() 1325 self.__gotoWidget.hide()
1323 if self.__editor.hasSelection(): 1326 txt = (
1324 txt = self.__editor.selectionToHexString() 1327 self.__editor.selectionToHexString()
1325 else: 1328 if self.__editor.hasSelection() else
1326 txt = "" 1329 ""
1330 )
1327 self.__searchWidget.show(txt) 1331 self.__searchWidget.show(txt)
1328 1332
1329 def __replace(self): 1333 def __replace(self):
1330 """ 1334 """
1331 Private method to handle the replace action. 1335 Private method to handle the replace action.
1332 """ 1336 """
1333 self.__searchWidget.hide() 1337 self.__searchWidget.hide()
1334 self.__gotoWidget.hide() 1338 self.__gotoWidget.hide()
1335 if self.__editor.hasSelection(): 1339 txt = (
1336 txt = self.__editor.selectionToHexString() 1340 self.__editor.selectionToHexString()
1337 else: 1341 if self.__editor.hasSelection() else
1338 txt = "" 1342 ""
1343 )
1339 self.__replaceWidget.show(txt) 1344 self.__replaceWidget.show(txt)
1340 1345
1341 def __goto(self): 1346 def __goto(self):
1342 """ 1347 """
1343 Private method to handle the goto action. 1348 Private method to handle the goto action.

eric ide

mercurial