cam.operators.async_op#

Fabex ‘async_op.py’

Functions and Classes to allow asynchronous updates. Used to report progress during path calculation.

Exceptions#

AsyncCancelledException

Common base class for all non-exit exceptions.

Classes#

Module Contents#

exception AsyncCancelledException[source]#

Bases: Exception

Common base class for all non-exit exceptions.

class AsyncOperatorMixin[source]#
timer = None[source]#
coroutine = None[source]#
_is_cancelled = False[source]#
modal(context, event)[source]#

Handle modal operations for a Blender event.

This function processes events in a modal operator. It checks for specific event types, such as TIMER and ESC, and performs actions accordingly. If the event type is TIMER, it attempts to execute a tick function, managing the timer and status text in the Blender workspace. If an exception occurs during the tick execution, it handles the error gracefully by removing the timer and reporting the error. The function also allows for cancellation of the operation when the ESC key is pressed.

Parameters:
  • context (bpy.context) – The current Blender context.

  • event (bpy.types.Event) – The event being processed.

show_progress(context, text, n, value_type)[source]#

Display the progress of a task in the workspace and console.

This function updates the status text in the Blender workspace to show the current progress of a task. It formats the progress message based on the provided parameters and outputs it to both the Blender interface and the standard output. If the value of n is not None, it includes the formatted number and value type in the progress message; otherwise, it simply displays the provided text.

Parameters:
  • context – The context in which the progress is displayed (typically the Blender context).

  • text (str) – A message indicating the task being performed.

  • n (float or None) – The current progress value to be displayed.

  • value_type (str) – A string representing the type of value (e.g., percentage, units).

tick(context)[source]#

Execute a tick of the coroutine and handle its progress.

This method checks if the coroutine is initialized; if not, it initializes it by calling execute_async with the provided context. It then attempts to send a signal to the coroutine to either continue its execution or handle cancellation. If the coroutine is cancelled, it raises a StopIteration exception. The method also processes messages from the coroutine, displaying progress or other messages as needed.

Parameters:

context – The context in which the coroutine is executed.

Returns:

True if the tick was processed successfully, False if the coroutine has

completed.

Return type:

bool

Raises:
  • StopIteration – If the coroutine has completed its execution.

  • Exception – If an unexpected error occurs during the execution of the tick.

execute(context)[source]#

Execute the modal operation based on the context.

This function checks if the application is running in the background. If it is, it continuously ticks until the operation is complete. If not, it sets up a timer for the modal operation and adds the modal handler to the window manager, allowing the operation to run in a modal state.

Parameters:

context (bpy.types.Context) – The context in which the operation is executed.

Returns:

A dictionary indicating the status of the operation, either

{‘FINISHED’} if completed or {‘RUNNING_MODAL’} if running in modal.

Return type:

dict

class AsyncTestOperator[source]#

Bases: bpy.types.Operator, AsyncOperatorMixin

Test Async Operator

bl_idname = 'object.cam_async_test_operator'[source]#
bl_label = 'Test Operator for Async Stuff'[source]#
bl_options[source]#
async execute_async(context)[source]#

Execute an asynchronous operation with a progress indicator.

This function runs a loop 100 times, calling an asynchronous function to report progress for each iteration. It is designed to be used in an asynchronous context where the progress of a task needs to be tracked and reported.

Parameters:

context – The context in which the asynchronous operation is executed.