2017-12-11 22:00:16 -05:00
|
|
|
# test subclassing framebuf.FrameBuffer
|
|
|
|
|
|
|
|
try:
|
2022-08-18 02:57:45 -04:00
|
|
|
import framebuf, sys
|
2017-12-11 22:00:16 -05:00
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
2021-05-19 20:02:57 -04:00
|
|
|
# This test and its .exp file is based on a little-endian architecture.
|
2022-08-18 02:57:45 -04:00
|
|
|
if sys.byteorder != "little":
|
2021-05-19 20:02:57 -04:00
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-12-11 22:00:16 -05:00
|
|
|
class FB(framebuf.FrameBuffer):
|
|
|
|
def __init__(self, n):
|
|
|
|
self.n = n
|
|
|
|
super().__init__(bytearray(2 * n * n), n, n, framebuf.RGB565)
|
|
|
|
|
|
|
|
def foo(self):
|
|
|
|
self.hline(0, 2, self.n, 0x0304)
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-12-11 22:00:16 -05:00
|
|
|
fb = FB(n=3)
|
|
|
|
fb.pixel(0, 0, 0x0102)
|
|
|
|
fb.foo()
|
|
|
|
print(bytes(fb))
|
2020-02-19 06:45:32 -05:00
|
|
|
|
|
|
|
# Test that blitting a subclass works.
|
|
|
|
fb2 = framebuf.FrameBuffer(bytearray(2 * 3 * 3), 3, 3, framebuf.RGB565)
|
|
|
|
fb.fill(0)
|
|
|
|
fb.pixel(0, 0, 0x0506)
|
|
|
|
fb.pixel(2, 2, 0x0708)
|
|
|
|
fb2.blit(fb, 0, 0)
|
|
|
|
print(bytes(fb2))
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2020-02-19 06:45:32 -05:00
|
|
|
# Test that blitting something that isn't a subclass fails with TypeError.
|
|
|
|
class NotAFrameBuf:
|
|
|
|
pass
|
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2020-02-19 06:45:32 -05:00
|
|
|
try:
|
|
|
|
fb.blit(NotAFrameBuf(), 0, 0)
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
|
|
|
|
try:
|
|
|
|
fb.blit(None, 0, 0)
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|