Reusable popup message box. Args: parent: The parent widget. message (str): The message to display. page (int, optional): Page index to switch to after dialog closes. show_cancel (bool): Whether to show the Cancel button.
(
parent,
message: str,
page: int = None,
show_cancel: bool = False,
cancel_page: int = HOME_PAGE,
)
| 136 | |
| 137 | |
| 138 | def show_popup_message( |
| 139 | parent, |
| 140 | message: str, |
| 141 | page: int = None, |
| 142 | show_cancel: bool = False, |
| 143 | cancel_page: int = HOME_PAGE, |
| 144 | ): |
| 145 | """Reusable popup message box. |
| 146 | |
| 147 | Args: |
| 148 | parent: The parent widget. |
| 149 | message (str): The message to display. |
| 150 | page (int, optional): Page index to switch to after dialog closes. |
| 151 | show_cancel (bool): Whether to show the Cancel button. |
| 152 | """ |
| 153 | dialog = QtWidgets.QDialog(parent) |
| 154 | dialog.setWindowTitle("Message") |
| 155 | dialog.setFixedSize(350, 100) |
| 156 | dialog.setStyleSheet("background-color: #f0f0f0;") |
| 157 | |
| 158 | layout = QtWidgets.QVBoxLayout(dialog) |
| 159 | layout.setSpacing(10) |
| 160 | layout.setContentsMargins(15, 15, 15, 15) |
| 161 | |
| 162 | label = QtWidgets.QLabel(message) |
| 163 | label.setStyleSheet("font-size: 12px; color: #2c3e50;") |
| 164 | label.setWordWrap(True) |
| 165 | layout.addWidget(label) |
| 166 | |
| 167 | # Decide which buttons to show |
| 168 | if show_cancel: |
| 169 | button_box = QtWidgets.QDialogButtonBox( |
| 170 | QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel |
| 171 | ) |
| 172 | else: |
| 173 | button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok) |
| 174 | |
| 175 | button_box.setStyleSheet(""" |
| 176 | QPushButton { |
| 177 | background-color: #3498db; |
| 178 | color: white; |
| 179 | border-radius: 4px; |
| 180 | padding: 6px 12px; |
| 181 | min-width: 80px; |
| 182 | } |
| 183 | QPushButton:hover { |
| 184 | background-color: #2980b9; |
| 185 | } |
| 186 | QPushButton:pressed { |
| 187 | background-color: #1c6ea4; |
| 188 | } |
| 189 | """) |
| 190 | layout.addWidget(button_box) |
| 191 | |
| 192 | # Connect buttons |
| 193 | def on_accept(): |
| 194 | if page is not None: |
| 195 | parent.setCurrentIndex(page) |
no outgoing calls
no test coverage detected