@@ -221,14 +221,6 @@ - (BOOL)closeButtonPressed;
221
221
- (void )dealloc ;
222
222
@end
223
223
224
- @interface ToolWindow : NSWindow
225
- {
226
- }
227
- - (ToolWindow*)initWithContentRect : (NSRect )rect master : (NSWindow *)window ;
228
- - (void )masterCloses : (NSNotification *)notification ;
229
- - (void )close ;
230
- @end
231
-
232
224
@interface View : NSView <NSWindowDelegate >
233
225
{ PyObject* canvas;
234
226
NSRect rubberband;
@@ -1000,74 +992,48 @@ -(void)zoom:(id)sender
1000
992
}
1001
993
1002
994
-(void )configure_subplots : (id )sender
1003
- { PyObject* canvas;
1004
- View* view;
1005
- PyObject* size;
1006
- NSRect rect;
1007
- int width, height;
995
+ {
996
+ PyObject *mod = NULL , *base_class = NULL , *ret = NULL ;
997
+ PyObject *subplot_tool = NULL , *subplot_figure = NULL , *subplot_canvas = NULL ;
1008
998
1009
- rect.origin .x = 100 ;
1010
- rect.origin .y = 350 ;
1011
999
PyGILState_STATE gstate = PyGILState_Ensure ();
1012
- PyObject* master = PyObject_GetAttrString (toolbar, " canvas" );
1013
- if (master==nil )
1014
- {
1015
- PyErr_Print ();
1016
- PyGILState_Release (gstate);
1017
- return ;
1018
- }
1019
- canvas = PyObject_CallMethod (toolbar, " prepare_configure_subplots" , " " );
1020
- if (!canvas)
1021
- {
1022
- PyErr_Print ();
1023
- Py_DECREF (master);
1024
- PyGILState_Release (gstate);
1025
- return ;
1026
- }
1027
1000
1028
- view = ((FigureCanvas*)canvas)->view ;
1029
- if (!view) /* Something really weird going on */
1030
- {
1031
- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
1001
+ /* Prepare the subplot tool via the superclass. */
1002
+ if (!(mod = PyImport_ImportModule (" matplotlib.backend_bases" ))
1003
+ || !(base_class = PyObject_GetAttrString (mod, " NavigationToolbar2" ))
1004
+ || !(ret = PyObject_CallMethod (base_class, " configure_subplots" ,
1005
+ " O" , toolbar))) {
1032
1006
PyErr_Print ();
1033
- Py_DECREF (canvas);
1034
- Py_DECREF (master);
1035
- PyGILState_Release (gstate);
1036
- return ;
1007
+ goto exit ;
1037
1008
}
1038
1009
1039
- size = PyObject_CallMethod (canvas, " get_width_height " , " " );
1040
- Py_DECREF (canvas);
1041
- if (!size )
1042
- {
1010
+ /* The subplot_tool attribute is set by the superclass method. */
1011
+ if (!(subplot_tool = PyObject_GetAttrString (toolbar, " subplot_tool " ))
1012
+ || !(subplot_figure = PyObject_GetAttrString (subplot_tool, " figure " ) )
1013
+ || !(subplot_canvas = PyObject_GetAttrString (subplot_figure, " canvas " ))) {
1043
1014
PyErr_Print ();
1044
- Py_DECREF (master);
1045
- PyGILState_Release (gstate);
1046
- return ;
1015
+ goto exit ;
1047
1016
}
1048
1017
1049
- int ok = PyArg_ParseTuple (size, " ii" , &width, &height);
1050
- Py_DECREF (size);
1051
- if (!ok)
1018
+ if (!((FigureCanvas*)subplot_canvas)->view ) /* Something really weird going on */
1052
1019
{
1020
+ PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
1053
1021
PyErr_Print ();
1054
- Py_DECREF (master);
1055
- PyGILState_Release (gstate);
1056
- return ;
1022
+ goto exit ;
1057
1023
}
1058
1024
1059
- NSWindow * mw = [((FigureCanvas*)master)->view window ];
1060
- Py_DECREF (master);
1061
- PyGILState_Release (gstate);
1025
+ NSWindow * child = [((FigureCanvas*)subplot_canvas)->view window ];
1026
+ [child setStyleMask: [child styleMask ] | NSWindowStyleMaskUtilityWindow];
1062
1027
1063
- rect.size .width = width;
1064
- rect.size .height = height;
1028
+ exit :
1029
+ Py_XDECREF (subplot_canvas);
1030
+ Py_XDECREF (subplot_figure);
1031
+ Py_XDECREF (subplot_tool);
1032
+ Py_XDECREF (ret);
1033
+ Py_XDECREF (base_class);
1034
+ Py_XDECREF (mod);
1065
1035
1066
- ToolWindow* window = [ [ToolWindow alloc ] initWithContentRect: rect
1067
- master: mw];
1068
- [window setContentView: view];
1069
- [view release ];
1070
- [window makeKeyAndOrderFront: nil ];
1036
+ PyGILState_Release (gstate);
1071
1037
}
1072
1038
1073
1039
-(void )save_figure : (id )sender
@@ -1524,36 +1490,6 @@ - (void)dealloc
1524
1490
}
1525
1491
@end
1526
1492
1527
- @implementation ToolWindow
1528
- - (ToolWindow*)initWithContentRect : (NSRect )rect master : (NSWindow *)window
1529
- {
1530
- [self initWithContentRect: rect
1531
- styleMask: NSWindowStyleMaskTitled
1532
- | NSWindowStyleMaskClosable
1533
- | NSWindowStyleMaskResizable
1534
- | NSWindowStyleMaskMiniaturizable
1535
- backing: NSBackingStoreBuffered
1536
- defer: YES ];
1537
- [self setTitle: @" Subplot Configuration Tool" ];
1538
- [[NSNotificationCenter defaultCenter ] addObserver: self
1539
- selector: @selector (masterCloses: )
1540
- name: NSWindowWillCloseNotification
1541
- object: window];
1542
- return self;
1543
- }
1544
-
1545
- - (void )masterCloses : (NSNotification *)notification
1546
- {
1547
- [self close ];
1548
- }
1549
-
1550
- - (void )close
1551
- {
1552
- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
1553
- [super close ];
1554
- }
1555
- @end
1556
-
1557
1493
@implementation View
1558
1494
- (BOOL )isFlipped
1559
1495
{
0 commit comments