91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
from PyQt5.QtWidgets import *
|
||
from PyQt5.QtCore import Qt
|
||
|
||
from LSZXPagesLibrary.circular_synchronization import CircularProgressSynchronization
|
||
|
||
|
||
class PopDialogSynchronization:
|
||
|
||
def __init__(self, parent):
|
||
super().__init__()
|
||
self.cancel_action = None
|
||
self.commit_action = None
|
||
self.parent = parent
|
||
|
||
desktop = QDesktopWidget()
|
||
self.screenRect = desktop.availableGeometry()
|
||
self.dialog = QDialog(
|
||
flags=Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint
|
||
) # 设置无图标和标题
|
||
self.dialog.setStyleSheet("background-color:#ffffff;")
|
||
self.dialog.setContentsMargins(0, 20, 0, 20)
|
||
self.dialog.setFixedSize(int(self.screenRect.width() * 0.35),
|
||
int(self.screenRect.height() * 0.45)) # 设置对话框的宽度为屏幕的35%,高度为屏幕的70%
|
||
|
||
self.circle_percentage = CircularProgressSynchronization()
|
||
self.tips_label = self._init_tips_label()
|
||
self.cancel_btn = self._init_cancel_button()
|
||
self.cancel_btn.clicked.connect(self.cancel_button_action)
|
||
|
||
# 总布局
|
||
self.main_layout = QVBoxLayout()
|
||
self.main_layout.addWidget(self.circle_percentage, 50)
|
||
self.main_layout.addWidget(self.tips_label, 15)
|
||
self.main_layout.addWidget(self.cancel_btn, 35)
|
||
|
||
self.dialog.setLayout(self.main_layout)
|
||
|
||
# 添加遮罩层,设置parent,确保遮罩层在父页面中显示
|
||
self.overlay = QWidget(self.parent)
|
||
self.overlay.setStyleSheet("background-color: rgba(0, 0, 0, 0.5);")
|
||
self.overlay.resize(self.screenRect.width(), self.screenRect.height())
|
||
self.overlay.hide()
|
||
|
||
def show(self):
|
||
self.overlay.show()
|
||
self.dialog.show()
|
||
|
||
def close(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
|
||
# 取消按钮响应事件
|
||
def cancel_button_action(self):
|
||
self.dialog.hide()
|
||
self.overlay.hide()
|
||
if self.cancel_action:
|
||
self.cancel_action()
|
||
|
||
def connect(self, func):
|
||
self.cancel_action = func
|
||
|
||
# 初始化取消按钮
|
||
@staticmethod
|
||
def _init_cancel_button():
|
||
cancel_btn = QPushButton("取消同步")
|
||
cancel_btn.setStyleSheet(
|
||
"background-color: #f56c6c;"
|
||
"color: #ffffff;"
|
||
"border-radius: 4px;"
|
||
"border: none;"
|
||
"font: 600 24px \"Microsoft YaHei UI\";"
|
||
"margin-left: 120px;"
|
||
"margin-right: 120px;"
|
||
"padding-top: 20px;"
|
||
"padding-bottom: 20px;"
|
||
"letter-spacing: 4px;"
|
||
)
|
||
return cancel_btn
|
||
|
||
@staticmethod
|
||
def _init_tips_label():
|
||
tips_label = QLabel("数据同步中……")
|
||
tips_label.setAlignment(Qt.AlignCenter)
|
||
tips_label.setStyleSheet(
|
||
"color: #222222;"
|
||
"margin-bottom: 10px;"
|
||
"margin-top: 10px;"
|
||
"font: 600 26px \"Microsoft YaHei UI\";"
|
||
)
|
||
return tips_label
|