::Drag and Drop Callbacks::

April 13th, 2011 by hamish download the zooToolBox

Building UI in maya is usually a fairly horrible task.  I have my own UI wrappers which make building maya less painful.  It actually makes it very similar to writing UI in toolkits like wxpython or pyqt – obviously without the ability to control painting.  And it also makes encapsulating UI really easy – which is a big deal.  Anyway if you’re interested there is a post here that goes into a bit more detail – or you can check out the code for something like the Skeleton Builder UI, or the up-coming picker tool.

Which is actually where the drag/drop functionality gets used.  So in this tool there is a canvas on which you can place “buttons” and arrange them in various ways.  These buttons can have somewhat arbitrary functionality, but by default they simply select objects.  The idea being that you can arrange them in the shape of your character such that picking the appropriate rig control is easy and intuitive (you’ve probably seen them before).  In viewport controls are great, but they can make the silhouette harder to read, and they’re sometimes hard to find which causes the animator to do more camera manipulation than is desirable.  Of course having to move the mouse/focus over to a picker tool isn’t ideal either but it definitely has its time and place in the toolset.

But again I digress.  So part of making the tool reasonably easy to use is to make it easy to arrange these buttons – and the easiest way to do that is to use a drag and drop paradigm.  Well, I guess technically the easiest way is to make it auto-magic, but that is a topic for a future post (and is an up-coming skeleton builder feature!  ;).

Anyway – so drag and drop.  I’ve never bothered with drag and drop in maya before.  Looking at the docs I figued it’d be straight forward enough.  And in hindsight it actually is straight forward – although when I was prototyping I was blocked by a horrible bug/shortcoming.

Currently I’m laden with maya 2009 – and the following doesn’t seem to apply to 2011 (not sure about 2010).  But in 2009 if you set a drop callback that returns nothing, or an empty list – the drop callback silently fails.  Thats right – no warning, no error, no exception, just silent failure.  In fact, for awhile there I figured perhaps drop callbacks hadn’t been implemented in 2009 for python.  It wouldn’t be the first widget to be incompletely exposed via python – look at the press command for the treeView widget (incidentally the tree widget wrapping in baseMelUI has a nice workaround for this)…

Just to be explicit – here is an example that fails:

def dropCB( * ): return []

By changing the drop callback to return [""] makes everything work as expected.

Anyway – hopefully this little nugget saves someone else a few tufts of hair.  Of course, after discovering this I found this page – which, while not talking python here would probably have put me back on track.


This post is public domain

This entry was posted on Wednesday, April 13th, 2011 at 09:40 and is filed under main. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.