【问题标题】:Maya / Python: How to close a custom UI window after the user has pressed enter in a textField?Maya / Python:用户在文本字段中按下回车后如何关闭自定义 UI 窗口?
【发布时间】:2012-09-06 22:59:58
【问题描述】:

我需要知道在用户按下回车后如何正确关闭此窗口。

txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)

按下回车后调用此函数:def ren():

我尝试将 cmds.deleteUI(renUI) 放入 refFc 函数中,但这会导致崩溃。

这里是完整的代码:

import maya.cmds as cmds

'''
Rename popup box for outliner - copy/paste this script into a hotkey field in the hotkey editor
'''


class ReUI():
    def __init__(self):

        renUI = 'renUI'

        if cmds.window(renUI, exists = True):
            cmds.deleteUI(renUI)

        renUI = cmds.window(renUI, t = 'JT Rename UI', sizeable = True, tb = True, mnb = False, mxb = False, menuBar = True, tlb = False, nm = 5)
        form = cmds.formLayout()
        rowA = cmds.rowColumnLayout(w = 350, h = 30)



        item = cmds.ls(os = True)[0]

        def ren():
            def renFc(self):
                print 'yes'
                tval = cmds.textField(txtA, text = True, q = True)
                cmds.rename(item, tval)

            txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)

        ren()

        cmds.showWindow(renUI)



r = ReUI()

【问题讨论】:

    标签: python window maya


    【解决方案1】:

    恐怕你遇到了一个很小的小错误。有关更多详细信息,请查看此处的线程:http://forums.cgsociety.org/archive/index.php/t-1000345.html

    只是以防链接失效 - 基本上,在 2011/2012 年,看起来有一个问题,即在 Maya/QT 完成清理之前点击 enter 并调用 deleteUI 会删除对象,从而给您一个段错误类型的情况。

    不过有一种解决方法,您想导入 maya.utils 包并在您的 deleteUI 调用周围使用 executeDeferred() 命令(请参阅:http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/Python_Python_in_Maya.htm,topicNumber=d30e725143)。到 2013 年看看这个问题是否已修复?

    我刚刚修改了您的代码以插入相关行来演示它的工作原理,但它在很大程度上依赖于字符串 'renUI'

    (哦,那个函数 ren() 并没有真正的帮助......你可以摆脱它并取消缩进那个块。)

    import maya.utils # you need this line!
    class ReUI():
        def __init__(self):
    
            renUI = 'renUI'
    
            if cmds.window(renUI, exists = True):
                cmds.deleteUI(renUI)
    
            renUI = cmds.window(renUI, t = 'JT Rename UI', sizeable = True, tb = True, mnb = False, mxb = False, menuBar = True, tlb = False, nm = 5)
            form = cmds.formLayout()
            rowA = cmds.rowColumnLayout(w = 350, h = 30)
    
    
    
            item = cmds.ls(os = True)[0]
    
            def ren():
                def renFc(self):
                    print 'yes'
                    tval = cmds.textField(txtA, text = True, q = True)
                    cmds.rename(item, tval)
                    maya.utils.executeDeferred("cmds.deleteUI('renUI')") # and this one!
    
                txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)
    
            ren()
    
            cmds.showWindow(renUI)
    
    
    
    r = ReUI()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2021-06-02
      • 2012-11-01
      • 2012-06-08
      • 2021-05-28
      • 1970-01-01
      • 2016-05-24
      相关资源
      最近更新 更多