2
2
#include < Cocoa/Cocoa.h>
3
3
#include < ApplicationServices/ApplicationServices.h>
4
4
#include < Python.h>
5
- #include " mplutils.h"
6
5
7
6
/* Proper way to check for the OS X version we are compiling for, from
8
7
* https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/cross_development/Using/using.html
@@ -258,20 +257,21 @@ static CGFloat _get_device_scale(CGContextRef cr)
258
257
return pixelSize.width ;
259
258
}
260
259
261
- int mpl_check_modifier (
260
+ bool
261
+ mpl_check_modifier (
262
262
NSUInteger modifiers, NSEventModifierFlags flag,
263
263
PyObject* list, char const * name)
264
264
{
265
- int status = 0 ;
265
+ bool failed = false ;
266
266
if (modifiers & flag) {
267
267
PyObject* py_name = NULL ;
268
268
if (!(py_name = PyUnicode_FromString (name))
269
269
|| PyList_Append (list, py_name)) {
270
- status = - 1 ; // failure
270
+ failed = true ;
271
271
}
272
272
Py_XDECREF (py_name);
273
273
}
274
- return status ;
274
+ return failed ;
275
275
}
276
276
277
277
PyObject* mpl_modifiers (NSEvent * event)
@@ -498,14 +498,16 @@ int mpl_check_modifier(
498
498
499
499
static PyTypeObject FigureCanvasType = {
500
500
PyVarObject_HEAD_INIT (NULL , 0 )
501
- .tp_name = " _macosx.FigureCanvas" ,
501
+ .tp_name = " matplotlib.backends._macosx.FigureCanvas" ,
502
+ .tp_doc = PyDoc_STR (" A FigureCanvas object wraps a Cocoa NSView object." ),
502
503
.tp_basicsize = sizeof (FigureCanvas),
503
- .tp_dealloc = (destructor)FigureCanvas_dealloc,
504
- .tp_repr = (reprfunc)FigureCanvas_repr,
505
504
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
506
- . tp_init = (initproc)FigureCanvas_init,
505
+
507
506
.tp_new = (newfunc)FigureCanvas_new,
508
- .tp_doc = " A FigureCanvas object wraps a Cocoa NSView object." ,
507
+ .tp_init = (initproc)FigureCanvas_init,
508
+ .tp_dealloc = (destructor)FigureCanvas_dealloc,
509
+ .tp_repr = (reprfunc)FigureCanvas_repr,
510
+
509
511
.tp_methods = (PyMethodDef[]){
510
512
{" update" ,
511
513
(PyCFunction)FigureCanvas_update,
@@ -518,15 +520,15 @@ int mpl_check_modifier(
518
520
{" set_cursor" ,
519
521
(PyCFunction)FigureCanvas_set_cursor,
520
522
METH_VARARGS,
521
- " Set the active cursor." },
523
+ PyDoc_STR ( " Set the active cursor." ) },
522
524
{" set_rubberband" ,
523
525
(PyCFunction)FigureCanvas_set_rubberband,
524
526
METH_VARARGS,
525
- " Specify a new rubberband rectangle and invalidate it." },
527
+ PyDoc_STR ( " Specify a new rubberband rectangle and invalidate it." ) },
526
528
{" remove_rubberband" ,
527
529
(PyCFunction)FigureCanvas_remove_rubberband,
528
530
METH_NOARGS,
529
- " Remove the current rubberband rectangle." },
531
+ PyDoc_STR ( " Remove the current rubberband rectangle." ) },
530
532
{" _start_event_loop" ,
531
533
(PyCFunction)FigureCanvas__start_event_loop,
532
534
METH_KEYWORDS | METH_VARARGS,
@@ -745,14 +747,16 @@ int mpl_check_modifier(
745
747
746
748
static PyTypeObject FigureManagerType = {
747
749
PyVarObject_HEAD_INIT (NULL , 0 )
748
- .tp_name = " _macosx.FigureManager" ,
750
+ .tp_name = " matplotlib.backends._macosx.FigureManager" ,
751
+ .tp_doc = PyDoc_STR (" A FigureManager object wraps a Cocoa NSWindow object." ),
749
752
.tp_basicsize = sizeof (FigureManager),
750
- .tp_dealloc = (destructor)FigureManager_dealloc,
751
- .tp_repr = (reprfunc)FigureManager_repr,
752
753
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
753
- . tp_init = (initproc)FigureManager_init,
754
+
754
755
.tp_new = (newfunc)FigureManager_new,
755
- .tp_doc = " A FigureManager object wraps a Cocoa NSWindow object." ,
756
+ .tp_init = (initproc)FigureManager_init,
757
+ .tp_dealloc = (destructor)FigureManager_dealloc,
758
+ .tp_repr = (reprfunc)FigureManager_repr,
759
+
756
760
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
757
761
{" _show" ,
758
762
(PyCFunction)FigureManager__show,
@@ -766,11 +770,11 @@ int mpl_check_modifier(
766
770
{" _set_window_mode" ,
767
771
(PyCFunction)FigureManager__set_window_mode,
768
772
METH_VARARGS,
769
- " Set the window open mode (system, tab, window)" },
773
+ PyDoc_STR ( " Set the window open mode (system, tab, window)" ) },
770
774
{" set_icon" ,
771
775
(PyCFunction)FigureManager_set_icon,
772
776
METH_STATIC | METH_VARARGS,
773
- " Set application icon" },
777
+ PyDoc_STR ( " Set application icon" ) },
774
778
{" set_window_title" ,
775
779
(PyCFunction)FigureManager_set_window_title,
776
780
METH_VARARGS},
@@ -826,8 +830,7 @@ - (NavigationToolbar2Handler*)initWithToolbar:(PyObject*)theToolbar
826
830
827
831
- (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *[7 ])buttons
828
832
{
829
- int i;
830
- for (i = 0 ; i < 7 ; i++) {
833
+ for (int i = 0 ; i < 7 ; i++) {
831
834
SEL action = actions[i];
832
835
NSButton * button = buttons[i];
833
836
[button setTarget: self ];
@@ -1036,14 +1039,16 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
1036
1039
1037
1040
static PyTypeObject NavigationToolbar2Type = {
1038
1041
PyVarObject_HEAD_INIT (NULL , 0 )
1039
- .tp_name = " _macosx.NavigationToolbar2" ,
1042
+ .tp_name = " matplotlib.backends._macosx.NavigationToolbar2" ,
1043
+ .tp_doc = PyDoc_STR (" NavigationToolbar2" ),
1040
1044
.tp_basicsize = sizeof (NavigationToolbar2),
1041
- .tp_dealloc = (destructor)NavigationToolbar2_dealloc,
1042
- .tp_repr = (reprfunc)NavigationToolbar2_repr,
1043
1045
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1044
- . tp_init = (initproc)NavigationToolbar2_init,
1046
+
1045
1047
.tp_new = (newfunc)NavigationToolbar2_new,
1046
- .tp_doc = " NavigationToolbar2" ,
1048
+ .tp_init = (initproc)NavigationToolbar2_init,
1049
+ .tp_dealloc = (destructor)NavigationToolbar2_dealloc,
1050
+ .tp_repr = (reprfunc)NavigationToolbar2_repr,
1051
+
1047
1052
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
1048
1053
{" set_message" ,
1049
1054
(PyCFunction)NavigationToolbar2_set_message,
@@ -1782,13 +1787,16 @@ - (void)flagsChanged:(NSEvent *)event
1782
1787
1783
1788
static PyTypeObject TimerType = {
1784
1789
PyVarObject_HEAD_INIT (NULL , 0 )
1785
- .tp_name = " _macosx.Timer" ,
1790
+ .tp_name = " matplotlib.backends._macosx.Timer" ,
1791
+ .tp_doc = PyDoc_STR (" A Timer object that contains an NSTimer that gets added to "
1792
+ " the event loop when started." ),
1786
1793
.tp_basicsize = sizeof (Timer),
1787
- .tp_dealloc = (destructor)Timer_dealloc,
1788
- .tp_repr = (reprfunc)Timer_repr,
1789
1794
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1795
+
1790
1796
.tp_new = (newfunc)Timer_new,
1791
- .tp_doc = " A Timer object that contains an NSTimer that gets added to the event loop when started." ,
1797
+ .tp_dealloc = (destructor)Timer_dealloc,
1798
+ .tp_repr = (reprfunc)Timer_repr,
1799
+
1792
1800
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
1793
1801
{" _timer_start" ,
1794
1802
(PyCFunction)Timer__timer_start,
@@ -1801,46 +1809,53 @@ - (void)flagsChanged:(NSEvent *)event
1801
1809
};
1802
1810
1803
1811
static struct PyModuleDef moduledef = {
1804
- PyModuleDef_HEAD_INIT, " _macosx" , " Mac OS X native backend" , -1 ,
1805
- (PyMethodDef[]){
1812
+ .m_base = PyModuleDef_HEAD_INIT,
1813
+ .m_name = " _macosx" ,
1814
+ .m_doc = PyDoc_STR (" Mac OS X native backend" ),
1815
+ .m_size = -1 ,
1816
+ .m_methods = (PyMethodDef[]){
1806
1817
{" event_loop_is_running" ,
1807
1818
(PyCFunction)event_loop_is_running,
1808
1819
METH_NOARGS,
1809
- " Return whether the macosx backend has set up the NSApp main event loop." },
1820
+ PyDoc_STR (
1821
+ " Return whether the macosx backend has set up the NSApp main event loop." )},
1810
1822
{" wake_on_fd_write" ,
1811
1823
(PyCFunction)wake_on_fd_write,
1812
1824
METH_VARARGS,
1813
- " Arrange for Python to invoke its signal handlers when (any) data is\n "
1814
- " written on the file descriptor given as argument." },
1825
+ PyDoc_STR (
1826
+ " Arrange for Python to invoke its signal handlers when (any) data is\n "
1827
+ " written on the file descriptor given as argument." )},
1815
1828
{" stop" ,
1816
1829
(PyCFunction)stop,
1817
1830
METH_NOARGS,
1818
- " Stop the NSApp." },
1831
+ PyDoc_STR ( " Stop the NSApp." ) },
1819
1832
{" show" ,
1820
1833
(PyCFunction)show,
1821
1834
METH_NOARGS,
1822
- " Show all the figures and enter the main loop.\n "
1823
- " \n "
1824
- " This function does not return until all Matplotlib windows are closed,\n "
1825
- " and is normally not needed in interactive sessions." },
1835
+ PyDoc_STR (
1836
+ " Show all the figures and enter the main loop.\n "
1837
+ " \n "
1838
+ " This function does not return until all Matplotlib windows are closed,\n "
1839
+ " and is normally not needed in interactive sessions." )},
1826
1840
{" choose_save_file" ,
1827
1841
(PyCFunction)choose_save_file,
1828
1842
METH_VARARGS,
1829
- " Query the user for a location where to save a file." },
1843
+ PyDoc_STR ( " Query the user for a location where to save a file." ) },
1830
1844
{} /* Sentinel */
1831
1845
},
1832
1846
};
1833
1847
1834
1848
#pragma GCC visibility push(default)
1835
1849
1836
- PyObject* PyInit__macosx (void )
1850
+ PyMODINIT_FUNC
1851
+ PyInit__macosx (void )
1837
1852
{
1838
1853
PyObject *m;
1839
1854
if (!(m = PyModule_Create (&moduledef))
1840
- || prepare_and_add_type (&FigureCanvasType, m )
1841
- || prepare_and_add_type (&FigureManagerType, m )
1842
- || prepare_and_add_type (&NavigationToolbar2Type, m )
1843
- || prepare_and_add_type (&TimerType, m )) {
1855
+ || PyModule_AddType (m, &FigureCanvasType )
1856
+ || PyModule_AddType (m, &FigureManagerType )
1857
+ || PyModule_AddType (m, &NavigationToolbar2Type )
1858
+ || PyModule_AddType (m, &TimerType )) {
1844
1859
Py_XDECREF (m);
1845
1860
return NULL ;
1846
1861
}
0 commit comments