Mon, 11 Jan 2016 19:46:19 +0100
Improved the search/replace history handling of the hex editor and added input validators.
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: add more format types (Dec, Oct, Bin, UTF-8) |
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
|
23 | # 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
|
24 | class HexEditSearchReplaceWidget(QWidget): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | 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
|
27 | """ |
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
|
28 | 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
|
29 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | Constructor |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | @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
|
33 | @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
|
34 | @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
|
35 | @type HexEditMainWindow |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @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
|
37 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @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
|
39 | @type QWidget |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | super(HexEditSearchReplaceWidget, self).__init__(parent) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__replace = replace |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.__editor = editor |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | |
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
|
46 | self.__formatAndValidators = [ |
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
|
47 | (self.tr("Hex"), QRegExpValidator((QRegExp("[0-9a-f]*")))), |
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
|
48 | (self.tr("Text"), None), |
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
|
49 | ] |
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
|
50 | |
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
|
51 | 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
|
52 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | 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
|
54 | 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
|
55 | self.__ui = Ui_HexEditReplaceWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | 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
|
58 | self.__ui = Ui_HexEditSearchWidget() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | self.__ui.setupUi(self) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | 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
|
62 | self.__ui.findPrevButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | UI.PixmapCache.getIcon("1leftarrow.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | self.__ui.findNextButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | UI.PixmapCache.getIcon("1rightarrow.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | self.__ui.replaceButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | UI.PixmapCache.getIcon("editReplace.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | self.__ui.replaceSearchButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | UI.PixmapCache.getIcon("editReplaceSearch.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | self.__ui.replaceAllButton.setIcon( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | UI.PixmapCache.getIcon("editReplaceAll.png")) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | |
4659
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
75 | for format, validator in self.__formatAndValidators: |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
76 | self.__ui.findFormatCombo.addItem(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
|
77 | if replace: |
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
|
78 | for format, validator in self.__formatAndValidators: |
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
|
79 | self.__ui.replaceFormatCombo.addItem(format) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | self.__ui.findtextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | 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
|
82 | self.__findByReturnPressed) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | self.__ui.replacetextCombo.setCompleter(None) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | 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
|
86 | self.on_replaceButton_clicked) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | self.findNextAct = E5Action( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | self.tr('Find Next'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | self.tr('Find Next'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | 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
|
92 | 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
|
93 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | 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
|
95 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | self.findPrevAct = E5Action( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | self.tr('Find Prev'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | self.tr('Find Prev'), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | 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
|
100 | 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
|
101 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | 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
|
103 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | self.__havefound = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | |
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
|
106 | @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
|
107 | 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
|
108 | """ |
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
|
109 | 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
|
110 | |
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
|
111 | @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
|
112 | @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
|
113 | """ |
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
|
114 | 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
|
115 | self.__ui.findtextCombo.setValidator( |
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
|
116 | self.__formatAndValidators[idx][1]) |
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 | |
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 | @pyqtSlot(str) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | 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
|
120 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | 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
|
122 | |
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
|
123 | @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
|
124 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | if not txt: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | self.__ui.findNextButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | self.findNextAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | self.__ui.findPrevButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | self.findPrevAct.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | self.__ui.replaceAllButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | self.__ui.findNextButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | self.findNextAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | self.__ui.findPrevButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | self.findPrevAct.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.__ui.replaceAllButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | |
4659
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
145 | @pyqtSlot(int) |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
146 | def on_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
|
147 | """ |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
148 | Private slot to handle a selection from the find 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
|
149 | |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
150 | @param idx index of the selected entry |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
151 | @type int |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
152 | """ |
2863d05e83c6
Improved the search/replace history handling of the hex editor and added input validators.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4656
diff
changeset
|
153 | if idx >= 0: |
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
|
154 | formatIndex = self.__ui.findtextCombo.itemData(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
|
155 | self.__ui.findFormatCombo.setCurrentIndex(formatIndex) |
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
|
156 | |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | def __getContent(self, replace=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | 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
|
160 | a bytearray. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | @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
|
163 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | @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
|
165 | @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
|
166 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | if replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | textCombo = self.__ui.replacetextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | formatCombo = self.__ui.replaceFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | history = self.__replaceHistory |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | textCombo = self.__ui.findtextCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | formatCombo = self.__ui.findFormatCombo |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | history = self.__findHistory |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | txt = textCombo.currentText() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | idx = formatCombo.currentIndex() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | if idx == 0: # hex format |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | ba = bytearray(QByteArray.fromHex( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | bytes(txt, encoding="ascii"))) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | ba = bytearray(txt, encoding="utf-8") |
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 | # 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
|
185 | # 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
|
186 | 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
|
187 | 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
|
188 | 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
|
189 | history.insert(0, historyEntry) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | 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
|
191 | 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
|
192 | textCombo.addItem(text, index) |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | return ba, txt |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | def on_findNextButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | 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
|
200 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | self.findPrevNext(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | def on_findPrevButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | 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
|
207 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | self.findPrevNext(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | def findPrevNext(self, prev=False): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | 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
|
213 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | @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
|
215 | @type bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | @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
|
217 | @rtype bool |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | 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
|
220 | self.show() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | return |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | self.__findBackwards = prev |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | ba, txt = self.__getContent() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | idx = -1 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | if len(ba) > 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | startIndex = self.__editor.cursorPosition() // 2 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | if prev: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | if self.__editor.hasSelection() and \ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | startIndex == self.__editor.getSelectionEnd(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | # skip to the selection start |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | startIndex = self.__editor.getSelectionBegin() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | 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
|
235 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | if self.__editor.hasSelection() and \ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | startIndex == self.__editor.getSelectionBegin() - 1: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | # skip to the selection end |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | startIndex = self.__editor.getSelectionEnd() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | 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
|
241 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | if idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | self.__ui.replaceButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | self.__ui.replaceSearchButton.setEnabled(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | 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
|
250 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | return idx >= 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | def __findByReturnPressed(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | 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
|
256 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | if self.__findBackwards: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | self.findPrevNext(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | 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
|
261 | |
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
|
262 | @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
|
263 | 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
|
264 | """ |
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
|
265 | 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
|
266 | |
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
|
267 | @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
|
268 | @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
|
269 | """ |
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
|
270 | 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
|
271 | self.__ui.replacetextCombo.setValidator( |
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
|
272 | self.__formatAndValidators[idx][1]) |
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
|
273 | |
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
|
274 | @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
|
275 | 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
|
276 | """ |
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
|
277 | 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
|
278 | |
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
|
279 | @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
|
280 | @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
|
281 | """ |
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
|
282 | 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
|
283 | formatIndex = self.__ui.replacetextCombo.itemData(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
|
284 | 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
|
285 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | def on_replaceButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | 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
|
290 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | self.__doReplace(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | def on_replaceSearchButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | 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
|
297 | one. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | self.__doReplace(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | def __doReplace(self, searchNext): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | 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
|
304 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | @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
|
306 | @type bool |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | # 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
|
309 | 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
|
310 | not self.__ui.replaceSearchButton.isEnabled(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | return |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | |
4654
9dafe6905667
Fixed an issue in the hex editor search and replace widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4653
diff
changeset
|
313 | 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
|
314 | rba, rtxt = self.__getContent(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | ok = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | if self.__editor.hasSelection(): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | # 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
|
319 | 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
|
320 | 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
|
321 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | if searchNext: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | ok = self.findPrevNext(self.__findBackwards) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | if not ok: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | self.__ui.replaceButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | self.__ui.replaceSearchButton.setEnabled(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | def on_replaceAllButton_clicked(self): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | 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
|
333 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | replacements = 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | cursorPosition = self.__editor.cursorPosition() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | fba, ftxt = self.__getContent(False) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | rba, rtxt = self.__getContent(True) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | idx = 0 |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | while idx >= 0: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | idx += len(rba) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | replacements += 1 |
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 | if replacements: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | self.tr("Replaced {0} occurrences.") |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | .format(replacements)) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | E5MessageBox.information( |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | self, self.windowTitle(), |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | 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
|
358 | .format(ftxt)) |
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 | self.__editor.setCursorPosition(cursorPosition) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | self.__editor.ensureVisible() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | def __showFind(self, text=''): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | 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
|
366 | |
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
|
367 | @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
|
368 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | self.__replace = False |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | 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
|
373 | 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
|
374 | 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
|
375 | 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
|
376 | 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
|
377 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | self.on_findtextCombo_editTextChanged(text) |
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 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | self.__findBackwards = False |
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 | def __showReplace(self, text=''): |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | 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
|
388 | |
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
|
389 | @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
|
390 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | self.__replace = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | 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
|
395 | 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
|
396 | 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
|
397 | 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
|
398 | 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
|
399 | self.__ui.findtextCombo.setEditText(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | self.__ui.findtextCombo.lineEdit().selectAll() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | self.__ui.findtextCombo.setFocus() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | self.on_findtextCombo_editTextChanged(text) |
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.__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
|
405 | 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
|
406 | 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
|
407 | 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
|
408 | 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
|
409 | self.__ui.replacetextCombo.setEditText('') |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | self.__havefound = True |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | self.__findBackwards = False |
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 | def show(self, text=''): |
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 | 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
|
417 | |
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
|
418 | @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
|
419 | @type str |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | if self.__replace: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | self.__showReplace(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | else: |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | self.__showFind(text) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | super(HexEditSearchReplaceWidget, self).show() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | self.activateWindow() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | @pyqtSlot() |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | def on_closeButton_clicked(self): |
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 close the widget. |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | self.__editor.setFocus(Qt.OtherFocusReason) |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | self.close() |
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 | def keyPressEvent(self, event): |
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 | 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
|
439 | |
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
|
440 | @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
|
441 | @type QKeyEvent |
4652
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | """ |
a88a2ba7a48a
Added search and replace capability to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | 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
|
444 | self.close() |