【问题标题】:How to query the "selected" item in maya's textScrollList?如何查询maya的textScrollList中的“选定”项?
【发布时间】:2017-04-03 23:33:23
【问题描述】:

我在 Maya 中使用 python,并尝试查询 textScrollList 中的“选定”项。在 Maya 的文档中,它展示了如何使用 uniqueTag 和 selectUniqueTagItem,我能够正常工作,但它不是我想要的。

在我的 textScrollList 中,它附加了一个包含列表的变量。当我使用 uniqueTag 标志时,它查询的是我分配的“标签”。我想查询列表中所选项目的内容,而不是标签名称。

例如:

tScrollList = cmds.textScrollList( numberOfRows=8, allowMultiSelection=False,
        append=fileList, showIndexedItem=4, dcc=('doubleClick()') )



def refreshGUI():

    cmds.textScrollList(tScrollList, edit=True, removeAll=True) #removes current list
    newList = searchInput() #this contains a list

    #repopulates list 
    for r in newList:
        cmds.textScrollList(tScrollList, edit=True, append=r, uniqueTag="selectedFile", dcc=('doubleClick()')) 



def doubleClick():

    cmds.textScrollList(tScrollList, edit=True, selectUniqueTagItem=["selectedFile"])

    clickList = cmds.textScrollList(tScrollList, query=True, selectUniqueTagItem= True)   
    print clickList

在我的 gui 中双击该项目,此示例将打印“selectedFile”。我正在尝试打印该列表中实际选定的项目,而不是该标签名称。谷歌搜索后我似乎找不到示例,任何帮助/示例将不胜感激!非常感谢。

【问题讨论】:

    标签: python user-interface maya


    【解决方案1】:

    您需要使用选择或双击命令,请查看docs,它非常清楚。

    这是一个工作的最小版本

    import maya.cmds as cmds
    
    cmds.window()
    cmds.paneLayout()
    fooBar = cmds.textScrollList( numberOfRows=8, allowMultiSelection=True,
                append=['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
                        'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen'],
                selectItem='six', showIndexedItem=4, dcc = "getSelected()")
    cmds.showWindow()
    
    def getSelected():
        someList = cmds.textScrollList(fooBar, q=1, si=1)
        print someList
    

    【讨论】:

    • 您好 Achayan,感谢您的回复。我确实使用了双击命令,它位于我的第一个 textScrollList 的第二行,它指向我的 doubleClick() 函数。我确实注意到你没有使用 uniqueTag 标志......我会试一试,看看它是否有效。
    • 成功了!!删除 uniqueTag 标志并简单地将 selectItem 标志添加为 True 使其返回列表中选择的确切项目。非常感谢。
    • 但是如果 textScrollList 对象被包装在类而不是模块级范围内怎么办。
    猜你喜欢
    • 2013-10-06
    • 2023-03-28
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    相关资源
    最近更新 更多