91 lines
3.2 KiB
Python
Executable file
91 lines
3.2 KiB
Python
Executable file
from PyQt6.QtWidgets import (
|
|
QWidget, QPushButton, QLabel, QFrame, QVBoxLayout, QHBoxLayout, QScrollArea
|
|
)
|
|
from PyQt6.QtGui import QFont
|
|
from PyQt6.QtCore import Qt, pyqtSignal
|
|
|
|
from gui.v2.ui.styles.styles import (
|
|
POPUP_ACTION_BUTTON_RED_QSS,
|
|
POPUP_BG_QSS,
|
|
POPUP_CANCEL_BUTTON_QSS,
|
|
POPUP_CLOSE_BUTTON_QSS,
|
|
)
|
|
|
|
|
|
class ConfirmationPopup(QWidget):
|
|
finished = pyqtSignal(bool)
|
|
|
|
def __init__(self, parent=None, message="", action_button_text="", cancel_button_text="Cancel"):
|
|
super().__init__(parent)
|
|
self.parent_window = parent
|
|
self.message = message
|
|
self.action_button_text = action_button_text
|
|
self.cancel_button_text = cancel_button_text
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
self.setMinimumSize(400, 200)
|
|
self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
|
|
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
|
|
|
main_layout = QVBoxLayout()
|
|
self.setLayout(main_layout)
|
|
|
|
bg_widget = QWidget(self)
|
|
bg_widget.setStyleSheet(POPUP_BG_QSS)
|
|
main_layout.addWidget(bg_widget)
|
|
|
|
content_layout = QVBoxLayout(bg_widget)
|
|
|
|
close_button = QPushButton("✕", self)
|
|
close_button.setStyleSheet(POPUP_CLOSE_BUTTON_QSS)
|
|
close_button.setFixedSize(30, 30)
|
|
close_button.clicked.connect(self.close)
|
|
content_layout.addWidget(
|
|
close_button, alignment=Qt.AlignmentFlag.AlignRight)
|
|
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setFrameShape(QFrame.Shape.NoFrame)
|
|
content_layout.addWidget(scroll_area)
|
|
|
|
scroll_content = QWidget()
|
|
scroll_layout = QVBoxLayout(scroll_content)
|
|
|
|
message_label = QLabel(self.message)
|
|
message_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
message_label.setFont(QFont("Arial", 14))
|
|
message_label.setStyleSheet("color: #333333; margin: 10px 0;")
|
|
message_label.setWordWrap(True)
|
|
scroll_layout.addWidget(message_label)
|
|
|
|
scroll_area.setWidget(scroll_content)
|
|
|
|
button_layout = QHBoxLayout()
|
|
content_layout.addLayout(button_layout)
|
|
|
|
cancel_button = QPushButton(self.cancel_button_text)
|
|
cancel_button.setFixedSize(150, 50)
|
|
cancel_button.setFont(QFont("Arial", 12))
|
|
cancel_button.setStyleSheet(POPUP_CANCEL_BUTTON_QSS)
|
|
cancel_button.clicked.connect(self.close)
|
|
button_layout.addWidget(cancel_button)
|
|
|
|
action_button = QPushButton(self.action_button_text)
|
|
action_button.setFixedSize(150, 50)
|
|
action_button.setFont(QFont("Arial", 12))
|
|
action_button.setStyleSheet(POPUP_ACTION_BUTTON_RED_QSS)
|
|
action_button.clicked.connect(self.perform_action)
|
|
button_layout.addWidget(action_button)
|
|
|
|
def perform_action(self):
|
|
self.finished.emit(True)
|
|
self.close()
|
|
|
|
def mousePressEvent(self, event):
|
|
self.oldPos = event.globalPosition().toPoint()
|
|
|
|
def mouseMoveEvent(self, event):
|
|
delta = event.globalPosition().toPoint() - self.oldPos
|
|
self.move(self.x() + delta.x(), self.y() + delta.y())
|
|
self.oldPos = event.globalPosition().toPoint()
|