@@ -697,6 +697,41 @@ static CGFloat _get_device_scale(CGContextRef cr)
697
697
Py_RETURN_NONE;
698
698
}
699
699
700
+ static PyObject*
701
+ FigureManager_set_icon (PyObject* null, PyObject* args, PyObject* kwds) {
702
+ PyObject* icon_path;
703
+ static char * kwlist[3 ] = { " icon_path" , NULL };
704
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " O&" , kwlist,
705
+ &PyUnicode_FSDecoder, &icon_path)) {
706
+ return NULL ;
707
+ }
708
+ const char * icon_path_ptr = PyUnicode_AsUTF8 (icon_path);
709
+ if (!icon_path_ptr) {
710
+ Py_DECREF (icon_path);
711
+ return NULL ;
712
+ }
713
+ @autoreleasepool {
714
+ NSString * ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
715
+ Py_DECREF (icon_path);
716
+ if (!ns_icon_path) {
717
+ PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
718
+ return NULL ;
719
+ }
720
+ NSImage * image = [[[NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
721
+ if (!image) {
722
+ PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
723
+ return NULL ;
724
+ }
725
+ if (!image.valid ) {
726
+ PyErr_SetString (PyExc_RuntimeError, " Image is not valid" );
727
+ return NULL ;
728
+ }
729
+ NSApplication * app = [NSApplication sharedApplication ];
730
+ app.applicationIconImage = image;
731
+ }
732
+ Py_RETURN_NONE;
733
+ }
734
+
700
735
static PyObject*
701
736
FigureManager_set_window_title (FigureManager* self,
702
737
PyObject *args, PyObject *kwds)
@@ -769,6 +804,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
769
804
{" destroy" ,
770
805
(PyCFunction)FigureManager_destroy,
771
806
METH_NOARGS},
807
+ {" set_icon" ,
808
+ (PyCFunction)FigureManager_set_icon,
809
+ METH_STATIC | METH_VARARGS | METH_KEYWORDS,
810
+ " Set application icon" },
772
811
{" set_window_title" ,
773
812
(PyCFunction)FigureManager_set_window_title,
774
813
METH_VARARGS},
0 commit comments