Skip to content

Commit 1bdc0ca

Browse files
committed
chore(gui-hex2str): migrate from legacy Qt to PyQt6
1 parent 4907d2a commit 1bdc0ca

1 file changed

Lines changed: 56 additions & 16 deletions

File tree

‎hex2str/gui.py‎

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,58 @@
88
import sys
99

1010
try:
11-
from PyQt5.QtWidgets import *
12-
from PyQt5.QtCore import *
13-
from PyQt5.QtGui import *
11+
from PyQt6.QtWidgets import (
12+
QApplication,
13+
QSizePolicy,
14+
QMessageBox,
15+
QRadioButton,
16+
QPlainTextEdit,
17+
QWidget,
18+
QLabel,
19+
QPushButton,
20+
QVBoxLayout,
21+
QHBoxLayout,
22+
QButtonGroup,
23+
QSplitter,
24+
QErrorMessage,
25+
QTextEdit,
26+
)
27+
from PyQt6.QtCore import Qt, qVersion
28+
from PyQt6.QtGui import QPalette, QTextCursor
29+
30+
QPalette.Active = QPalette.ColorGroup.Active
31+
QPalette.Inactive = QPalette.ColorGroup.Inactive
32+
33+
QPalette.Highlight = QPalette.ColorRole.Highlight
34+
QPalette.HighlightedText = QPalette.ColorRole.HighlightedText
35+
36+
Qt.TextSelectableByMouse = Qt.TextInteractionFlag.TextSelectableByMouse
37+
38+
QSizePolicy.Preferred = QSizePolicy.Policy.Preferred
39+
QSizePolicy.Expanding = QSizePolicy.Policy.Expanding
40+
41+
QTextCursor.MoveAnchor = QTextCursor.MoveMode.MoveAnchor
42+
QTextCursor.KeepAnchor = QTextCursor.MoveMode.KeepAnchor
1443

1544
except:
16-
try:
17-
from PyQt4.QtGui import *
18-
from PyQt4.QtCore import *
19-
20-
except:
21-
from PySide.QtGui import *
22-
from PySide.QtCore import *
45+
from PyQt5.QtWidgets import (
46+
QApplication,
47+
QSizePolicy,
48+
QMessageBox,
49+
QRadioButton,
50+
QPlainTextEdit,
51+
QWidget,
52+
QLabel,
53+
QPushButton,
54+
QVBoxLayout,
55+
QHBoxLayout,
56+
QButtonGroup,
57+
QSplitter,
58+
QErrorMessage,
59+
QTextEdit,
60+
)
61+
from PyQt5.QtCore import Qt, qVersion
62+
from PyQt5.QtGui import QPalette, QTextCursor
2363

2464
# Выбор функции конвертации в зависимости от значения радио-кнопки
2565
from hex2str import hex2str, str2hex
@@ -85,8 +125,8 @@ def __init__(self) -> None:
85125
self.button_detail_error.setToolTip("Detail error")
86126
self.button_detail_error.clicked.connect(self.show_detail_error_massage)
87127

88-
self.last_error_message = None
89-
self.last_detail_error_message = None
128+
self.last_error_message: str = ""
129+
self.last_detail_error_message: str = ""
90130

91131
layout_left_side = QVBoxLayout()
92132
layout_left_side.setContentsMargins(0, 0, 0, 0)
@@ -205,8 +245,8 @@ def _convert(self) -> None:
205245
self.label_error.clear()
206246
self.button_detail_error.hide()
207247

208-
self.last_error_message = None
209-
self.last_detail_error_message = None
248+
self.last_error_message: str = ""
249+
self.last_detail_error_message: str = ""
210250

211251
try:
212252
func = hex2str if self.radio_button_hex2str.isChecked() else str2hex
@@ -227,7 +267,7 @@ def _convert(self) -> None:
227267
self.last_detail_error_message = str(tb)
228268
self.button_detail_error.show()
229269

230-
self.label_error.setText("Error: " + self.last_error_message)
270+
self.label_error.setText(f"Error: {self.last_error_message}")
231271

232272
input_chars: int = len(self.text_edit_input.toPlainText())
233273
output_chars: int = len(self.text_edit_output.toPlainText())
@@ -244,4 +284,4 @@ def _convert(self) -> None:
244284
mw.text_edit_input.setPlainText("504F53542068747470733A")
245285
mw.show()
246286

247-
sys.exit(app.exec_())
287+
sys.exit(app.exec())

0 commit comments

Comments
 (0)