Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupled winforms event loop from AppContext. #2112

Merged
merged 13 commits into from
Sep 15, 2023
Prev Previous commit
Next Next commit
Renabled verification & refactored window closing.
  • Loading branch information
proneon267 committed Sep 12, 2023
commit 3ce07af6885d2f99547c642a6adb81d353c9c024
9 changes: 9 additions & 0 deletions core/src/toga/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ def _startup(self):
# This is a wrapper around the user's startup method that performs any
# post-setup validation.
self.startup()
self._verify_startup()

def _verify_startup(self):
if self.main_window is not None:
if not isinstance(self.main_window, MainWindow):
raise ValueError(
"toga.App.main_window must be of type MainWindow. "
"Does your startup() method assign a value of type MainWindow to self.main_window?"
)

def about(self) -> None:
"""Display the About dialog for the app.
Expand Down
34 changes: 10 additions & 24 deletions winforms/src/toga_winforms/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,17 @@ def winforms_FormClosing(self, sender, event):
# If the app is exiting, or a manual close has been requested,
# don't get confirmation; just close.
if not self.interface.app._impl._is_exiting and not self._is_closing:
# For handling window closing depending on its closeability
# settings or when there is an on_close event handler.
if not self.interface.closeable or self.interface.on_close._raw:
# If there is an on_close event handler, process it;
# but then cancel the close event. If the result of
# on_close handling indicates the window should close,
# then it will be manually triggered as part of that
# result handling.
self.interface.on_close(self)
# Close the app when the main_window or last window closes.
if (self.interface == self.interface.app.main_window) or (
len(self.interface.app.windows) == 0 and self.interface.app.on_exit
):
self.interface.app.on_exit(self.interface.app)

# For handling window closing when no on_close handler is provided.
elif self.interface.on_close._raw is None:
self.interface.close()
# Close the app when the main_window or last window closes.
if (self.interface == self.interface.app.main_window) or (
len(self.interface.app.windows) == 0 and self.interface.app.on_exit
):
self.interface.app.on_exit(self.interface.app)

# Closeability is implemented by shortcutting the close handler.
if self.interface.closeable:
if self.interface.on_close._raw is not None:
# If there is an on_close event handler, process it;
# but then cancel the close event. If the result of
# on_close handling indicates the window should close,
# then it will be manually triggered as part of that
# result handling.
self.interface.on_close(self)
elif self.interface.on_close._raw is None:
self.interface.close()
event.Cancel = True

def set_full_screen(self, is_full_screen):
Expand Down
Loading