import omni.ui as ui
import asyncio
from omni.kit.widget.imageview import ImageView
from functools import partial
# Create a window for displaying the image
window = ui.Window("Image Loading Progress", width=600, height=600)
# Create a future to track when the image is fully loaded
image_loaded_future = asyncio.Future()
# Callback function that reports the loading progress
def on_image_progress(future, progress):
    print(f"Image loading progress: {progress * 100:.1f}%")
    
    # When the image is fully loaded (progress = 1.0), resolve the future
    if progress >= 1.0 and not future.done():
        future.set_result(None)
        print("Image fully loaded!")
with window.frame:
    # Create the image view - replace with a valid image path
    image_view = ImageView("path/to/your/image.png")
    
    # Register the progress callback function
    image_view.set_progress_changed_fn(
        partial(on_image_progress, image_loaded_future)
    )
# Non-blocking way to handle when the image is loaded
def handle_future_completion(future):
    try:
        # This will either get the result or raise any exception from the future
        future.result()
        print("Image is now fully loaded - continue with your operations")
        
        # Clean up resources when appropriate
        # image_view.destroy()
    except Exception as e:
        print(f"Error during image loading: {e}")
# Add the callback to the future
image_loaded_future.add_done_callback(handle_future_completion)