CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-14-2013, 08:22 AM   #1
PozestStar
Your Majesty
portfolio
Melissa Starks
Cloth Sim Queen! Kinda...
Starving Artist ><
USA
 
Join Date: May 2007
Posts: 185
Send a message via AIM to PozestStar
[Python] Toggle button BG color on/off

I figured out how to toggle a buttons background color from one color to another, but I need help turning the background on and off. Here's an example. I can make the background red, but once it's red it never goes off. I'm sure I'm doing something silly. Also, if there's a more efficient way to do this, I'm all ears.

Thanks!

Code:
import maya.cmds as mc def exampleWin(): try: mc.deleteUI("eWin") except: pass eWin = mc.window("eWin", widthHeight = (300, 300), sizeable = False) eLayout = mc.rowLayout(nc = 1, parent = eWin) changeButton = mc.button("btn", width = 290, label = "Show Options", command = buttonProc) mc.showWindow(eWin) def buttonProc(*args): label = mc.button("btn", query = True, label = True) if label == "Show Options": mc.button("btn", edit = True, label = "Hide Options", enableBackground = True, backgroundColor = (1.0, 0.0, 0.0)) elif label == "Hide Options": #This is what I have, but it doesn't work mc.button("btn", edit = True, enableBackground = False, label = "Show Options") exampleWin()
 
Old 02-14-2013, 10:56 AM   #2
Nyro
Lurking
 
Nyro's Avatar
portfolio
A. D.
Vertex Slinger
Munich, Germany
 
Join Date: Dec 2006
Posts: 1,436
This is weird. I tried modifiying the code, but to no avail. It's the same in MEL by the way, so it's not a python thing. I'm testing this on Maya 2012.

Apparently, once a color is set, there is no way to force -enableBackgroundColor back to 0. I'd call this a bug, but then again, something tells me its connected to the Qt implementation in Maya.

If you look at a default button, wtihout color applied, it has this lightish grey background (value around .361). This isn't the same color as the UI background, which has .267. But we all know, when you apply a color to a regular button control, that color is applied to the rectangular background of the control, which is visible for a few pixels around the rounded edges of the button. You can see this with extreme values of 1.0 0 0 (red) and 0 1 0 (green).

However, this isn't the case for the default button, which should have its light grey background shine through at the corners. And, ecce!, if you manually change the color to a value of .361 (the default value), the corner pixels are visible.

Long essay on a minor issue. I think it's something that can't actually be done in the current implementation of Maya and Qt.

Workaround: if you're reasonably sure your users aren't using a different Qt theme (e.g. Plastique), then just manually set the -bgc to .361 .361 .361 instead of switching -ebg off.
 
Old 02-14-2013, 08:14 PM   #3
PozestStar
Your Majesty
portfolio
Melissa Starks
Cloth Sim Queen! Kinda...
Starving Artist ><
USA
 
Join Date: May 2007
Posts: 185
Send a message via AIM to PozestStar
Wow, thanks for taking the time to look into this. I didn't even mind switching from one color to another, I just thought I was doing something horribly wrong lol. In any case, thanks for the help! I really appreciate it. Now I know what to do.
 
Old 02-15-2013, 06:25 PM   #4
kdronez
Frequenter
 
kdronez's Avatar
portfolio
Veselin Gyurov
Noobie xD
Searching for Job T_T.
United Kingdom
 
Join Date: Mar 2009
Posts: 202
Quote:
Originally Posted by PozestStar
Wow, thanks for taking the time to look into this. I didn't even mind switching from one color to another, I just thought I was doing something horribly wrong lol. In any case, thanks for the help! I really appreciate it. Now I know what to do.


Heres the most redundant solution in history,but hey if they put some signal system like in Qt we wouldnt have to do it xD.

Code:
import maya.cmds as cmds def on_button_press(*args): q=cmds.button("but1",q=1,aop=1) if(q==1): cmds.button("but1",edit=1,aop=0,bgc=[1,1,1]) elif(q==0): cmds.button("but1",edit=1,aop=2,bgc=[ .361, .361, .361]) cmds.window( width=150 ) cmds.columnLayout( adjustableColumn=True ) cmds.button("but1", label='Button 1',aop=1,bgc=[ .361, .361, .361], command=on_button_press ) cmds.showWindow()
__________________
Maya Fluids own xD.
Graduate showreel:vimeo.com/64879738 xD
 
Old 02-15-2013, 06:25 PM   #5
kdronez
Frequenter
 
kdronez's Avatar
portfolio
Veselin Gyurov
Noobie xD
Searching for Job T_T.
United Kingdom
 
Join Date: Mar 2009
Posts: 202
sry for the spam here xD
__________________
Maya Fluids own xD.
Graduate showreel:vimeo.com/64879738 xD
 
Old 02-15-2013, 06:25 PM   #6
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:34 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.