There are a lot of dead UI hooks for python in 2009 that were re-implemented properly in 2011. My favorite is that half of the tree control accepts python callables and the other half doesn’t.
A similar problem has actually been posted here before.
I had a similar problem, and in purely academic interests, I’ll describe the solution I used here:
I ended up making a python module that would publish “anonymous” MEL procs that accepted the proper arguments and paired them with an ID, then called back into the python module from MEL with that ID to distribute the callback.
Major players:
“Client”: the code that wanted to have the UI callback
“Proxy”: the singleton that brokered the callback
General flow:
[ul]
[li]Client asks Proxy for something to give the UI callback and provides the callable it wants to be called. That looks like:
[/li]
melCall = Proxy.GetCallback( callable, [argType, argType, argType], retType )
[li]Proxy creates a UUID and publishes an “anonymous” MEL proc that loops back to the Proxy module. If you want to bullet-proof against the one-in-a-zillion UUID collision here, you do a whatIs on the potential proc first to make sure you’re clear.
[/li]
maya.mel.eval( 'global proc [retType] [namespace]_[UUID]_proc( [argType] $arg1, [argType] $arg2, [argType] $arg3 ){ return python( "Proxy.Call([UUID], " + $arg1 + "," + $arg2 + "," + $arg3 + ")" ); }' )
stringArrayToString is cleaner in practice, but + is simpler for the example.
[li]Proxy stores a dictionary with the UUID as the key, and a weakref to the callable then returns the generated proc name.
[/li][li]Client uses the MEL proc as the argument for the ui callback.
[/li]
b1=button( l='apples', p=f, w=60, h=20, dgc=melCall )
[li]When Maya hits the callback it goes to the “anonymous” proc, which calls the Proxy.
[/li][li]Proxy uses the UUID to grab the right callable from it’s internal dictionary, and pushes it to the proper callback if it’s still valid, otherwise it nukes the reference to keep the dictionary tidy.
[/li][/ul]
Scariest looking thing I’ve ever written, and it’s very important that you’re using the right singleton paradigm or else you’ll start missing callbacks. Luckily, by doing this, Proxy is the only piece of code that has to obey those very specific requirements. The exercise of actually constructing that horrific MEL procedure generating function is best left to the reader.
It’s terrible, but it works for every case of the UI being busted in python but not MEL in 2009 that I could find. Many of these were fixed in 2011, and 2011 even introduced a feature by which it is easier to register MEL functions for python calls such as this which mostly negates the need for the monstrosity I wrote.
A simpler solution, if you don’t need it to be general case, is to just publish a few specific MEL functions manually. Or if you’re going to be upgrading anytime soon, I’d just put this down as another tickmark for “should upgrade.”
I’ve been removed from this piece of code for a long time, and unfortunately cannot provide it verbatim, but if you have any other questions, I can do my best to answer them, and hopefully you strike upon an even better solution that makes me look like a fool!