eric6/HexEdit/HexEditGotoWidget.py

Sun, 11 Oct 2020 17:54:52 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Oct 2020 17:54:52 +0200
changeset 7775
4a1db75550bd
parent 7533
88261c96484b
child 7780
41420f82c0ac
permissions
-rw-r--r--

Changed code to not use deprecated 'QRegExp' anymore.

4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2016 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a movement (goto) widget for the hex editor.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
11 from PyQt5.QtCore import pyqtSlot, Qt, QRegularExpression
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
12 from PyQt5.QtGui import QRegularExpressionValidator
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtWidgets import QWidget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_HexEditGotoWidget import Ui_HexEditGotoWidget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
18 import Globals
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class HexEditGotoWidget(QWidget, Ui_HexEditGotoWidget):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing a movement (goto) widget for the hex editor.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self, editor, parent=None):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param editor reference to the hex editor widget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @type HexEditWidget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param parent reference to the parent widget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @type QWidget
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 super(HexEditGotoWidget, self).__init__(parent)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.setupUi(self)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__editor = editor
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
39 # keep this in sync with the logic in on_gotoButton_clicked()
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__formatAndValidators = {
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
41 "hex": (self.tr("Hex"), QRegularExpressionValidator(
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
42 QRegularExpression("[0-9a-f:]*"))),
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
43 "dec": (self.tr("Dec"), QRegularExpressionValidator(
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
44 QRegularExpression("[0-9]*"))),
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 }
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 formatOrder = ["hex", "dec"]
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__currentFormat = ""
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
50 self.closeButton.setIcon(UI.PixmapCache.getIcon("close"))
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
52 for dataFormat in formatOrder:
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
53 formatStr, validator = self.__formatAndValidators[dataFormat]
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
54 self.formatCombo.addItem(formatStr, dataFormat)
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.formatCombo.setCurrentIndex(0)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @pyqtSlot()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def on_closeButton_clicked(self):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Private slot to close the widget.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__editor.setFocus(Qt.OtherFocusReason)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.close()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @pyqtSlot(int)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 def on_formatCombo_currentIndexChanged(self, idx):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 Private slot to handle a selection of the format.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @param idx index of the selected entry
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @type int
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if idx >= 0:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
75 dataFormat = self.formatCombo.itemData(idx)
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
77 if dataFormat != self.__currentFormat:
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 txt = self.offsetEdit.text()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 newTxt = self.__convertText(
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
80 txt, self.__currentFormat, dataFormat)
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
81 self.__currentFormat = dataFormat
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.offsetEdit.setValidator(
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
84 self.__formatAndValidators[dataFormat][1])
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.offsetEdit.setText(newTxt)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 @pyqtSlot(str)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 def on_offsetEdit_textChanged(self, offset):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Private slot handling a change of the entered offset.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @param offset entered offset
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @type str
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.gotoButton.setEnabled(bool(offset))
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @pyqtSlot()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 def on_gotoButton_clicked(self):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 Private slot to move the cursor and extend the selection.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
103 dataFormat = self.formatCombo.itemData(self.formatCombo.currentIndex())
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
104 if dataFormat == "hex":
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
105 offset = self.offsetEdit.text().replace(":", "")
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
106 # get rid of ':' address separators
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
107 offset = int(offset, 16)
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 offset = int(self.offsetEdit.text(), 10)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 fromCursor = self.cursorCheckBox.isChecked()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 backwards = self.backCheckBox.isChecked()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 extendSelection = self.selectionCheckBox.isChecked()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.__editor.goto(offset, fromCursor=fromCursor, backwards=backwards,
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 extendSelection=extendSelection)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 def show(self):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Public slot to show the widget.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 """
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
122 self.offsetEdit.selectAll()
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.offsetEdit.setFocus()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 super(HexEditGotoWidget, self).show()
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
125
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
126 def reset(self):
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
127 """
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
128 Public slot to reset the input widgets.
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
129 """
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
130 self.offsetEdit.clear()
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
131 self.formatCombo.setCurrentIndex(0)
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
132 self.cursorCheckBox.setChecked(False)
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
133 self.backCheckBox.setChecked(False)
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
134 self.selectionCheckBox.setChecked(False)
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def keyPressEvent(self, event):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 Protected slot to handle key press events.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 @param event reference to the key press event
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 @type QKeyEvent
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 if event.key() == Qt.Key_Escape:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 self.close()
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def __convertText(self, txt, oldFormat, newFormat):
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Private method to convert text from one format into another.
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @param txt text to be converted
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @type str
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 @param oldFormat current format of the text
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @type str
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @param newFormat format to convert to
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 @type str
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @return converted text
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @rtype str
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 """
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
159 if txt and oldFormat and newFormat and oldFormat != newFormat:
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 # step 1: convert the text to an integer using the old format
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 if oldFormat == "hex":
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
162 txt = txt.replace(":", "") # get rid of ':' address separators
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 index = int(txt, 16)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 index = int(txt, 10)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 # step 2: convert the integer to text using the new format
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if newFormat == "hex":
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 txt = "{0:x}".format(index)
4687
f1d921533cc5 Little improvements to the hex editor goto widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4670
diff changeset
170 txt = Globals.strGroup(txt, ":", 4)
4670
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 else:
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 txt = "{0:d}".format(index)
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
d401ba329d24 Added 'Goto' functionality to the hex editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return txt

eric ide

mercurial