How do I update a ProgressBarControl during a loop in DL6?

I am updating one of our job scripts for deadline 6 which iterates through the selected jobs and creates new jobs. I can’t seem to update my progress bar during the submission loop Is there a way to for a DeadlineScriptDialog() to update? The console indicates I am feeding correct values to “ProgressBox”

Thanks,
Dan

[code] # Update progress Bar

		progress = int (100.0/numJobs)
		progress = (i+1)*progress
		if progress > 100:
			progress = 100
		scriptDialog.SetValue( "ProgressBox", progress )
		print progress			

[/code]

Can you post your script, or a simple script that reproduces the problem? We can test it here and try to figure out the problem.

Thanks!

  • Ryan

Here goes - core logic pulled out and replaced with some sleep time.

[code]’’’
test job script
‘’’

from System.IO import *
from System.Text import *

from Deadline.Scripting import *
from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog

from datetime import date

import os
import shutil
import ConfigParser
import time

########################################################################

Globals

########################################################################

scriptDialog = None
settings = None

########################################################################

Main Function Called By Deadline

########################################################################

def main():
global scriptDialog
global settings

dialogWidth = 300
dialogHeight = 265
labelWidth = 100
tabHeight = 600
padding = 24
smallControlWidth = dialogWidth-labelWidth-padding
fullControlWidth = dialogWidth-labelWidth-padding

scriptDialog = DeadlineScriptDialog()
scriptDialog.SetSize( dialogWidth+padding, dialogHeight )
scriptDialog.SetTitle( 'Test Script' )



# Progress Bar
scriptDialog.AddRow()
scriptDialog.AddRangeControl( "ProgressBox", "ProgressBarControl", 1, 1, 100, 0, 0, dialogWidth, -1 )
scriptDialog.EndRow()


# Submit and Cancel buttons
scriptDialog.AddRow()
cancelButton = scriptDialog.AddControl( 'CancelButton', 'ButtonControl', 'Cancel', 100, -1 )
cancelButton.ValueModified.connect(CancelButtonPressed)
submitButton = scriptDialog.AddControl( 'SubmitButton', 'ButtonControl', 'Submit', 100, -1)
submitButton.ValueModified.connect(SubmitButtonPressed)
scriptDialog.EndRow()

scriptDialog.ShowDialog( True )

########################################################################

Helper Functions

########################################################################

########################################################################

Button Functions

########################################################################

def CancelButtonPressed( *args ):
global scriptDialog
scriptDialog.CloseDialog()

def SubmitButtonPressed( *args ):
global scriptDialog

submitResultsString = ''

# Get list of jobs
jobs = JobUtils.GetSelectedJobs()
numJobs = len( jobs )


# Iterate through selected jobs
for i in range( 0, numJobs ):
	job = jobs [i]
	outputDirectories = job.JobOutputDirectories
	outputFilenames = job.JobOutputFileNames
	
	# Iterate thrugh renders in job
	for j in range ( 0, len (outputDirectories) ):

		# simulate job sumbmission
		time.sleep(2)
		
		# Update progress Bar 
		progress = int (100.0/numJobs)
		progress = (i+1)*progress
		if progress > 100:
			progress = 100
		scriptDialog.SetValue( "ProgressBox", progress )
		print ("Perecent of jobs submitted: " + str(progress) + "\n" )
		
	
	
scriptDialog.CloseDialog()
scriptDialog.ShowMessageBox ( "Full submission results are in console. Last submission results:\n\n" + submitResultsString , 'Results of Submission' )

[/code]

Thanks! We were able to reproduce, and this will be fixed in 6.1.

I’ve attached a script that works around the problem for now. It stores the progress bar control as a global and repaints it after every value update.

'''
test job script
'''


from System.IO import *
from System.Text import *

from Deadline.Scripting import *
from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog

from datetime import date

import os
import shutil
import ConfigParser
import time

########################################################################
## Globals
########################################################################

scriptDialog = None
settings = None
progressBarControl = None

########################################################################
## Main Function Called By Deadline
########################################################################

def __main__():
   global scriptDialog
   global settings
   global progressBarControl
   
   dialogWidth = 300
   dialogHeight = 265
   labelWidth = 100
   tabHeight = 600
   padding = 24
   smallControlWidth = dialogWidth-labelWidth-padding
   fullControlWidth = dialogWidth-labelWidth-padding
   
   scriptDialog = DeadlineScriptDialog()
   scriptDialog.SetSize( dialogWidth+padding, dialogHeight )
   scriptDialog.SetTitle( 'Test Script' )
   


   # Progress Bar
   scriptDialog.AddRow()
   progressBarControl = scriptDialog.AddRangeControl( "ProgressBox", "ProgressBarControl", 1, 1, 100, 0, 0, dialogWidth, -1 )
   scriptDialog.EndRow()


   # Submit and Cancel buttons
   scriptDialog.AddRow()
   cancelButton = scriptDialog.AddControl( 'CancelButton', 'ButtonControl', 'Cancel', 100, -1 )
   cancelButton.ValueModified.connect(CancelButtonPressed)
   submitButton = scriptDialog.AddControl( 'SubmitButton', 'ButtonControl', 'Submit', 100, -1)
   submitButton.ValueModified.connect(SubmitButtonPressed)
   scriptDialog.EndRow()
   
   scriptDialog.ShowDialog( True )


