Book Image

Practical Maya Programming with Python

By : Robert Galanakis
Book Image

Practical Maya Programming with Python

By: Robert Galanakis

Overview of this book

Table of Contents (17 chapters)
Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with menus


Working effectively with Maya's menu system involves marrying Maya UI commands with PySide to get the best of both worlds. Maya's menus are an abstraction of standard Qt widgets, and we should use that same abstraction, through UI commands, rather than creating our own. However, we may still want to work with the controls in more sophisticated ways than Maya allows, requiring us access to the actual Qt object.

For the next few sections, we'll create a way to highlight menu items as new until the first time they are clicked.

Creating a top-level menu

Maya's UI commands work just like its other commands. A UI object is represented by a pipe-delimited hierarchical path, such as 'MayaWindow|DemoMenu|menuItem254'. When we use a command to create a UI object, such as a menu, we need to know the path to its parent.

In the case of creating an entry on Maya's menu bar alongside File, Edit, and Help, we need to know the path to the main Maya window. We can do this through the following...