2021-07-10 09:45:50 +00:00
|
|
|
# menu.py micro-gui demo of Menu class
|
|
|
|
|
|
|
|
# Released under the MIT License (MIT). See LICENSE.
|
|
|
|
# Copyright (c) 2021 Peter Hinch
|
|
|
|
|
|
|
|
import hardware_setup # Create a display instance
|
|
|
|
from gui.core.ugui import Screen, ssd
|
2021-07-14 15:42:08 +00:00
|
|
|
import gui.fonts.freesans20 as font
|
2021-07-10 09:45:50 +00:00
|
|
|
from gui.core.writer import CWriter
|
|
|
|
|
2022-02-06 12:05:38 +00:00
|
|
|
from gui.widgets import Menu, CloseButton
|
2021-07-10 09:45:50 +00:00
|
|
|
from gui.core.colors import *
|
|
|
|
|
|
|
|
class BaseScreen(Screen):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
def cb(button, n):
|
2021-07-14 15:42:08 +00:00
|
|
|
print('Help callback', n)
|
2021-07-10 09:45:50 +00:00
|
|
|
|
|
|
|
def cb_sm(lb, n):
|
|
|
|
print('Submenu callback', lb.value(), lb.textvalue(), n)
|
|
|
|
|
|
|
|
super().__init__()
|
2021-07-16 13:27:42 +00:00
|
|
|
metals2 = (('Gold', cb_sm, (6,)),
|
|
|
|
('Silver', cb_sm, (7,)),
|
|
|
|
('Iron', cb_sm, (8,)),
|
|
|
|
('Zinc', cb_sm, (9,)),
|
|
|
|
('Copper', cb_sm, (10,)))
|
|
|
|
|
|
|
|
gases = (('Helium', cb_sm, (0,)),
|
|
|
|
('Neon', cb_sm, (1,)),
|
|
|
|
('Argon', cb_sm, (2,)),
|
|
|
|
('Krypton', cb_sm, (3,)),
|
|
|
|
('Xenon', cb_sm, (4,)),
|
|
|
|
('Radon', cb_sm, (5,)))
|
|
|
|
|
|
|
|
metals = (('Lithium', cb_sm, (6,)),
|
|
|
|
('Sodium', cb_sm, (7,)),
|
|
|
|
('Potassium', cb_sm, (8,)),
|
|
|
|
('Rubidium', cb_sm, (9,)),
|
|
|
|
('More', metals2))
|
|
|
|
|
|
|
|
mnu = (('Gas', gases),
|
|
|
|
('Metal',metals),
|
2021-07-14 15:42:08 +00:00
|
|
|
('Help', cb, (2,)))
|
2021-07-16 13:27:42 +00:00
|
|
|
|
2021-07-14 15:42:08 +00:00
|
|
|
wri = CWriter(ssd, font, GREEN, BLACK, verbose=False)
|
2021-07-10 09:45:50 +00:00
|
|
|
Menu(wri, bgcolor=BLUE, textcolor=WHITE, args = mnu)
|
|
|
|
CloseButton(wri)
|
|
|
|
|
|
|
|
|
|
|
|
Screen.change(BaseScreen)
|