::UI “Events” in maya::

March 10th, 2010 by hamish download the zooToolBox

I have a feeling UI programming in maya will actually not suck anywhere near as much with 2011 coming along soon.  I’m not 100% sure, but it sounds as though you’ll be able to use the scripted bindings for QT directly in maya for UI work in 2011.  If this is true – and I’m not sure it is – then things will certainly get a lot more exciting.  I’ve been restricted many times by maya’s lack of decent UI in the past, and integrating something like wxpython, while possible, is also a drag.

So anyway, this last week I was writing some UI to a tool that isn’t really finalized yet.  I want to keep the UI code flexible and modular so that its easy to change it up without creating a bunch of work.  Anyway if you’ve ever programmed UI using WX or QT there is this concept of events.  Basically pieces of UI can listen to events of a certain kind and define a function that gets called when that widget “hears” such an event.  Event driven UI’s are pretty common and make for a really powerful way of expressing action and reaction without having to make widgets aware of one another.  Because you’re not defining the relationship between widgets, doing things like radically changing up UI layouts is easier to achieve.

Anyway, so I wanted something like this in maya for my mel UIs.  So I made the simplest solution on the planet – which actually works out really well.  Basically I have a bunch of classes I wrote that wrap the maya mel UI widgets.  The base class has a sendEvent method and a process event method.  The sendEvent method basically just walks up the UI hierarchy and runs processEvent with the given event args.  And thats it.  Super simple, but it means I can write modular UI classes, and glue them together easily, or break off a piece of UI into a separate window etc.

Previously I’ve had to have child UI hold a handle to parent UI to call update functions or vice versa which makes this sort of modularization annoying at best, impossible at worst.  So anyway, super low tech simple solution – works a charm.  Anyone got a better idea?

Share

This post is public domain

This entry was posted on Wednesday, March 10th, 2010 at 22:19 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.

  • Francois Maree

    Found this cool clip showing the guy creating a UI in Maya 2011. Not sure if you seen it but it looks rad!

    http://area.autodesk.com/blogs/stevenr/maya_2011_highlight_qt_user_interface

  • hamish

    eff yes. sweet, thanks for that. looks great. finally, decent UI for tools… i hope its easy to code up UI from python

  • Chad Dombrova

    yup, now that 2011 is built using Qt, you can use PyQt to get the running QApplication and add widgets to it. no need for pump thread. i’m looking to add a good set of PyQt tools for PyMEL (which is included in 2011, btw!)

  • hamish

    nice! yeah the QT thing makes me excited about 2011. the last time I got excited about a maya release was whatever version they release python integration. being able to leverage the same UI code inside or outside of maya is a big deal.

  • Clint

    I have been testing your animStore script for captureing and applying animation in Maya. Then we migrated to Windows Vista and now Win 7. Since then the AnimStore wont display poses nor save animation into the stores. Is this something tied to the coding that relates to the OS or might there be some other reason or fix. Thanks. Hope we can find a solution I really like the tool over others out there.

  • hamish

    bummer. i’m not familiar with windows7 – i’m still on XP and vista. its unlikely that there is code that would break under windows7 (although I can’t guarantee that). the display thing may be related to video card perhaps, but i’m not sure how to debug such an issue remotely i’m afraid.