@@ -363,10 +363,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
363363static void
364364FigureCanvas_dealloc (FigureCanvas* self)
365365{
366- if (self->view ) {
367- [self ->view setCanvas: NULL ];
368- [self ->view release ];
369- }
366+ [self ->view setCanvas: NULL ];
367+ [self ->view release ];
370368 Py_TYPE (self)->tp_free ((PyObject*)self);
371369}
372370
@@ -380,34 +378,21 @@ static CGFloat _get_device_scale(CGContextRef cr)
380378static PyObject*
381379FigureCanvas_draw (FigureCanvas* self)
382380{
383- View* view = self->view ;
384- if (view) { /* The figure may have been closed already */
385- [view display ];
386- }
381+ [self ->view display ];
387382 Py_RETURN_NONE;
388383}
389384
390385static PyObject*
391386FigureCanvas_draw_idle (FigureCanvas* self)
392387{
393- View* view = self->view ;
394- if (!view) {
395- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
396- return NULL ;
397- }
398- [view setNeedsDisplay: YES ];
388+ [self ->view setNeedsDisplay: YES ];
399389 Py_RETURN_NONE;
400390}
401391
402392static PyObject*
403393FigureCanvas_flush_events (FigureCanvas* self)
404394{
405- View* view = self->view ;
406- if (!view) {
407- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
408- return NULL ;
409- }
410- [view displayIfNeeded ];
395+ [self ->view displayIfNeeded ];
411396 Py_RETURN_NONE;
412397}
413398
@@ -450,12 +435,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
450435static PyObject*
451436FigureCanvas_remove_rubberband (FigureCanvas* self)
452437{
453- View* view = self->view ;
454- if (!view) {
455- PyErr_SetString (PyExc_RuntimeError, " NSView* is NULL" );
456- return NULL ;
457- }
458- [view removeRubberband ];
438+ [self ->view removeRubberband ];
459439 Py_RETURN_NONE;
460440}
461441
@@ -614,11 +594,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
614594 PyObject* obj;
615595 FigureCanvas* canvas;
616596
617- if (!self->window ) {
618- PyErr_SetString (PyExc_RuntimeError, " NSWindow* is NULL" );
619- return -1 ;
620- }
621-
622597 if (!PyArg_ParseTuple (args, " O" , &obj)) { return -1 ; }
623598
624599 canvas = (FigureCanvas*)obj;
@@ -668,32 +643,23 @@ static CGFloat _get_device_scale(CGContextRef cr)
668643static void
669644FigureManager_dealloc (FigureManager* self)
670645{
671- Window* window = self->window ;
672- if (window) {
673- [window close ];
674- }
646+ [self ->window close ];
675647 Py_TYPE (self)->tp_free ((PyObject*)self);
676648}
677649
678650static PyObject*
679651FigureManager_show (FigureManager* self)
680652{
681- Window* window = self->window ;
682- if (window) {
683- [window makeKeyAndOrderFront: nil ];
684- [window orderFrontRegardless ];
685- }
653+ [self ->window makeKeyAndOrderFront: nil ];
654+ [self ->window orderFrontRegardless ];
686655 Py_RETURN_NONE;
687656}
688657
689658static PyObject*
690659FigureManager_destroy (FigureManager* self)
691660{
692- Window* window = self->window ;
693- if (window) {
694- [window close ];
695- self->window = NULL ;
696- }
661+ [self ->window close ];
662+ self->window = NULL ;
697663 Py_RETURN_NONE;
698664}
699665
@@ -744,30 +710,19 @@ static CGFloat _get_device_scale(CGContextRef cr)
744710 if (!PyArg_ParseTuple (args, " s" , &title)) {
745711 return NULL ;
746712 }
747- Window* window = self->window ;
748- if (window) {
749- NSString * ns_title = [[[NSString alloc ]
750- initWithCString: title
751- encoding: NSUTF8StringEncoding] autorelease ];
752- [window setTitle: ns_title];
753- }
713+ NSString * ns_title = [[[NSString alloc ]
714+ initWithCString: title
715+ encoding: NSUTF8StringEncoding] autorelease ];
716+ [self ->window setTitle: ns_title];
754717 Py_RETURN_NONE;
755718}
756719
757720static PyObject*
758721FigureManager_get_window_title (FigureManager* self)
759722{
760- Window* window = self->window ;
761- PyObject* result = NULL ;
762- if (window) {
763- NSString * title = [window title ];
764- if (title) {
765- const char * cTitle = [title UTF8String ];
766- result = PyUnicode_FromString (cTitle);
767- }
768- }
769- if (result) {
770- return result;
723+ NSString * title = [self ->window title ];
724+ if (title) {
725+ return PyUnicode_FromString ([title UTF8String ]);
771726 } else {
772727 Py_RETURN_NONE;
773728 }
@@ -1366,7 +1321,7 @@ -(void)drawRect:(NSRect)rect
13661321
13671322 CGContextRef cr = [[NSGraphicsContext currentContext ] CGContext ];
13681323
1369- if (!(renderer = PyObject_CallMethod (canvas, " _draw" , " " , NULL ))
1324+ if (!(renderer = PyObject_CallMethod (canvas, " _draw" , " " ))
13701325 || !(renderer_buffer = PyObject_GetAttrString (renderer, " _renderer" ))) {
13711326 PyErr_Print ();
13721327 goto exit;
@@ -1392,7 +1347,7 @@ - (void)updateDevicePixelRatio:(double)scale
13921347 PyGILState_STATE gstate = PyGILState_Ensure ();
13931348
13941349 device_scale = scale;
1395- if (!(change = PyObject_CallMethod (canvas, " _set_device_pixel_ratio" , " d" , device_scale, NULL ))) {
1350+ if (!(change = PyObject_CallMethod (canvas, " _set_device_pixel_ratio" , " d" , device_scale))) {
13961351 PyErr_Print ();
13971352 goto exit;
13981353 }
0 commit comments