@@ -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,24 @@ -(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 ;
1008
997
1009
- rect.origin .x = 100 ;
1010
- rect.origin .y = 350 ;
1011
998
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
-
1028
- view = ((FigureCanvas*)canvas)->view ;
1029
- if (!view) /* Something really weird going on */
1030
- {
1031
- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
1032
- PyErr_Print ();
1033
- Py_DECREF (canvas);
1034
- Py_DECREF (master);
1035
- PyGILState_Release (gstate);
1036
- return ;
1037
- }
1038
999
1039
- size = PyObject_CallMethod (canvas, " get_width_height" , " " );
1040
- Py_DECREF (canvas);
1041
- if (!size)
1042
- {
1000
+ /* Prepare the subplot tool via the superclass. */
1001
+ if (!(mod = PyImport_ImportModule (" matplotlib.backend_bases" ))
1002
+ || !(base_class = PyObject_GetAttrString (mod, " NavigationToolbar2" ))
1003
+ || !(ret = PyObject_CallMethod (base_class, " configure_subplots" ,
1004
+ " O" , toolbar))) {
1043
1005
PyErr_Print ();
1044
- Py_DECREF (master);
1045
- PyGILState_Release (gstate);
1046
- return ;
1047
1006
}
1048
1007
1049
- int ok = PyArg_ParseTuple (size, " ii" , &width, &height);
1050
- Py_DECREF (size);
1051
- if (!ok)
1052
- {
1053
- PyErr_Print ();
1054
- Py_DECREF (master);
1055
- PyGILState_Release (gstate);
1056
- return ;
1057
- }
1008
+ Py_XDECREF (ret);
1009
+ Py_XDECREF (base_class);
1010
+ Py_XDECREF (mod);
1058
1011
1059
- NSWindow * mw = [((FigureCanvas*)master)->view window ];
1060
- Py_DECREF (master);
1061
1012
PyGILState_Release (gstate);
1062
-
1063
- rect.size .width = width;
1064
- rect.size .height = height;
1065
-
1066
- ToolWindow* window = [ [ToolWindow alloc ] initWithContentRect: rect
1067
- master: mw];
1068
- [window setContentView: view];
1069
- [view release ];
1070
- [window makeKeyAndOrderFront: nil ];
1071
1013
}
1072
1014
1073
1015
-(void )save_figure : (id )sender
@@ -1524,36 +1466,6 @@ - (void)dealloc
1524
1466
}
1525
1467
@end
1526
1468
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
1469
@implementation View
1558
1470
- (BOOL )isFlipped
1559
1471
{
0 commit comments