Sat, 26 Apr 2025 12:34:32 +0200
MicroPython
- Added a configuration option to disable the support for the no longer produced Pimoroni Pico Wireless Pack.
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 | |
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10690
diff
changeset
|
3 | # Copyright (c) 2016 - 2025 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 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
10 | from PyQt6.QtCore import QByteArray, QRegularExpression, Qt, pyqtSlot |
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
|
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 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9413
diff
changeset
|
14 | from eric7.EricGui import EricPixmapCache |
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
|
15 | 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
|
16 | 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
|
17 | |
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 | class HexEditSearchReplaceWidget(QWidget): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | 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
|
22 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
23 | |
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
|
24 | 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
|
25 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
27 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | @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
|
29 | @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
|
30 | @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
|
31 | @type HexEditMainWindow |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | @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
|
33 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | @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
|
35 | @type QWidget |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | """ |
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
|
37 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.__replace = replace |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | self.__editor = editor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | |
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
|
42 | # 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
|
43 | self.__formatAndValidators = { |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | "hex": ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | self.tr("Hex"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | QRegularExpressionValidator(QRegularExpression("[0-9a-f]*")), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | "dec": ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | self.tr("Dec"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | QRegularExpressionValidator(QRegularExpression("[0-9]*")), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
51 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | "oct": ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
53 | self.tr("Oct"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
54 | QRegularExpressionValidator(QRegularExpression("[0-7]*")), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | ), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
56 | "bin": ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
57 | self.tr("Bin"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
58 | QRegularExpressionValidator(QRegularExpression("[01]*")), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
59 | ), |
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
|
60 | "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
|
61 | # 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
|
62 | "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
|
63 | # 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
|
64 | } |
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
|
65 | 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
|
66 | |
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
|
67 | 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
|
68 | self.__currentReplaceFormat = "" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | |
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
|
70 | 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
|
71 | if replace: |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
72 | from .Ui_HexEditReplaceWidget import ( # __IGNORE_WARNING_I-101__ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
73 | Ui_HexEditReplaceWidget, |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
74 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | |
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
|
76 | 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
|
77 | self.__ui = Ui_HexEditReplaceWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | else: |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
79 | from .Ui_HexEditSearchWidget import ( # __IGNORE_WARNING_I-101__ |
9482
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
80 | Ui_HexEditSearchWidget, |
a2bc06a54d9d
Corrected/acknowledged some bad import style and removed some obsolete code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9473
diff
changeset
|
81 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | self.__ui = Ui_HexEditSearchWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | self.__ui.setupUi(self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
85 | |
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
|
86 | 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
|
87 | 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
|
88 | 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
|
89 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | 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
|
91 | 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
|
92 | 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
|
93 | EricPixmapCache.getIcon("editReplaceSearch") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | ) |
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
|
95 | 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
|
96 | 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
|
97 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
98 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
99 | for dataFormat in formatOrder: |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
100 | formatStr, _validator = self.__formatAndValidators[dataFormat] |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
101 | 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
|
102 | 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
|
103 | for dataFormat in formatOrder: |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
104 | formatStr, _validator = self.__formatAndValidators[dataFormat] |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
105 | 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
|
106 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | self.__ui.findtextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | 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
|
109 | self.__findByReturnPressed |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
110 | ) |
10190
dbe6394786ea
Little improvement to the various search (and replace) widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
111 | self.__ui.findtextCombo.lineEdit().setClearButtonEnabled(True) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | self.__ui.replacetextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | 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
|
115 | self.on_replaceButton_clicked |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | ) |
10190
dbe6394786ea
Little improvement to the various search (and replace) widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
117 | self.__ui.replacetextCombo.lineEdit().setClearButtonEnabled(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | |
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
|
119 | self.findNextAct = EricAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | self.tr("Find Next"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | self.tr("Find Next"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
122 | 0, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
123 | 0, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
125 | "hexEditor_search_widget_find_next", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
126 | ) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | 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
|
128 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | 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
|
130 | |
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
|
131 | self.findPrevAct = EricAction( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
132 | self.tr("Find Prev"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | self.tr("Find Prev"), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
134 | 0, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
135 | 0, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
136 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
137 | "hexEditor_search_widget_find_prev", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
138 | ) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | 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
|
140 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | 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
|
142 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.__havefound = False |
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 | @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
|
146 | 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
|
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 | 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
|
149 | |
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
|
150 | @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
|
151 | @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
|
152 | """ |
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
|
153 | 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
|
154 | 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
|
155 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
156 | 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
|
157 | 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
|
158 | 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
|
159 | self.__currentFindFormat = findFormat |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | |
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
|
161 | self.__ui.findtextCombo.setValidator( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
162 | self.__formatAndValidators[findFormat][1] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
163 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
164 | |
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
|
165 | 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
|
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 | @pyqtSlot(str) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | 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
|
169 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | 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
|
171 | |
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
|
172 | @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
|
173 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | if not txt: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | self.__ui.findNextButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | self.__ui.findPrevButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | self.__ui.replaceAllButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | self.__ui.findNextButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | self.findNextAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | self.__ui.findPrevButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | self.findPrevAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | 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
|
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 | @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
|
195 | 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
|
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 | 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
|
198 | |
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
|
199 | @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
|
200 | @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
|
201 | """ |
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
|
202 | 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
|
203 | 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
|
204 | 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
|
205 | 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
|
206 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | def __getContent(self, replace=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | 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
|
210 | a bytearray. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
211 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | @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
|
213 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | @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
|
215 | @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
|
216 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | textCombo = self.__ui.replacetextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | formatCombo = self.__ui.replaceFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | history = self.__replaceHistory |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | textCombo = self.__ui.findtextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | formatCombo = self.__ui.findFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | history = self.__findHistory |
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 | txt = textCombo.currentText() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | 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
|
228 | 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
|
229 | 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
|
230 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | # 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
|
232 | # 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | history.insert(0, historyEntry) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | 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
|
238 | 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
|
239 | textCombo.addItem(text, index) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | return ba, txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
242 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | def on_findNextButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | 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
|
247 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | self.findPrevNext(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
249 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | def on_findPrevButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | 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
|
254 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | self.findPrevNext(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
256 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | def findPrevNext(self, prev=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | 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
|
260 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | @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
|
262 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | @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
|
264 | @rtype bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | 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
|
267 | 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
|
268 | return False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
269 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | self.__findBackwards = prev |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | ba, txt = self.__getContent() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
272 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | idx = -1 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | if len(ba) > 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | startIndex = self.__editor.cursorPosition() // 2 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | if prev: |
7254
f00d825fbdb3
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
277 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
278 | self.__editor.hasSelection() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
279 | and startIndex == self.__editor.getSelectionEnd() |
7254
f00d825fbdb3
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
280 | ): |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | # skip to the selection start |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | startIndex = self.__editor.getSelectionBegin() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | 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
|
284 | else: |
7254
f00d825fbdb3
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
285 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
286 | self.__editor.hasSelection() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
287 | 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
|
288 | ): |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | # skip to the selection end |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | startIndex = self.__editor.getSelectionEnd() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | 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
|
292 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | if idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | self.__ui.replaceButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | self.__ui.replaceSearchButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | 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
|
298 | EricMessageBox.information( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
299 | 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
|
300 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
301 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | return idx >= 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
303 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | def __findByReturnPressed(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | 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
|
307 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | if self.__findBackwards: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | self.findPrevNext(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | self.findPrevNext(False) |
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 | @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
|
314 | 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
|
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 | 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
|
317 | |
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
|
318 | @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
|
319 | @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
|
320 | """ |
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
|
321 | 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
|
322 | 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
|
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 | 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
|
325 | 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
|
326 | newTxt = self.__convertText( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
327 | txt, self.__currentReplaceFormat, replaceFormat |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
328 | ) |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
329 | self.__currentReplaceFormat = replaceFormat |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
330 | |
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
|
331 | self.__ui.replacetextCombo.setValidator( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
332 | self.__formatAndValidators[replaceFormat][1] |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
333 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
334 | |
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
|
335 | 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
|
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 | @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
|
338 | 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
|
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 | 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
|
341 | |
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
|
342 | @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
|
343 | @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
|
344 | """ |
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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | 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
|
349 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | def on_replaceButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | 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
|
354 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | self.__doReplace(False) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
356 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | def on_replaceSearchButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | 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
|
361 | one. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | self.__doReplace(True) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
364 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | def __doReplace(self, searchNext): |
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 | 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
|
368 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | @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
|
370 | @type bool |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | # 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
|
373 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
374 | not self.__ui.replaceButton.isEnabled() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
375 | 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
|
376 | ): |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
378 | |
4654
9dafe6905667
Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4653
diff
changeset
|
379 | fba, ftxt = self.__getContent(False) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
380 | 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
|
381 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | ok = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | if self.__editor.hasSelection(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | # 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
|
385 | 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
|
386 | 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
|
387 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | if searchNext: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | 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
|
390 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | if not ok: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | 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
|
394 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | def on_replaceAllButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | 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
|
399 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | replacements = 0 |
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 | cursorPosition = self.__editor.cursorPosition() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
403 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | fba, ftxt = self.__getContent(False) |
10690
fab36645aa7d
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
405 | 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
|
406 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | idx = 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | while idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | 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
|
410 | 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
|
411 | 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
|
412 | idx += len(rba) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | replacements += 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
414 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | 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
|
416 | EricMessageBox.information( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
417 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
418 | self.windowTitle(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
419 | 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
|
420 | ) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | 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
|
422 | EricMessageBox.information( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
423 | self, |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
424 | self.windowTitle(), |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
425 | 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
|
426 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
427 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | self.__editor.setCursorPosition(cursorPosition) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | self.__editor.ensureVisible() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
430 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
431 | def __showFind(self, text=""): |
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 | 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
|
434 | |
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
|
435 | @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
|
436 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | self.__replace = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
439 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | 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
|
441 | 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
|
442 | 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
|
443 | 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
|
444 | 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
|
445 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | 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
|
449 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | self.__findBackwards = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
452 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
453 | def __showReplace(self, text=""): |
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 | 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
|
456 | |
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
|
457 | @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
|
458 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | self.__replace = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
461 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | 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
|
463 | 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
|
464 | 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
|
465 | 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
|
466 | 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
|
467 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | 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
|
471 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | 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
|
473 | 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
|
474 | 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
|
475 | 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
|
476 | 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
|
477 | self.__ui.replacetextCombo.setEditText("") |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
478 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | self.__findBackwards = False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
481 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
482 | def show(self, text=""): |
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 | 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
|
485 | |
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
|
486 | @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
|
487 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | self.__showReplace(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | 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
|
493 | super().show() |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | self.activateWindow() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
495 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | def on_closeButton_clicked(self): |
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 | 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
|
500 | """ |
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
|
501 | 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
|
502 | self.close() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | def keyPressEvent(self, event): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | 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
|
507 | |
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
|
508 | @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
|
509 | @type QKeyEvent |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | """ |
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
|
511 | 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
|
512 | self.close() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
513 | |
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
|
514 | 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
|
515 | """ |
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 | 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
|
517 | |
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
|
518 | @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
|
519 | @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
|
520 | @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
|
521 | @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
|
522 | @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
|
523 | @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
|
524 | @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
|
525 | @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
|
526 | """ |
4687
f1d921533cc5
Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4662
diff
changeset
|
527 | 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
|
528 | # 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
|
529 | 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
|
530 | |
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
|
531 | # 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
|
532 | 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
|
533 | |
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
|
534 | return txt |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
535 | |
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
|
536 | 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
|
537 | """ |
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
|
538 | 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
|
539 | |
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
|
540 | @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
|
541 | @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
|
542 | @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
|
543 | @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
|
544 | """ |
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 | 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
|
546 | 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
|
547 | 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
|
548 | ba.insert(0, modulus) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
549 | |
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
|
550 | return ba |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
551 | |
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
|
552 | 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
|
553 | """ |
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 | 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
|
555 | |
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
|
556 | @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
|
557 | @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
|
558 | @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
|
559 | @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
|
560 | """ |
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
|
561 | 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
|
562 | 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
|
563 | value = value * 256 + b |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
564 | |
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
|
565 | return value |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
566 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
567 | 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
|
568 | """ |
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 | 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
|
570 | |
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
|
571 | @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
|
572 | @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
|
573 | @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
|
574 | @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
|
575 | @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
|
576 | @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
|
577 | @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
|
578 | 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
|
579 | """ |
10373
093dcebe5ecb
Corrected some uses of dict.keys(), dict.values() and dict.items().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10190
diff
changeset
|
580 | if dataFormat not in self.__formatAndValidators: |
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
|
581 | 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
|
582 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
583 | if dataFormat == "hex": # hex format |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
584 | 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
|
585 | 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
|
586 | 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
|
587 | 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
|
588 | 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
|
589 | 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
|
590 | 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
|
591 | 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
|
592 | 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
|
593 | 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
|
594 | 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
|
595 | |
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
|
596 | return ba |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
597 | |
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5389
diff
changeset
|
598 | 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
|
599 | """ |
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 | 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
|
601 | |
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
|
602 | @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
|
603 | @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
|
604 | @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
|
605 | @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
|
606 | @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
|
607 | @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
|
608 | @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
|
609 | 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
|
610 | """ |
10373
093dcebe5ecb
Corrected some uses of dict.keys(), dict.values() and dict.items().
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10190
diff
changeset
|
611 | if dataFormat not in self.__formatAndValidators: |
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
|
612 | 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
|
613 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
614 | 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
|
615 | 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
|
616 | 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
|
617 | 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
|
618 | 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
|
619 | 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
|
620 | 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
|
621 | 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
|
622 | 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
|
623 | 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
|
624 | 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
|
625 | 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
|
626 | |
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
|
627 | return txt |