Skip to content

Use standard subplot window in macosx backend #21663

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 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 8 additions & 103 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ - (BOOL)closeButtonPressed;
- (void)dealloc;
@end

@interface ToolWindow : NSWindow
{
}
- (ToolWindow*)initWithContentRect:(NSRect)rect master:(NSWindow*)window;
- (void)masterCloses:(NSNotification*)notification;
- (void)close;
@end

@interface View : NSView <NSWindowDelegate>
{ PyObject* canvas;
NSRect rubberband;
Expand Down Expand Up @@ -959,74 +951,17 @@ -(void)zoom:(id)sender
}

-(void)configure_subplots:(id)sender
{ PyObject* canvas;
View* view;
PyObject* size;
NSRect rect;
int width, height;

rect.origin.x = 100;
rect.origin.y = 350;
PyGILState_STATE gstate = PyGILState_Ensure();
PyObject* master = PyObject_GetAttrString(toolbar, "canvas");
if (master==nil)
{
PyErr_Print();
PyGILState_Release(gstate);
return;
}
canvas = PyObject_CallMethod(toolbar, "prepare_configure_subplots", "");
if (!canvas)
{
PyErr_Print();
Py_DECREF(master);
PyGILState_Release(gstate);
return;
}

view = ((FigureCanvas*)canvas)->view;
if (!view) /* Something really weird going on */
{
PyErr_SetString(PyExc_RuntimeError, "NSView* is NULL");
PyErr_Print();
Py_DECREF(canvas);
Py_DECREF(master);
PyGILState_Release(gstate);
return;
}

size = PyObject_CallMethod(canvas, "get_width_height", "");
Py_DECREF(canvas);
if (!size)
{
PyErr_Print();
Py_DECREF(master);
PyGILState_Release(gstate);
return;
}

int ok = PyArg_ParseTuple(size, "ii", &width, &height);
Py_DECREF(size);
if (!ok)
{
{
PyObject* result;
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
result = PyObject_CallMethod(toolbar, "configure_subplots", NULL);
if (result) {
Py_DECREF(result);
} else {
PyErr_Print();
Py_DECREF(master);
PyGILState_Release(gstate);
return;
}

NSWindow* mw = [((FigureCanvas*)master)->view window];
Py_DECREF(master);
PyGILState_Release(gstate);

rect.size.width = width;
rect.size.height = height;

ToolWindow* window = [ [ToolWindow alloc] initWithContentRect: rect
master: mw];
[window setContentView: view];
[view release];
[window makeKeyAndOrderFront: nil];
}

-(void)save_figure:(id)sender
Expand Down Expand Up @@ -1455,36 +1390,6 @@ - (void)dealloc
}
@end

@implementation ToolWindow
- (ToolWindow*)initWithContentRect:(NSRect)rect master:(NSWindow*)window
{
[self initWithContentRect: rect
styleMask: NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable
| NSWindowStyleMaskResizable
| NSWindowStyleMaskMiniaturizable
backing: NSBackingStoreBuffered
defer: YES];
[self setTitle: @"Subplot Configuration Tool"];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(masterCloses:)
name: NSWindowWillCloseNotification
object: window];
return self;
}

- (void)masterCloses:(NSNotification*)notification
{
[self close];
}

- (void)close
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super close];
}
@end

@implementation View
- (BOOL)isFlipped
{
Expand Down