带有选项按钮的双重回调
Double callback with option button
当我在 2 个选项之间切换时,它总是 returns 双结果 (tex,tex/sculpt,sculpt)。我过去的项目也发生过这种情况,但我从未解决过。重新启动 maya 没有用,即使重写代码它一直在发生。有什么建议吗?
import maya.cmds as cmds
class UI(object):
def __init__(self):
a=cmds.window()
cmds.showWindow(a)
cmds.columnLayout()
self.displaceOptions = cmds.radioButtonGrp(la2=['Texture', 'Sculpting'], nrb=2, en=True, cc=self.check)
def check(self, *args):
option = cmds.radioButtonGrp(self.displaceOptions, q=True, sl=True)
if option == 1:
self.dispTexture()
elif option == 2:
self.dispSculpt()
def dispTexture(*args):
print('tex')
def dispSculpt(*args):
print('sculpt')
UI()
原因是 changeCommand 对两次更改的状态更改作出反应,第一个单选按钮被停用,然后另一个被激活。 UI() 的第一次调用没有单选按钮 selected,如果你 select 一个,回调只被调用一次,因为状态只改变一次。
您可以使用 onCommand 或 offCommand,它们的行为应该更符合您的预期。
当我在 2 个选项之间切换时,它总是 returns 双结果 (tex,tex/sculpt,sculpt)。我过去的项目也发生过这种情况,但我从未解决过。重新启动 maya 没有用,即使重写代码它一直在发生。有什么建议吗?
import maya.cmds as cmds
class UI(object):
def __init__(self):
a=cmds.window()
cmds.showWindow(a)
cmds.columnLayout()
self.displaceOptions = cmds.radioButtonGrp(la2=['Texture', 'Sculpting'], nrb=2, en=True, cc=self.check)
def check(self, *args):
option = cmds.radioButtonGrp(self.displaceOptions, q=True, sl=True)
if option == 1:
self.dispTexture()
elif option == 2:
self.dispSculpt()
def dispTexture(*args):
print('tex')
def dispSculpt(*args):
print('sculpt')
UI()
原因是 changeCommand 对两次更改的状态更改作出反应,第一个单选按钮被停用,然后另一个被激活。 UI() 的第一次调用没有单选按钮 selected,如果你 select 一个,回调只被调用一次,因为状态只改变一次。 您可以使用 onCommand 或 offCommand,它们的行为应该更符合您的预期。