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, _):
|
|
|
|
self.graphic.value(f"/moon/m{self.image:02d}")
|
|
|
|
self.image += 1
|
|
|
|
self.image %= 28
|
|
|
|
if self.image == 3:
|
|
|
|
self.graphic.color(BLUE)
|
|
|
|
else:
|
|
|
|
self.graphic.color(WHITE)
|
2022-05-17 15:41:54 +00:00
|
|
|
|
|
|
|
def test():
|
|
|
|
print("Bitmap demo.")
|
|
|
|
Screen.change(BaseScreen) # A class is passed here, not an instance.
|
|
|
|
|
|
|
|
test()
|