util_error_popup

Path: /utilities/util_error_popup.py

Overview

This module provides a thread-safe mechanism to display modal error dialogs using PyQt5, allowing installation or operation errors to halt or continue based on user choice.

Purpose & Use Cases

Display critical error messages during installation processes, offering options to stop or continue.

Show modal dialogs from background threads by marshalling UI calls onto the main Qt thread.

Dependencies

PyQt5 (QtWidgets, QtCore)

threading, sys (Python Standard Library)

Configuration & Parameters

Parameter Type Description Default
message string The error text to display in the dialog. N/A
allow_continue bool Whether to show a 'Continue Anyways' button. false

Usage Example

from utilities.util_error_popup import show_error_popup
        
        # Display an error and allow the user to continue
        if not show_error_popup("Failed to create download directory:\nPermission denied", allow_continue=True):
            # Execution will exit if the user chose to stop
            pass
        

Behavior & Implementation

The show_error_popup function creates or retrieves a Qt Application instance, hides any overlay widgets, and displays a modal QDialog with the provided message. If invoked from a non-GUI thread, it emits a signal to the main thread's ErrorDialogManager, waiting on a threading.Event for the user's response. The dialog presents 'Stop Installation' and optionally 'Continue Anyways' buttons, and restores overlay visibility after closing.

Error Handling

On 'Stop Installation' or dialog rejection, show_error_popup calls sys.exit(1). Any exceptions during dialog management propagate and result in application termination to avoid silent failures. Threading errors in signal delivery are not caught, causing the application to exit.

Security Considerations

Displays only the provided message text without HTML rendering, mitigating injection risks. Relies on Qt's safe text handling. Do not pass untrusted HTML or markup.

Logging

This module does not log internally; calling code should log before invoking show_error_popup to capture context. QDialog events are not logged.

Testing & Validation

Manual testing can be done by invoking show_error_popup on the main thread and from background threads, verifying correct modal behavior and process exit. Automated UI tests should mock QApplication and simulate button clicks.

Author

Author: Raven Development Team