@@ -629,37 +629,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
629
629
return (PyObject*)self;
630
630
}
631
631
632
- int set_icon (PyObject* icon_path) {
633
- if (!icon_path) {
634
- return 0 ;
635
- }
636
- const char * icon_path_ptr = PyUnicode_AsUTF8 (icon_path);
637
- if (!icon_path_ptr) {
638
- Py_DECREF (icon_path);
639
- return -1 ;
640
- }
641
- @autoreleasepool {
642
- NSString * ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
643
- if (!ns_icon_path) {
644
- Py_DECREF (icon_path);
645
- PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
646
- return -1 ;
647
- }
648
- NSImage * image = [[[NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
649
- if (!image) {
650
- PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
651
- return -1 ;
652
- }
653
- if (!image.valid ) {
654
- PyErr_SetString (PyExc_RuntimeError, " Image is not valid" );
655
- return -1 ;
656
- }
657
- NSApplication * app = [NSApplication sharedApplication ];
658
- app.applicationIconImage = image;
659
- }
660
- return 0 ;
661
- }
662
-
663
632
static int
664
633
FigureManager_init (FigureManager *self, PyObject *args, PyObject *kwds)
665
634
{
@@ -669,21 +638,14 @@ int set_icon(PyObject* icon_path) {
669
638
PyObject* size;
670
639
int width, height;
671
640
FigureCanvas* canvas;
672
- PyObject* icon_path;
673
641
674
642
if (!self->window ) {
675
643
PyErr_SetString (PyExc_RuntimeError, " NSWindow* is NULL" );
676
644
return -1 ;
677
645
}
678
- static char * kwlist[3 ] = { " canvas" , " icon_path" , NULL };
679
- icon_path = NULL ;
680
- if (!PyArg_ParseTupleAndKeywords (args, kwds,
681
- " O!|O&" , kwlist,
682
- &FigureCanvasType, &canvas,
683
- &PyUnicode_FSDecoder, &icon_path)) {
684
- return -1 ;
685
- }
686
- if (set_icon (icon_path)) {
646
+ static char * kwlist[3 ] = { " canvas" , NULL };
647
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " O!" , kwlist,
648
+ &FigureCanvasType, &canvas)) {
687
649
return -1 ;
688
650
}
689
651
@@ -762,6 +724,41 @@ int set_icon(PyObject* icon_path) {
762
724
Py_RETURN_NONE;
763
725
}
764
726
727
+ static PyObject*
728
+ FigureManager_set_icon (PyObject* null, PyObject* args, PyObject* kwds) {
729
+ PyObject* icon_path;
730
+ static char * kwlist[3 ] = { " icon_path" , NULL };
731
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " O&" , kwlist,
732
+ &PyUnicode_FSDecoder, &icon_path)) {
733
+ return NULL ;
734
+ }
735
+ const char * icon_path_ptr = PyUnicode_AsUTF8 (icon_path);
736
+ if (!icon_path_ptr) {
737
+ Py_DECREF (icon_path);
738
+ return NULL ;
739
+ }
740
+ @autoreleasepool {
741
+ NSString * ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
742
+ Py_DECREF (icon_path);
743
+ if (!ns_icon_path) {
744
+ PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
745
+ return NULL ;
746
+ }
747
+ NSImage * image = [[[NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
748
+ if (!image) {
749
+ PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
750
+ return NULL ;
751
+ }
752
+ if (!image.valid ) {
753
+ PyErr_SetString (PyExc_RuntimeError, " Image is not valid" );
754
+ return NULL ;
755
+ }
756
+ NSApplication * app = [NSApplication sharedApplication ];
757
+ app.applicationIconImage = image;
758
+ }
759
+ Py_RETURN_NONE;
760
+ }
761
+
765
762
static PyObject*
766
763
FigureManager_set_window_title (FigureManager* self,
767
764
PyObject *args, PyObject *kwds)
@@ -828,6 +825,11 @@ int set_icon(PyObject* icon_path) {
828
825
METH_NOARGS,
829
826
NULL , // docstring inherited.
830
827
},
828
+ {" set_icon" ,
829
+ (PyCFunction)FigureManager_set_icon,
830
+ METH_STATIC | METH_VARARGS | METH_KEYWORDS,
831
+ NULL , // Set application icon
832
+ },
831
833
{" set_window_title" ,
832
834
(PyCFunction)FigureManager_set_window_title,
833
835
METH_VARARGS,
0 commit comments