Timer in the Maya Widget

210 views
Skip to first unread message

PBLN RAO

unread,
Sep 11, 2012, 8:28:10 AM9/11/12
to python_in...@googlegroups.com
Hi,

I just wanted to create a timer display in Maya.

I have a tool which i have docked to "right"

I added a label to the window and tried to display the counter. i am echoing the result.

i could able to see the result in the script editor but the label never gets updated and also maya doesn't respond to any of the task.

how can i make it to run separately so that i can work in maya and the timer gets updated as well (like we see time in some webpages).

Justin Israel

unread,
Sep 11, 2012, 11:15:22 AM9/11/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
I would need to see a snippet of your code to know why it isn't updating the label from a single manual operation. But once you get that working properly, you can start a QTimer to do the updates: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtimer.html

It uses the event loop. You would connect the timeout signal to your update slot. 

self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.updateLabel)
self.timer.start(1000)

PBLN RAO

unread,
Sep 12, 2012, 7:08:53 AM9/12/12
to python_in...@googlegroups.com
Justin,

find the attached file which i used to time update.
After commenting the Print statement in "Sec2TC" function. maya is responding.

But i used your Qtimer as you suggested.
timemechine.py

Justin Israel

unread,
Sep 12, 2012, 10:31:21 AM9/12/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
That while loop in your StartTimer function is a problem. You can't have the main application thread go into a blocking loop and sleep. It will hang up the app while it is running. 
So you did get rid of that completely and are using the QTimer now? No more while loops and sleeps? If so, you should be good now. 
<timemechine.py>

PBLN RAO

unread,
Sep 13, 2012, 12:41:53 AM9/13/12
to python_in...@googlegroups.com
Yes Justin,

i have shifted to QTimer now. and its fine...

Thx for your valuable guidance.
Reply all
Reply to author
Forward
0 new messages