File: framebuf_subclass.py

package info (click to toggle)
micropython 1.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 48,944 kB
  • sloc: ansic: 317,850; python: 59,539; xml: 4,241; makefile: 3,530; sh: 1,421; javascript: 744; asm: 681; cpp: 45; exp: 11; pascal: 6
file content (51 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# test subclassing framebuf.FrameBuffer

try:
    import framebuf, sys
except ImportError:
    print("SKIP")
    raise SystemExit

# This test and its .exp file is based on a little-endian architecture.
if sys.byteorder != "little":
    print("SKIP")
    raise SystemExit


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)


fb = FB(n=3)
fb.pixel(0, 0, 0x0102)
fb.foo()
print(bytes(fb))

# 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))


# Test that blitting something that isn't a subclass fails with TypeError.
class NotAFrameBuf:
    pass


try:
    fb.blit(NotAFrameBuf(), 0, 0)
except TypeError:
    print("TypeError")

try:
    fb.blit(None, 0, 0)
except TypeError:
    print("TypeError")