# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
# Topic: FBProgress, FBSleep

from pyfbsdk import FBProgress, FBSleep

# Create a FBProgress object and set default values for the caption and text.
lFbp = FBProgress()

# Call ProgressBegin() before use any other function and property.

# Set the custom task name.
lFbp.Caption = "My Task"

# Now simulate work being done. Sleep 20 ms at each iteration.
for lVal in range(100):
    # Stop the progress if user request cancellation by pressing and holding "ESC" key
    if (lFbp.UserRequestCancell()):

    # Change sub description of the task.    
    if (lVal < 50) :
        lFbp.Text = "Processing First Part ..."
        lFbp.Text = "Processing Second Part ..."

    # Sleep 20 ms to simulate the task execution time.
    # Update progress percentage.
    lFbp.Percent = lVal

# We must call ProgressDone() to after progress is finished or cancelled.
# to reset the progress bar to normal status.

# Cleanup.
del( lFbp, lVal, FBProgress, FBSleep )