Skip to content

Commit

Permalink
Fix some custom winhandler not calling closeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Mar 20, 2024
1 parent 6b3b1be commit 55ff572
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Tools/HolocronToolset/src/toolset/utils/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
if TYPE_CHECKING:
import os

from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import QMainWindow

from gui.editor import Editor
Expand All @@ -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()


Expand Down

0 comments on commit 55ff572

Please sign in to comment.