Fri, 15 Jan 2016 18:24:01 +0100
Completed the supported formats of the search and replace entry of the hex editor.
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 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
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 | |
4653
e8b51747c48e
Added a forgotten '__future__' statement to the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4652
diff
changeset
|
10 | from __future__ import unicode_literals |
e8b51747c48e
Added a forgotten '__future__' statement to the last commit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4652
diff
changeset
|
11 | |
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
|
12 | from PyQt5.QtCore import pyqtSlot, Qt, QByteArray, QRegExp |
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
|
13 | from PyQt5.QtGui import QRegExpValidator |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | from PyQt5.QtWidgets import QWidget |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | from E5Gui.E5Action import E5Action |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | from E5Gui import E5MessageBox |
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 | import UI.PixmapCache |
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 | |
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
|
22 | # TODO: change the text of the combo when the format changes |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | class HexEditSearchReplaceWidget(QWidget): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | 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
|
26 | """ |
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
|
27 | 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
|
28 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | Constructor |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | @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
|
32 | @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
|
33 | @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
|
34 | @type HexEditMainWindow |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @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
|
36 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @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
|
38 | @type QWidget |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | super(HexEditSearchReplaceWidget, self).__init__(parent) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.__replace = replace |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__editor = editor |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | |
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
|
45 | # 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
|
46 | self.__formatAndValidators = { |
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
|
47 | "hex": (self.tr("Hex"), QRegExpValidator((QRegExp("[0-9a-f]*")))), |
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
|
48 | "dec": (self.tr("Dec"), QRegExpValidator((QRegExp("[0-9]*")))), |
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
|
49 | "oct": (self.tr("Oct"), QRegExpValidator((QRegExp("[0-7]*")))), |
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
|
50 | "bin": (self.tr("Bin"), QRegExpValidator((QRegExp("[01]*")))), |
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
|
51 | "text": (self.tr("Text"), None), # text as latin-1 |
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
|
52 | "utf-8": (self.tr("UTF-8"), None), # text as utf-8 |
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
|
53 | } |
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
|
54 | formatOrder = ["hex", "dec", "oct", "bin", "text", "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
|
55 | |
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
|
56 | 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
|
57 | self.__currentReplaceFormat = "" |
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
|
58 | |
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
|
59 | 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
|
60 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | from .Ui_HexEditReplaceWidget import Ui_HexEditReplaceWidget |
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
|
62 | 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
|
63 | self.__ui = Ui_HexEditReplaceWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | from .Ui_HexEditSearchWidget import Ui_HexEditSearchWidget |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | self.__ui = Ui_HexEditSearchWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | self.__ui.setupUi(self) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | self.__ui.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | self.__ui.findPrevButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | UI.PixmapCache.getIcon("1leftarrow.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | self.__ui.findNextButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | UI.PixmapCache.getIcon("1rightarrow.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | self.__ui.replaceButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | UI.PixmapCache.getIcon("editReplace.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | self.__ui.replaceSearchButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | UI.PixmapCache.getIcon("editReplaceSearch.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | self.__ui.replaceAllButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | UI.PixmapCache.getIcon("editReplaceAll.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | |
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
|
83 | for format in formatOrder: |
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
|
84 | formatStr, validator = self.__formatAndValidators[format] |
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
|
85 | self.__ui.findFormatCombo.addItem(formatStr, format) |
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
|
86 | if replace: |
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
|
87 | for format in formatOrder: |
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
|
88 | formatStr, validator = self.__formatAndValidators[format] |
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
|
89 | self.__ui.replaceFormatCombo.addItem(formatStr, format) |
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
|
90 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | self.__ui.findtextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | self.__ui.findtextCombo.lineEdit().returnPressed.connect( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | self.__findByReturnPressed) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | self.__ui.replacetextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | self.__ui.replacetextCombo.lineEdit().returnPressed.connect( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | self.on_replaceButton_clicked) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | self.findNextAct = E5Action( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | self.tr('Find Next'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | self.tr('Find Next'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | 0, 0, self, 'hexEditor_search_widget_find_next') |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | 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
|
104 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | self.__ui.findtextCombo.addAction(self.findNextAct) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | self.findPrevAct = E5Action( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | self.tr('Find Prev'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | self.tr('Find Prev'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | 0, 0, self, 'hexEditor_search_widget_find_prev') |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | 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
|
112 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | self.__ui.findtextCombo.addAction(self.findPrevAct) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | self.__havefound = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | |
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
|
117 | @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
|
118 | 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
|
119 | """ |
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
|
120 | Private slot to handle a selection from the find format. |
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
|
121 | |
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
|
122 | @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
|
123 | @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
|
124 | """ |
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
|
125 | if idx >= 0: |
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
|
126 | format = self.__ui.findFormatCombo.itemData(idx) |
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
|
127 | |
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
|
128 | if format != 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
|
129 | txt = self.__ui.findtextCombo.currentText() |
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
|
130 | newTxt = self.__convertText( |
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
|
131 | txt, self.__currentFindFormat, format) |
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
|
132 | self.__currentFindFormat = format |
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
|
133 | |
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
|
134 | self.__ui.findtextCombo.setValidator( |
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
|
135 | self.__formatAndValidators[format][1]) |
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
|
136 | |
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
|
137 | self.__ui.findtextCombo.setEditText(newTxt) |
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
|
138 | |
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
|
139 | @pyqtSlot(str) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | 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
|
141 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | Private slot to enable/disable the find buttons. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | |
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
|
144 | @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
|
145 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | if not txt: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | self.__ui.findNextButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | self.__ui.findPrevButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | self.__ui.replaceAllButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | self.__ui.findNextButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | self.findNextAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | self.__ui.findPrevButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | self.findPrevAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | self.__ui.replaceAllButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | |
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
|
166 | @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
|
167 | 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
|
168 | """ |
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
|
169 | Private slot to handle a selection from the find 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
|
170 | |
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
|
171 | @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
|
172 | @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
|
173 | """ |
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
|
174 | 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
|
175 | 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
|
176 | 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
|
177 | self.__ui.findFormatCombo.setCurrentIndex(formatIndex) |
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
|
178 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | def __getContent(self, replace=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | 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
|
182 | a bytearray. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | @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
|
185 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | @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
|
187 | @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
|
188 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | textCombo = self.__ui.replacetextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | formatCombo = self.__ui.replaceFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | history = self.__replaceHistory |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | textCombo = self.__ui.findtextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | formatCombo = self.__ui.findFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | history = self.__findHistory |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | txt = textCombo.currentText() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | idx = formatCombo.currentIndex() |
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
|
200 | format = formatCombo.itemData(idx) |
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
|
201 | if format == "hex": # hex format |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | ba = bytearray(QByteArray.fromHex( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | bytes(txt, encoding="ascii"))) |
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 | elif format == "dec": |
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 | ba = self.__int2bytearray(int(txt, 10)) |
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
|
206 | elif format == "oct": |
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
|
207 | ba = self.__int2bytearray(int(txt, 8)) |
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
|
208 | elif format == "bin": |
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
|
209 | ba = self.__int2bytearray(int(txt, 2)) |
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
|
210 | elif format == "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
|
211 | ba = bytearray(txt, encoding="latin-1") |
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
|
212 | elif format == "utf-8": |
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
|
213 | ba = bytearray(txt, encoding="utf-8") |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | else: |
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
|
215 | ba = bytearray() |
4652
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 | # 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
|
218 | # 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
|
219 | 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
|
220 | 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
|
221 | 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
|
222 | history.insert(0, historyEntry) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | 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
|
224 | 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
|
225 | textCombo.addItem(text, index) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | return ba, txt |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | def on_findNextButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | 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
|
233 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | self.findPrevNext(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | def on_findPrevButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | 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
|
240 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | self.findPrevNext(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | def findPrevNext(self, prev=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | Public slot to find the next occurrence of the search term. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | @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
|
248 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | @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
|
250 | @rtype bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | 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
|
253 | self.show() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | return |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | self.__findBackwards = prev |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | ba, txt = self.__getContent() |
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 | idx = -1 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | if len(ba) > 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | startIndex = self.__editor.cursorPosition() // 2 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | if prev: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | if self.__editor.hasSelection() and \ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | startIndex == self.__editor.getSelectionEnd(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | # skip to the selection start |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | startIndex = self.__editor.getSelectionBegin() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | 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
|
268 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | if self.__editor.hasSelection() and \ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | startIndex == self.__editor.getSelectionBegin() - 1: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | # skip to the selection end |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | startIndex = self.__editor.getSelectionEnd() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | idx = self.__editor.indexOf(ba, startIndex) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | if idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | self.__ui.replaceButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | self.__ui.replaceSearchButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | self.tr("'{0}' was not found.").format(txt)) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | return idx >= 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | def __findByReturnPressed(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | 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
|
289 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | if self.__findBackwards: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | self.findPrevNext(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | self.findPrevNext(False) |
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
|
294 | |
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
|
295 | @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
|
296 | 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
|
297 | """ |
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
|
298 | Private slot to handle a selection from the replace format. |
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
|
299 | |
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
|
300 | @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
|
301 | @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
|
302 | """ |
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
|
303 | if idx >= 0: |
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
|
304 | format = self.__ui.replaceFormatCombo.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
|
305 | |
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
|
306 | if format != self.__currentReplaceFormat: |
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
|
307 | 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
|
308 | newTxt = self.__convertText( |
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
|
309 | txt, self.__currentReplaceFormat, format) |
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
|
310 | self.__currentReplaceFormat = format |
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
|
311 | |
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
|
312 | self.__ui.replacetextCombo.setValidator( |
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
|
313 | self.__formatAndValidators[format][1]) |
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
|
314 | |
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
|
315 | self.__ui.replacetextCombo.setEditText(newTxt) |
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
|
316 | |
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
|
317 | @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
|
318 | 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
|
319 | """ |
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 | Private slot to handle a selection from the replace 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
|
321 | |
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
|
322 | @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
|
323 | @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
|
324 | """ |
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
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | 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
|
329 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | def on_replaceButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | 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
|
334 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | self.__doReplace(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | def on_replaceSearchButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | 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
|
341 | one. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | self.__doReplace(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | def __doReplace(self, searchNext): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | Private method 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
|
348 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | @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
|
350 | @type bool |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | # Check enabled status due to dual purpose usage of this method |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | if not self.__ui.replaceButton.isEnabled() and \ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | not self.__ui.replaceSearchButton.isEnabled(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | return |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | |
4654
9dafe6905667
Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4653
diff
changeset
|
357 | fba, ftxt = self.__getContent(False) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | rba, rtxt = self.__getContent(True) |
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 | ok = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | if self.__editor.hasSelection(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | # 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
|
363 | 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
|
364 | self.__editor.replaceByteArray(startIdx, len(fba), rba) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | if searchNext: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | ok = self.findPrevNext(self.__findBackwards) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | if not ok: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | def on_replaceAllButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | 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
|
377 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | replacements = 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | cursorPosition = self.__editor.cursorPosition() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | fba, ftxt = self.__getContent(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | rba, rtxt = self.__getContent(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | idx = 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | while idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | 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
|
388 | 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
|
389 | 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
|
390 | idx += len(rba) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | replacements += 1 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | if replacements: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | self.tr("Replaced {0} occurrences.") |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | .format(replacements)) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
399 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | self.tr("Nothing replaced because '{0}' was not found.") |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | .format(ftxt)) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | self.__editor.setCursorPosition(cursorPosition) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | self.__editor.ensureVisible() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | def __showFind(self, text=''): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | Private method to display this widget in find mode. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | |
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
|
411 | @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
|
412 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | self.__replace = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | 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
|
417 | 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
|
418 | self.__ui.findtextCombo.addItem(txt, index) |
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
|
419 | self.__ui.findFormatCombo.setCurrentIndex(0) # 0 is always Hex |
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
|
420 | 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
|
421 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | self.on_findtextCombo_editTextChanged(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | self.__findBackwards = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | def __showReplace(self, text=''): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | Private slot to display this widget in replace mode. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | |
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
|
433 | @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
|
434 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | self.__replace = True |
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.__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
|
439 | 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
|
440 | self.__ui.findtextCombo.addItem(txt, index) |
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 | self.__ui.findFormatCombo.setCurrentIndex(0) # 0 is always Hex |
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.on_findFormatCombo_currentIndexChanged(0) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | self.on_findtextCombo_editTextChanged(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | 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
|
449 | 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
|
450 | self.__ui.replacetextCombo.addItem(txt, index) |
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
|
451 | self.__ui.replaceFormatCombo.setCurrentIndex(0) # 0 is always Hex |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
452 | self.on_replaceFormatCombo_currentIndexChanged(0) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | self.__ui.replacetextCombo.setEditText('') |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | self.__findBackwards = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | def show(self, text=''): |
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 | Public slot to show the widget. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | |
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
|
462 | @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
|
463 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | self.__showReplace(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | self.__showFind(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | super(HexEditSearchReplaceWidget, self).show() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | self.activateWindow() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | def on_closeButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | 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
|
476 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
477 | self.__editor.setFocus(Qt.OtherFocusReason) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | self.close() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | def keyPressEvent(self, event): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | Protected slot to handle key press events. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | |
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
|
484 | @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
|
485 | @type QKeyEvent |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | if event.key() == Qt.Key_Escape: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | self.close() |
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
|
489 | |
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
|
490 | 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
|
491 | """ |
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
|
492 | Private method to convert text from one format into another. |
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
|
493 | |
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
|
494 | @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
|
495 | @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
|
496 | @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
|
497 | @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
|
498 | @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
|
499 | @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
|
500 | @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
|
501 | @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
|
502 | """ |
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
|
503 | # TODO: implement the conversion method |
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
|
504 | return txt |
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
|
505 | |
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
|
506 | 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
|
507 | """ |
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
|
508 | Private method to convert an integer into a byte 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
|
509 | |
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
|
510 | @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
|
511 | @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
|
512 | @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
|
513 | @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
|
514 | """ |
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
|
515 | 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
|
516 | 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
|
517 | 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
|
518 | ba.insert(0, modulus) |
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 | |
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
|
520 | return ba |
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
|
521 | |
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
|
522 | 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
|
523 | """ |
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
|
524 | Private method to convert a byte array to an integer 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
|
525 | |
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
|
526 | @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
|
527 | @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
|
528 | @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
|
529 | @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
|
530 | """ |
bf927c5576c6
Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4660
diff
changeset
|
531 | 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
|
532 | 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
|
533 | value = value * 256 + b |
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
|
534 | |
bf927c5576c6
Completed the supported formats of the search and replace entry of the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4660
diff
changeset
|
535 | return value |