From ba689010eacab205c6793de50638b1d239443f7a Mon Sep 17 00:00:00 2001 From: VALLONGOL Date: Wed, 14 May 2025 10:05:48 +0200 Subject: [PATCH] fix call tool like external module --- geoelevation/__init__.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/geoelevation/__init__.py b/geoelevation/__init__.py index 12ffc40..2bbc816 100644 --- a/geoelevation/__init__.py +++ b/geoelevation/__init__.py @@ -228,12 +228,33 @@ class _LibraryProgressWindow(threading.Thread): def get_point_elevation( latitude: float, longitude: float, - show_progress_dialog_flag: bool = False, + # MODIFIED: Renamed parameter back to show_progress_dialog for backward compatibility. + # WHY: The external tool expects this parameter name. + # HOW: Changed the parameter name in the function signature. + show_progress_dialog: bool = False, progress_dialog_custom_message: str = "Retrieving elevation data from remote sources.\nThis may take a moment..." ) -> Optional[float]: """ Retrieves the elevation for a given geographic point (latitude, longitude). - (Full docstring from previous version - no changes to the core logic here) + + Args: + latitude (float): The latitude of the point. + longitude (float): The longitude of the point. + show_progress_dialog (bool, optional): If True, attempts to display a simple + progress window. Defaults to False. + (May only work in environments where + Tkinter can be safely run in a background + thread, like the main process). + progress_dialog_custom_message (str, optional): Custom message for the progress + dialog. Defaults to a standard message. + + Returns: + Optional[float]: The elevation in meters, float('nan') if the point is on a NoData area, + or None if data is unavailable or an error occurs. + + Raises: + RuntimeError: If core dependencies like Rasterio are not available. + ValueError: If input coordinates are invalid. """ progress_window_instance: Optional[_LibraryProgressWindow] = None try: @@ -246,7 +267,10 @@ def get_point_elevation( library_logger.error(f"GeoElevation API: Invalid longitude provided: {longitude}") return None - if show_progress_dialog_flag: + # MODIFIED: Use the renamed parameter show_progress_dialog. + # WHY: The variable name inside the function must match the parameter name in the signature. + # HOW: Changed the variable name here. + if show_progress_dialog: library_logger.debug("GeoElevation API: Progress dialog requested. Preparing window.") progress_window_instance = _LibraryProgressWindow( progress_message_text=progress_dialog_custom_message @@ -370,6 +394,10 @@ __all__ = [ "ElevationManager", # Expose for advanced users or type hinting "RASTERIO_AVAILABLE", # Allow checking for this critical dependency "GEOELEVATION_DEM_CACHE_DEFAULT" # Expose the default DEM cache path constant + # Note: deg_to_dms_string is imported but not added to __all__ as it's a utility, + # typically accessed via the map_viewer subpackage or directly if needed, + # but not considered a primary public API function of the top-level package. + # Similarly, bounds functions are not added to __all__. ] library_logger.debug("GeoElevation package (__init__.py) has been loaded and configured.") \ No newline at end of file