100 lines
3.7 KiB
Python
100 lines
3.7 KiB
Python
# --- FILE: gitsync_tool/__main__.py ---
|
|
|
|
"""
|
|
Entry point for launching the Git Sync Tool application when run as a module
|
|
using 'python -m gitsync_tool'.
|
|
Initializes the Tkinter root window and the main application controller.
|
|
"""
|
|
|
|
import tkinter as tk
|
|
import sys
|
|
import traceback
|
|
from tkinter import messagebox # Import messagebox for fatal errors
|
|
from typing import Optional
|
|
|
|
# ---<<< MODIFICA IMPORT >>>---
|
|
# Importa la classe principale dell'applicazione dal modulo app nel pacchetto corrente
|
|
from gitsync_tool.app import GitSvnSyncApp
|
|
|
|
# ---<<< FINE MODIFICA IMPORT >>>---
|
|
|
|
|
|
def main() -> None:
|
|
"""
|
|
Main function to initialize and run the Tkinter application.
|
|
Creates the root window and the GitSvnSyncApp controller.
|
|
"""
|
|
root: Optional[tk.Tk] = None
|
|
app: Optional[GitSvnSyncApp] = None
|
|
|
|
# Use a try...except...finally block to catch fatal errors during startup/runtime
|
|
try:
|
|
# 1. Create the main Tkinter root window
|
|
print("Creating Tkinter root window...")
|
|
root = tk.Tk()
|
|
# Set initial minimum window size (adjust as needed)
|
|
root.minsize(width=850, height=750)
|
|
print("Tkinter root window created.")
|
|
|
|
# 2. Initialize the main application controller class
|
|
print("Initializing GitSvnSyncApp controller...")
|
|
# Pass the root window to the application controller
|
|
app = GitSvnSyncApp(root)
|
|
print("GitSvnSyncApp initialization attempt complete.")
|
|
|
|
# 3. Start the Tkinter event loop (only if GUI initialized successfully)
|
|
# Check if the app and its main_frame were created without fatal errors
|
|
if (
|
|
app
|
|
and hasattr(app, "main_frame")
|
|
and app.main_frame
|
|
and app.main_frame.winfo_exists()
|
|
):
|
|
print("Starting Tkinter main event loop...")
|
|
# This call blocks until the main window is closed
|
|
root.mainloop()
|
|
print("Tkinter main event loop finished.")
|
|
else:
|
|
# Log critical failure if GUI init failed (error likely shown already by app)
|
|
print(
|
|
"CRITICAL: Application initialization failed before main event loop could start. Exiting.",
|
|
file=sys.stderr,
|
|
)
|
|
# Attempt to clean up the root window if it exists
|
|
if root and root.winfo_exists():
|
|
try:
|
|
root.destroy()
|
|
except Exception:
|
|
pass # Ignore errors during final cleanup
|
|
|
|
except Exception as e:
|
|
# Catch any unexpected errors during startup or the main loop
|
|
print(f"FATAL APPLICATION ERROR: {e}", file=sys.stderr)
|
|
# Print the full traceback to stderr for debugging
|
|
traceback.print_exc(file=sys.stderr)
|
|
# Attempt to show a final graphical error message
|
|
try:
|
|
# Determine parent window for the messagebox
|
|
parent_window = root if root and root.winfo_exists() else None
|
|
messagebox.showerror(
|
|
"Fatal Application Error",
|
|
f"The application encountered a critical error and must close:\n\n{e}",
|
|
parent=parent_window,
|
|
)
|
|
except Exception as msg_e:
|
|
# Fallback if even the error message fails
|
|
print(f"FATAL (GUI error message failed: {msg_e}):\n{e}", file=sys.stderr)
|
|
finally:
|
|
# This block executes whether an exception occurred or not
|
|
print("Application exiting.")
|
|
# sys.exit(1) # Optionally force exit code 1 on error
|
|
|
|
|
|
# Standard Python entry point check:
|
|
# Ensures that main() is called only when this script is executed directly
|
|
# (which happens when running 'python -m gitsync_tool').
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# --- END OF FILE gitsync_tool/__main__.py ---
|