Created
April 14, 2023 11:39
-
-
Save allrobot/aad2aa88f8ccdd8043a857478eebfab7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtCore import * | |
from PyQt5.QtGui import QIcon | |
from PyQt5.QtWidgets import * | |
class InterruptProcessing(QDialog): | |
quit_interrupt=pyqtSignal() | |
retry=pyqtSignal() | |
ignored=pyqtSignal() | |
cancel=pyqtSignal() | |
def __init__(self, text:str,parent=None): | |
super(InterruptProcessing,self).__init__(parent) | |
self.error_text = '' | |
# 设置窗口标题 | |
self.setWindowTitle("警告") | |
self.setModal(True) | |
self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint) | |
# self.setWindowFlag(Qt.WindowCloseButtonHint) | |
self.resize(200, 100) | |
# 在窗口中添加标签 | |
self.label = QLabel(self) | |
self.label.setText(text) | |
# 在窗口中添加两个按钮 | |
self.button1 = QPushButton("重试", self) | |
self.button1.clicked.connect(self.button1_event) | |
self.button2 = QPushButton("忽略", self) | |
self.button2.clicked.connect(self.button2_event) | |
self.button3 = QPushButton("取消", self) | |
self.button3.clicked.connect(self.button3_event) | |
# 将按钮和标签放在一个水平布局中 | |
hbox = QHBoxLayout() | |
# hbox.addStretch(1) | |
hbox.addWidget(self.button1) | |
hbox.addWidget(self.button2) | |
hbox.addWidget(self.button3) | |
# 将文本框和水平布局放在一个垂直布局中 | |
vbox = QVBoxLayout() | |
vbox.addWidget(self.label) | |
vbox.addLayout(hbox) | |
# 设置窗口的布局 | |
self.setLayout(vbox) | |
self.show() | |
def get_result(self): | |
return self.result() | |
def button1_event(self): | |
self.retry.emit() | |
def button2_event(self): | |
self.ignored.emit() | |
def button3_event(self): | |
self.cancel.emit() | |
def closeEvent(self, event): | |
self.quit_interrupt.emit() | |
event.accept() | |
def keyPressEvent(self, event): | |
if event.key(): | |
event.ignore() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment