Skip to content

Commit

Permalink
add maya parenting, tested ☑
Browse files Browse the repository at this point in the history
basic parenting only, no submenu
  • Loading branch information
hannesdelbeke committed Jan 30, 2023
1 parent 63d0484 commit 7d67fea
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions unimenu/dccs/maya.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pymel.core as pm # todo replace with cmds because it's faster
from unimenu.dccs._abstract import AbstractMenuMaker
import maya.mel
import maya.cmds


class MenuMaker(AbstractMenuMaker):
Expand All @@ -11,9 +13,11 @@ def setup_menu(cls, data) -> pm.menu:
# todo parent logic currently is re implemented in every dcc module
# can we move it to the abstract class?
# if we provide a parent in the config, we might want to parent to a submenu
if parent:
menu = find_menu(parent)
else:
menu = cls.create_root_menu(label)


menu = cls.create_root_menu(label)
cls._setup_menu_items(menu, data.get("items"))
return menu

Expand All @@ -27,11 +31,11 @@ def create_root_menu(cls, label, window_name=None):
window_name = window_name or "gMainWindow" # default value

maya_window = pm.language.melGlobals[window_name]
return pm.menu(label, parent=maya_window, tearOff=True)
return pm.menu(label, parent=maya_window, tearOff=True) # todo garantuee uniqye name

@classmethod
def add_sub_menu(cls, parent, label: str):
return pm.menuItem(subMenu=True, label=label, parent=parent, tearOff=True)
return pm.menuItem(label, subMenu=True, label=label, parent=parent, tearOff=True)

@classmethod
def add_to_menu(cls, parent, label: str, command: str, icon: str = None, tooltip: str = None):
Expand All @@ -53,5 +57,18 @@ def add_separator(cls, parent, label: str = None):
return pm.menuItem(divider=True, parent=parent, dividerLabel=label)


def find_menu(name):
gMainWindow = maya.mel.eval('$temp=$gMainWindow')
# get all the menus that are children of the main menu
mainWindowMenus = maya.cmds.window(gMainWindow, query=True, menuArray=True)
for menu in mainWindowMenus:
print(menu)
if menu.lower() == name.lower():
return menu

# TODO get their children recursively



setup_menu = MenuMaker.setup_menu
teardown_menu = MenuMaker.teardown_menu

0 comments on commit 7d67fea

Please sign in to comment.