########################################################################
## Helper Functions
########################################################################
   

########################################################################
## Button Functions
########################################################################




def CancelButtonPressed( *args ):
   global scriptDialog
   scriptDialog.CloseDialog()


def SubmitButtonPressed( *args ):
   global scriptDialog
   global progressBarControl
   
   submitResultsString = ''
   
   # Get list of jobs
   jobs = JobUtils.GetSelectedJobs()
   numJobs = len( jobs )
   

   # Iterate through selected jobs
   for i in range( 0, numJobs ):
      job = jobs [i]
      outputDirectories = job.JobOutputDirectories
      outputFilenames = job.JobOutputFileNames
      
      # Iterate thrugh renders in job
      for j in range ( 0, len (outputDirectories) ):

         # simulate job sumbmission
         time.sleep(2)
         
         # Update progress Bar 
         progress = int (100.0/numJobs)
         progress = (i+1)*progress
         if progress > 100:
            progress = 100
         scriptDialog.SetValue( "ProgressBox", progress )
         progressBarControl.repaint()
         print ("Perecent of jobs submitted: " + str(progress) + "\n" )
         
      
      
   scriptDialog.CloseDialog()
   scriptDialog.ShowMessageBox ( "Full submission results are in console. Last submission results:\n\n" + submitResultsString , 'Results of Submission' )

thanks, Ryan!

I spoke too soon - The work around doesn’t work on OSX (it does on windows). The behaviour is still the same. Will wait for a fix in DL 6.1

Hmm, that fix I gave you is what we’re doing internally now, so it sounds like that still won’t help for OSX.

You may need to set up a thread in your UI to make it work properly. The problem is that you’re trying to update the UI in a blocking loop, and the UI doesn’t become responsive until that loop is finished. If you want to see an example of a script UI that uses threading, you can look at the Shotgun UI script that is shipped with Deadline:
\your\repository\events\Shotgun\ShotgunUI.py

Cheers,

  • Ryan

Thanks Ryan. I thought that’s what was probably going on. I’ll take a look at the shotgun script.

OOP confuses me and I couldn’t come up with a clean working solution. Based on the python threading docs I came up with a kludge that gives feedback in the console and lets the user continue working. (I got rid of the progress bar)

[code]’’’
test job script
‘’’

from System.IO import *
from System.Text import *

from Deadline.Scripting import *
from DeadlineUI.Controls.Scripting.DeadlineScriptDialog import DeadlineScriptDialog

from datetime import date

import os
import shutil
import ConfigParser
import time
import threading

########################################################################

Globals

########################################################################

scriptDialog = None
settings = None
progressBarControl = None

########################################################################

Threads To do core logic and interface update

########################################################################

class workThread ( threading.Thread):
def init(self, threadID, name ):
threading.Thread.init(self)
self.threadID = threadID
self.name = name
def run(self):
global scriptDialog

	print "Starting " + self.name
	SubmitJobs()
	print "Exiting " + self.name

########################################################################

Main Function Called By Deadline

########################################################################

def main():
global scriptDialog
global settings
global progressBarControl

dialogWidth = 300
dialogHeight = 265
labelWidth = 100
tabHeight = 600
padding = 24
smallControlWidth = dialogWidth-labelWidth-padding
fullControlWidth = dialogWidth-labelWidth-padding

scriptDialog = DeadlineScriptDialog()
scriptDialog.SetSize( dialogWidth+padding, dialogHeight )
scriptDialog.SetTitle( 'Test Script' )


# Submit and Cancel buttons
scriptDialog.AddRow()
cancelButton = scriptDialog.AddControl( 'CancelButton', 'ButtonControl', 'Cancel', 100, -1 )
cancelButton.ValueModified.connect(CancelButtonPressed)
submitButton = scriptDialog.AddControl( 'SubmitButton', 'ButtonControl', 'Submit', 100, -1)
submitButton.ValueModified.connect(SubmitButtonPressed)
scriptDialog.EndRow()

scriptDialog.ShowDialog( True )

########################################################################

Helper Functions

########################################################################

def SubmitJobs ():
submitResultsString = ‘’

# Get list of jobs
jobs = JobUtils.GetSelectedJobs()
numJobs = len( jobs )


# Iterate through selected jobs
for i in range( 0, numJobs ):
	job = jobs [i]
	outputDirectories = job.JobOutputDirectories
	outputFilenames = job.JobOutputFileNames
	
	# Iterate thrugh renders in job
	for j in range ( 0, len (outputDirectories) ):

		# simulate job sumbmission
		time.sleep(2)
		
		# Update progress Bar 
		progress = int (100.0/numJobs)
		progress = (i+1)*progress
		if progress > 100:
			progress = 100
		print ("Perecent of jobs submitted: " + str(progress) + "\n" )

########################################################################

Button Functions

########################################################################

def CancelButtonPressed( *args ):
global scriptDialog
scriptDialog.CloseDialog()

def SubmitButtonPressed( *args ):
global scriptDialog

workerThread = workThread (1, "workThread")
workerThread.start()
scriptDialog.CloseDialog()
scriptDialog.ShowMessageBox ( "Full submission results are in console and your jobs will start appearing soon", 'Results of Submission' )[/code]