hydraveil-gui/gui/v2/ui/popups/error_popup.py

96 lines
3 KiB
Python

from typing import Optional, Callable, Any
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QApplication
from PyQt6.QtCore import Qt
class ErrorPopup(QDialog):
def __init__(
self,
choice: bool,
title: str,
message: str,
end_app: Optional[bool] = False,
on_answer: Optional[Callable] = None,
passed_result: Optional[Any] = None,
**kwargs
):
super().__init__(**kwargs)
# Protocol state
self.title_text = title
self.on_answer = on_answer
self.passed_result = passed_result
self.end_app = end_app
# Window Configuration
self.setWindowTitle(title)
self.setFixedSize(400, 300)
self.setModal(True)
# Dark Theme Styling (Replacing Kivy Canvas/RoundedRectangle)
self.setStyleSheet("""
QDialog {
background-color: #1a1a1a;
border-radius: 20px;
}
QLabel {
color: #33ff33;
font-size: 24px;
background: transparent;
border: none;
}
QPushButton {
color: white;
font-size: 20px;
border-radius: 10px;
padding: 10px;
min-height: 50px;
}
""")
# Layout setup
main_layout = QVBoxLayout()
main_layout.setContentsMargins(20, 20, 20, 20)
main_layout.setSpacing(20)
# MESSAGE LABEL
self.message_label = QLabel(message)
self.message_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.message_label.setWordWrap(True)
main_layout.addWidget(self.message_label)
if choice:
# BUTTON LAYOUT for Yes/No
button_layout = QHBoxLayout()
button_layout.setSpacing(20)
yes_btn = QPushButton("Yes")
yes_btn.setStyleSheet("background-color: #1b4d1b;")
yes_btn.clicked.connect(lambda: self._choice_response(True))
no_btn = QPushButton("No")
no_btn.setStyleSheet("background-color: #801a1a;")
no_btn.clicked.connect(lambda: self._choice_response(False))
button_layout.addWidget(yes_btn)
button_layout.addWidget(no_btn)
main_layout.addLayout(button_layout)
else:
# OK button
ok_btn = QPushButton("OK")
ok_btn.setStyleSheet("background-color: #1b4d1b;")
ok_btn.clicked.connect(self.accept) # Closes the dialog
main_layout.addWidget(ok_btn)
self.setLayout(main_layout)
def _choice_response(self, user_choice: bool):
if self.on_answer:
self.on_answer(user_choice, self.passed_result)
self.accept()
def _terminate_app(self):
"""Desktop equivalent of App.get_running_app().stop()"""
QApplication.quit()
def show(self):
self.exec()