Executing IronPython Codes with Progress Bar

I had a code to reload data table (which takes long time) and end users were keep on hitting Action button as they were not sure if something is happening. Sounds familiar to you as well ?
What to do ?
Probably if they see a progress bar it will be better, right ? Well TIBCO Community already have a post about it. Then why this post ?
Because you need keep a few things in mind -

  1. I don't like code - fewer lines would have done the thing 👲
  2. No error stack-trace 
  3. Some extra precautions needed.💀
Let's start. First of all, my code -

from Spotfire.Dxp.Framework.ApplicationModel import *
import traceback , time

proc=Application.GetService[ProgressService]()
def ex():
try:
# Wait for 5 seconds, Just to keep progress screen up for demo - remove from actual code
time.sleep(5)
proc.CurrentProgress.ExecuteSubtask("Refreshing Data")
Document.Data.Tables.ReloadAllData()
proc.CurrentProgress.ExecuteSubtask("Refresh is Complete")
except:
traceback.print_exc()
proc.ExecuteWithProgress("Refreshing Data Manually","Trying to refresh all Data Tables with a progress bar", ex)

Now coming back to precautions; this thing should be unchecked if you don't want to struggle with an error -
Also, please handle the exceptions wisely, using default except block may help in debug; but a well handled code brings robustness.
Regarding additional wait- do not use if you don't need it.
This is what you can expect in client -

Share: