Disable one UI button with another [Python]

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 05 May 2013   #1
Disable one UI button with another [Python]

I need some help with a UI i'm developing. Basically I have two methods of adding information but only one can be used for the tool to work. I have looked at the disable command but I need a way to set it to alternate depending on which button is pressed first. This is kind of what I was thinking:

if button[1] is pressed:
cmds.disable(button[2])
if button[2] is pressed:
cmds.disable(button[1])

If there is a simpler way that would also be helpful to know. Thanks
 
Old 05 May 2013   #2
The code below disable one or another button.
Clearly, after you disable one button, you will not be able to disable the other one!

Code:
import maya.cmds as mc from functools import partial class BaseWindow(object): def __init__(self): self.name = 'baseWindow' self.title = 'Base Window' if (mc.window(self.name, q=1, exists=1)): mc.deleteUI(self.name) self.myWindow = mc.window(self.name, title=self.title) self.myLayout = mc.rowLayout(nc=2) self.buttonA = mc.button('buttonA', l='Button A', c=partial(self.disableButton, 'buttonB')) self.buttonB = mc.button('buttonB', l='Button B', c=partial(self.disableButton, 'buttonA')) mc.showWindow(self.myWindow) def disableButton(self, buttonName, *args): mc.button(buttonName, e=True, enable=False) BaseWindow()
 
Old 05 May 2013   #3
@Jamone22: Did you consider using a radio button group?

David
__________________
http://www.djx.com.au
 
Old 11 November 2013   #4
Hi guys, I'm a similar situation where I have a bunch of buttons in sequence.
button 1, button 2, button 3

I would like to have the second one disabled at the beginning, and enable it after the first one is pressed, and have the other two disabled when the second one is enabled, and get back where it is disabled and the other 2 enabled when I press it back again.

Is it too tricky ?
Cheers guys.
 
Old 11 November 2013   #5
organize it so that there is one place that decides which buttons are enabled and which are not. rerun that function everytime any of the buttons are clicked. will be easier to maintain this way.
__________________
Victor
ngskintools.com - skinning plugin for Autodesk Maya
 
Old 11 November 2013   #6
Quote:
Originally Posted by uiron
organize it so that there is one place that decides which buttons are enabled and which are not. rerun that function everytime any of the buttons are clicked. will be easier to maintain this way.



Hi there, I thought about that, but cause I'm not that good in scripting, I was hoping a little example ? just a base really, the concept, and then I'll work it out .

Cheers
 
Old 11 November 2013   #7
won't be a working example, but to get the idea:

Code:
currentStep = 1 def updateUI(): mc.button(button1, e=True, enable=currentStep==1) mc.button(button2, e=True, enable=currentStep==2) mc.button(button3, e=True, enable=currentStep==3) def button1Handler(): // do button 1 work currentStep = 2 updateUI() def button2Handler(): currentStep = 3 updateUI() def button3Handler(): currentStep = 1 updateUI()


updateUI method becomes a single central place where, based on current state, you decide what should be enabled and what not.
__________________
Victor
ngskintools.com - skinning plugin for Autodesk Maya
 
Old 11 November 2013   #8
Quote:
Originally Posted by uiron
won't be a working example, but to get the idea:

Code:
currentStep = 1 def updateUI(): mc.button(button1, e=True, enable=currentStep==1) mc.button(button2, e=True, enable=currentStep==2) mc.button(button3, e=True, enable=currentStep==3) def button1Handler(): // do button 1 work currentStep = 2 updateUI() def button2Handler(): currentStep = 3 updateUI() def button3Handler(): currentStep = 1 updateUI()


updateUI method becomes a single central place where, based on current state, you decide what should be enabled and what not.


Thank you very much !
 
Old 11 November 2013   #9
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.
 
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 10:39 PM.


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