2021-06-23 17:05:14 +00:00
|
|
|
# screen_change.py Minimal micro-gui demo showing a Button causing a screen change.
|
|
|
|
|
2021-06-24 17:42:16 +00:00
|
|
|
# Released under the MIT License (MIT). See LICENSE.
|
|
|
|
# Copyright (c) 2021 Peter Hinch
|
|
|
|
|
2021-06-23 17:05:14 +00:00
|
|
|
# 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
|
|
|
|
|
|
|
|
from gui.widgets.buttons import Button, CloseButton
|
|
|
|
from gui.widgets.label import Label
|
|
|
|
from gui.core.writer import CWriter
|
|
|
|
|
|
|
|
# Font for CWriter
|
2021-06-25 15:56:14 +00:00
|
|
|
import gui.fonts.arial10 as font
|
2021-06-23 17:05:14 +00:00
|
|
|
from gui.core.colors import *
|
|
|
|
|
|
|
|
# Defining a button in this way enables it to be re-used on
|
|
|
|
# multiple Screen instances. Note that a Screen class is
|
|
|
|
# passed, not an instance.
|
|
|
|
def fwdbutton(wri, row, col, cls_screen, text='Next'):
|
|
|
|
def fwd(button):
|
|
|
|
Screen.change(cls_screen) # Callback
|
|
|
|
|
2021-06-25 15:56:14 +00:00
|
|
|
Button(wri, row, col, callback = fwd,
|
2021-06-23 17:05:14 +00:00
|
|
|
fgcolor = BLACK, bgcolor = GREEN,
|
2021-06-25 15:56:14 +00:00
|
|
|
text = text, shape = RECTANGLE)
|
2021-06-23 17:05:14 +00:00
|
|
|
|
2021-06-25 15:56:14 +00:00
|
|
|
wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
|
2021-06-23 17:05:14 +00:00
|
|
|
|
|
|
|
# This screen overlays BaseScreen.
|
|
|
|
class BackScreen(Screen):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
Label(wri, 2, 2, 'New screen.')
|
|
|
|
CloseButton(wri)
|
|
|
|
|
|
|
|
|
|
|
|
class BaseScreen(Screen):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
super().__init__()
|
|
|
|
Label(wri, 2, 2, 'Base screen.')
|
|
|
|
fwdbutton(wri, 40, 2, BackScreen)
|
|
|
|
CloseButton(wri)
|
|
|
|
|
|
|
|
|
|
|
|
def test():
|
|
|
|
print('Screen change demo.')
|
|
|
|
Screen.change(BaseScreen) # Pass class, not instance!
|
|
|
|
|
|
|
|
test()
|