81 lines
2.9 KiB
Python
81 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Main entry point script for the GeoElevation application.
|
|
Works for both `python -m geoelevation` and as PyInstaller entry point.
|
|
Uses absolute imports.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import traceback
|
|
import multiprocessing
|
|
import tkinter as tk
|
|
|
|
# --- Import the necessary modules using ABSOLUTE paths ---
|
|
try:
|
|
# MODIFIED: Changed relative import to absolute import.
|
|
# WHY: To make this script work consistently as a direct entry point
|
|
# (for PyInstaller) and when run via `python -m`. Assumes the
|
|
# 'geoelevation' package is findable in sys.path.
|
|
# HOW: Changed 'from .elevation_gui import ElevationApp' to
|
|
# 'from geoelevation.elevation_gui import ElevationApp'.
|
|
from geoelevation.elevation_gui import ElevationApp
|
|
# Import other components if needed for setup (using absolute paths)
|
|
# from geoelevation.config import DEFAULT_CACHE_DIR # Example if you had config
|
|
|
|
except ImportError as e:
|
|
# Error message adjusted slightly for absolute import context
|
|
print(f"ERROR: Could not import required modules using absolute paths (e.g., 'geoelevation.elevation_gui').")
|
|
print(f" Ensure the 'geoelevation' package is correctly structured and accessible.")
|
|
print(f"ImportError: {e}")
|
|
print(f"Current sys.path: {sys.path}")
|
|
# Try to determine expected base path for context
|
|
try:
|
|
script_path = os.path.dirname(os.path.abspath(__file__))
|
|
parent_path = os.path.dirname(script_path)
|
|
print(f" Expected package 'geoelevation' potentially under: {parent_path}")
|
|
except NameError:
|
|
pass # __file__ might not be defined in some rare cases
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"ERROR: An unexpected error occurred during initial imports: {e}")
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
|
|
|
|
def main():
|
|
"""
|
|
Initializes and runs the ElevationApp GUI application.
|
|
"""
|
|
root_window = tk.Tk()
|
|
try:
|
|
# Instantiate ElevationApp, passing the root window
|
|
app = ElevationApp(parent_widget=root_window)
|
|
# Start the Tkinter event loop
|
|
root_window.mainloop()
|
|
except Exception as e:
|
|
print(f"FATAL ERROR: An unexpected error occurred during application execution: {e}")
|
|
traceback.print_exc()
|
|
try:
|
|
error_root = tk.Tk()
|
|
error_root.withdraw()
|
|
from tkinter import messagebox
|
|
messagebox.showerror(
|
|
"Fatal Error",
|
|
f"Application failed to run:\n{e}\n\nSee console for details.",
|
|
parent=error_root
|
|
)
|
|
error_root.destroy()
|
|
except Exception:
|
|
pass
|
|
sys.exit(1)
|
|
|
|
# --- Main Execution Guard ---
|
|
if __name__ == "__main__":
|
|
# !!! IMPORTANT for PyInstaller and multiprocessing !!!
|
|
# Must be called in the main entry script for frozen executables.
|
|
multiprocessing.freeze_support()
|
|
|
|
# print(f"Running GeoElevation via __main__.py...")
|
|
main() |