CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-15-2013, 03:44 PM   #1
Jamone22
New Member
portfolio
Ben Lane
BSc 3D Computer Animation
Swansea Metropolitan
Swansea, United Kingdom
 
Join Date: Mar 2012
Posts: 13
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-15-2013, 05:40 PM   #2
nookie
Know-it-All
 
nookie's Avatar
portfolio
Luca Fiorentini
Lighting Artist
Lucasfilm Animation
Singapore, Singapore
 
Join Date: Jan 2004
Posts: 367
Send a message via MSN to nookie
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-15-2013, 10:40 PM   #3
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,347
@Jamone22: Did you consider using a radio button group?

David
__________________
http://www.djx.com.au
 
Old 11-12-2013, 11:16 AM   #4
Pisellino
PRO
 
Pisellino's Avatar
Alessio Nitti
Creative Scientist
Touch Surgery
London, United%2BKingdom
 
Join Date: Dec 2006
Posts: 77
Send a message via MSN to Pisellino
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-12-2013, 11:26 AM   #5
uiron
neglostyti
 
uiron's Avatar
portfolio
Viktoras Makauskas
Lithuania
 
Join Date: Jun 2005
Posts: 592
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-12-2013, 12:16 PM   #6
Pisellino
PRO
 
Pisellino's Avatar
Alessio Nitti
Creative Scientist
Touch Surgery
London, United%2BKingdom
 
Join Date: Dec 2006
Posts: 77
Send a message via MSN to Pisellino
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-12-2013, 12:28 PM   #7
uiron
neglostyti
 
uiron's Avatar
portfolio
Viktoras Makauskas
Lithuania
 
Join Date: Jun 2005
Posts: 592
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-12-2013, 12:41 PM   #8
Pisellino
PRO
 
Pisellino's Avatar
Alessio Nitti
Creative Scientist
Touch Surgery
London, United%2BKingdom
 
Join Date: Dec 2006
Posts: 77
Send a message via MSN to Pisellino
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-12-2013, 12:41 PM   #9
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:15 PM.


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