How to create blinking button

60 views
Skip to first unread message

Virbhadra Gupta

unread,
Mar 12, 2018, 1:42:30 AM3/12/18
to Python Programming for Autodesk Maya
Hello i am trying to create one script to create blinking image button
I can change image with image or symbolButton command
But problem it i can use any loop like while maya will be stuck while loop is running
I think we can create it using scriptjob ??
If yes how can i do it plz can anyone get me reference
Thanks in advance!!!!

Marcus Ottosson

unread,
Mar 12, 2018, 4:25:38 AM3/12/18
to python_in...@googlegroups.com
Hi Virbhadra,

Are you able to share what you have so far?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7cf3ab01-a5bb-4164-ba52-139e8cd34b8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Mar 12, 2018, 6:53:58 AM3/12/18
to python_in...@googlegroups.com
I don't see anything in scriptJob that would help with scheduling a timer function to control blinking a button. But yes you need to avoid blocking Maya's main thread. 

If you want a really basic loop to happen while some kind of mode is active and you want to blink a button, then you have to "pump" the main Maya thread during the loop with something like maya.utils.processIdleEvents(). Not the best solution available. 

If you want to stick with Maya and the python standard library only, you could maybe do this with a timer thread, and calls to maya.utils.executeInMainThreadWithResult(), which will call your blink toggle function



Using a thread let's you have a timer that doesn't block Maya and will make the call happen in the mail thread using executeInMainThreadWithResult. Using this particular call will make sure to block your button toggles until Maya is able to run them and not have the timer just stacking up toggles. 

If you want to make use of PySide you could also just do your UI work with that, and use a Qtimer or a property animation. Here is a similar answer I gave in 2012 when someone wanted to do a shakey window animation :

Justin 



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Virbhadra Gupta

unread,
Mar 14, 2018, 8:13:02 AM3/14/18
to Python Programming for Autodesk Maya
Hey this sample of my code

wid= newWin"
mode= True

cmds.window(wid)
cmds.rowLayout(nc=2, cw=(30,50)
img=cmds.image(image=circle.png)
btn=cmda.button(l="start")
cmds.showWindow(wid)

def apply():
global mode
while mode:
time.sleep(0.2)
cmds.image(img, e=True, image="circle.png")
time.sleep(0.2)
cmds.image(img, e=True, image="circlePoly.png")
if not mode:
break
t=threading.Thread(target=apply, args=())
t.start()

with this i can run separate thread in maya but this code is not updating in window i have tried cmds.refresh(win) still it won't work.
How can i hv blink effect with this.

Justin Israel

unread,
Mar 14, 2018, 2:36:08 PM3/14/18
to python_in...@googlegroups.com
Did you read my earlier reply? It addresses this exact approach. You can't call Maya API commands from another thread. You need to use the executeInMainThreadWithResult to have your call run in the main thread. 

Also I would advise against using a global variable to stop your thread. Make it a class with an apply method, and a bool field. Then you can tell the instance of that class when to stop. 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages