How to make a persistent menu on a panel?

How to make a persistent menu on a panel?

manuel.spkDKCCG
Contributor Contributor
919 Views
2 Replies
Message 1 of 3

How to make a persistent menu on a panel?

manuel.spkDKCCG
Contributor
Contributor

Hi!
I'm trying to add a new menu on the Camera Sequencer's (or any other window) menu bar.

I'm using this command, as I read on the documentation:

 

cmds.menu( label='Tools', parent="sequenceEditorPanel1")

 

And this works great. When I execute It, I can see my new menu called "Tools" on the Camera Sequencer window.

The only problem comes, when I close this Window, and opened It again, the menu has gone away.

So... Do I have to call this line everytime I open my Camera Sequencer Window? If so... How can I do this?
Is there any way to make this menu persistent?

Thanks!

0 Likes
Accepted solutions (1)
920 Views
2 Replies
Replies (2)
Message 2 of 3

tdHendrix
Collaborator
Collaborator

Maya has a file that it runs at startup called userSetup.py. You can put your code in there and it should show up every time you open Maya.

 

My userSetup.py directory is here: C:\Users\your.name\Documents\maya\scripts


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter
0 Likes
Message 3 of 3

manuel.spkDKCCG
Contributor
Contributor
Accepted solution

Thanks! But I guess that would not solve my problem, because my menu is disapearing everytime I close the Camera Sequencer Window... not the Maya Window.

 

If this can help someone, I've come to this (not optimal, I guess) solution, based on other solutions I've found. While Maya is in Idle state, is constantly asking if Camera Sequencer is opened. When It's opened, It adds the Tools Menu on the window.

 

import maya.cmds as cmds
import pymel.core as pm

class WindowWatcher():
    """ A class to watch for a particular window in Maya """

    def __init__(self, window_name, on_open_callback, on_close_callback=None):
        self.window_name = window_name
        self.on_open_callback = on_open_callback
        self.on_close_callback = on_close_callback
        self.window_opened = False       

    def check_for_window_open(self):        
        if not self.window_opened:
            if self.window_name in cmds.getPanel(vis=1):
                self.on_open_callback.__call__()
                self.window_opened = True
        else:
            if not self.window_name in cmds.getPanel(vis=1):
                self.window_opened = False
                if self.on_close_callback:
                    self.on_close_callback.__call__()


camera_sequencer_name = "sequenceEditorPanel1"
def on_open_camera_sequencer():
    # your on_window_open code here
    cmds.menu( label='Tools', parent="sequenceEditorPanel1", tearOff = True)

camera_sequencer_watcher = WindowWatcher(camera_sequencer_name, on_open_camera_sequencer)

cmds.scriptJob(event=["idle", pm.windows.Callback(camera_sequencer_watcher.check_for_window_open)])

 

I'm pretty sure there's a better way to do this, but I couldn't find It. If someone knows a better solution, pls, I'd love to know.

Thanks!

0 Likes