GUI

Tips and Tricks

How do you save and load presets within a GUI?

you need to use the optionVar command. (when the slider/control changes value is the easiest/failsafe way to do it). Check out the docs for that command and the usage examples should be obvious. shout up if not. (Naughty Nathan)

Custom Locator Node controllers

LocatorNodes.mll

How do you make them?

Have to rewrite (or use this existing rewrite and compile it) the locator class in the Maya API

NOTE: you can also increase the thickness of your controllers in the viewport by going to 'Shading >Thicker Lines'. It thickens all the lines in your scene so it's not AS great, but better than nothing..

Custom Marking Menu

Tutorial (Pratik Gulati)

Docking your custom GUI window in Maya 2011

Post on Maya Station here

and here

Customizing a Maya menu

TD Matt writes a great post here

excerpts:

Modifying the Maya constraint menu to include the snap options

In my scripts directory I have one called mayaMod. In here are all scripts that are modified versions of Maya's default scripts for building UI elements and various other things. When Maya starts, these scripts are sourced and in memory overwrite the default ones with my modified versions. With this structure I still have the default versions in their original location should things go wrong.

Note that the path is partially constructed from the string variable $NT_scriptRoot.

The picture below shows the top of AniConstraintsMenu procedure. $NT_scriptRoot is generated by calling a simple procedure that returns the highest level directory of all my scripts. By constructing paths in this way it is very easy to move your entire scripts directory between drives/projects/work/home as you only have a single procedure to modify to ensure that all your scripts can be sourced and run.

global proc AniConstraintsMenu( string $parent )

{


string $NT_scriptRoot = NT_getScriptRoot();


setParent -menu $parent;

if( `menu -q -ni $parent` != 0 ) {

//

// Menu is built already - just return

//

return;

}

(from TD Matt)

Building GUI Elements

Hi guys,

There are lots of ways to develop a Maya GUI script and I'm wondering

what options you choose and the reason or experience behind. Say, we

have the following ways to do GUI scripting:

* Native maya python way, just like the direct translation of mel

way.

* Pymel way, with OO-like widgets, helpful layout wrappers and

flexible lambda for callbacks.

* PyQt + Qt Designer way, layout your widgets in Qt Designer and

write your domain logic and behaviors.

* ... you name it...

Your opinions?

  • I've personally chosen a Maya Python OO way, building my own GUI object and

  • that works great for me.

  • Only reason for not using pymel was that I made my tools before it got

  • standardized and as I was releasing them to the masses I didn't want

  • unnecessary dependencies.

  • Reason for not to use Mayas native way is because it's silly :)

  • Would love to use Qt but haven't tried it yet - again due to keeping the

  • dependencies out of the equation.

  • However if you are developing for inhouse use only, those issues are easy to

  • settle and I'd prolly go for pymel coding and Qt interfaces :)

  • (J. Welner)

PyQT is the best way I think but it need to have PyQT wich is not in

the default python binding.

Maya2011 + loadUI can be a good alternative to "old MEL method".

(Narann)

in MEL

Adding a layout to a GUI:

use the parent flag to parent it to an existing layout on creation:

frameLayout -p 'topLayout' -n "newFrameLayout"

Removing a layout from a GUI

deleteUI -layout True "newFrameLayout"

Dynamic UI in Maya Using Python

I need to be able to save variable information from my frame layout in the GUI somewhere where it will be useful. How?

One post here

and here:

Add/Remove frameLayouts in a window using MEL (thanks Andy!!)

Icon Text Buttons

Where do you put them?

Documents\maya\2013-x64\prefs\icons

PyQT

What is PyQT?

What are the advantages of using PyQT?

But in some cases I agree. e.g. the uiTemplates are a horror with python. There all calls are converted into mel commands which then call python scripts. Not very conveniant. This way, a lot of object oriented features doesnt work.

That is why we don't use the templates, nor any ELF stuff no mas.

PyQt4 + designer = done in 5 minutes, callbacks galore, deeper/richer interfaces, pluggable/reusable components, etc, etc...

I still have die hard ELF fans at work, I do not expect them to go away anytime soon, but after a decade coding MEL and six in python and QT, I fail to understand the benefit of doing it in MEL. We have been using PyQt+Python since Maya 2008.

Albiet a little screwy in 2011 now that they have incorporated it, BUT, that just means we are technically stuck at version 4.7.1 of QT for 2011, but can still use 4.8+ for anything previous.

(Alexander Morano)

Node-based interface for Maya using PyQt

  • Tim Withers Apr 17 02:27PM -0700

  • Well hello. So I just completed this interface to be used in conjunction

  • with my Masters' Thesis and figured I'd post it here to show a little bit

  • more of what PyQt can do? The goal of the interface was to bring a

  • node-based, Houdini/Nuke/Fusion/Naiad, type interface to Maya. When I

  • started I didn't know Python or PyQt, and really didn't even know if what I

  • wanted to achieve was possible with PyQt. So I started learning! I

  • watched both of Justin Israel's videos on CMIVFX (link to these videos are

  • in my vimeo link) to get me started, then Justin mentored me through the

  • development process.

  • I wasn't sure of how flexible PyQt was or how customizable it could be.

  • Like I said, I didn't even know if making a node-based interface was

  • possible before I started, but YEP, it is! Obviously the underlying

  • algorithms are not as sophisticated as Houdini or Naiad, but it does what I

  • set out for it to do. The interface alleviates a lot of the frustrating

  • interface aspects of Maya. For me, some of the more frustrating aspects

  • are the collision events, instancing, poor menu design, lack of

  • organization, and the SHIFT+CLICK garbage to create relationships between

  • objects (WHICH ORDER DO I CLICK? I DON'T EVER REMEMBER and 9 times out of

  • 10 I get it wrong).

  • The link to the video is here: https://vimeo.com/40380911

