From 55ff572fc51405a7646c22cf85c0e6222720384d Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Wed, 20 Mar 2024 08:26:57 -0500 Subject: [PATCH] Fix some custom winhandler not calling closeEvent --- Tools/HolocronToolset/src/toolset/utils/window.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Tools/HolocronToolset/src/toolset/utils/window.py b/Tools/HolocronToolset/src/toolset/utils/window.py index a897860ff..865e25dab 100644 --- a/Tools/HolocronToolset/src/toolset/utils/window.py +++ b/Tools/HolocronToolset/src/toolset/utils/window.py @@ -14,6 +14,7 @@ if TYPE_CHECKING: import os + from PyQt5.QtGui import QCloseEvent from PyQt5.QtWidgets import QMainWindow from gui.editor import Editor @@ -23,13 +24,21 @@ def addWindow(window: QWidget): - def removeFromList(a0): - QWidget.closeEvent(window, a0) + # Save the original closeEvent method + original_closeEvent = window.closeEvent + + # Define a new closeEvent method that also calls the original + def newCloseEvent(event: QCloseEvent | None = None, *args, **kwargs): # Make arg optional just in case the class has the wrong definition. if window in WINDOWS: WINDOWS.remove(window) + # Call the original closeEvent + original_closeEvent(event, *args, **kwargs) # type: ignore[reportArgumentType] + + # Override the widget's closeEvent with the new one + window.closeEvent = newCloseEvent # type: ignore[reportAttributeAccessIssue] + # Add the window to the global list and show it WINDOWS.append(window) - window.closeEvent = removeFromList window.show()