custom Menu bar

63 views
Skip to first unread message

Ronny Ascencio

unread,
Dec 20, 2024, 1:13:14 PM12/20/24
to gaffer-dev
Hello I am trying to do a custom menu in the top menu bar but I am not able to make it work i have been searching and havent found something any know have a simple but correct example? 
I am loading the .py file form a resources path  and it loads correctly is printing in terminal  the debug but is not adding the menu to the menu bar of gaffer 

here is the code :

import functools
import GafferUI
import GafferSceneUI
import Gaffer


def test_function(menu):
    print("Test menu item selected")


GafferUI.ScriptWindow.menuDefinition().append(
    "/Test/Version Up",
    {
        "command": functools.partial(test_function),
        "label": "Version Up",
        "shortCut": ""
    }
)

Murray Stevenson

unread,
Dec 20, 2024, 2:37:24 PM12/20/24
to gaffer-dev
Hi,

It looks like you're very close to a working solution. The .py file needs to be installed in a location on $GAFFER_STARTUP_PATHS, such as the gaffer/startup/gui folder in your user home directory, and you'll need to modify the following line:

`GafferUI.ScriptWindow.menuDefinition().append(`

to provide `application` to menuDefinition() so that you're modifying the menuDefinition for the current application:

`GafferUI.ScriptWindow.menuDefinition( application ).append(`

For more background, you can find a bit more info in the startup config tutorials, and in this blog post about Gaffer's app structure and startup configs: https://blog.gafferhq.org/?p=210

Cheers,

Murray

---


def test_function(menu):
    print("Test menu item selected")

GafferUI.ScriptWindow.menuDefinition( application ).append(

    "/Test/Version Up",
    {
        "command": functools.partial(test_function),
        "label": "Version Up",
        "shortCut": ""
    }
)

Reply all
Reply to author
Forward
0 new messages