@@ -611,24 +611,25 @@ static CGFloat _get_device_scale(CGContextRef cr)
611
611
View* view;
612
612
PyObject* size;
613
613
int width, height;
614
- PyObject* obj;
615
614
FigureCanvas* canvas;
616
615
617
616
if (!self->window ) {
618
617
PyErr_SetString (PyExc_RuntimeError, " NSWindow* is NULL" );
619
618
return -1 ;
620
619
}
620
+ static char * kwlist[3 ] = { " canvas" , NULL };
621
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " O!" , kwlist,
622
+ &FigureCanvasType, &canvas)) {
623
+ return -1 ;
624
+ }
621
625
622
- if (!PyArg_ParseTuple (args, " O" , &obj)) { return -1 ; }
623
-
624
- canvas = (FigureCanvas*)obj;
625
626
view = canvas->view ;
626
627
if (!view) { /* Something really weird going on */
627
628
PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
628
629
return -1 ;
629
630
}
630
631
631
- size = PyObject_CallMethod (obj , " get_width_height" , " " );
632
+ size = PyObject_CallMethod ((PyObject*)canvas , " get_width_height" , " " );
632
633
if (!size) { return -1 ; }
633
634
if (!PyArg_ParseTuple (size, " ii" , &width, &height)) {
634
635
Py_DECREF (size);
@@ -697,6 +698,41 @@ static CGFloat _get_device_scale(CGContextRef cr)
697
698
Py_RETURN_NONE;
698
699
}
699
700
701
+ static PyObject*
702
+ FigureManager_set_icon (PyObject* null, PyObject* args, PyObject* kwds) {
703
+ PyObject* icon_path;
704
+ static char * kwlist[3 ] = { " icon_path" , NULL };
705
+ if (!PyArg_ParseTupleAndKeywords (args, kwds, " O&" , kwlist,
706
+ &PyUnicode_FSDecoder, &icon_path)) {
707
+ return NULL ;
708
+ }
709
+ const char * icon_path_ptr = PyUnicode_AsUTF8 (icon_path);
710
+ if (!icon_path_ptr) {
711
+ Py_DECREF (icon_path);
712
+ return NULL ;
713
+ }
714
+ @autoreleasepool {
715
+ NSString * ns_icon_path = [NSString stringWithUTF8String: icon_path_ptr];
716
+ Py_DECREF (icon_path);
717
+ if (!ns_icon_path) {
718
+ PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
719
+ return NULL ;
720
+ }
721
+ NSImage * image = [[[NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
722
+ if (!image) {
723
+ PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
724
+ return NULL ;
725
+ }
726
+ if (!image.valid ) {
727
+ PyErr_SetString (PyExc_RuntimeError, " Image is not valid" );
728
+ return NULL ;
729
+ }
730
+ NSApplication * app = [NSApplication sharedApplication ];
731
+ app.applicationIconImage = image;
732
+ }
733
+ Py_RETURN_NONE;
734
+ }
735
+
700
736
static PyObject*
701
737
FigureManager_set_window_title (FigureManager* self,
702
738
PyObject *args, PyObject *kwds)
@@ -769,6 +805,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
769
805
{" destroy" ,
770
806
(PyCFunction)FigureManager_destroy,
771
807
METH_NOARGS},
808
+ {" set_icon" ,
809
+ (PyCFunction)FigureManager_set_icon,
810
+ METH_STATIC | METH_VARARGS | METH_KEYWORDS,
811
+ " Set application icon" },
772
812
{" set_window_title" ,
773
813
(PyCFunction)FigureManager_set_window_title,
774
814
METH_VARARGS},
0 commit comments