@@ -363,10 +363,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
363
363
static void
364
364
FigureCanvas_dealloc (FigureCanvas* self)
365
365
{
366
- if (self->view ) {
367
- [self ->view setCanvas: NULL ];
368
- [self ->view release ];
369
- }
366
+ [self ->view setCanvas: NULL ];
367
+ [self ->view release ];
370
368
Py_TYPE (self)->tp_free ((PyObject*)self);
371
369
}
372
370
@@ -380,34 +378,21 @@ static CGFloat _get_device_scale(CGContextRef cr)
380
378
static PyObject*
381
379
FigureCanvas_draw (FigureCanvas* self)
382
380
{
383
- View* view = self->view ;
384
- if (view) { /* The figure may have been closed already */
385
- [view display ];
386
- }
381
+ [self ->view display ];
387
382
Py_RETURN_NONE;
388
383
}
389
384
390
385
static PyObject*
391
386
FigureCanvas_draw_idle (FigureCanvas* self)
392
387
{
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 ];
399
389
Py_RETURN_NONE;
400
390
}
401
391
402
392
static PyObject*
403
393
FigureCanvas_flush_events (FigureCanvas* self)
404
394
{
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 ];
411
396
Py_RETURN_NONE;
412
397
}
413
398
@@ -450,12 +435,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
450
435
static PyObject*
451
436
FigureCanvas_remove_rubberband (FigureCanvas* self)
452
437
{
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 ];
459
439
Py_RETURN_NONE;
460
440
}
461
441
@@ -614,11 +594,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
614
594
PyObject* obj;
615
595
FigureCanvas* canvas;
616
596
617
- if (!self->window ) {
618
- PyErr_SetString (PyExc_RuntimeError, " NSWindow* is NULL" );
619
- return -1 ;
620
- }
621
-
622
597
if (!PyArg_ParseTuple (args, " O" , &obj)) { return -1 ; }
623
598
624
599
canvas = (FigureCanvas*)obj;
@@ -668,32 +643,23 @@ static CGFloat _get_device_scale(CGContextRef cr)
668
643
static void
669
644
FigureManager_dealloc (FigureManager* self)
670
645
{
671
- Window* window = self->window ;
672
- if (window) {
673
- [window close ];
674
- }
646
+ [self ->window close ];
675
647
Py_TYPE (self)->tp_free ((PyObject*)self);
676
648
}
677
649
678
650
static PyObject*
679
651
FigureManager_show (FigureManager* self)
680
652
{
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 ];
686
655
Py_RETURN_NONE;
687
656
}
688
657
689
658
static PyObject*
690
659
FigureManager_destroy (FigureManager* self)
691
660
{
692
- Window* window = self->window ;
693
- if (window) {
694
- [window close ];
695
- self->window = NULL ;
696
- }
661
+ [self ->window close ];
662
+ self->window = NULL ;
697
663
Py_RETURN_NONE;
698
664
}
699
665
@@ -744,30 +710,19 @@ static CGFloat _get_device_scale(CGContextRef cr)
744
710
if (!PyArg_ParseTuple (args, " s" , &title)) {
745
711
return NULL ;
746
712
}
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];
754
717
Py_RETURN_NONE;
755
718
}
756
719
757
720
static PyObject*
758
721
FigureManager_get_window_title (FigureManager* self)
759
722
{
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 ]);
771
726
} else {
772
727
Py_RETURN_NONE;
773
728
}
@@ -1366,7 +1321,7 @@ -(void)drawRect:(NSRect)rect
1366
1321
1367
1322
CGContextRef cr = [[NSGraphicsContext currentContext ] CGContext ];
1368
1323
1369
- if (!(renderer = PyObject_CallMethod (canvas, " _draw" , " " , NULL ))
1324
+ if (!(renderer = PyObject_CallMethod (canvas, " _draw" , " " ))
1370
1325
|| !(renderer_buffer = PyObject_GetAttrString (renderer, " _renderer" ))) {
1371
1326
PyErr_Print ();
1372
1327
goto exit ;
@@ -1392,7 +1347,7 @@ - (void)updateDevicePixelRatio:(double)scale
1392
1347
PyGILState_STATE gstate = PyGILState_Ensure ();
1393
1348
1394
1349
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))) {
1396
1351
PyErr_Print ();
1397
1352
goto exit ;
1398
1353
}
0 commit comments