Skip to content

Instantly share code, notes, and snippets.

@zewt
Created October 19, 2021 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zewt/59757a1b32c56f1f46a38a54cc00d129 to your computer and use it in GitHub Desktop.
Save zewt/59757a1b32c56f1f46a38a54cc00d129 to your computer and use it in GitHub Desktop.
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