66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
# radian/core/main_controller.py
|
|
|
|
from radian.gui.main_window import MainWindow
|
|
from radian.utils import logger
|
|
from radian.config.logging_config import LOGGING_CONFIG
|
|
|
|
# Get a logger for this specific module
|
|
log = logger.get_logger(__name__)
|
|
|
|
class MainController:
|
|
"""
|
|
The main controller of the RADIAN application.
|
|
|
|
It orchestrates the application's lifecycle, including initializing the GUI,
|
|
setting up the logging system, loading components, and handling shutdown.
|
|
"""
|
|
def __init__(self):
|
|
self.app: MainWindow | None = None
|
|
|
|
def run(self):
|
|
"""
|
|
Initializes and starts the RADIAN application.
|
|
"""
|
|
# 1. Initialize the main window (the GUI)
|
|
self.app = MainWindow()
|
|
|
|
# 2. Set up the centralized logging system
|
|
self._setup_logging()
|
|
|
|
# 3. Set up a graceful shutdown procedure
|
|
self.app.protocol("WM_DELETE_WINDOW", self._on_shutdown)
|
|
|
|
log.info("RADIAN application started.")
|
|
log.info("Welcome to the Radar Data Integration & Analysis Network.")
|
|
|
|
# 4. Start the Tkinter main event loop
|
|
self.app.mainloop()
|
|
|
|
def _setup_logging(self):
|
|
"""Initializes the basic logger and adds the Tkinter handler."""
|
|
# Set up the queue, processor, and file/console handlers
|
|
logger.setup_basic_logging(
|
|
root_tk_instance_for_processor=self.app,
|
|
logging_config_dict=LOGGING_CONFIG
|
|
)
|
|
|
|
# Add the handler that writes to our GUI log widget
|
|
logger.add_tkinter_handler(
|
|
gui_log_widget=self.app.log_text,
|
|
root_tk_instance_for_gui_handler=self.app,
|
|
logging_config_dict=LOGGING_CONFIG
|
|
)
|
|
log.info("Logging system configured and GUI handler attached.")
|
|
|
|
def _on_shutdown(self):
|
|
"""Handles the application shutdown sequence."""
|
|
log.info("Shutdown sequence initiated...")
|
|
|
|
# --- Future shutdown logic for components would go here ---
|
|
|
|
# Properly shut down the logging system
|
|
logger.shutdown_logging_system()
|
|
|
|
# Destroy the main window
|
|
if self.app:
|
|
self.app.destroy() |