Skip to content

Commit

Permalink
feat(ETKMainWindow)!: add ETKMainWindow.EVENTS.PRE_EXIT to REPLACE ET…
Browse files Browse the repository at this point in the history
…KMainWindow.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).
  • Loading branch information
JohannesK71083 committed Aug 1, 2024
1 parent 9c63a8c commit 0e036cb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ETKMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<KeyPress>", "KEY_RELEASED": "<KeyRelease>", "FOCUS_IN": "<FocusIn>", "FOCUS_OUT": "<FocusOut>", "START": "<Custom>", "EXIT": "<Custom>"}
_values = {"KEY_PRESSED": "<KeyPress>", "KEY_RELEASED": "<KeyRelease>", "FOCUS_IN": "<FocusIn>", "FOCUS_OUT": "<FocusOut>", "START": "<Custom>", "PRE_EXIT": "<Custom>", "EXIT": "<Custom>"}

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
Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0e036cb

Please sign in to comment.