Skip to content

menu

Motion Builder menu definition of AYON.

AYONMenu

Bases: object

Object representing AYON menu.

Source code in client/ayon_motionbuilder/api/menu.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class AYONMenu(object):
    """Object representing AYON menu.

    """

    def __init__(self):
        super().__init__()
        self.main_widget = self.get_main_widget()
        self.menu = None

        timer = QtCore.QTimer()
        # set number of event loops to wait.
        timer.setInterval(1)
        timer.timeout.connect(self._on_timer)
        timer.start()

        self._timer = timer
        self._counter = 0

    def _on_timer(self):
        if self._counter < 1:
            self._counter += 1
            return

        self._counter = 0
        self._timer.stop()
        self._build_ayon_menu()

    @staticmethod
    def get_main_widget():
        """Get motion builder main window."""
        top_widgets = QtWidgets.QApplication.topLevelWidgets()
        for widget in top_widgets:
            if widget.inherits("QMainWindow"):
                return widget
        raise RuntimeError('Cannot find motion builder main window.')

    def get_main_menubar(self) -> QtWidgets.QMenuBar:
        """Get main Menubar by motion builder main window."""
        return list(self.main_widget.findChildren(QtWidgets.QMenuBar))[0]

    def _get_or_create_ayon_menu(
            self, name: str = "&AYON",
            before: str = "&Help") -> QtWidgets.QAction:
        """Create AYON menu.

        Args:
            name (str, Optional): AYON menu name.
            before (str, Optional): Name of the motion builder main menu
                item to add AYON menu before.

        Returns:
            QtWidgets.QAction: AYON menu action.

        """
        if self.menu is not None:
            return self.menu

        menu_bar = self.get_main_menubar()
        menu_items = menu_bar.findChildren(
            QtWidgets.QMenu, options=QtCore.Qt.FindDirectChildrenOnly)
        help_action = None
        for item in menu_items:
            if name in item.title():
                # we already have AYON menu
                return item

            if before in item.title():
                help_action = item.menuAction()
        tab_menu_label = os.environ.get("AYON_MENU_LABEL") or "AYON"
        op_menu = QtWidgets.QMenu("&{}".format(tab_menu_label))
        menu_bar.insertMenu(help_action, op_menu)

        self.menu = op_menu
        return op_menu

    def _build_ayon_menu(self) -> QtWidgets.QAction:
        """Build items in AYON menu."""
        ayon_menu = self._get_or_create_ayon_menu()
        load_action = QtWidgets.QAction("Load...", ayon_menu)
        load_action.triggered.connect(self.load_callback)
        ayon_menu.addAction(load_action)

        publish_action = QtWidgets.QAction("Publish...", ayon_menu)
        publish_action.triggered.connect(self.publish_callback)
        ayon_menu.addAction(publish_action)

        manage_action = QtWidgets.QAction("Manage...", ayon_menu)
        manage_action.triggered.connect(self.manage_callback)
        ayon_menu.addAction(manage_action)

        library_action = QtWidgets.QAction("Library...", ayon_menu)
        library_action.triggered.connect(self.library_callback)
        ayon_menu.addAction(library_action)

        ayon_menu.addSeparator()
        ayon_menu = self._get_or_create_ayon_menu()
        workfiles_action = QtWidgets.QAction("Work Files...", ayon_menu)
        workfiles_action.triggered.connect(self.workfiles_callback)
        ayon_menu.addAction(workfiles_action)

    def load_callback(self):
        """Callback to show Loader tool."""
        host_tools.show_loader(parent=self.main_widget)

    def publish_callback(self):
        """Callback to show Publisher tool."""
        host_tools.show_publisher(parent=self.main_widget)

    def manage_callback(self):
        """Callback to show Scene Manager/Inventory tool."""
        host_tools.show_scene_inventory(parent=self.main_widget)

    def library_callback(self):
        """Callback to show Library Loader tool."""
        host_tools.show_library_loader(parent=self.main_widget)

    def workfiles_callback(self):
        """Callback to show Workfiles tool."""
        host_tools.show_workfiles(parent=self.main_widget)

get_main_menubar()

Get main Menubar by motion builder main window.

Source code in client/ayon_motionbuilder/api/menu.py
48
49
50
def get_main_menubar(self) -> QtWidgets.QMenuBar:
    """Get main Menubar by motion builder main window."""
    return list(self.main_widget.findChildren(QtWidgets.QMenuBar))[0]

get_main_widget() staticmethod

Get motion builder main window.

Source code in client/ayon_motionbuilder/api/menu.py
39
40
41
42
43
44
45
46
@staticmethod
def get_main_widget():
    """Get motion builder main window."""
    top_widgets = QtWidgets.QApplication.topLevelWidgets()
    for widget in top_widgets:
        if widget.inherits("QMainWindow"):
            return widget
    raise RuntimeError('Cannot find motion builder main window.')

library_callback()

Callback to show Library Loader tool.

Source code in client/ayon_motionbuilder/api/menu.py
124
125
126
def library_callback(self):
    """Callback to show Library Loader tool."""
    host_tools.show_library_loader(parent=self.main_widget)

load_callback()

Callback to show Loader tool.

Source code in client/ayon_motionbuilder/api/menu.py
112
113
114
def load_callback(self):
    """Callback to show Loader tool."""
    host_tools.show_loader(parent=self.main_widget)

manage_callback()

Callback to show Scene Manager/Inventory tool.

Source code in client/ayon_motionbuilder/api/menu.py
120
121
122
def manage_callback(self):
    """Callback to show Scene Manager/Inventory tool."""
    host_tools.show_scene_inventory(parent=self.main_widget)

publish_callback()

Callback to show Publisher tool.

Source code in client/ayon_motionbuilder/api/menu.py
116
117
118
def publish_callback(self):
    """Callback to show Publisher tool."""
    host_tools.show_publisher(parent=self.main_widget)

workfiles_callback()

Callback to show Workfiles tool.

Source code in client/ayon_motionbuilder/api/menu.py
128
129
130
def workfiles_callback(self):
    """Callback to show Workfiles tool."""
    host_tools.show_workfiles(parent=self.main_widget)