eric7/HexEdit/HexEditMainWindow.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8322
b422b4e77d19
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
16 from PyQt6.QtGui import QKeySequence, QAction 16 from PyQt6.QtGui import QKeySequence, QAction
17 from PyQt6.QtWidgets import ( 17 from PyQt6.QtWidgets import (
18 QWhatsThis, QLabel, QWidget, QVBoxLayout, QDialog, QFrame, QMenu 18 QWhatsThis, QLabel, QWidget, QVBoxLayout, QDialog, QFrame, QMenu
19 ) 19 )
20 20
21 from E5Gui.E5Action import E5Action 21 from E5Gui.EricAction import EricAction
22 from E5Gui.E5MainWindow import E5MainWindow 22 from E5Gui.EricMainWindow import EricMainWindow
23 from E5Gui import E5FileDialog, E5MessageBox 23 from E5Gui import EricFileDialog, EricMessageBox
24 from E5Gui.E5ClickableLabel import E5ClickableLabel 24 from E5Gui.EricClickableLabel import EricClickableLabel
25 25
26 from Globals import strGroup, recentNameHexFiles 26 from Globals import strGroup, recentNameHexFiles
27 27
28 from .HexEditWidget import HexEditWidget 28 from .HexEditWidget import HexEditWidget
29 from .HexEditSearchReplaceWidget import HexEditSearchReplaceWidget 29 from .HexEditSearchReplaceWidget import HexEditSearchReplaceWidget
34 34
35 import Preferences 35 import Preferences
36 import Utilities 36 import Utilities
37 37
38 38
39 class HexEditMainWindow(E5MainWindow): 39 class HexEditMainWindow(EricMainWindow):
40 """ 40 """
41 Class implementing the web browser main window. 41 Class implementing the web browser main window.
42 42
43 @signal editorClosed() emitted after the window was requested to close down 43 @signal editorClosed() emitted after the window was requested to close down
44 """ 44 """
154 154
155 def __initFileActions(self): 155 def __initFileActions(self):
156 """ 156 """
157 Private method to define the file related user interface actions. 157 Private method to define the file related user interface actions.
158 """ 158 """
159 self.newWindowAct = E5Action( 159 self.newWindowAct = EricAction(
160 self.tr('New Window'), 160 self.tr('New Window'),
161 UI.PixmapCache.getIcon("newWindow"), 161 UI.PixmapCache.getIcon("newWindow"),
162 self.tr('New &Window'), 162 self.tr('New &Window'),
163 0, 0, self, 'hexEditor_file_new_window') 163 0, 0, self, 'hexEditor_file_new_window')
164 self.newWindowAct.setStatusTip(self.tr( 164 self.newWindowAct.setStatusTip(self.tr(
170 )) 170 ))
171 self.newWindowAct.triggered.connect(self.__openHexFileNewWindow) 171 self.newWindowAct.triggered.connect(self.__openHexFileNewWindow)
172 self.__actions.append(self.newWindowAct) 172 self.__actions.append(self.newWindowAct)
173 173
174 # correct texts will be set later 174 # correct texts will be set later
175 self.openAct = E5Action( 175 self.openAct = EricAction(
176 self.tr('Open'), 176 self.tr('Open'),
177 UI.PixmapCache.getIcon("open"), 177 UI.PixmapCache.getIcon("open"),
178 self.tr('&Open...'), 178 self.tr('&Open...'),
179 QKeySequence(self.tr("Ctrl+O", "File|Open")), 179 QKeySequence(self.tr("Ctrl+O", "File|Open")),
180 0, self, 'hexEditor_file_open') 180 0, self, 'hexEditor_file_open')
181 self.openAct.triggered.connect(self.__openHexFile) 181 self.openAct.triggered.connect(self.__openHexFile)
182 self.__actions.append(self.openAct) 182 self.__actions.append(self.openAct)
183 183
184 # correct texts will be set later 184 # correct texts will be set later
185 self.openReadOnlyAct = E5Action( 185 self.openReadOnlyAct = EricAction(
186 "", "", 186 "", "",
187 0, 0, self, 'hexEditor_file_open_read_only') 187 0, 0, self, 'hexEditor_file_open_read_only')
188 self.openReadOnlyAct.triggered.connect(self.__openHexFileReadOnly) 188 self.openReadOnlyAct.triggered.connect(self.__openHexFileReadOnly)
189 self.__actions.append(self.openReadOnlyAct) 189 self.__actions.append(self.openReadOnlyAct)
190 190
191 self.saveAct = E5Action( 191 self.saveAct = EricAction(
192 self.tr('Save'), 192 self.tr('Save'),
193 UI.PixmapCache.getIcon("fileSave"), 193 UI.PixmapCache.getIcon("fileSave"),
194 self.tr('&Save'), 194 self.tr('&Save'),
195 QKeySequence(self.tr("Ctrl+S", "File|Save")), 195 QKeySequence(self.tr("Ctrl+S", "File|Save")),
196 0, self, 'hexEditor_file_save') 196 0, self, 'hexEditor_file_save')
200 """<p>Save the contents of the hex editor window.</p>""" 200 """<p>Save the contents of the hex editor window.</p>"""
201 )) 201 ))
202 self.saveAct.triggered.connect(self.__saveHexFile) 202 self.saveAct.triggered.connect(self.__saveHexFile)
203 self.__actions.append(self.saveAct) 203 self.__actions.append(self.saveAct)
204 204
205 self.saveAsAct = E5Action( 205 self.saveAsAct = EricAction(
206 self.tr('Save As'), 206 self.tr('Save As'),
207 UI.PixmapCache.getIcon("fileSaveAs"), 207 UI.PixmapCache.getIcon("fileSaveAs"),
208 self.tr('Save &As...'), 208 self.tr('Save &As...'),
209 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")), 209 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")),
210 0, self, 'hexEditor_file_save_as') 210 0, self, 'hexEditor_file_save_as')
215 """<p>Saves the current binary data to a new file.</p>""" 215 """<p>Saves the current binary data to a new file.</p>"""
216 )) 216 ))
217 self.saveAsAct.triggered.connect(self.__saveHexFileAs) 217 self.saveAsAct.triggered.connect(self.__saveHexFileAs)
218 self.__actions.append(self.saveAsAct) 218 self.__actions.append(self.saveAsAct)
219 219
220 self.saveReadableAct = E5Action( 220 self.saveReadableAct = EricAction(
221 self.tr('Save As Readable'), 221 self.tr('Save As Readable'),
222 self.tr('Save As &Readable...'), 222 self.tr('Save As &Readable...'),
223 0, 0, self, 'hexEditor_file_save_readable') 223 0, 0, self, 'hexEditor_file_save_readable')
224 self.saveReadableAct.setStatusTip( 224 self.saveReadableAct.setStatusTip(
225 self.tr('Save the current binary data to a new file in a readable' 225 self.tr('Save the current binary data to a new file in a readable'
230 """ format.</p>""" 230 """ format.</p>"""
231 )) 231 ))
232 self.saveReadableAct.triggered.connect(self.__saveHexFileReadable) 232 self.saveReadableAct.triggered.connect(self.__saveHexFileReadable)
233 self.__actions.append(self.saveReadableAct) 233 self.__actions.append(self.saveReadableAct)
234 234
235 self.closeAct = E5Action( 235 self.closeAct = EricAction(
236 self.tr('Close'), 236 self.tr('Close'),
237 UI.PixmapCache.getIcon("close"), 237 UI.PixmapCache.getIcon("close"),
238 self.tr('&Close'), 238 self.tr('&Close'),
239 QKeySequence(self.tr("Ctrl+W", "File|Close")), 239 QKeySequence(self.tr("Ctrl+W", "File|Close")),
240 0, self, 'hexEditor_file_close') 240 0, self, 'hexEditor_file_close')
245 """<p>Closes the current hex editor window.</p>""" 245 """<p>Closes the current hex editor window.</p>"""
246 )) 246 ))
247 self.closeAct.triggered.connect(self.close) 247 self.closeAct.triggered.connect(self.close)
248 self.__actions.append(self.closeAct) 248 self.__actions.append(self.closeAct)
249 249
250 self.closeAllAct = E5Action( 250 self.closeAllAct = EricAction(
251 self.tr('Close All'), 251 self.tr('Close All'),
252 self.tr('Close &All'), 252 self.tr('Close &All'),
253 0, 0, self, 'hexEditor_file_close_all') 253 0, 0, self, 'hexEditor_file_close_all')
254 self.closeAllAct.setStatusTip(self.tr( 254 self.closeAllAct.setStatusTip(self.tr(
255 'Close all hex editor windows')) 255 'Close all hex editor windows'))
258 """<p>Closes all hex editor windows.</p>""" 258 """<p>Closes all hex editor windows.</p>"""
259 )) 259 ))
260 self.closeAllAct.triggered.connect(self.__closeAll) 260 self.closeAllAct.triggered.connect(self.__closeAll)
261 self.__actions.append(self.closeAllAct) 261 self.__actions.append(self.closeAllAct)
262 262
263 self.closeOthersAct = E5Action( 263 self.closeOthersAct = EricAction(
264 self.tr('Close Others'), 264 self.tr('Close Others'),
265 self.tr('Close Others'), 265 self.tr('Close Others'),
266 0, 0, self, 'hexEditor_file_close_others') 266 0, 0, self, 'hexEditor_file_close_others')
267 self.closeOthersAct.setStatusTip(self.tr( 267 self.closeOthersAct.setStatusTip(self.tr(
268 'Close all other hex editor windows')) 268 'Close all other hex editor windows'))
271 """<p>Closes all other hex editor windows.</p>""" 271 """<p>Closes all other hex editor windows.</p>"""
272 )) 272 ))
273 self.closeOthersAct.triggered.connect(self.__closeOthers) 273 self.closeOthersAct.triggered.connect(self.__closeOthers)
274 self.__actions.append(self.closeOthersAct) 274 self.__actions.append(self.closeOthersAct)
275 275
276 self.exitAct = E5Action( 276 self.exitAct = EricAction(
277 self.tr('Quit'), 277 self.tr('Quit'),
278 UI.PixmapCache.getIcon("exit"), 278 UI.PixmapCache.getIcon("exit"),
279 self.tr('&Quit'), 279 self.tr('&Quit'),
280 QKeySequence(self.tr("Ctrl+Q", "File|Quit")), 280 QKeySequence(self.tr("Ctrl+Q", "File|Quit")),
281 0, self, 'hexEditor_file_quit') 281 0, self, 'hexEditor_file_quit')
290 290
291 def __initEditActions(self): 291 def __initEditActions(self):
292 """ 292 """
293 Private method to create the Edit actions. 293 Private method to create the Edit actions.
294 """ 294 """
295 self.undoAct = E5Action( 295 self.undoAct = EricAction(
296 self.tr('Undo'), 296 self.tr('Undo'),
297 UI.PixmapCache.getIcon("editUndo"), 297 UI.PixmapCache.getIcon("editUndo"),
298 self.tr('&Undo'), 298 self.tr('&Undo'),
299 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")), 299 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")),
300 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")), 300 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")),
305 """<p>Undo the last change done.</p>""" 305 """<p>Undo the last change done.</p>"""
306 )) 306 ))
307 self.undoAct.triggered.connect(self.__editor.undo) 307 self.undoAct.triggered.connect(self.__editor.undo)
308 self.__actions.append(self.undoAct) 308 self.__actions.append(self.undoAct)
309 309
310 self.redoAct = E5Action( 310 self.redoAct = EricAction(
311 self.tr('Redo'), 311 self.tr('Redo'),
312 UI.PixmapCache.getIcon("editRedo"), 312 UI.PixmapCache.getIcon("editRedo"),
313 self.tr('&Redo'), 313 self.tr('&Redo'),
314 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")), 314 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")),
315 0, self, 'hexEditor_edit_redo') 315 0, self, 'hexEditor_edit_redo')
319 """<p>Redo the last change done.</p>""" 319 """<p>Redo the last change done.</p>"""
320 )) 320 ))
321 self.redoAct.triggered.connect(self.__editor.redo) 321 self.redoAct.triggered.connect(self.__editor.redo)
322 self.__actions.append(self.redoAct) 322 self.__actions.append(self.redoAct)
323 323
324 self.revertAct = E5Action( 324 self.revertAct = EricAction(
325 self.tr('Revert to last saved state'), 325 self.tr('Revert to last saved state'),
326 self.tr('Re&vert to last saved state'), 326 self.tr('Re&vert to last saved state'),
327 QKeySequence(self.tr("Ctrl+Y", "Edit|Revert")), 327 QKeySequence(self.tr("Ctrl+Y", "Edit|Revert")),
328 0, 328 0,
329 self, 'hexEditor_edit_revert') 329 self, 'hexEditor_edit_revert')
334 """ editor.</p>""" 334 """ editor.</p>"""
335 )) 335 ))
336 self.revertAct.triggered.connect(self.__editor.revertToUnmodified) 336 self.revertAct.triggered.connect(self.__editor.revertToUnmodified)
337 self.__actions.append(self.revertAct) 337 self.__actions.append(self.revertAct)
338 338
339 self.cutAct = E5Action( 339 self.cutAct = EricAction(
340 self.tr('Cut'), 340 self.tr('Cut'),
341 UI.PixmapCache.getIcon("editCut"), 341 UI.PixmapCache.getIcon("editCut"),
342 self.tr('Cu&t'), 342 self.tr('Cu&t'),
343 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")), 343 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")),
344 QKeySequence(self.tr("Shift+Del", "Edit|Cut")), 344 QKeySequence(self.tr("Shift+Del", "Edit|Cut")),
349 """<p>Cut the selected binary area to the clipboard.</p>""" 349 """<p>Cut the selected binary area to the clipboard.</p>"""
350 )) 350 ))
351 self.cutAct.triggered.connect(self.__editor.cut) 351 self.cutAct.triggered.connect(self.__editor.cut)
352 self.__actions.append(self.cutAct) 352 self.__actions.append(self.cutAct)
353 353
354 self.copyAct = E5Action( 354 self.copyAct = EricAction(
355 self.tr('Copy'), 355 self.tr('Copy'),
356 UI.PixmapCache.getIcon("editCopy"), 356 UI.PixmapCache.getIcon("editCopy"),
357 self.tr('&Copy'), 357 self.tr('&Copy'),
358 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")), 358 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")),
359 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")), 359 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")),
364 """<p>Copy the selected binary area to the clipboard.</p>""" 364 """<p>Copy the selected binary area to the clipboard.</p>"""
365 )) 365 ))
366 self.copyAct.triggered.connect(self.__editor.copy) 366 self.copyAct.triggered.connect(self.__editor.copy)
367 self.__actions.append(self.copyAct) 367 self.__actions.append(self.copyAct)
368 368
369 self.pasteAct = E5Action( 369 self.pasteAct = EricAction(
370 self.tr('Paste'), 370 self.tr('Paste'),
371 UI.PixmapCache.getIcon("editPaste"), 371 UI.PixmapCache.getIcon("editPaste"),
372 self.tr('&Paste'), 372 self.tr('&Paste'),
373 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")), 373 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")),
374 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")), 374 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")),
379 """<p>Paste the clipboard contents.</p>""" 379 """<p>Paste the clipboard contents.</p>"""
380 )) 380 ))
381 self.pasteAct.triggered.connect(self.__editor.paste) 381 self.pasteAct.triggered.connect(self.__editor.paste)
382 self.__actions.append(self.pasteAct) 382 self.__actions.append(self.pasteAct)
383 383
384 self.selectAllAct = E5Action( 384 self.selectAllAct = EricAction(
385 self.tr('Select All'), 385 self.tr('Select All'),
386 UI.PixmapCache.getIcon("editSelectAll"), 386 UI.PixmapCache.getIcon("editSelectAll"),
387 self.tr('&Select All'), 387 self.tr('&Select All'),
388 QKeySequence(self.tr("Ctrl+A", "Edit|Select All")), 388 QKeySequence(self.tr("Ctrl+A", "Edit|Select All")),
389 0, 389 0,
395 """<p>Selects the complete binary data.</p>""" 395 """<p>Selects the complete binary data.</p>"""
396 )) 396 ))
397 self.selectAllAct.triggered.connect(self.__editor.selectAll) 397 self.selectAllAct.triggered.connect(self.__editor.selectAll)
398 self.__actions.append(self.selectAllAct) 398 self.__actions.append(self.selectAllAct)
399 399
400 self.deselectAllAct = E5Action( 400 self.deselectAllAct = EricAction(
401 self.tr('Deselect all'), 401 self.tr('Deselect all'),
402 self.tr('&Deselect all'), 402 self.tr('&Deselect all'),
403 QKeySequence(self.tr("Alt+Ctrl+A", "Edit|Deselect all")), 403 QKeySequence(self.tr("Alt+Ctrl+A", "Edit|Deselect all")),
404 0, 404 0,
405 self, 'hexEditor_edit_deselect_all') 405 self, 'hexEditor_edit_deselect_all')
409 """<p>Deselect all all binary data.</p>""" 409 """<p>Deselect all all binary data.</p>"""
410 )) 410 ))
411 self.deselectAllAct.triggered.connect(self.__editor.deselectAll) 411 self.deselectAllAct.triggered.connect(self.__editor.deselectAll)
412 self.__actions.append(self.deselectAllAct) 412 self.__actions.append(self.deselectAllAct)
413 413
414 self.saveSelectionReadableAct = E5Action( 414 self.saveSelectionReadableAct = EricAction(
415 self.tr('Save Selection Readable'), 415 self.tr('Save Selection Readable'),
416 self.tr('Save Selection Readable...'), 416 self.tr('Save Selection Readable...'),
417 0, 0, self, 'hexEditor_edit_selection_save_readable') 417 0, 0, self, 'hexEditor_edit_selection_save_readable')
418 self.saveSelectionReadableAct.setStatusTip( 418 self.saveSelectionReadableAct.setStatusTip(
419 self.tr('Save the binary data of the current selection to a file' 419 self.tr('Save the binary data of the current selection to a file'
425 )) 425 ))
426 self.saveSelectionReadableAct.triggered.connect( 426 self.saveSelectionReadableAct.triggered.connect(
427 self.__saveSelectionReadable) 427 self.__saveSelectionReadable)
428 self.__actions.append(self.saveSelectionReadableAct) 428 self.__actions.append(self.saveSelectionReadableAct)
429 429
430 self.readonlyAct = E5Action( 430 self.readonlyAct = EricAction(
431 self.tr('Set Read Only'), 431 self.tr('Set Read Only'),
432 self.tr('Set Read Only'), 432 self.tr('Set Read Only'),
433 0, 0, self, 'hexEditor_edit_readonly', True) 433 0, 0, self, 'hexEditor_edit_readonly', True)
434 self.readonlyAct.setStatusTip(self.tr( 434 self.readonlyAct.setStatusTip(self.tr(
435 'Change the edit mode to read only')) 435 'Change the edit mode to read only'))
441 self.readonlyAct.setChecked(False) 441 self.readonlyAct.setChecked(False)
442 self.readonlyAct.toggled[bool].connect(self.__editor.setReadOnly) 442 self.readonlyAct.toggled[bool].connect(self.__editor.setReadOnly)
443 self.__editor.readOnlyChanged.connect(self.readonlyAct.setChecked) 443 self.__editor.readOnlyChanged.connect(self.readonlyAct.setChecked)
444 self.__actions.append(self.readonlyAct) 444 self.__actions.append(self.readonlyAct)
445 445
446 self.searchAct = E5Action( 446 self.searchAct = EricAction(
447 self.tr('Search'), 447 self.tr('Search'),
448 UI.PixmapCache.getIcon("find"), 448 UI.PixmapCache.getIcon("find"),
449 self.tr('&Search...'), 449 self.tr('&Search...'),
450 QKeySequence(self.tr("Ctrl+F", "Search|Search")), 450 QKeySequence(self.tr("Ctrl+F", "Search|Search")),
451 0, 451 0,
457 """ data to search for in various formats.</p>""" 457 """ data to search for in various formats.</p>"""
458 )) 458 ))
459 self.searchAct.triggered.connect(self.__search) 459 self.searchAct.triggered.connect(self.__search)
460 self.__actions.append(self.searchAct) 460 self.__actions.append(self.searchAct)
461 461
462 self.searchNextAct = E5Action( 462 self.searchNextAct = EricAction(
463 self.tr('Search next'), 463 self.tr('Search next'),
464 UI.PixmapCache.getIcon("findNext"), 464 UI.PixmapCache.getIcon("findNext"),
465 self.tr('Search &next'), 465 self.tr('Search &next'),
466 QKeySequence(self.tr("F3", "Search|Search next")), 466 QKeySequence(self.tr("F3", "Search|Search next")),
467 0, 467 0,
474 """ entered search data are reused.</p>""" 474 """ entered search data are reused.</p>"""
475 )) 475 ))
476 self.searchNextAct.triggered.connect(self.__searchWidget.findPrevNext) 476 self.searchNextAct.triggered.connect(self.__searchWidget.findPrevNext)
477 self.__actions.append(self.searchNextAct) 477 self.__actions.append(self.searchNextAct)
478 478
479 self.searchPrevAct = E5Action( 479 self.searchPrevAct = EricAction(
480 self.tr('Search previous'), 480 self.tr('Search previous'),
481 UI.PixmapCache.getIcon("findPrev"), 481 UI.PixmapCache.getIcon("findPrev"),
482 self.tr('Search &previous'), 482 self.tr('Search &previous'),
483 QKeySequence(self.tr("Shift+F3", "Search|Search previous")), 483 QKeySequence(self.tr("Shift+F3", "Search|Search previous")),
484 0, 484 0,
492 )) 492 ))
493 self.searchPrevAct.triggered.connect( 493 self.searchPrevAct.triggered.connect(
494 lambda: self.__searchWidget.findPrevNext(True)) 494 lambda: self.__searchWidget.findPrevNext(True))
495 self.__actions.append(self.searchPrevAct) 495 self.__actions.append(self.searchPrevAct)
496 496
497 self.replaceAct = E5Action( 497 self.replaceAct = EricAction(
498 self.tr('Replace'), 498 self.tr('Replace'),
499 self.tr('&Replace...'), 499 self.tr('&Replace...'),
500 QKeySequence(self.tr("Ctrl+R", "Search|Replace")), 500 QKeySequence(self.tr("Ctrl+R", "Search|Replace")),
501 0, 501 0,
502 self, 'hexEditor_edit_search_replace') 502 self, 'hexEditor_edit_search_replace')
508 """ replacement data in various formats.</p>""" 508 """ replacement data in various formats.</p>"""
509 )) 509 ))
510 self.replaceAct.triggered.connect(self.__replace) 510 self.replaceAct.triggered.connect(self.__replace)
511 self.__actions.append(self.replaceAct) 511 self.__actions.append(self.replaceAct)
512 512
513 self.gotoAct = E5Action( 513 self.gotoAct = EricAction(
514 self.tr('Goto Offset'), 514 self.tr('Goto Offset'),
515 UI.PixmapCache.getIcon("goto"), 515 UI.PixmapCache.getIcon("goto"),
516 self.tr('&Goto Offset...'), 516 self.tr('&Goto Offset...'),
517 QKeySequence(QCoreApplication.translate( 517 QKeySequence(QCoreApplication.translate(
518 'ViewManager', "Ctrl+G", "Search|Goto Offset")), 518 'ViewManager', "Ctrl+G", "Search|Goto Offset")),
546 546
547 def __initHelpActions(self): 547 def __initHelpActions(self):
548 """ 548 """
549 Private method to create the Help actions. 549 Private method to create the Help actions.
550 """ 550 """
551 self.aboutAct = E5Action( 551 self.aboutAct = EricAction(
552 self.tr('About'), 552 self.tr('About'),
553 self.tr('&About'), 553 self.tr('&About'),
554 0, 0, self, 'hexEditor_help_about') 554 0, 0, self, 'hexEditor_help_about')
555 self.aboutAct.setStatusTip(self.tr( 555 self.aboutAct.setStatusTip(self.tr(
556 'Display information about this software')) 556 'Display information about this software'))
558 """<b>About</b>""" 558 """<b>About</b>"""
559 """<p>Display some information about this software.</p>""")) 559 """<p>Display some information about this software.</p>"""))
560 self.aboutAct.triggered.connect(self.__about) 560 self.aboutAct.triggered.connect(self.__about)
561 self.__actions.append(self.aboutAct) 561 self.__actions.append(self.aboutAct)
562 562
563 self.aboutQtAct = E5Action( 563 self.aboutQtAct = EricAction(
564 self.tr('About Qt'), 564 self.tr('About Qt'),
565 self.tr('About &Qt'), 565 self.tr('About &Qt'),
566 0, 0, self, 'hexEditor_help_about_qt') 566 0, 0, self, 'hexEditor_help_about_qt')
567 self.aboutQtAct.setStatusTip( 567 self.aboutQtAct.setStatusTip(
568 self.tr('Display information about the Qt toolkit')) 568 self.tr('Display information about the Qt toolkit'))
571 """<p>Display some information about the Qt toolkit.</p>""" 571 """<p>Display some information about the Qt toolkit.</p>"""
572 )) 572 ))
573 self.aboutQtAct.triggered.connect(self.__aboutQt) 573 self.aboutQtAct.triggered.connect(self.__aboutQt)
574 self.__actions.append(self.aboutQtAct) 574 self.__actions.append(self.aboutQtAct)
575 575
576 self.whatsThisAct = E5Action( 576 self.whatsThisAct = EricAction(
577 self.tr('What\'s This?'), 577 self.tr('What\'s This?'),
578 UI.PixmapCache.getIcon("whatsThis"), 578 UI.PixmapCache.getIcon("whatsThis"),
579 self.tr('&What\'s This?'), 579 self.tr('&What\'s This?'),
580 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")), 580 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")),
581 0, self, 'hexEditor_help_whats_this') 581 0, self, 'hexEditor_help_whats_this')
593 593
594 def __initConfigActions(self): 594 def __initConfigActions(self):
595 """ 595 """
596 Private method to create the Settings actions. 596 Private method to create the Settings actions.
597 """ 597 """
598 self.prefAct = E5Action( 598 self.prefAct = EricAction(
599 self.tr('Preferences'), 599 self.tr('Preferences'),
600 UI.PixmapCache.getIcon("configure"), 600 UI.PixmapCache.getIcon("configure"),
601 self.tr('&Preferences...'), 601 self.tr('&Preferences...'),
602 0, 0, self, 'hexEditor_settings_preferences') 602 0, 0, self, 'hexEditor_settings_preferences')
603 self.prefAct.setStatusTip(self.tr( 603 self.prefAct.setStatusTip(self.tr(
795 """ binary data.</p>""" 795 """ binary data.</p>"""
796 )) 796 ))
797 self.__sbSize.setFrameStyle( 797 self.__sbSize.setFrameStyle(
798 QFrame.Shape.StyledPanel | QFrame.Shadow.Plain) 798 QFrame.Shape.StyledPanel | QFrame.Shadow.Plain)
799 799
800 self.__sbEditMode = E5ClickableLabel(self.__statusBar) 800 self.__sbEditMode = EricClickableLabel(self.__statusBar)
801 self.__statusBar.addPermanentWidget(self.__sbEditMode) 801 self.__statusBar.addPermanentWidget(self.__sbEditMode)
802 self.__sbEditMode.setWhatsThis(self.tr( 802 self.__sbEditMode.setWhatsThis(self.tr(
803 """<p>This part of the status bar displays the edit mode.</p>""" 803 """<p>This part of the status bar displays the edit mode.</p>"""
804 )) 804 ))
805 self.__sbEditMode.setFrameStyle( 805 self.__sbEditMode.setFrameStyle(
806 QFrame.Shape.StyledPanel | QFrame.Shadow.Plain) 806 QFrame.Shape.StyledPanel | QFrame.Shadow.Plain)
807 self.__sbEditMode.clicked.connect(self.__toggleEditMode) 807 self.__sbEditMode.clicked.connect(self.__toggleEditMode)
808 808
809 self.__sbReadOnly = E5ClickableLabel(self.__statusBar) 809 self.__sbReadOnly = EricClickableLabel(self.__statusBar)
810 self.__statusBar.addPermanentWidget(self.__sbReadOnly) 810 self.__statusBar.addPermanentWidget(self.__sbReadOnly)
811 self.__sbReadOnly.setWhatsThis(self.tr( 811 self.__sbReadOnly.setWhatsThis(self.tr(
812 """<p>This part of the status bar displays the read""" 812 """<p>This part of the status bar displays the read"""
813 """ only mode.</p>""" 813 """ only mode.</p>"""
814 )) 814 ))
944 self.__project is not None and 944 self.__project is not None and
945 self.__project.isOpen() 945 self.__project.isOpen()
946 ): 946 ):
947 self.__lastOpenPath = self.__project.getProjectPath() 947 self.__lastOpenPath = self.__project.getProjectPath()
948 948
949 fileName = E5FileDialog.getOpenFileName( 949 fileName = EricFileDialog.getOpenFileName(
950 self, 950 self,
951 self.tr("Open binary file in new window"), 951 self.tr("Open binary file in new window"),
952 self.__lastOpenPath, 952 self.__lastOpenPath,
953 self.tr("All Files (*)")) 953 self.tr("All Files (*)"))
954 if fileName: 954 if fileName:
965 965
966 @return flag indicating, if it is ok to continue 966 @return flag indicating, if it is ok to continue
967 @rtype bool 967 @rtype bool
968 """ 968 """
969 if self.__editor.isModified(): 969 if self.__editor.isModified():
970 ret = E5MessageBox.okToClearData( 970 ret = EricMessageBox.okToClearData(
971 self, 971 self,
972 self.tr("eric Hex Editor"), 972 self.tr("eric Hex Editor"),
973 self.tr("""The loaded file has unsaved changes."""), 973 self.tr("""The loaded file has unsaved changes."""),
974 self.__saveHexFile) 974 self.__saveHexFile)
975 if not ret: 975 if not ret:
983 @param fileName name of the binary file to load 983 @param fileName name of the binary file to load
984 @type str 984 @type str
985 """ 985 """
986 file = QFile(fileName) 986 file = QFile(fileName)
987 if not file.exists(): 987 if not file.exists():
988 E5MessageBox.warning( 988 EricMessageBox.warning(
989 self, self.tr("eric Hex Editor"), 989 self, self.tr("eric Hex Editor"),
990 self.tr("The file '{0}' does not exist.") 990 self.tr("The file '{0}' does not exist.")
991 .format(fileName)) 991 .format(fileName))
992 return 992 return
993 993
994 if not file.open(QFile.ReadOnly): 994 if not file.open(QFile.ReadOnly):
995 E5MessageBox.warning( 995 EricMessageBox.warning(
996 self, self.tr("eric Hex Editor"), 996 self, self.tr("eric Hex Editor"),
997 self.tr("Cannot read file '{0}:\n{1}.") 997 self.tr("Cannot read file '{0}:\n{1}.")
998 .format(fileName, file.errorString())) 998 .format(fileName, file.errorString()))
999 return 999 return
1000 1000
1019 self.__project is not None and 1019 self.__project is not None and
1020 self.__project.isOpen() 1020 self.__project.isOpen()
1021 ): 1021 ):
1022 self.__lastOpenPath = self.__project.getProjectPath() 1022 self.__lastOpenPath = self.__project.getProjectPath()
1023 1023
1024 fileName = E5FileDialog.getOpenFileName( 1024 fileName = EricFileDialog.getOpenFileName(
1025 self, 1025 self,
1026 self.tr("Open binary file"), 1026 self.tr("Open binary file"),
1027 self.__lastOpenPath, 1027 self.__lastOpenPath,
1028 self.tr("All Files (*)")) 1028 self.tr("All Files (*)"))
1029 if fileName: 1029 if fileName:
1070 ): 1070 ):
1071 self.__lastSavePath = self.__project.getProjectPath() 1071 self.__lastSavePath = self.__project.getProjectPath()
1072 if not self.__lastSavePath and self.__lastOpenPath: 1072 if not self.__lastSavePath and self.__lastOpenPath:
1073 self.__lastSavePath = self.__lastOpenPath 1073 self.__lastSavePath = self.__lastOpenPath
1074 1074
1075 fileName = E5FileDialog.getSaveFileName( 1075 fileName = EricFileDialog.getSaveFileName(
1076 self, 1076 self,
1077 self.tr("Save binary file"), 1077 self.tr("Save binary file"),
1078 self.__lastSavePath, 1078 self.__lastSavePath,
1079 self.tr("All Files (*)"), 1079 self.tr("All Files (*)"),
1080 E5FileDialog.DontConfirmOverwrite) 1080 EricFileDialog.DontConfirmOverwrite)
1081 if not fileName: 1081 if not fileName:
1082 return False 1082 return False
1083 1083
1084 if QFileInfo(fileName).exists(): 1084 if QFileInfo(fileName).exists():
1085 res = E5MessageBox.yesNo( 1085 res = EricMessageBox.yesNo(
1086 self, 1086 self,
1087 self.tr("Save binary file"), 1087 self.tr("Save binary file"),
1088 self.tr("<p>The file <b>{0}</b> already exists." 1088 self.tr("<p>The file <b>{0}</b> already exists."
1089 " Overwrite it?</p>").format(fileName), 1089 " Overwrite it?</p>").format(fileName),
1090 icon=E5MessageBox.Warning) 1090 icon=EricMessageBox.Warning)
1091 if not res: 1091 if not res:
1092 return False 1092 return False
1093 1093
1094 self.__lastSavePath = os.path.dirname(fileName) 1094 self.__lastSavePath = os.path.dirname(fileName)
1095 1095
1104 @return flag indicating success 1104 @return flag indicating success
1105 @rtype bool 1105 @rtype bool
1106 """ 1106 """
1107 file = QFile(fileName) 1107 file = QFile(fileName)
1108 if not file.open(QFile.WriteOnly): 1108 if not file.open(QFile.WriteOnly):
1109 E5MessageBox.warning( 1109 EricMessageBox.warning(
1110 self, self.tr("eric Hex Editor"), 1110 self, self.tr("eric Hex Editor"),
1111 self.tr("Cannot write file '{0}:\n{1}.") 1111 self.tr("Cannot write file '{0}:\n{1}.")
1112 .format(fileName, file.errorString())) 1112 .format(fileName, file.errorString()))
1113 1113
1114 self.__checkActions() 1114 self.__checkActions()
1117 1117
1118 res = file.write(self.__editor.data()) != -1 1118 res = file.write(self.__editor.data()) != -1
1119 file.close() 1119 file.close()
1120 1120
1121 if not res: 1121 if not res:
1122 E5MessageBox.warning( 1122 EricMessageBox.warning(
1123 self, self.tr("eric Hex Editor"), 1123 self, self.tr("eric Hex Editor"),
1124 self.tr("Cannot write file '{0}:\n{1}.") 1124 self.tr("Cannot write file '{0}:\n{1}.")
1125 .format(fileName, file.errorString())) 1125 .format(fileName, file.errorString()))
1126 1126
1127 self.__checkActions() 1127 self.__checkActions()
1152 ): 1152 ):
1153 savePath = self.__project.getProjectPath() 1153 savePath = self.__project.getProjectPath()
1154 if not savePath and self.__lastOpenPath: 1154 if not savePath and self.__lastOpenPath:
1155 savePath = self.__lastOpenPath 1155 savePath = self.__lastOpenPath
1156 1156
1157 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 1157 fileName, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
1158 self, 1158 self,
1159 self.tr("Save to readable file"), 1159 self.tr("Save to readable file"),
1160 savePath, 1160 savePath,
1161 self.tr("Text Files (*.txt);;All Files (*)"), 1161 self.tr("Text Files (*.txt);;All Files (*)"),
1162 self.tr("Text Files (*.txt)"), 1162 self.tr("Text Files (*.txt)"),
1163 E5FileDialog.DontConfirmOverwrite) 1163 EricFileDialog.DontConfirmOverwrite)
1164 if not fileName: 1164 if not fileName:
1165 return 1165 return
1166 1166
1167 ext = QFileInfo(fileName).suffix() 1167 ext = QFileInfo(fileName).suffix()
1168 if not ext: 1168 if not ext:
1169 ex = selectedFilter.split("(*")[1].split(")")[0] 1169 ex = selectedFilter.split("(*")[1].split(")")[0]
1170 if ex: 1170 if ex:
1171 fileName += ex 1171 fileName += ex
1172 if QFileInfo(fileName).exists(): 1172 if QFileInfo(fileName).exists():
1173 res = E5MessageBox.yesNo( 1173 res = EricMessageBox.yesNo(
1174 self, 1174 self,
1175 self.tr("Save to readable file"), 1175 self.tr("Save to readable file"),
1176 self.tr("<p>The file <b>{0}</b> already exists." 1176 self.tr("<p>The file <b>{0}</b> already exists."
1177 " Overwrite it?</p>").format(fileName), 1177 " Overwrite it?</p>").format(fileName),
1178 icon=E5MessageBox.Warning) 1178 icon=EricMessageBox.Warning)
1179 if not res: 1179 if not res:
1180 return 1180 return
1181 1181
1182 file = QFile(fileName) 1182 file = QFile(fileName)
1183 if not file.open(QFile.WriteOnly): 1183 if not file.open(QFile.WriteOnly):
1184 E5MessageBox.warning( 1184 EricMessageBox.warning(
1185 self, self.tr("eric Hex Editor"), 1185 self, self.tr("eric Hex Editor"),
1186 self.tr("Cannot write file '{0}:\n{1}.") 1186 self.tr("Cannot write file '{0}:\n{1}.")
1187 .format(fileName, file.errorString())) 1187 .format(fileName, file.errorString()))
1188 return 1188 return
1189 1189
1194 ) 1194 )
1195 res = file.write(readableData.encode("latin1")) != -1 1195 res = file.write(readableData.encode("latin1")) != -1
1196 file.close() 1196 file.close()
1197 1197
1198 if not res: 1198 if not res:
1199 E5MessageBox.warning( 1199 EricMessageBox.warning(
1200 self, self.tr("eric Hex Editor"), 1200 self, self.tr("eric Hex Editor"),
1201 self.tr("Cannot write file '{0}:\n{1}.") 1201 self.tr("Cannot write file '{0}:\n{1}.")
1202 .format(fileName, file.errorString())) 1202 .format(fileName, file.errorString()))
1203 return 1203 return
1204 1204
1298 1298
1299 def __about(self): 1299 def __about(self):
1300 """ 1300 """
1301 Private slot to show a little About message. 1301 Private slot to show a little About message.
1302 """ 1302 """
1303 E5MessageBox.about( 1303 EricMessageBox.about(
1304 self, self.tr("About eric Hex Editor"), 1304 self, self.tr("About eric Hex Editor"),
1305 self.tr("The eric Hex Editor is a simple editor component" 1305 self.tr("The eric Hex Editor is a simple editor component"
1306 " to edit binary files.")) 1306 " to edit binary files."))
1307 1307
1308 def __aboutQt(self): 1308 def __aboutQt(self):
1309 """ 1309 """
1310 Private slot to handle the About Qt dialog. 1310 Private slot to handle the About Qt dialog.
1311 """ 1311 """
1312 E5MessageBox.aboutQt(self, "eric Hex Editor") 1312 EricMessageBox.aboutQt(self, "eric Hex Editor")
1313 1313
1314 def __whatsThis(self): 1314 def __whatsThis(self):
1315 """ 1315 """
1316 Private slot called in to enter Whats This mode. 1316 Private slot called in to enter Whats This mode.
1317 """ 1317 """

eric ide

mercurial