micropython-micro-gui/gui/demos/bitmap.py

46 wiersze
1.3 KiB
Python

2022-05-21 17:56:04 +00:00
# bitmap.py Display a changing bitmap via the BitMap widget.
2022-05-17 15:41:54 +00:00
# Released under the MIT License (MIT). See LICENSE.
# Copyright (c) 2022 Peter Hinch
# hardware_setup must be imported before other modules because of RAM use.
import hardware_setup # Create a display instance
from gui.core.ugui import Screen, ssd
2022-05-21 17:56:04 +00:00
from gui.widgets import Label, Button, CloseButton, BitMap
2022-05-17 15:41:54 +00:00
from gui.core.writer import CWriter
import gui.fonts.arial10 as arial10
from gui.core.colors import *
class BaseScreen(Screen):
def __init__(self):
super().__init__()
wri = CWriter(ssd, arial10, GREEN, BLACK)
col = 2
row = 2
Label(wri, row, col, "Bitmap Demo.")
2022-05-21 17:56:04 +00:00
row = 25
self.graphic = BitMap(wri, row, col, 99, 99, fgcolor=WHITE, bgcolor=BLACK)
col = 120
Button(wri, row, col, text="Next", callback=self.cb)
2022-05-17 15:41:54 +00:00
CloseButton(wri) # Quit the application
2022-05-21 17:56:04 +00:00
self.image = 0
def cb(self, _):
2024-04-18 16:46:18 +00:00
self.graphic.value(f"/m{self.image:02d}")
2022-05-21 17:56:04 +00:00
self.image += 1
self.image %= 4
2022-05-21 17:56:04 +00:00
if self.image == 3:
self.graphic.color(BLUE)
else:
self.graphic.color(WHITE)
2022-05-17 15:41:54 +00:00
2024-04-18 16:46:18 +00:00
2022-05-17 15:41:54 +00:00
def test():
print("Bitmap demo.")
Screen.change(BaseScreen) # A class is passed here, not an instance.
2024-04-18 16:46:18 +00:00
2022-05-17 15:41:54 +00:00
test()