From 0e036cb9a462d4ed9a3f65f9b4d045f1a9d652b5 Mon Sep 17 00:00:00 2001 From: Johannes Kerger <49689041+JohannesK71083@users.noreply.github.com> Date: Thu, 1 Aug 2024 04:38:32 +0200 Subject: [PATCH] feat(ETKMainWindow)!: add ETKMainWindow.EVENTS.PRE_EXIT to REPLACE ETKMainWindow.EVENTS.EXIT and readd ETKMainWindow.EVENTS.EXIT with the functionally that the name implies. BREAKING CHANGES: ETKMainWindow.EVENTS.EXIT is now executed directly before exiting the application. Therefore it is no longer possible to abort the exit inside a EXIT-eventhandler -> use ETKMainWindow.EVENTS.PRE_EXIT instead (it has the same properties as ETKMainWindow.EVENTS.EXIT before). --- ETKMainWindow.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ETKMainWindow.py b/ETKMainWindow.py index e49a52d..e1fb16c 100644 --- a/ETKMainWindow.py +++ b/ETKMainWindow.py @@ -21,9 +21,10 @@ class EVENTS(ETKBaseTkObject.EVENTS): FOCUS_IN: ETKMainWindow.EVENTS FOCUS_OUT: ETKMainWindow.EVENTS START: ETKMainWindow.EVENTS + PRE_EXIT: ETKMainWindow.EVENTS EXIT: ETKMainWindow.EVENTS - _values = {"KEY_PRESSED": "", "KEY_RELEASED": "", "FOCUS_IN": "", "FOCUS_OUT": "", "START": "", "EXIT": ""} + _values = {"KEY_PRESSED": "", "KEY_RELEASED": "", "FOCUS_IN": "", "FOCUS_OUT": "", "START": "", "PRE_EXIT": "", "EXIT": ""} def __init__(self, pos: Vector2d = Vector2d(0, 0), size: Optional[Vector2d] = None, caption: str = "Window-Title", fullscreen: bool = True, *, visibility: bool = True, background_color: int = 0xAAAAAA, scheduler_disabled: bool = False, scale_factor: float = 1, **kwargs: Any) -> None: from .ETKCanvas import ETKCanvas @@ -40,6 +41,7 @@ def raise_exception(exc: Exception, *_: Any): self.__fullscreen = False self.canvas = ETKCanvas(self._main, Vector2d(), Vector2d()) self.__caption = "" + self.__exit_ongoing = False super().__init__(main=self._main, pos=pos, size=Vector2d(1920, 1080), background_color=background_color, visibility=visibility, **kwargs) @@ -165,11 +167,16 @@ def run(self) -> None: self._tk_object.mainloop() def exit(self) -> None: - self._handle_event(ETKEventData(self, self.EVENTS.EXIT), ignore_scheduler=True) + if self.__exit_ongoing: + return + self.__exit_ongoing = True + self._handle_event(ETKEventData(self, self.EVENTS.PRE_EXIT), ignore_scheduler=True) if not self.exit_locked and not self.exit_ignore_next: + self._handle_event(ETKEventData(self, self.EVENTS.EXIT), ignore_scheduler=True) sys.exit() if self.exit_ignore_next: self.exit_ignore_next = False + self.__exit_ongoing = False def update_gui(self) -> None: self._main.scheduler.handle_actions()