76 lines
3.1 KiB
Python
76 lines
3.1 KiB
Python
# FlightMonitor/__main__.py
|
|
import tkinter as tk
|
|
|
|
# MODIFIED: Import the logging configuration dictionary
|
|
# WHY: Need to pass configuration to the logger setup function.
|
|
# HOW: Added import.
|
|
from .data.logging_config import LOGGING_CONFIG # Import the config dictionary
|
|
|
|
# MODIFIED: Import the logger setup function AND get_logger function
|
|
# WHY: Need to call the centralized setup function early and get logger instances.
|
|
# HOW: Added get_logger to the import statement.
|
|
from .utils.logger import setup_logging, get_logger
|
|
|
|
from .gui.main_window import MainWindow
|
|
from .controller.app_controller import AppController
|
|
|
|
|
|
def main():
|
|
"""
|
|
Main function to launch the Flight Monitor application.
|
|
Initializes the Tkinter root, sets up logging, creates the controller
|
|
and the main window, and starts the event loop.
|
|
"""
|
|
# Initialize the Tkinter root window FIRST
|
|
root = tk.Tk()
|
|
|
|
# MODIFIED: Setup logging AFTER Tkinter root is created
|
|
# WHY: The TkinterTextHandler requires a root instance.
|
|
# Setup logging as early as possible after dependencies are met.
|
|
# HOW: Called setup_logging here, passing the necessary arguments including the config.
|
|
setup_logging(
|
|
gui_log_widget=None, root_tk_instance=root, logging_config_dict=LOGGING_CONFIG
|
|
)
|
|
|
|
# Now that basic logging is set up, we can use module_logger
|
|
# MODIFIED: Call get_logger directly to get the logger for this module.
|
|
# WHY: get_logger is a function, not a method of setup_logging.
|
|
# HOW: Changed setup_logging.get_logger to just get_logger.
|
|
module_logger_main = get_logger(
|
|
__name__
|
|
) # Get logger using the function from logger.py
|
|
module_logger_main.info("Application starting...")
|
|
|
|
# Create the application controller
|
|
app_controller = AppController()
|
|
|
|
# Create the main application window
|
|
# Pass the root and the controller to the MainWindow.
|
|
# MainWindow itself will now handle the creation and passing of its log widget
|
|
# to setup_logging (which we already called above, but will be called again by MW if it needs to).
|
|
# Ideally, MainWindow's __init__ should just receive the logger configuration somehow
|
|
# and pass its log widget to setup_logging if it exists.
|
|
# With the current design, MainWindow will call setup_logging *again* in its __init__,
|
|
# passing its log widget. This is fine; setup_logging is designed to handle re-initialization
|
|
# and replace handlers.
|
|
main_app_window = MainWindow(root, app_controller)
|
|
|
|
# Set the main window instance in the controller
|
|
app_controller.set_main_window(main_app_window)
|
|
|
|
# Start the Tkinter event loop
|
|
module_logger_main.info("Starting Tkinter main loop.")
|
|
root.mainloop()
|
|
module_logger_main.info("Tkinter main loop finished.")
|
|
|
|
# Cleanup should happen when the window is closed (WM_DELETE_WINDOW)
|
|
# or after mainloop exits (if it exits cleanly).
|
|
# The on_application_exit in the controller handles non-GUI cleanup.
|
|
# The shutdown_gui_logging is called by MainWindow's _on_closing.
|
|
|
|
module_logger_main.info("Application finished.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|