mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-gui.git
synced 2025-06-24 13:14:11 +08:00
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
from PyQt5.QtCore import Qt, QSize
|
|
from PyQt5.QtGui import QColor, QPixmap
|
|
from PyQt5.QtWidgets import QFrame, QGridLayout, QLabel, QGraphicsDropShadowEffect, QPushButton
|
|
|
|
from core.context import AppContext
|
|
|
|
|
|
class MessageBox(QFrame):
|
|
def __init__(self, title, mode, text, parent=None):
|
|
super(MessageBox, self).__init__(parent)
|
|
self.title = title
|
|
self.mode = mode
|
|
self.text = text
|
|
|
|
self.setWindowModality(Qt.WindowModal)
|
|
self.setAttribute(Qt.WA_DeleteOnClose)
|
|
self.setWindowTitle("")
|
|
|
|
self.effect_shadow = QGraphicsDropShadowEffect(self)
|
|
self.effect_shadow.setOffset(0, 0) # 偏移
|
|
self.effect_shadow.setBlurRadius(10) # 阴影半径
|
|
self.effect_shadow.setColor(QColor(85,89,119)) # 阴影颜色
|
|
self.setGraphicsEffect(self.effect_shadow)
|
|
|
|
self.setGeometry((AppContext.get_main_window().geometry().width() - 420) / 2,
|
|
(AppContext.get_main_window().geometry().height() - 220) / 2,
|
|
420, 220)
|
|
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
layout = QGridLayout()
|
|
layout.setContentsMargins(30,20,30,20)
|
|
self.setLayout(layout)
|
|
|
|
icon_label = QLabel()
|
|
icon_label.setFixedWidth(60)
|
|
if self.mode == "warning":
|
|
icon_label.setPixmap(self.set_icon("assets/warning.png"))
|
|
elif self.mode == "error":
|
|
icon_label.setPixmap(self.set_icon("assets/error.png"))
|
|
elif self.mode == "info":
|
|
icon_label.setPixmap(self.set_icon("assets/info.png"))
|
|
elif self.mode == "success":
|
|
icon_label.setPixmap(self.set_icon("assets/success.png"))
|
|
layout.addWidget(icon_label, 0, 0)
|
|
|
|
title_label = QLabel()
|
|
title_label.setText(self.title)
|
|
title_label.setAlignment(Qt.AlignLeft)
|
|
title_label.setStyleSheet("font-size: 18px; font-weight: bold;")
|
|
layout.addWidget(title_label, 0, 1, Qt.AlignVCenter)
|
|
|
|
text_label = QLabel()
|
|
text_label.setText(self.text)
|
|
text_label.setWordWrap(True)
|
|
text_label.setAlignment(Qt.AlignLeft)
|
|
layout.addWidget(text_label, 1, 1, Qt.AlignTop)
|
|
|
|
button = QPushButton()
|
|
button.setText("关闭")
|
|
button.clicked.connect(lambda: self.close())
|
|
layout.addWidget(button, 2, 1, Qt.AlignRight)
|
|
|
|
@staticmethod
|
|
def set_icon(path):
|
|
pixmap = QPixmap(path)
|
|
scaled_pixmap = pixmap.scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
return scaled_pixmap |