Progressbar - python


#1

Hey Guys,
I have a small script which some times get in to too much of a process and the UI updates goes for a toss. I have a function to create progress bar and ‘executing deferred’ the main function as to run it in other thread. Now, it works but I want to make the progress bar, which is in the main thread, get updated from the other function, step by step. For eg:


def UI():
      window with progress bar
def operation():
      the actual operation
      update progressbar here
      operation
      update progressbar here and so on.. 

any thoughts? Thanks in advance guys.


#2

I’m not sure what you want. What happens if you simply try to implement it? Does it not work?


#3

No, it does not update the UI and maya gets busy doing the process if its heavy. To put it exactly, If maya is totally occupied on doing a process, even python for that case, it wont update the UI. Python has an option of new thread and update the UI in one and do the process in other, equivalent to maya.utils.exectuteDefferred. Now it loads UI but updating the progressbar is again not working.

Now, to put it simply, I want to run a function which does a heavy task (of almost 2 to 3 minutes ) and have a progress bar for it.


#4

Ah okay, what python method did you use to start the worker task in a seperate thread?


#5

do you want to run a process in another than maya thread and update maya’s control (progressbar for example)?


#6

No, not at all. The whole script runs only in maya but UI is not getting updated as maya gets busy with the task. So I want a progress bar for an operation


#7

@Haggy: I used thread from threading module and maya.utils.executeDifferred aswell.


#8

I still do not understand what you exactly do without seeing the code.

You write:

Python has an option of new thread and update the UI in one and do the process in other, equivalent to maya.utils.exectuteDefferred. Now it loads UI but updating the progressbar is again not working.

executeDeferred does not use threading. It only waits with the execution of a procedure until maya is idle. And I do not really understand why your update does not work because it is designed exactly for these process. Maybe we are talking about different things. The code below shows an example how I would implement it.

import maya.cmds as cmds
import math
window = cmds.window()
cmds.columnLayout()
progressControl = cmds.progressBar(maxValue=100, width=300)
cmds.showWindow( window )
for i in range(10000):
	for k in range(1000):
		x = math.sin(math.sin(math.cos(i))) # do some heavy work
	if i%100 == 0:
		cmds.progressBar(progressControl, edit=True, step=1)


#9

if your progress bar is in Qt use QApplication.processEvents() in your loop to update the progress bar.
if you are using the standard maya progress bar, just increment the step in your for loop.


#10

Thanks guys, but the problem for me was, I had the progress bar and other UI related items in another function and trying to update the progressbar from the other function, which actually was the problem. As I am using maya progressbar, I can’t use qt progressbar events(). Anyways, thanks for the response and I would post the code if possible so that you guys could have a better idea of what i am trying to do


#11

It should be no difference at all in which function you define which UI. e.g. you can defne the progress bar in a completly different function, method, file. As long as you know the UI name (progressControl below) of the progress bar control, you can update it.

cmds.progressBar(progressControl, edit=True, step=1)

#12

Thanks haggi… will try like this and see…