from gui.v2.ui.styles.css.error_css import GOTHIC_DARK_THEME, CORPORATE_PUNK_DYING_ROT, get_message_style from PyQt6.QtWidgets import ( QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QScrollArea, QWidget, QApplication, QFrame ) from PyQt6.QtCore import Qt from typing import Optional, Callable, Any 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) # Gothic Dark Theme Styling (Applied once here, covers all children) self.setStyleSheet(GOTHIC_DARK_THEME) # 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) # Blindly apply the CSS returned by the helper self.message_label.setStyleSheet(get_message_style(message)) # SCROLL AREA scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setWidget(self.message_label) main_layout.addWidget(scroll) 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(CORPORATE_PUNK_DYING_ROT) 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): """Quit the Graphical App""" QApplication.quit() def show(self): self.exec()