generated from hannesdelbeke/maya-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpip_qt_maya_plugin.py
58 lines (41 loc) · 1.97 KB
/
pip_qt_maya_plugin.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
import sys
import maya.api.OpenMaya as om
import maya.cmds as cmds
import os
MENU_NAME = "ToolsMenu" # no spaces in names, use CamelCase
MENU_LABEL = "Tools" # no spaces in names, use CamelCase
MENU_ENTRY_LABEL = "Python package manager"
MENU_PARENT = "MayaWindow" # do not change
_pip_qt_widget = None
def maya_useNewAPI(): # noqa
pass # dummy method to tell Maya this plugin uses Maya Python API 2.0
# =============================== Menu ===========================================
def show(*args):
import pip_qt
# hookup interpeter to prevent freezing during py-pip install
if not sys.executable.endswith("maya.exe"):
raise Exception(sys.executable, "doesn't end in maya.exe, can't hookup python interpreter")
pip_qt.py_pip.python_interpreter = sys.executable.replace("maya.exe", "mayapy.exe")
# TODO add support for other OS
user_home = os.path.expanduser("~")
pip_qt.py_pip.default_target_path = os.path.join(user_home, "Documents", "Maya", "scripts")
global _pip_qt_widget
_pip_qt_widget = pip_qt.show()
def loadMenu():
if not cmds.menu(f"{MENU_PARENT}|{MENU_NAME}", exists=True):
cmds.menu(MENU_NAME, label=MENU_LABEL, parent=MENU_PARENT)
cmds.menuItem(label=MENU_ENTRY_LABEL, command=show, parent=f"{MENU_PARENT}|{MENU_NAME}")
def unloadMenuItem():
if cmds.menu(MENU_NAME, exists=True):
menu_item_long_name = MENU_NAME + "|" + MENU_ENTRY_LABEL
# Check if the menu item exists; if it does, delete it
if cmds.menuItem(menu_item_long_name, exists=True):
cmds.deleteUI(menu_item_long_name, menuItem=True)
# Check if the menu is now empty; if it is, delete the menu
if not cmds.menu(MENU_NAME, query=True, itemArray=True):
cmds.deleteUI(MENU_NAME, menu=True)
# =============================== Plugin (un)load ===========================================
def initializePlugin(plugin):
loadMenu()
def uninitializePlugin(plugin):
unloadMenuItem()