diff --git a/openadapt/app/tray.py b/openadapt/app/tray.py index dd52c91ac..d5b3e9277 100644 --- a/openadapt/app/tray.py +++ b/openadapt/app/tray.py @@ -104,7 +104,19 @@ class DashboardMonitor(QObject): ready = Signal() - def __init__(self, app: QApplication = None, port=5173): + def __init__(self, app: QApplication = None, port: int = 5173) -> None: + """Initializes the DashboardMonitor. + + Args: + app (QApplication, optional): The QApplication instance. Defaults to None. + port (int, optional): The port number for the dashboard. Defaults to 5173. + + Attributes: + stop_flag (Event): An event flag to signal stopping the monitor. + port (int): The port number for the dashboard. + _is_ready (bool): A flag indicating if the monitor is ready. + monitor_thread (QThread or None): The thread for monitoring. + """ super().__init__() self.stop_flag = Event() self.port = port @@ -123,16 +135,16 @@ def __init__(self, app: QApplication = None, port=5173): # Connect to our own ready signal to update state self.ready.connect(self._update_ready_state) - def _update_ready_state(self): + def _update_ready_state(self) -> None: """Update internal ready state when signal is emitted.""" self._is_ready = True print("DEBUG(DashboardMonitor): Ready state updated") - def on_thread_finished(self): + def on_thread_finished(self) -> None: """Handle thread finished signal.""" logger.info("Dashboard monitor thread finished") - def monitor_startup(self): + def monitor_startup(self) -> None: """Monitor dashboard startup process.""" logger.info("Starting dashboard monitoring") start_time = time.time() @@ -162,7 +174,7 @@ def monitor_startup(self): finally: self.monitor_thread.quit() - def on_dashboard_ready(self): + def on_dashboard_ready(self) -> None: """Handle dashboard being ready.""" try: self.ready.emit() @@ -170,12 +182,12 @@ def on_dashboard_ready(self): except Exception as e: logger.error(f"Error emitting signal: {e}") - def check_ready_state(self): + def check_ready_state(self) -> None: """Check if dashboard is ready and re-emit if necessary.""" if self._is_ready: QTimer.singleShot(0, self.on_dashboard_ready) - def stop(self): + def stop(self) -> None: """Stop monitoring and cleanup thread.""" logger.info("Stopping dashboard monitor") self.stop_flag.set() @@ -615,7 +627,7 @@ def launch_dashboard(self) -> None: except Exception as e: logger.error(f"Launch dashboard error: {e}") - def on_dashboard_ready(self): + def on_dashboard_ready(self) -> None: """Handle dashboard being ready.""" logger.info("Dashboard is ready - performing final setup") diff --git a/openadapt/entrypoint.py b/openadapt/entrypoint.py index 6711a29aa..7ac480ff2 100644 --- a/openadapt/entrypoint.py +++ b/openadapt/entrypoint.py @@ -6,10 +6,8 @@ from PySide6.QtCore import QObject, Qt, QTimer, Signal from PySide6.QtWidgets import QApplication -from openadapt.app import tray from openadapt.build_utils import redirect_stdout_stderr from openadapt.custom_logger import logger -from openadapt.error_reporting import configure_error_reporting from openadapt.splash_screen import LoadingScreen @@ -19,20 +17,26 @@ class LoadingManager(QObject): progress_updated = Signal(int, str) loading_complete = Signal() - def __init__(self, splash_screen, app): + def __init__(self, splash_screen: LoadingScreen, app: QApplication) -> None: + """Initializes the main application entry point. + + Args: + splash_screen: The splash screen to be displayed during startup. + app: The main application instance. + """ super().__init__() self.splash = splash_screen self.app = app self.progress_updated.connect(self._update_progress) - def _update_progress(self, value, message): + def _update_progress(self, value: int, message: str) -> None: """Update progress bar and process events.""" self.splash.update_progress(value) self.splash.update_status(message) self.app.processEvents() logger.debug(f"Progress: {value}% - {message}") - def start_loading_sequence(self): + def start_loading_sequence(self) -> None: """Execute the loading sequence with visible progress updates.""" # Initial setup - 0% self.progress_updated.emit(0, "Initializing...") @@ -41,16 +45,18 @@ def start_loading_sequence(self): try: from openadapt.config import print_config - print_config() self.progress_updated.emit(20, "Loading configuration...") + print_config() except Exception as e: logger.error(f"Configuration error: {e}") return False # Error reporting setup - 40% try: - configure_error_reporting() + from openadapt.error_reporting import configure_error_reporting + self.progress_updated.emit(40, "Configuring error reporting...") + configure_error_reporting() except Exception as e: logger.error(f"Error reporting setup failed: {e}") return False @@ -67,6 +73,8 @@ def start_loading_sequence(self): # System tray setup - 80% try: + from openadapt.app import tray + self.progress_updated.emit(80, "Setting up system tray...") tray_instance = tray.SystemTrayIcon(app=self.app) @@ -98,7 +106,7 @@ def run_openadapt() -> None: if not tray_instance: raise Exception("Loading sequence failed") - def on_dashboard_ready(): + def on_dashboard_ready() -> None: logger.info("Dashboard ready - closing splash screen") loading_manager.progress_updated.emit(100, "Ready!") @@ -120,7 +128,14 @@ def on_dashboard_ready(): # Connect dashboard monitor signals if hasattr(tray_instance, "dashboard_monitor"): - def on_dashboard_ready_wrapper(): + def on_dashboard_ready_wrapper() -> None: + """Wrapper function that logs a debug message. + + calls the on_dashboard_ready function. + + Returns: + None + """ logger.debug("Dashboard ready wrapper called") on_dashboard_ready() @@ -130,14 +145,13 @@ def on_dashboard_ready_wrapper(): ) logger.debug("Signal handler connected") - # If dashboard monitor thread is not running, assume it's already ready if ( not hasattr(tray_instance.dashboard_monitor, "monitor_thread") or not tray_instance.dashboard_monitor.monitor_thread.isRunning() ): logger.debug( - "Dashboard appears to be already ready, calling handler" - " directly" + "Dashboard appears to be already ready, " + "calling handler directly" ) on_dashboard_ready_wrapper() diff --git a/openadapt/splash_screen.py b/openadapt/splash_screen.py index 1060e8762..964d0fc03 100644 --- a/openadapt/splash_screen.py +++ b/openadapt/splash_screen.py @@ -8,7 +8,8 @@ class LoadingScreen(QSplashScreen): """A minimal splash screen for.""" - def __init__(self): + def __init__(self) -> None: + """Initialize the loading screen.""" pixmap = QPixmap(400, 100) pixmap.fill(QColor(0, 0, 0, 180)) @@ -59,25 +60,25 @@ def __init__(self): } """) - def update_status(self, message: str): + def update_status(self, message: str) -> None: """Update the status message displayed on the splash screen.""" self.status_label.setText(message) self.repaint() QApplication.processEvents() - def update_progress(self, value: int): + def update_progress(self, value: int) -> None: """Update progress value with immediate visual feedback.""" value = max(0, min(100, value)) # for smooth progress updates QTimer.singleShot(0, lambda: self._do_update(value)) - def _do_update(self, value): + def _do_update(self, value: int) -> None: """Internal method to perform the actual progress update.""" self.progress_bar.setValue(value) self.repaint() QApplication.processEvents() - def show(self): + def show(self) -> None: """Show the splash screen.""" super().show() self.raise_()