Why is Maya 2009 TreeView handling syntax error when dragging?
I am using TreeView control in Maya 2009 but I am getting syntax error when dragging. My code looks like this (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 dragging and dropping an item, I get the following command 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 ran into were with treeView still making MEL function calls in most of its callbacks. The above errors are raised by the MEL interpreter as it tries to pass command name arguments.
source to share
See http://download.autodesk.com/us/maya/2009help/CommandsPython/treeView.html : dragAndDropCommand is STRING - you are passing a related method to Maya using its view. I'm not sure, but I suspect the line should be calling a top-level (module-level) function and not a bound method.
source to share
As of May 2010, the treeView widget still requires a row name for the mel procedure for some of its callbacks, but not others. For example dragCallback and dropCallback work as expected, but selectCommand and others don't. Many other widgets accept python function for their callbacks. Although the docs list the arguments for some of the treeView callbacks as strings, it is not specified that the string should be the name of a mel procedure, and this is certainly controversial.
source to share