@@ -95,13 +95,20 @@ def font(self, s: str, x: int, y: int, c: int = None, size: int = None, show: bo
95
95
half_char: 是否半字节显示 ASCII 字符
96
96
auto_wrap: 自动换行
97
97
"""
98
- c = c or self ._font_color
99
- size = size or self ._font_size
100
- reverse = reverse or self ._reverse
101
- clear = clear or self ._clear
102
- show = show or self ._show
103
- half_char = half_char or self ._font_half_char
104
- auto_wrap = auto_wrap or self ._font_auto_wrap
98
+ if c is None :
99
+ c = self ._font_color
100
+ if size is None :
101
+ size = self ._font_size
102
+ if reverse is None :
103
+ reverse = self ._reverse
104
+ if clear is None :
105
+ clear = self ._clear
106
+ if show is None :
107
+ show = self ._show
108
+ if half_char is None :
109
+ half_char = self ._font_half_char
110
+ if auto_wrap is None :
111
+ auto_wrap = self ._font_auto_wrap
105
112
106
113
self ._font .text (
107
114
display = self .display , # 显示对象 必要
@@ -135,17 +142,23 @@ def pbm(self, file: str, x, y, show: bool = None, clear: bool = None, color: int
135
142
y: 显示器上示图片位置的 y 坐标
136
143
show: 是否立即显示
137
144
clear: 是否清除之前显示的内容
138
- color: 黑白图像的默认颜色
145
+ color: 显示黑白图像或将彩色图像以黑白模式显示时的默认颜色
139
146
key: 显示图像时不显示的颜色
140
147
reverse: 是否反转颜色
141
148
format: 显示图像时使用的模式:framebuf.MONO_HLSB(单色显示),framebuf.RGB565(彩色显示)
142
149
"""
143
- show = show or self ._show
144
- clear = clear or self ._clear
145
- color = color or self ._img_color
146
- key = key or self ._img_key
147
- reverse = reverse or self ._reverse
148
- format = format or self ._img_format
150
+ if show is None :
151
+ show = self ._show
152
+ if clear is None :
153
+ clear = self ._clear
154
+ if color is None :
155
+ color = self ._img_color
156
+ if key is None :
157
+ key = self ._img_key
158
+ if reverse is None :
159
+ reverse = self ._reverse
160
+ if format is None :
161
+ format = self ._img_format
149
162
if clear : # 清屏
150
163
self .clear ()
151
164
with open (file , "rb" ) as f :
@@ -201,8 +214,8 @@ def pbm(self, file: str, x, y, show: bool = None, clear: bool = None, color: int
201
214
if show : # 立即显示
202
215
self .show ()
203
216
204
- def bmp (self , file : str , x , y , show : bool = None , clear : bool = None , key : int = None , reverse : bool = None ,
205
- format : int = None ):
217
+ def bmp (self , file : str , x , y , show : bool = None , clear : bool = None , color : int = None , key : int = None ,
218
+ reverse : bool = None , format : int = None ):
206
219
"""
207
220
显示 bmp 图片
208
221
@@ -215,15 +228,23 @@ def bmp(self, file: str, x, y, show: bool = None, clear: bool = None, key: int =
215
228
y: 显示器上示图片位置的 y 坐标
216
229
show: 是否立即显示
217
230
clear: 是否清除之前显示的内容
231
+ color: 显示黑白图像或将彩色图像以黑白模式显示时的默认颜色
218
232
key: 显示图像时不显示的颜色
219
233
reverse: 是否反转颜色
220
234
format: 显示图像时使用的模式:framebuf.MONO_HLSB(单色显示),framebuf.RGB565(彩色显示)
221
235
"""
222
- show = show or self ._show
223
- clear = clear or self ._clear
224
- key = key or self ._img_key
225
- reverse = reverse or self ._reverse
226
- format = format or self ._img_format
236
+ if show is None :
237
+ show = self ._show
238
+ if clear is None :
239
+ clear = self ._clear
240
+ if color is None :
241
+ color = self ._img_color
242
+ if key is None :
243
+ key = self ._img_key
244
+ if reverse is None :
245
+ reverse = self ._reverse
246
+ if format is None :
247
+ format = self ._img_format
227
248
with open (file , 'rb' ) as f :
228
249
if f .read (2 ) == b'BM' : # 检查文件头来判断是否为支持的文件类型
229
250
dummy = f .read (8 ) # 文件大小占四个字节,文件作者占四个字节,file size(4), creator bytes(4)
@@ -272,10 +293,10 @@ def bmp(self, file: str, x, y, show: bool = None, clear: bool = None, key: int =
272
293
if _color :
273
294
_color = 0
274
295
else :
275
- _color = self . _img_color
296
+ _color = color
276
297
else :
277
298
if _color :
278
- _color = self . _img_color
299
+ _color = color
279
300
else :
280
301
_color = 0
281
302
if _color != key : # 不显示指定颜色
0 commit comments