Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ef8be2

Browse files
author
Michiel de Hoon
committed
Modifying the MacOSX backend to make its interactive behavior consistent with the other backends
1 parent 1d8b6fb commit 9ef8be2

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

lib/matplotlib/backends/backend_macosx.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,12 @@ def draw_if_interactive():
224224
it will be redrawn as soon as the event loop resumes via PyOS_InputHook.
225225
This function should be called after each draw event, even if
226226
matplotlib is not running interactively.
227-
"""
228-
figManager = Gcf.get_active()
229-
if figManager is not None:
230-
figManager.canvas.invalidate()
227+
"""
228+
if matplotlib.is_interactive():
229+
figManager = Gcf.get_active()
230+
if figManager is not None:
231+
figManager.canvas.invalidate()
232+
231233

232234
def new_figure_manager(num, *args, **kwargs):
233235
"""
@@ -371,9 +373,8 @@ def notify_axes_change(fig):
371373
# This is ugly, but this is what tkagg and gtk are doing.
372374
# It is needed to get ginput() working.
373375
self.canvas.figure.show = lambda *args: self.show()
374-
375-
def show(self):
376-
self.canvas.draw()
376+
if matplotlib.is_interactive():
377+
self.show()
377378

378379
def close(self):
379380
Gcf.destroy(self.num)

src/_macosx.m

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
803803
self->color[0] = r;
804804
self->color[1] = g;
805805
self->color[2] = b;
806+
self->color[3] = 1.0;
806807

807808
Py_INCREF(Py_None);
808809
return Py_None;
@@ -2279,7 +2280,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
22792280
{"Arial", 14},
22802281
{"Helvetica", 15},
22812282
{"Avant Garde", 16},
2282-
{"sans-serif", 10},
2283+
{"sans-serif", 15},
22832284
{"Apple Chancery", 17},
22842285
{"Textile", 18},
22852286
{"Zapf Chancery", 19},
@@ -2364,8 +2365,8 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
23642365
"Arial-BoldItalicMT"},
23652366
{"Helvetica", /* 15 */
23662367
"Helvetica-Bold",
2367-
"",
2368-
""},
2368+
"Arial-ItalicMT",
2369+
"Arial-BoldItalicMT"},
23692370
{"AvantGardeITC-Book", /* 16 */
23702371
"AvantGardeITC-Demi",
23712372
"AvantGardeITC-BookOblique",
@@ -2681,7 +2682,6 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
26812682
PyErr_SetString(PyExc_RuntimeError, "CGContextRef is NULL");
26822683
return NULL;
26832684
}
2684-
26852685
if(!PyArg_ParseTuple(args, "ffu#Ofssf",
26862686
&x,
26872687
&y,
@@ -3755,7 +3755,6 @@ static void _data_provider_release(void* info, const void* data, size_t size)
37553755
[window setDelegate: view];
37563756
[window makeFirstResponder: view];
37573757
[[window contentView] addSubview: view];
3758-
[window makeKeyAndOrderFront: nil];
37593758

37603759
nwin++;
37613760

@@ -3788,6 +3787,20 @@ static void _data_provider_release(void* info, const void* data, size_t size)
37883787
Py_TYPE(self)->tp_free((PyObject*)self);
37893788
}
37903789

3790+
static PyObject*
3791+
FigureManager_show(FigureManager* self)
3792+
{
3793+
Window* window = self->window;
3794+
if(window)
3795+
{
3796+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
3797+
[window makeKeyAndOrderFront: nil];
3798+
[pool release];
3799+
}
3800+
Py_INCREF(Py_None);
3801+
return Py_None;
3802+
}
3803+
37913804
static PyObject*
37923805
FigureManager_destroy(FigureManager* self)
37933806
{
@@ -3804,6 +3817,11 @@ static void _data_provider_release(void* info, const void* data, size_t size)
38043817
}
38053818

38063819
static PyMethodDef FigureManager_methods[] = {
3820+
{"show",
3821+
(PyCFunction)FigureManager_show,
3822+
METH_NOARGS,
3823+
"Shows the window associated with the figure manager."
3824+
},
38073825
{"destroy",
38083826
(PyCFunction)FigureManager_destroy,
38093827
METH_NOARGS,
@@ -4662,7 +4680,9 @@ -(void)save_figure:(id)sender
46624680
NSText* messagebox = [[NSText alloc] initWithFrame: rect];
46634681
[messagebox setFont: font];
46644682
[messagebox setDrawsBackground: NO];
4665-
[messagebox setEditable: NO];
4683+
[messagebox setSelectable: NO];
4684+
/* if selectable, the messagebox can become first responder,
4685+
* which is not supposed to happen */
46664686
rect = [messagebox frame];
46674687
rect.origin.y = 0.5 * (height - rect.size.height);
46684688
[messagebox setFrameOrigin: rect.origin];

0 commit comments

Comments
 (0)