Created
October 19, 2021 18:06
-
-
Save zewt/59757a1b32c56f1f46a38a54cc00d129 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide2 import QtCore, QtGui, QtWidgets | |
from maya import OpenMayaUI as omui | |
from shiboken2 import wrapInstance | |
class ClosingWindow(QtGui.QWindow): | |
def eventFilter(self, object, event): | |
# Prevent this window from being closed. It should stay alive until Maya exits. | |
if object is self and event.type() == QtCore.QEvent.Close: | |
return True | |
return False | |
def __init__(self): | |
super().__init__() | |
# Try to stay hidden and at the end of alt-tab, but make sure we have an alt-tab entry. | |
self.setTitle('Closing...') | |
self.setFlags(QtCore.Qt.Dialog|QtCore.Qt.Window|QtCore.Qt.WindowStaysOnBottomHint) | |
self.installEventFilter(self) | |
class MainWindowFilter(QtCore.QObject): | |
def eventFilter(self, object, event): | |
# Open CloseWindow when the main Maya window is closed. | |
global window | |
if event.type() == QtCore.QEvent.Close: | |
window = ClosingWindow() | |
window.show() | |
window.setVisibility(QtGui.QWindow.Minimized) | |
return False | |
def __init__(self): | |
super().__init__() | |
main_window = omui.MQtUtil.mainWindow() | |
window = wrapInstance(int(main_window), QtWidgets.QMainWindow) | |
window.window().installEventFilter(self) | |
def go(): | |
global filter | |
filter = MainWindowFilter() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment