为什么 Maya 2009 TreeView 控件在拖动时出现语法错误?
我在 Maya 2009 中使用 TreeView 控件,但在拖放时遇到语法错误。 我的代码如下(为了简洁而简化):
class View(event.Dispatcher):
def __init__(self):
self.window = cmds.window()
tree_view = cmds.treeView(
numberOfButtons=1,
allowReparenting=True,
dragAndDropCommand=self.tree_view_onDrag
)
cmds.showWindow(self.window)
def tree_view_onDrag(self, dropped_items, old_parents, old_indexes, new_parent, new_indexes, item_before, item_after, *args):
print "worked"
当我拖放元素时,我在控制台中执行以下命令:
<bound method View.tree_view_onDrag of {"layer 3"} {""} {1} "layer 1" {0} "" "layer 2";
并收到以下错误:
// Error: <bound method View.tree_view_onDrag of {"layer 3"} {""} {1} "layer 1" {0}€ //
// Error: Line 1.1: Syntax error //
编辑:事实证明,问题我遇到的问题是,treeView 仍在对其大多数事件回调执行 MEL 函数调用。 当 MEL 解释器尝试将参数提供给命令名称时,会引发上述错误。
I'm using the TreeView control in Maya 2009 but I'm getting a syntax error on drag and drop. My code is as follows (simplified for brevity):
class View(event.Dispatcher):
def __init__(self):
self.window = cmds.window()
tree_view = cmds.treeView(
numberOfButtons=1,
allowReparenting=True,
dragAndDropCommand=self.tree_view_onDrag
)
cmds.showWindow(self.window)
def tree_view_onDrag(self, dropped_items, old_parents, old_indexes, new_parent, new_indexes, item_before, item_after, *args):
print "worked"
When I drag and drop and element I get the following command is executed in the console:
<bound method View.tree_view_onDrag of {"layer 3"} {""} {1} "layer 1" {0} "" "layer 2";
And get the following error:
// Error: <bound method View.tree_view_onDrag of {"layer 3"} {""} {1} "layer 1" {0}€ //
// Error: Line 1.1: Syntax error //
EDIT: It turns out that the issues I was having were due to the treeView still implementing MEL function calls on most of its event callbacks. The errors above are being thrown by the MEL interpreter as it attempts to feed arguments to a command name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参见 http://download.autodesk.com/us/maya/2009help /CommandsPython/treeView.html:dragAndDropCommand 是一个字符串 - 您正在传递一个绑定方法,Maya 使用它的 repr。 我不确定,但我怀疑字符串应该命名顶级(模块级)函数,而不是绑定方法。
See http://download.autodesk.com/us/maya/2009help/CommandsPython/treeView.html: dragAndDropCommand is a STRING -- you're passing a bound method, Maya's using its repr. I'm not sure, but I suspect that string should name a top-level (module-level) function, not a bound method.
截至 Maya 2010,treeView 小部件似乎仍然需要 mel 过程的字符串名称才能用于其某些回调,但不适用于其他回调。 例如,dragCallback 和 dropCallback 确实按预期工作,但 selectCommand 和其他命令则不然。 许多其他小部件确实接受 python 函数作为回调。 尽管文档将某些 treeView 回调的参数列为字符串,但没有说明该字符串必须是 mel 过程名称,并且它肯定是不一致的。
As of Maya 2010 the treeView widget appears to still require a string name of a mel procedure to be used for some of its callbacks, but not for others. For example, the dragCallback and dropCallback do work as expected, but the selectCommand and others don't. Many other widgets do accept a python function for their callbacks. Even though the docs list the arguments for some treeView callbacks as strings, it isn't stated that the string must be a mel procedure name, and it is certainly inconsistent.