Skip to main content

Progress

The Progress API in Anchorpoint provides functionality to display progress indicators and status updates during long-running operations. Progress dialogs help users understand that operations are running and provide feedback on completion status. The progress logic is usually placed in an asynchronous function.

Usage​

The Progress class is used to show progress dialogs and status updates to users during operations. You create a Progress instance and use its methods to update the display. This code should be placed in an asynchronous function, that is managed by the context.

import anchorpoint

# Create a progress dialog
progress = anchorpoint.Progress(
title="Processing Files",
text="Please wait while files are being processed...",
infinite=False,
cancelable=True
)

# Report progress percentage
progress.report_progress(0.5) # 50% complete
progress.set_text("Processing files...")

# Check if user canceled
if progress.canceled:
print("Operation was canceled")

Progress Class​

Constructor​

  • anchorpoint.Progress(title, text=None, infinite=True, cancelable=False, show_loading_screen=False, delay=None)

    Creates a Progress object that starts spinning in the Anchorpoint UI. When creating a Progress object a spinning indicator is shown to the user indicating that something is being processed.

    Arguments

    • title (str): Title text displayed in the progress dialog
    • text (str, optional): Additional descriptive text shown below the title
    • infinite (bool, optional): If True, shows an infinite progress bar; if False, shows determinate progress (default: True)
    • cancelable (bool, optional): Whether users can cancel the operation (default: False)
    • show_loading_screen (bool, optional): Whether to show a loading screen overlay (default: False)
    • delay (float, optional): Delay in seconds before showing the progress indicator (default: None)

Methods​

  • finish() Explicitly finishes the progress indicator.

  • report_progress(percentage) Reports progress to the users by showing a loading bar. Only works if infinite=False.

    Arguments

    • percentage (float): Percentage from 0.0 to 1.0
  • set_cancelable(cancelable) Changes if the progress indicator is cancelable.

    Arguments

    • cancelable (bool): Whether to allow cancellation
  • set_text(text) Updates the text in the progress indicator.

    Arguments

    • text (str): The text to set
  • stop_progress() Falls back to a spinning progress indicator.

Properties​

canceled (bool)

  • True if the user has canceled the action
  • Can be polled when doing a long running async job to check for user cancellation
  • Returns False if the operation is still running normally

Examples​

Simple Spinning Progress​

import anchorpoint

# Create a simple infinite spinning progress indicator
progress = anchorpoint.Progress("My Action", "Rendering the scene")

# Do some work...
import time
time.sleep(2)

# Explicitly finish the progress
progress.finish()

Shows an infinite progress.

Determinate Progress with Percentage​

import anchorpoint

# Create progress with percentage reporting
progress = anchorpoint.Progress("My Action", "Rendering the scene", infinite=False)

# Report 50% progress
progress.report_progress(0.5)

# Update the text
progress.set_text("Almost done...")

# Report completion
progress.report_progress(1.0)

Shows a percentage-based progress.

Cancelable Progress​

import anchorpoint
import time

# Create cancelable progress
progress = anchorpoint.Progress("Long Operation", "Processing data...", cancelable=True)

# Simulate long operation with cancellation check
for i in range(100):
if progress.canceled:
print("Operation was canceled by user")
break

# Do some work
time.sleep(0.1)

# Update progress if using determinate mode
if not progress.infinite:
progress.report_progress(i / 100.0)

progress.finish()

In this example the option to cancel the progress is enabled. Once the user clicks on cancel, a print statement is shown and the progress is finished.

Progress Reporting in an asynchronous function​

import anchorpoint
import time

def process_files(files, progress):
"""Process a list of files with progress updates"""
total_files = len(files)

for i, file_path in enumerate(files):
# Update progress percentage
percentage = i / total_files
progress.report_progress(percentage)
progress.set_text(f"Processing: {file_path}")

# Check for cancellation
if progress.canceled:
print(f"Processing canceled at file {i}")
return False

# Simulate file processing
print(f"Processing {file_path}")
time.sleep(0.5)

# Final update
progress.report_progress(1.0)
progress.set_text("Processing complete")
return True

ctx = anchorpoint.get_context()

# Create progress object
progress = anchorpoint.Progress("Processing Files", "Processing selected files...", infinite=False, cancelable=True)

# Process selected files
if ctx.selected_files:
result = ctx.run_async(process_files, ctx.selected_files, progress)
if result:
print("All files processed successfully")
else:
print("Processing was interrupted")

This is a real life scenario how progress should be implemented in a asynchronous function using the context class.