Skip to content

Commit ea11cfe

Browse files
committed
修复:函数参数与默认值不一致时导致未达到预期显示效果的BUG,新增:bmp图片显示的color参数
1 parent 40a4dd3 commit ea11cfe

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

text.txt renamed to fonts/text.txt

File renamed without changes.

libs/easydisplay.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ def font(self, s: str, x: int, y: int, c: int = None, size: int = None, show: bo
9595
half_char: 是否半字节显示 ASCII 字符
9696
auto_wrap: 自动换行
9797
"""
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
105112

106113
self._font.text(
107114
display=self.display, # 显示对象 必要
@@ -135,17 +142,23 @@ def pbm(self, file: str, x, y, show: bool = None, clear: bool = None, color: int
135142
y: 显示器上示图片位置的 y 坐标
136143
show: 是否立即显示
137144
clear: 是否清除之前显示的内容
138-
color: 黑白图像的默认颜色
145+
color: 显示黑白图像或将彩色图像以黑白模式显示时的默认颜色
139146
key: 显示图像时不显示的颜色
140147
reverse: 是否反转颜色
141148
format: 显示图像时使用的模式:framebuf.MONO_HLSB(单色显示),framebuf.RGB565(彩色显示)
142149
"""
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
149162
if clear: # 清屏
150163
self.clear()
151164
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
201214
if show: # 立即显示
202215
self.show()
203216

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):
206219
"""
207220
显示 bmp 图片
208221
@@ -215,15 +228,23 @@ def bmp(self, file: str, x, y, show: bool = None, clear: bool = None, key: int =
215228
y: 显示器上示图片位置的 y 坐标
216229
show: 是否立即显示
217230
clear: 是否清除之前显示的内容
231+
color: 显示黑白图像或将彩色图像以黑白模式显示时的默认颜色
218232
key: 显示图像时不显示的颜色
219233
reverse: 是否反转颜色
220234
format: 显示图像时使用的模式:framebuf.MONO_HLSB(单色显示),framebuf.RGB565(彩色显示)
221235
"""
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
227248
with open(file, 'rb') as f:
228249
if f.read(2) == b'BM': # 检查文件头来判断是否为支持的文件类型
229250
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 =
272293
if _color:
273294
_color = 0
274295
else:
275-
_color = self._img_color
296+
_color = color
276297
else:
277298
if _color:
278-
_color = self._img_color
299+
_color = color
279300
else:
280301
_color = 0
281302
if _color != key: # 不显示指定颜色

0 commit comments

Comments
 (0)