-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathneMenuMngr.py
72 lines (53 loc) · 1.84 KB
/
neMenuMngr.py
1
2
3
4
5
6
7
8
9
10
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
# Copyright (c) 2020. James B Dunlop
# pylint: disable=import-error, invalid-name, missing-class-docstring, line-too-long, missing-module-docstring, invalid-name
import importlib
import inspect
import logging
import nemodulemapping as nemodulemapping
from neMenuManager.menuManager import MenuManager
logger = logging.getLogger(__name__)
MODULE_MAPPING = nemodulemapping.MODULE_MAPPING
def addNodeEditorMenusByNodeType(nodeType, manager=None):
"""
Args:
nodeType (str): Name of the nodeType in Maya. eg: "transform"
Returns:
neMenuManager.MenuManager()
"""
if manager is None:
manager = MenuManager()
for package, moduleName, className in MODULE_MAPPING.get(nodeType, [[None] * 3]):
if moduleName is None or package is None or className is None:
raise Exception("MODULE_MAPPING MISSING: {}".format(nodeType))
module = importlib.import_module(moduleName, package)
try:
inspect.isclass(getattr(module, className))
except AttributeError:
raise Exception(
"Failed to find class for typeID: {} in module: {}".format(
nodeType, moduleName
)
)
getClass = getattr(module, className)
neMenu = getClass()
manager.addMenu(neMenu)
return manager
def addMenus(removeExisting=False):
""" Iter through the entire MODULE_MAPPING dict and add all the nodeTypes to the menuManager.
Returns:
None
"""
manager = MenuManager()
if removeExisting:
manager.removeAll()
for nodeType in MODULE_MAPPING.keys():
addNodeEditorMenusByNodeType(nodeType, manager)
return manager
def removeMenus():
""" Removes all the menus.
Returns:
None
"""
manager = MenuManager()
manager.removeAll()
return manager