src/eric7/HexEdit/HexEditSearchReplaceWidget.py

Tue, 18 Oct 2022 16:06:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 18 Oct 2022 16:06:21 +0200
branch
eric7
changeset 9413
80c06d472826
parent 9221
bf71ee032bb4
child 9473
3f23dbf37dbe
permissions
-rw-r--r--

Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.

4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
3 # Copyright (c) 2016 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a search and replace widget for the hex editor.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
10 from PyQt6.QtCore import pyqtSlot, Qt, QByteArray, QRegularExpression
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
11 from PyQt6.QtGui import QRegularExpressionValidator
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
12 from PyQt6.QtWidgets import QWidget
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
14 from eric7.EricGui.EricAction import EricAction
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
15 from eric7.EricWidgets import EricMessageBox
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
17 from eric7.EricGui import EricPixmapCache
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class HexEditSearchReplaceWidget(QWidget):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing a search and replace widget for the hex editor.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
24
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
25 def __init__(self, editor, mainWindow, replace=False, parent=None):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
28
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param editor reference to the hex editor widget
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @type HexEditWidget
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
31 @param mainWindow reference to the main window
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
32 @type HexEditMainWindow
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param replace flag indicating a replace widget
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type bool
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param parent reference to the parent widget
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @type QWidget
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
38 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__replace = replace
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__editor = editor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
43 # keep this in sync with the logic in __getContent()
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
44 self.__formatAndValidators = {
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45 "hex": (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46 self.tr("Hex"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47 QRegularExpressionValidator(QRegularExpression("[0-9a-f]*")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 "dec": (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50 self.tr("Dec"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51 QRegularExpressionValidator(QRegularExpression("[0-9]*")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 "oct": (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54 self.tr("Oct"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55 QRegularExpressionValidator(QRegularExpression("[0-7]*")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56 ),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 "bin": (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 self.tr("Bin"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 QRegularExpressionValidator(QRegularExpression("[01]*")),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60 ),
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
61 "iso-8859-1": (self.tr("Text"), None),
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
62 # text as latin-1/iso-8859-1
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
63 "utf-8": (self.tr("UTF-8"), None),
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
64 # text as utf-8
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
65 }
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
66 formatOrder = ["hex", "dec", "oct", "bin", "iso-8859-1", "utf-8"]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
68 self.__currentFindFormat = ""
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
69 self.__currentReplaceFormat = ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
71 self.__findHistory = mainWindow.getSRHistory("search")
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 from .Ui_HexEditReplaceWidget import Ui_HexEditReplaceWidget
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
75 self.__replaceHistory = mainWindow.getSRHistory("replace")
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__ui = Ui_HexEditReplaceWidget()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 else:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 from .Ui_HexEditSearchWidget import Ui_HexEditSearchWidget
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__ui = Ui_HexEditSearchWidget()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__ui.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
83 self.__ui.closeButton.setIcon(EricPixmapCache.getIcon("close"))
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
84 self.__ui.findPrevButton.setIcon(EricPixmapCache.getIcon("1leftarrow"))
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
85 self.__ui.findNextButton.setIcon(EricPixmapCache.getIcon("1rightarrow"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if replace:
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
88 self.__ui.replaceButton.setIcon(EricPixmapCache.getIcon("editReplace"))
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__ui.replaceSearchButton.setIcon(
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
90 EricPixmapCache.getIcon("editReplaceSearch")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 )
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
92 self.__ui.replaceAllButton.setIcon(
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
93 EricPixmapCache.getIcon("editReplaceAll")
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
94 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
95
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
96 for dataFormat in formatOrder:
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
97 formatStr, validator = self.__formatAndValidators[dataFormat]
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
98 self.__ui.findFormatCombo.addItem(formatStr, dataFormat)
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
99 if replace:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
100 for dataFormat in formatOrder:
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
101 formatStr, validator = self.__formatAndValidators[dataFormat]
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
102 self.__ui.replaceFormatCombo.addItem(formatStr, dataFormat)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.__ui.findtextCombo.setCompleter(None)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.__ui.findtextCombo.lineEdit().returnPressed.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106 self.__findByReturnPressed
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
107 )
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__ui.replacetextCombo.setCompleter(None)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__ui.replacetextCombo.lineEdit().returnPressed.connect(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
111 self.on_replaceButton_clicked
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
112 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
114 self.findNextAct = EricAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115 self.tr("Find Next"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116 self.tr("Find Next"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117 0,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
118 0,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120 "hexEditor_search_widget_find_next",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121 )
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.findNextAct.triggered.connect(self.on_findNextButton_clicked)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.findNextAct.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__ui.findtextCombo.addAction(self.findNextAct)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
126 self.findPrevAct = EricAction(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127 self.tr("Find Prev"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128 self.tr("Find Prev"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
129 0,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130 0,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132 "hexEditor_search_widget_find_prev",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 )
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.findPrevAct.triggered.connect(self.on_findPrevButton_clicked)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.findPrevAct.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.__ui.findtextCombo.addAction(self.findPrevAct)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.__havefound = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
139
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
140 @pyqtSlot(int)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
141 def on_findFormatCombo_currentIndexChanged(self, idx):
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
142 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
143 Private slot to handle a selection from the find format.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
145 @param idx index of the selected entry
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
146 @type int
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
147 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
148 if idx >= 0:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
149 findFormat = self.__ui.findFormatCombo.itemData(idx)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
151 if findFormat != self.__currentFindFormat:
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
152 txt = self.__ui.findtextCombo.currentText()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
153 newTxt = self.__convertText(txt, self.__currentFindFormat, findFormat)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
154 self.__currentFindFormat = findFormat
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
155
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
156 self.__ui.findtextCombo.setValidator(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
157 self.__formatAndValidators[findFormat][1]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
159
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
160 self.__ui.findtextCombo.setEditText(newTxt)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
161
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
162 @pyqtSlot(str)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 def on_findtextCombo_editTextChanged(self, txt):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 Private slot to enable/disable the find buttons.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
166
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
167 @param txt text of the find text combo
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
168 @type str
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 if not txt:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.__ui.findNextButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.findNextAct.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.__ui.findPrevButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.findPrevAct.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 if self.__replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.__ui.replaceButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.__ui.replaceSearchButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self.__ui.replaceAllButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 else:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 self.__ui.findNextButton.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.findNextAct.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 self.__ui.findPrevButton.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.findPrevAct.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 if self.__replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.__ui.replaceButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 self.__ui.replaceSearchButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.__ui.replaceAllButton.setEnabled(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
188
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
189 @pyqtSlot(int)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
190 def on_findtextCombo_activated(self, idx):
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
191 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
192 Private slot to handle a selection from the find history.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
194 @param idx index of the selected entry
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
195 @type int
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
196 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
197 if idx >= 0:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
198 formatIndex = self.__ui.findtextCombo.itemData(idx)
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
199 if formatIndex is not None:
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
200 self.__ui.findFormatCombo.setCurrentIndex(formatIndex)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
201
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 def __getContent(self, replace=False):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 Private method to get the contents of the find/replace combo as
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 a bytearray.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 @param replace flag indicating to retrieve the replace contents
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 @type bool
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @return search or replace term as text and binary data
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 @rtype tuple of bytearray and str
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 if replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 textCombo = self.__ui.replacetextCombo
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 formatCombo = self.__ui.replaceFormatCombo
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 history = self.__replaceHistory
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 else:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 textCombo = self.__ui.findtextCombo
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 formatCombo = self.__ui.findFormatCombo
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 history = self.__findHistory
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 txt = textCombo.currentText()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 idx = formatCombo.currentIndex()
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
223 findFormat = formatCombo.itemData(idx)
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
224 ba = self.__text2bytearray(txt, findFormat)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 # This moves any previous occurrence of this statement to the head
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 # of the list and updates the combobox
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
228 historyEntry = (idx, txt)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
229 if historyEntry in history:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
230 history.remove(historyEntry)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
231 history.insert(0, historyEntry)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 textCombo.clear()
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
233 for index, text in history:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
234 textCombo.addItem(text, index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
235
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 return ba, txt
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
237
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 def on_findNextButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 Private slot to find the next occurrence.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 self.findPrevNext(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
244
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 def on_findPrevButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 Private slot to find the previous occurrence.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 self.findPrevNext(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 def findPrevNext(self, prev=False):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 Public slot to find the next occurrence of the search term.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
255
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 @param prev flag indicating a backwards search
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 @type bool
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 @return flag indicating a successful search
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @rtype bool
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 if not self.__havefound or not self.__ui.findtextCombo.currentText():
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 self.show()
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
263 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.__findBackwards = prev
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 ba, txt = self.__getContent()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 idx = -1
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 if len(ba) > 0:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 startIndex = self.__editor.cursorPosition() // 2
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 if prev:
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
272 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 self.__editor.hasSelection()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 and startIndex == self.__editor.getSelectionEnd()
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
275 ):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 # skip to the selection start
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 startIndex = self.__editor.getSelectionBegin()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 idx = self.__editor.lastIndexOf(ba, startIndex)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 else:
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
280 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281 self.__editor.hasSelection()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
282 and startIndex == self.__editor.getSelectionBegin() - 1
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
283 ):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 # skip to the selection end
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 startIndex = self.__editor.getSelectionEnd()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 idx = self.__editor.indexOf(ba, startIndex)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
287
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 if idx >= 0:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 if self.__replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.__ui.replaceButton.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self.__ui.replaceSearchButton.setEnabled(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
293 EricMessageBox.information(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294 self, self.windowTitle(), self.tr("'{0}' was not found.").format(txt)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
295 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
296
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 return idx >= 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 def __findByReturnPressed(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 Private slot to handle a return pressed in the find combo.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 if self.__findBackwards:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 self.findPrevNext(True)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 else:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.findPrevNext(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
308 @pyqtSlot(int)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
309 def on_replaceFormatCombo_currentIndexChanged(self, idx):
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
310 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
311 Private slot to handle a selection from the replace format.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
312
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
313 @param idx index of the selected entry
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
314 @type int
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
315 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
316 if idx >= 0:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
317 replaceFormat = self.__ui.replaceFormatCombo.itemData(idx)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
319 if replaceFormat != self.__currentReplaceFormat:
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
320 txt = self.__ui.replacetextCombo.currentText()
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
321 newTxt = self.__convertText(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
322 txt, self.__currentReplaceFormat, replaceFormat
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
323 )
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
324 self.__currentReplaceFormat = replaceFormat
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
326 self.__ui.replacetextCombo.setValidator(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
327 self.__formatAndValidators[replaceFormat][1]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
328 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
329
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
330 self.__ui.replacetextCombo.setEditText(newTxt)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
331
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
332 @pyqtSlot(int)
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
333 def on_replacetextCombo_activated(self, idx):
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
334 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
335 Private slot to handle a selection from the replace history.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
336
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
337 @param idx index of the selected entry
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
338 @type int
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
339 """
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
340 if idx >= 0:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
341 formatIndex = self.__ui.replacetextCombo.itemData(idx)
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
342 if formatIndex is not None:
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
343 self.__ui.replaceFormatCombo.setCurrentIndex(formatIndex)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 def on_replaceButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 Private slot to replace one occurrence of data.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 self.__doReplace(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 def on_replaceSearchButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 Private slot to replace one occurrence of data and search for the next
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 one.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 self.__doReplace(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 def __doReplace(self, searchNext):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 Private method to replace one occurrence of data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
363
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 @param searchNext flag indicating to search for the next occurrence
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
365 @type bool
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 # Check enabled status due to dual purpose usage of this method
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
368 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
369 not self.__ui.replaceButton.isEnabled()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
370 and not self.__ui.replaceSearchButton.isEnabled()
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
371 ):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373
4654
9dafe6905667 Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4653
diff changeset
374 fba, ftxt = self.__getContent(False)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 rba, rtxt = self.__getContent(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
376
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 ok = False
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 if self.__editor.hasSelection():
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 # we did a successful search before
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 startIdx = self.__editor.getSelectionBegin()
4654
9dafe6905667 Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4653
diff changeset
381 self.__editor.replaceByteArray(startIdx, len(fba), rba)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
382
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 if searchNext:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 ok = self.findPrevNext(self.__findBackwards)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
385
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 if not ok:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 self.__ui.replaceButton.setEnabled(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 self.__ui.replaceSearchButton.setEnabled(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 def on_replaceAllButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 Private slot to replace all occurrences of data.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 replacements = 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
396
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 cursorPosition = self.__editor.cursorPosition()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
398
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 fba, ftxt = self.__getContent(False)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 rba, rtxt = self.__getContent(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
401
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 idx = 0
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 while idx >= 0:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 idx = self.__editor.indexOf(fba, idx)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if idx >= 0:
4654
9dafe6905667 Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4653
diff changeset
406 self.__editor.replaceByteArray(idx, len(fba), rba)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 idx += len(rba)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 replacements += 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
409
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 if replacements:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
411 EricMessageBox.information(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
412 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
413 self.windowTitle(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
414 self.tr("Replaced {0} occurrences.").format(replacements),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
415 )
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 else:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
417 EricMessageBox.information(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
418 self,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
419 self.windowTitle(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
420 self.tr("Nothing replaced because '{0}' was not found.").format(ftxt),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
421 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
422
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 self.__editor.setCursorPosition(cursorPosition)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 self.__editor.ensureVisible()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
425
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
426 def __showFind(self, text=""):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 Private method to display this widget in find mode.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
429
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
430 @param text hex encoded text to be shown in the findtext edit
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
431 @type str
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 self.__replace = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
434
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 self.__ui.findtextCombo.clear()
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
436 for index, txt in self.__findHistory:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
437 self.__ui.findtextCombo.addItem(txt, index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
438 self.__ui.findFormatCombo.setCurrentIndex(0) # 0 is always Hex
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
439 self.on_findFormatCombo_currentIndexChanged(0)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 self.__ui.findtextCombo.setEditText(text)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 self.__ui.findtextCombo.lineEdit().selectAll()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 self.__ui.findtextCombo.setFocus()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 self.on_findtextCombo_editTextChanged(text)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
444
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 self.__havefound = True
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 self.__findBackwards = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
447
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
448 def __showReplace(self, text=""):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 Private slot to display this widget in replace mode.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
451
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
452 @param text hex encoded text to be shown in the findtext edit
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
453 @type str
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 self.__replace = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
456
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 self.__ui.findtextCombo.clear()
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
458 for index, txt in self.__findHistory:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
459 self.__ui.findtextCombo.addItem(txt, index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
460 self.__ui.findFormatCombo.setCurrentIndex(0) # 0 is always Hex
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
461 self.on_findFormatCombo_currentIndexChanged(0)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 self.__ui.findtextCombo.setEditText(text)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 self.__ui.findtextCombo.lineEdit().selectAll()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 self.__ui.findtextCombo.setFocus()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 self.on_findtextCombo_editTextChanged(text)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
466
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 self.__ui.replacetextCombo.clear()
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
468 for index, txt in self.__replaceHistory:
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
469 self.__ui.replacetextCombo.addItem(txt, index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
470 self.__ui.replaceFormatCombo.setCurrentIndex(0) # 0 is always Hex
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
471 self.on_replaceFormatCombo_currentIndexChanged(0)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
472 self.__ui.replacetextCombo.setEditText("")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
473
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 self.__havefound = True
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 self.__findBackwards = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
476
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
477 def show(self, text=""):
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 Public slot to show the widget.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
480
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
481 @param text hex encoded text to be shown in the findtext edit
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
482 @type str
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 if self.__replace:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 self.__showReplace(text)
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 else:
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 self.__showFind(text)
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
488 super().show()
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 self.activateWindow()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
490
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 @pyqtSlot()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 def on_closeButton_clicked(self):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 Private slot to close the widget.
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
496 self.__editor.setFocus(Qt.FocusReason.OtherFocusReason)
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 self.close()
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 def keyPressEvent(self, event):
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 """
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 Protected slot to handle key press events.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
502
4659
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
503 @param event reference to the key press event
2863d05e83c6 Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4656
diff changeset
504 @type QKeyEvent
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
506 if event.key() == Qt.Key.Key_Escape:
4652
a88a2ba7a48a Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
508
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
509 def __convertText(self, txt, oldFormat, newFormat):
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
510 """
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
511 Private method to convert text from one format into another.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
512
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
513 @param txt text to be converted
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
514 @type str
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
515 @param oldFormat current format of the text
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
516 @type str
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
517 @param newFormat format to convert to
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
518 @type str
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
519 @return converted text
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
520 @rtype str
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
521 """
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4662
diff changeset
522 if txt and oldFormat and newFormat and oldFormat != newFormat:
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
523 # step 1: convert the text to a byte array using the old format
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
524 byteArray = self.__text2bytearray(txt, oldFormat)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
525
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
526 # step 2: convert the byte array to text using the new format
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
527 txt = self.__bytearray2text(byteArray, newFormat)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
528
4660
9096e8a2df54 Added capability to search for a UTF-8 encoded text in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4659
diff changeset
529 return txt
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
530
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
531 def __int2bytearray(self, value):
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
532 """
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
533 Private method to convert an integer to a byte array.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
534
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
535 @param value value to be converted
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
536 @type int
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
537 @return byte array for the given value
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
538 @rtype bytearray
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
539 """
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
540 ba = bytearray()
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
541 while value > 0:
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
542 value, modulus = divmod(value, 256)
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
543 ba.insert(0, modulus)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
544
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
545 return ba
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
546
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
547 def __bytearray2int(self, array):
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
548 """
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
549 Private method to convert a byte array to an integer value.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
550
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
551 @param array byte array to be converted
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
552 @type bytearray
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
553 @return integer value of the given array
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
554 @rtype int
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
555 """
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
556 value = 0
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
557 for b in array:
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
558 value = value * 256 + b
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
559
4661
bf927c5576c6 Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4660
diff changeset
560 return value
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
561
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
562 def __text2bytearray(self, txt, dataFormat):
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
563 """
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
564 Private method to convert a text to a byte array.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
565
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
566 @param txt text to be converted
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
567 @type str
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
568 @param dataFormat format of the text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
569 @type str
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
570 @return converted text
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
571 @rtype bytearray
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
572 @exception ValueError raised to indicate an invalid dataFormat
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
573 parameter
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
574 """
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
575 if dataFormat not in self.__formatAndValidators.keys():
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
576 raise ValueError("Bad value for 'dataFormat' parameter.")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
577
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
578 if dataFormat == "hex": # hex format
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
579 ba = bytearray(QByteArray.fromHex(bytes(txt, encoding="ascii")))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
580 elif dataFormat == "dec": # decimal format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
581 ba = self.__int2bytearray(int(txt, 10))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
582 elif dataFormat == "oct": # octal format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
583 ba = self.__int2bytearray(int(txt, 8))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
584 elif dataFormat == "bin": # binary format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
585 ba = self.__int2bytearray(int(txt, 2))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
586 elif dataFormat == "iso-8859-1": # latin-1/iso-8859-1 text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
587 ba = bytearray(txt, encoding="iso-8859-1")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
588 elif dataFormat == "utf-8": # utf-8 text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
589 ba = bytearray(txt, encoding="utf-8")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
590
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
591 return ba
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
592
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
593 def __bytearray2text(self, array, dataFormat):
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
594 """
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
595 Private method to convert a byte array to a text.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
596
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
597 @param array byte array to be converted
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
598 @type bytearray
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
599 @param dataFormat format of the text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
600 @type str
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
601 @return formatted text
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
602 @rtype str
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
603 @exception ValueError raised to indicate an invalid dataFormat
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
604 parameter
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
605 """
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
606 if dataFormat not in self.__formatAndValidators.keys():
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
607 raise ValueError("Bad value for 'dataFormat' parameter.")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
608
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
609 if dataFormat == "hex": # hex format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
610 txt = "{0:x}".format(self.__bytearray2int(array))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
611 elif dataFormat == "dec": # decimal format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
612 txt = "{0:d}".format(self.__bytearray2int(array))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
613 elif dataFormat == "oct": # octal format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
614 txt = "{0:o}".format(self.__bytearray2int(array))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
615 elif dataFormat == "bin": # binary format
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
616 txt = "{0:b}".format(self.__bytearray2int(array))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
617 elif dataFormat == "iso-8859-1": # latin-1/iso-8859-1 text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
618 txt = str(array, encoding="iso-8859-1")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
619 elif dataFormat == "utf-8": # utf-8 text
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
620 txt = str(array, encoding="utf-8", errors="replace")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
621
4662
33e6bd4b1721 Added function to change the search/replace text according to the selected format in the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4661
diff changeset
622 return txt

eric ide

mercurial