@@ -697,6 +697,41 @@ static CGFloat _get_device_scale(CGContextRef cr)
697697 Py_RETURN_NONE;
698698}
699699
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+
700735static PyObject*
701736FigureManager_set_window_title (FigureManager* self,
702737 PyObject *args, PyObject *kwds)
@@ -769,6 +804,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
769804 {" destroy" ,
770805 (PyCFunction)FigureManager_destroy,
771806 METH_NOARGS},
807+ {" set_icon" ,
808+ (PyCFunction)FigureManager_set_icon,
809+ METH_STATIC | METH_VARARGS | METH_KEYWORDS,
810+ " Set application icon" },
772811 {" set_window_title" ,
773812 (PyCFunction)FigureManager_set_window_title,
774813 METH_VARARGS},
0 commit comments