making PyQT Window in Maya

  • "Jo Jürgens"Apr 18 04:24PM +0200

  • I played around with this a bit. Here's how to add a PyQt menu to Maya, so

  • you can have icons in Maya menus (you loose optionBoxes though)

  • http://pastebin.com/h9KG4pRz

  • import os

  • from PyQt4 import QtCore as QtCore

  • from PyQt4 import QtGui as QtGui

  • import sip

  • import pymel.all as p

  • import maya.OpenMayaUI as apiUI

  • class MayaQtMenu(QtGui.QWidget):

  • '''Show qTools menu (with icons) inside Maya'''

  • def __init__(self, name, label='', parent=None, lazy=False):

  • parent = parent or self.getMayaWindow()

  • QtGui.QWidget.__init__(self, parent)

  • label = label or name

  • self.name = name.replace(' ', '_')

  • if p.menu(self.name, exists=True):

  • p.menu(self.name, e=True, dai=True)

  • else:

  • p.menu(self.name, l=label, parent='MayaWindow')

  • self.menu = self.toQtObject(self.name)

  • if not lazy:

  • self.addItems()

  • def addItems(self):

  • '''Add menu items (actions) to menu. Placeholder. Must be implemented by

  • subclass'''

  • pass

  • def getMayaWindow(self):

  • ptr = apiUI.MQtUtil.mainWindow()

  • return sip.wrapinstance(long(ptr), QtCore.QObject)

  • def toQtObject(self, mayaName):

  • '''

  • Given the name of a Maya UI element of any type,

  • return the corresponding QWidget or QAction.

  • If the object does not exist, returns None

  • '''

  • ptr = apiUI.MQtUtil.findControl(mayaName)

  • if ptr is None:

  • ptr = apiUI.MQtUtil.findLayout(mayaName)

  • if ptr is None:

  • ptr = apiUI.MQtUtil.findMenuItem(mayaName)

  • if ptr is not None:

  • return sip.wrapinstance(long(ptr), QtCore.QObject)

  • class qtIconsMenu(MayaQtMenu):

  • def addItems(self):

  • iconPath = p.util.getEnv('MAYA_LOCATION') + '/icons/'

  • pngs = [iconPath + f for f in os.listdir(iconPath) if '.png' in f]

  • by_letter = {}

  • for f in pngs:

  • prefix = os.path.basename(f).replace('icons','').replace('icons','')[0]

  • by_letter.setdefault(prefix, [])

  • by_letter[prefix].append(f)

  • for prefix, icons in by_letter.items():

  • submenu = QtGui.QMenu(self.menu)

  • submenu.setTearOffEnabled(True)

  • submenu.setTitle(prefix)

  • self.menu.addAction(submenu.menuAction())

  • def printPath(path):

  • print path

  • for iconPath in icons:

  • icon = QtGui.QIcon()

  • icon.addPixmap(QtGui.QPixmap(iconPath),

  • QtGui.QIcon.Normal, QtGui.QIcon.Off)

  • menuItem = QtGui.QAction(self)

  • menuItem.setIcon(icon)

  • menuItem.setText(os.path.basename(iconPath))

  • menuItem.triggered.connect(lambda x, f=iconPath: printPath(f))

  • submenu.addAction(menuItem)

  • if __name__=='__main__':

  • qtIconsMenu('Maya Icons')

PyQt Web Resources

Installing PyQT for Maya 2011 (JustinFX)

PyQt wrappers for easy creation/identification of PyQt widgets/

layouts:

http://pastebin.com/kNSeTMmX

Nathan Thorpe on general PyQt & Maya usage:

http://nathanhorne.com/?p=183

Extensive thread about attaching controls to UIs created in Designer:

http://groups.google.com/group/python_inside_maya/browse_thread/thread/ffb519d21f8a46fc/d10133b98d28f036?lnk=gst&q=qt#d10133b98d28f036

(PIM user group)

http://nathanhorne.com/?p=183

http://www.creativecrash.com/maya/tutorials/scripting/mel/c/maya-mel-qt-and-you-interfacing-with-the-qt-designer

(from Maya Station)