+ VRED 2018 PYSIDE2

In VRED 2018 we can finally use PySide2. Here is a short example of how I add a menu to the main window on launch.

preferences

Add the following lines to the end of the script preferences

import sys

dir_name = 'path/to/dir'
if not dir_name in sys.path:
  sys.path.append(dir_name)

import your.module.menu
reload(your.module.menu)
your.module.menu.add_menu()

The contents of the menu module. This example will add a menu to the main menu bar.

from PySide2 import QtWidgets
from shiboken2 import wrapInstance
import vrVredUi
import vrScenegraph

def get_main_window(): 

       main_window_ptr = vrVredUi.getMainWindow()
       return wrapInstance(long(main_window_ptr), QtWidgets.QMainWindow)

def add_menu():

    main_window = get_main_window()
    menu_bar = main_window.menuBar()
    menu_name = 'My Menu'

    action_list = menu_bar.actions()
    for action in action_list:
        if action.text() == menu_name:
            menu_bar.removeAction(action)
            print 'Removed Menu: {}'.format(menu_name)

    menu = menu_bar.addMenu(menu_name)

    create_group_action = menu.addAction('Create Group')
    create_group_action.triggered.connect(create_group)


def create_group(): 

    vrScenegraph.createNode('Group', 'Hello Group')
    vrScenegraph.updateScenegraph(True)
    print('Group created!')