@@ -227,6 +227,7 @@ def __init__(self, display=None, scale=1):
227
227
self ._pencolor = 1
228
228
self .pencolor (Color .WHITE )
229
229
self ._bg_pic = None
230
+ self ._bg_pic_filename = ""
230
231
self ._turtle_pic = None
231
232
self ._turtle_odb = None
232
233
self ._turtle_alt_sprite = None
@@ -915,33 +916,34 @@ def bgcolor(self, c=None):
915
916
self ._fg_bitmap [w , h ] = self ._bg_color
916
917
return Color .colors [self ._bg_color ]
917
918
918
- def set_bgpic (self , file ):
919
- """
920
- Set a picture as background.
921
-
922
- set_bgpic(filename)
923
- Set backgroud picture using OnDiskBitmap.
924
- """
925
- self ._bg_pic = open (file , 'rb' )
926
- odb = displayio .OnDiskBitmap (self ._bg_pic )
927
- self ._odb_tilegrid = displayio .TileGrid (odb , pixel_shader = displayio .ColorConverter ())
928
- self ._bg_addon_group .append (self ._odb_tilegrid )
929
- # centered
930
- self ._odb_tilegrid .y = ((self ._h * self ._fg_scale )// 2 ) - (odb .height // 2 )
931
- self ._odb_tilegrid .x = ((self ._w * self ._fg_scale )// 2 ) - (odb .width // 2 )
932
-
933
- def del_bgpic (self ):
934
- """
935
- Remove the background picture, if any
936
-
937
- del_bgpic()
938
- Remove the picture and close the file
919
+ # pylint:disable=inconsistent-return-statements
920
+ def bgpic (self , picname = None ):
921
+ """Set background image or return name of current backgroundimage.
922
+ Optional argument:
923
+ picname -- a string, name of an image file or "nopic".
924
+ If picname is a filename, set the corresponding image as background.
925
+ If picname is "nopic", delete backgroundimage, if present.
926
+ If picname is None, return the filename of the current backgroundimage.
939
927
"""
940
- if self ._bg_pic is not None :
941
- self ._bg_addon_group .remove (self ._odb_tilegrid )
942
- self ._odb_tilegrid = None
943
- self ._bg_pic .close ()
944
- self ._bg_pic = None
928
+ if picname is None :
929
+ return self ._bg_pic_filename
930
+ if picname == "nopic" :
931
+ if self ._bg_pic is not None :
932
+ self ._bg_addon_group .remove (self ._odb_tilegrid )
933
+ self ._odb_tilegrid = None
934
+ self ._bg_pic .close ()
935
+ self ._bg_pic = None
936
+ self ._bg_pic_filename = ""
937
+ else :
938
+ self ._bg_pic = open (picname , 'rb' )
939
+ odb = displayio .OnDiskBitmap (self ._bg_pic )
940
+ self ._odb_tilegrid = displayio .TileGrid (odb , pixel_shader = displayio .ColorConverter ())
941
+ self ._bg_addon_group .append (self ._odb_tilegrid )
942
+ self ._bg_pic_filename = picname
943
+ # centered
944
+ self ._odb_tilegrid .y = ((self ._h * self ._fg_scale )// 2 ) - (odb .height // 2 )
945
+ self ._odb_tilegrid .x = ((self ._w * self ._fg_scale )// 2 ) - (odb .width // 2 )
946
+ # pylint:enable=inconsistent-return-statements
945
947
946
948
###########################################################################
947
949
# More drawing control
0 commit comments