mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Add popup() function for the menu so we can trigger it to pop-up
This commit is contained in:
parent
4a09ffd0f1
commit
1d7a43e5ca
1 changed files with 22 additions and 5 deletions
|
|
@ -2,7 +2,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from avalon.vendor.Qt import QtWidgets, QtCore
|
from avalon.vendor.Qt import QtWidgets, QtCore, QtGui
|
||||||
|
|
||||||
import maya.cmds as cmds
|
import maya.cmds as cmds
|
||||||
|
|
||||||
|
|
@ -12,6 +12,15 @@ self._menu = "colorbleed"
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_menu():
|
||||||
|
"""Return the menu instance if it currently exists in Maya"""
|
||||||
|
|
||||||
|
app = QtWidgets.QApplication.instance()
|
||||||
|
widgets = dict((w.objectName(), w) for w in app.allWidgets())
|
||||||
|
menu = widgets.get(self._menu)
|
||||||
|
return menu
|
||||||
|
|
||||||
|
|
||||||
def deferred():
|
def deferred():
|
||||||
|
|
||||||
import scriptsmenu.launchformaya as launchformaya
|
import scriptsmenu.launchformaya as launchformaya
|
||||||
|
|
@ -37,12 +46,11 @@ def deferred():
|
||||||
|
|
||||||
def uninstall():
|
def uninstall():
|
||||||
|
|
||||||
log.info("Attempting to uninstall ..")
|
menu = _get_menu()
|
||||||
app = QtWidgets.QApplication.instance()
|
|
||||||
widgets = dict((w.objectName(), w) for w in app.allWidgets())
|
|
||||||
menu = widgets.get(self._menu)
|
|
||||||
|
|
||||||
if menu:
|
if menu:
|
||||||
|
log.info("Attempting to uninstall ..")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
menu.deleteLater()
|
menu.deleteLater()
|
||||||
del menu
|
del menu
|
||||||
|
|
@ -55,3 +63,12 @@ def install():
|
||||||
uninstall()
|
uninstall()
|
||||||
# Allow time for uninstallation to finish.
|
# Allow time for uninstallation to finish.
|
||||||
cmds.evalDeferred(deferred)
|
cmds.evalDeferred(deferred)
|
||||||
|
|
||||||
|
|
||||||
|
def popup():
|
||||||
|
"""Pop-up the existing menu near the mouse cursor"""
|
||||||
|
menu = _get_menu()
|
||||||
|
|
||||||
|
cursor = QtGui.QCursor()
|
||||||
|
point = cursor.pos()
|
||||||
|
menu.exec_(point)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue