@@ -204,7 +204,6 @@ - (void)close;
204
204
@interface View : NSView <NSWindowDelegate >
205
205
{ PyObject* canvas;
206
206
NSRect rubberband;
207
- BOOL inside;
208
207
NSTrackingRectTag tracking;
209
208
@public double device_scale;
210
209
}
@@ -337,6 +336,14 @@ static CGFloat _get_device_scale(CGContextRef cr)
337
336
338
337
NSRect rect = NSMakeRect (0.0 , 0.0 , width, height);
339
338
self->view = [self ->view initWithFrame: rect];
339
+ self->view .autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
340
+ int opts = (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
341
+ NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect);
342
+ [self ->view addTrackingArea: [
343
+ [NSTrackingArea alloc ] initWithRect: rect
344
+ options: opts
345
+ owner: self ->view
346
+ userInfo: nil ]];
340
347
[self ->view setCanvas: (PyObject*)self ];
341
348
return 0 ;
342
349
}
@@ -704,7 +711,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
704
711
[window setTitle: [NSString stringWithCString: title
705
712
encoding: NSASCIIStringEncoding]];
706
713
707
- [window setAcceptsMouseMovedEvents: YES ];
708
714
[window setDelegate: view];
709
715
[window makeFirstResponder: view];
710
716
[[window contentView ] addSubview: view];
@@ -804,6 +810,22 @@ static CGFloat _get_device_scale(CGContextRef cr)
804
810
}
805
811
}
806
812
813
+ static PyObject*
814
+ FigureManager_resize (FigureManager* self, PyObject *args, PyObject *kwds)
815
+ {
816
+ int width, height;
817
+ if (!PyArg_ParseTuple (args, " ii" , &width, &height)) {
818
+ return NULL ;
819
+ }
820
+ Window* window = self->window ;
821
+ if (window)
822
+ {
823
+ // 36 comes from hard-coded size of toolbar later in code
824
+ [window setContentSize: NSMakeSize (width, height + 36 .)];
825
+ }
826
+ Py_RETURN_NONE;
827
+ }
828
+
807
829
static PyMethodDef FigureManager_methods[] = {
808
830
{" show" ,
809
831
(PyCFunction)FigureManager_show,
@@ -825,6 +847,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
825
847
METH_NOARGS,
826
848
" Returns the title of the window associated with the figure manager."
827
849
},
850
+ {" resize" ,
851
+ (PyCFunction)FigureManager_resize,
852
+ METH_VARARGS,
853
+ " Resize the window (in pixels)."
854
+ },
828
855
{NULL } /* Sentinel */
829
856
};
830
857
@@ -1564,8 +1591,6 @@ - (View*)initWithFrame:(NSRect)rect
1564
1591
{
1565
1592
self = [super initWithFrame: rect];
1566
1593
rubberband = NSZeroRect ;
1567
- inside = false ;
1568
- tracking = 0 ;
1569
1594
device_scale = 1 ;
1570
1595
return self;
1571
1596
}
@@ -1574,7 +1599,6 @@ - (void)dealloc
1574
1599
{
1575
1600
FigureCanvas* fc = (FigureCanvas*)canvas;
1576
1601
if (fc) fc->view = NULL ;
1577
- [self removeTrackingRect: tracking];
1578
1602
[super dealloc ];
1579
1603
}
1580
1604
@@ -1703,8 +1727,6 @@ - (void)windowDidResize: (NSNotification*)notification
1703
1727
width = size.width ;
1704
1728
height = size.height ;
1705
1729
1706
- [self setFrameSize: size];
1707
-
1708
1730
PyGILState_STATE gstate = PyGILState_Ensure ();
1709
1731
PyObject* result = PyObject_CallMethod (
1710
1732
canvas, " resize" , " ii" , width, height);
@@ -1713,11 +1735,6 @@ - (void)windowDidResize: (NSNotification*)notification
1713
1735
else
1714
1736
PyErr_Print ();
1715
1737
PyGILState_Release (gstate);
1716
- if (tracking) [self removeTrackingRect: tracking];
1717
- tracking = [self addTrackingRect: [self bounds ]
1718
- owner: self
1719
- userData: nil
1720
- assumeInside: NO ];
1721
1738
[self setNeedsDisplay: YES ];
1722
1739
}
1723
1740
@@ -1760,8 +1777,6 @@ - (void)mouseEntered:(NSEvent *)event
1760
1777
{
1761
1778
PyGILState_STATE gstate;
1762
1779
PyObject* result;
1763
- NSWindow * window = [self window ];
1764
- if ([window isKeyWindow ]==false ) return ;
1765
1780
1766
1781
int x, y;
1767
1782
NSPoint location = [event locationInWindow ];
@@ -1778,29 +1793,20 @@ - (void)mouseEntered:(NSEvent *)event
1778
1793
else
1779
1794
PyErr_Print ();
1780
1795
PyGILState_Release (gstate);
1781
-
1782
- [window setAcceptsMouseMovedEvents: YES ];
1783
- inside = true ;
1784
1796
}
1785
1797
1786
1798
- (void )mouseExited : (NSEvent *)event
1787
1799
{
1788
1800
PyGILState_STATE gstate;
1789
1801
PyObject* result;
1790
- NSWindow * window = [self window ];
1791
- if ([window isKeyWindow ]==false ) return ;
1792
1802
1793
- if (inside==false ) return ;
1794
1803
gstate = PyGILState_Ensure ();
1795
1804
result = PyObject_CallMethod (canvas, " leave_notify_event" , " " );
1796
1805
if (result)
1797
1806
Py_DECREF (result);
1798
1807
else
1799
1808
PyErr_Print ();
1800
1809
PyGILState_Release (gstate);
1801
-
1802
- [[self window ] setAcceptsMouseMovedEvents: NO ];
1803
- inside = false ;
1804
1810
}
1805
1811
1806
1812
- (void )mouseDown : (NSEvent *)event
0 commit comments