wolfhece.async_image_loader
Author: HECE - University of Liege, Pierre Archambeau Date: 2024
Copyright (c) 2024 University of Liege. All rights reserved.
This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.
Module Contents
- class wolfhece.async_image_loader.ImageLoadPriority(*args, **kwds)[source]
Bases:
enum.Enum
Priority levels for image loading
- class wolfhece.async_image_loader.ImageLoadRequest[source]
Represents a request to load an image asynchronously
- priority: ImageLoadPriority[source]
- class wolfhece.async_image_loader.AsyncImageLoader(max_workers: int = 4, loop: asyncio.AbstractEventLoop | None = None)[source]
Manages asynchronous loading of images with a priority queue.
Allows scheduling images to be loaded in the background without blocking the UI. Uses asyncio with ThreadPoolExecutor for blocking I/O operations.
- _pending_requests: dict[str, ImageLoadRequest][source]
- schedule_load(request_id: str, loader_func: Callable, callback: Callable[[PIL.Image.Image | None], None], priority: ImageLoadPriority = ImageLoadPriority.NORMAL, bounds: tuple[float, float, float, float] = None) None[source]
Schedule an image to be loaded asynchronously
- Parameters:
request_id – Unique identifier for this request (used for deduplication)
loader_func – Callable that returns the image (PIL Image or None)
callback – Callable to invoke when image is ready: callback(image)
priority – ImageLoadPriority level
bounds – Optional spatial bounds (xmin, xmax, ymin, ymax) for tracking
- async _load_image(request: ImageLoadRequest) None[source]
Load an image asynchronously using executor
- Parameters:
request – ImageLoadRequest to process
- cancel_obsolete_for_texture(texture_id: str, keep_request_id: str) int[source]
Cancel all pending/active loads for a texture except the specified request
Useful when panning/zooming: old requests for the same texture become obsolete and can be cleared from the queue to improve responsiveness.
- Parameters:
texture_id – The texture identifier (e.g., self.idx from wolf_texture)
keep_request_id – The request ID to keep (typically the most recent one)
- Returns:
Number of requests cancelled
- wolfhece.async_image_loader._global_loader: AsyncImageLoader | None = None[source]
- wolfhece.async_image_loader.get_global_loader(max_workers: int = 4) AsyncImageLoader[source]
Get or create the global image loader instance
- Parameters:
max_workers – Number of worker threads (only used on first call)
- Returns:
Global AsyncImageLoader instance