Skip to content

Commit

Permalink
Fixed cocoa delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
proneon267 committed Sep 9, 2024
1 parent b03ad60 commit 749a35e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions cocoa/src/toga_cocoa/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
SEL,
CGSize,
NSMakeRect,
NSObject,
NSPoint,
NSSize,
objc_method,
Expand Down Expand Up @@ -51,7 +50,7 @@ def windowWillClose_(self, notification) -> None:
# the delegates and still triggers the delegate events.

# Assign an empty base NSObject to the window delegate.
self.delegate = NSObject.alloc().init()
# self.delegate = NSObject.alloc().init()

# Assigning the toolbar delegate to an empty base NSObject
# doesn't work as it requires conformity to the NSToolbarDelegate,
Expand All @@ -67,7 +66,7 @@ def windowWillClose_(self, notification) -> None:

@objc_method
def windowDidResize_(self, notification) -> None:
if self.interface.content:
if self.interface and self.interface.content:
# Set the window to the new size
self.interface.content.refresh()

Expand All @@ -90,7 +89,8 @@ def enteredMiniaturize_(self, sender) -> None:

@objc_method
def windowDidDeminiaturize_(self, notification) -> None:
self.impl._apply_state(self.impl._pending_state_transition)
if self.impl:
self.impl._apply_state(self.impl._pending_state_transition)

@objc_method
def windowDidEnterFullScreen_(self, notification) -> None:
Expand All @@ -101,17 +101,19 @@ def enteredFullScreen_(self, sender) -> None:
# Doing the following directly in `windowDidEnterFullScreen_` will result in error:
# ````2024-08-09 15:46:39.050 python[2646:37395] not in fullscreen state````
# and any subsequent window state calls to the OS will not work or will be glitchy.
if (
self.impl._pending_state_transition
and self.impl._pending_state_transition != WindowState.FULLSCREEN
):
self.impl._apply_state(WindowState.NORMAL)
else:
self.impl._pending_state_transition = None
if self.impl:
if (
self.impl._pending_state_transition
and self.impl._pending_state_transition != WindowState.FULLSCREEN
):
self.impl._apply_state(WindowState.NORMAL)
else:
self.impl._pending_state_transition = None

@objc_method
def windowDidExitFullScreen_(self, notification) -> None:
self.impl._apply_state(self.impl._pending_state_transition)
if self.impl:
self.impl._apply_state(self.impl._pending_state_transition)

######################################################################
# Toolbar delegate methods
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/window/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ async def test_window_state_direct_change(
# Set to final state
second_window.state = final_state
# Add delay to ensure windows are visible after animation.
await app_probe.redraw(f"Secondary window is in {final_state}", delay=1.65)
await app_probe.redraw(f"Secondary window is in {final_state}", delay=1.5)
assert second_window.state == final_state

@pytest.mark.parametrize(
Expand Down

0 comments on commit 749a35e

Please sign in to comment.