Skip to content

Fix missing return value in closeButtonPressed. #21792

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

Merged
merged 1 commit into from
Nov 29, 2021
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 29, 2021

Accidentally removed in f7a432a.

Closes f7a432a#r61013322. Would be nice if we could run with -Werror instead, which would have caught this, but I assume @dopplershift had a good reason to only use -Werror=unguarded-availability in #17956?

It's also not completely clear to me why the only call to closeButtonPressed (in windowShouldClose) is protected by respondsToSelector, and whether it could just be inlined there instead, using something like

diff --git i/src/_macosx.m w/src/_macosx.m
index 64875fe7f1..cf84ef02fa 100755
--- i/src/_macosx.m
+++ w/src/_macosx.m
@@ -1519,12 +1519,8 @@ - (BOOL)windowShouldClose:(NSNotification*)notification
                                            data1: 0
                                            data2: 0];
     [NSApp postEvent: event atStart: true];
-    if ([window respondsToSelector: @selector(closeButtonPressed)]) {
-        BOOL closed = [((Window*) window) closeButtonPressed];
-        /* If closed, the window has already been closed via the manager. */
-        if (closed) { return NO; }
-    }
-    return YES;
+    gil_call_method(manager, "close");
+    return NO;  // the window has already been closed via the manager.
 }
 
 - (void)mouseEntered:(NSEvent *)event

Still, this patch should fix the main problem at hand...

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

anntzer referenced this pull request Nov 29, 2021
Also, explicitly checking for whether zoombutton/panbutton are non-null
is unnecessary, as objc explicitly defines sending a message to null as
a noop.  Also, they should never be nil anyways...
Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update looks good.

For the other updates:

  • -Werror seems to compile fine for me locally without any warnings, so I agree this seems sensible to add in.

  • The manager isn't available on the view there, so I think we'd have to store that somewhere on the window and then call super to get to that method. However, I'm a bit confused why we need that chunk of code at all... I think that even calling window.close() programatically would have closed the window by this point, so we shouldn't have to worry about that case?
    Dropping that code works for me interactively with multiple windows as expected.

diff --git a/src/_macosx.m b/src/_macosx.m
index 64875fe7f1..5e3bd4fc96 100755
--- a/src/_macosx.m
+++ b/src/_macosx.m
@@ -226,7 +226,6 @@ - (void)windowDidResize:(NSNotification*)notification;
 - (View*)initWithFrame:(NSRect)rect;
 - (void)setCanvas: (PyObject*)newCanvas;
 - (void)windowWillClose:(NSNotification*)notification;
-- (BOOL)windowShouldClose:(NSNotification*)notification;
 - (BOOL)isFlipped;
 - (void)mouseEntered:(NSEvent*)event;
 - (void)mouseExited:(NSEvent*)event;
@@ -1291,7 +1290,11 @@ - (NSRect)constrainFrameRect:(NSRect)rect toScreen:(NSScreen*)screen
     return suggested;
 }

-- (BOOL)closeButtonPressed { gil_call_method(manager, "close"); }
+- (BOOL)closeButtonPressed
+{
+    gil_call_method(manager, "close");
+    return YES;
+}

 - (void)close
 {
@@ -1506,27 +1509,6 @@ - (void)windowWillClose:(NSNotification*)notification
     PyGILState_Release(gstate);
 }

-- (BOOL)windowShouldClose:(NSNotification*)notification
-{
-    NSWindow* window = [self window];
-    NSEvent* event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
-                                        location: NSZeroPoint
-                                   modifierFlags: 0
-                                       timestamp: 0.0
-                                    windowNumber: 0
-                                         context: nil
-                                          subtype: WINDOW_CLOSING
-                                           data1: 0
-                                           data2: 0];
-    [NSApp postEvent: event atStart: true];
-    if ([window respondsToSelector: @selector(closeButtonPressed)]) {
-        BOOL closed = [((Window*) window) closeButtonPressed];
-        /* If closed, the window has already been closed via the manager. */
-        if (closed) { return NO; }
-    }
-    return YES;
-}
-
 - (void)mouseEntered:(NSEvent *)event
 {
     PyGILState_STATE gstate;

@dopplershift
Copy link
Contributor

I'm pretty sure when I made that PR matplotlib wouldn't compile with -Werror, and it didn't seem trivial to make that a possibility.

@QuLogic QuLogic added this to the v3.6.0 milestone Nov 29, 2021
@QuLogic QuLogic merged commit f6122dc into matplotlib:main Nov 29, 2021
@anntzer anntzer deleted the cbp branch November 29, 2021 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants