2014-09-29 48 views
0

我已经使用Maya文档中的命令从头创建了一个ui。 ,我已经写了下面的功能适用两种scenerios:maya关闭窗口信号

  1. 当用户点击到另一个按钮 - 导入,其中还会像它写的代码,然后用下面的关闭关闭功能(请参阅readFile函数)
  2. 当用户点击按钮时关闭UI而不运行任何内容。

在我的剧本,以应付上述两种情况下,我写为下面的其中closeWindow是迎合Scenario1和cancelWindow是迎合Scenario2

def ui(self): 
    ... 
    cancelButton = cmds.button(label='Cancel', command=self.cancelWindow, width=150, height=35) 

def closeWindow(self, *args): 
    cmds.deleteUI(self.window, window=True) 

def cancelWindow(self, *args): 
    cmds.delete(camSel[0]) 
    cmds.deleteUI(self.window, window=True) 

def readFile(self, *args): 
    ... 
    self.closeWindow() 

这样,是有可能创造一些通过结合上述2(自动+手动),看到类似于PyQt(clicked(),returnPressed()等)的信号,看到deleteUI命令的用法是相同的?

回答

1

默认的Maya UI只提供回调,不提供信号。您可以通过调用事件处理程序对象而不是函数来创建一种'伪信号'。在这种情况下,按钮只知道'我已经触发了按钮事件',并且处理程序可以根据需要调用尽可能多的功能。

class Handler(object): 

    def __init__(self): 
     self.handlers = [] 

    def add_handler (self, func): 
     self.handlers.append(func) 

    def __call__(self, *args, **kwargs): 
     for eachfunc in handler: 
      eachfunc(*args, **kwargs) 

hndl = Handler() 
hndl.add_handler(function1) # do some ui work... 
hndl.add_handler(function2) # do some scene work... 
hndl.add_handler(function3) # do something over network, etc.... 

b = cmds.button('twoFunctions', c = Hndl) 

在大型复杂的UI这是一个很好的方式,让小事情像按钮higlights和注意力从重要的东西,如改变场景中分离出来的变化。在你的应用程序中,它几乎肯定是矫枉过正。你只有在关闭和取消之间共享1行,这不算太糟:)

Heres'more background on on pseudo-events in maya gui

您也可以直接使用Maya的QT来获得关闭事件...再次,似乎是矫枉过正。更多here