Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dynamic text #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions source/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
EXIT=1
CONT=0

TEXT, CMD, ARG = range(3)

SUBMENU=[]

def m_back(arg):
Expand Down Expand Up @@ -165,11 +167,17 @@ async def menu_update(self):
xfg=self.fg
xbg=self.bg

text = self.current[self.dispmenu + i][TEXT]

if callable(text):
text = text()

# screen.tft.fill_rect(24,40*(i+1),195,40,xbg)
if self.font==None:
screen.text(24,40*(i+1),self.current[self.dispmenu+i][0],xfg,xbg)
screen.text(24, 40 * (i + 1), text, xfg, xbg)
else:
screen.text_font(self.font,24,40*(i+1)+20,self.current[self.dispmenu+i][0],xfg,self.scale)
screen.text_font(self.font, 24, 40 * (i + 1) + 20, text, xfg,
self.scale)



Expand Down
32 changes: 17 additions & 15 deletions source/supercon_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ def planets(arg):
vectoros.launch_task('planets') # launch
return EXIT

def menu_custom(the_menu):
if the_menu.level==1:
if machine.Pin(22).value():
the_menu.current[2]=[" Sound Off",toggle_sound,0]
else:
the_menu.current[2]=[" Sound On",toggle_sound,1]

def dynamic_sound_text():
return " Sound Off" if machine.Pin(22).value() else " Sound On"


def toggle_sound(arg):
## toggle sound here
Expand Down Expand Up @@ -77,16 +75,20 @@ async def vos_main():
with Menu(clear_after=True,fg_color=colors.PHOSPHOR_DARK,bg_color=colors.PHOSPHOR_BG,
cursor_bg=colors.PHOSPHOR_BG, cursor_fg=colors.PHOSPHOR_BRIGHT) as amenu:
## name in menu, command to run, return value?
submenu=[[" Planets", planets, 0],[" Sketch",runsketch,0],[" Back",m_exit,None]]
mainmenu=[[" Lissajous", run_lissajous,None],
[" Demos", SUBMENU, submenu] ,
[" Sound", toggle_sound, None],
[" Reboot",reboot,False],
]

# comment next line for default font
submenu = [
[" Planets", planets, 0],
[" Sketch", runsketch, 0],
[" Back", m_exit, None],
]
mainmenu = [
[" Lissajous", run_lissajous, None],
[" Demos", SUBMENU, submenu],
[dynamic_sound_text, toggle_sound, None],
[" Reboot", reboot, False],
]

# comment next line for default font
amenu.set_font("*") # set default vector font
amenu.set_callback(menu_custom)
await amenu.do_menu(mainmenu)
vos_debug.debug_print(vos_debug.DEBUG_LEVEL_INFO,f"Menu waiting {vos_state.show_menu}")
while vos_state.show_menu==False: # wait until we have to be seen again
Expand Down