not needed any more
parent
8625b25ecb
commit
c4c80e3147
100
menu.py
100
menu.py
|
@ -1,100 +0,0 @@
|
||||||
from picotui.widgets import *
|
|
||||||
from picotui.menu import *
|
|
||||||
from picotui.context import Context
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import cli
|
|
||||||
|
|
||||||
fileToDo = None
|
|
||||||
|
|
||||||
# case insensitive search for files ending in yaml or yml.
|
|
||||||
def yamlFilter(filename):
|
|
||||||
return( re.search(".ya?ml$", filename, flags=re.IGNORECASE) != None)
|
|
||||||
|
|
||||||
# Dialog on the screen
|
|
||||||
d = None
|
|
||||||
|
|
||||||
# This routine is called to redraw screen "in menu's background"
|
|
||||||
def screen_redraw(s, allow_cursor=False):
|
|
||||||
s.attr_color(C_WHITE, C_BLUE)
|
|
||||||
s.cls()
|
|
||||||
s.attr_reset()
|
|
||||||
d.redraw()
|
|
||||||
|
|
||||||
|
|
||||||
# We have two independent widgets on screen: dialog and main menu,
|
|
||||||
# so can't call their individual loops, and instead should have
|
|
||||||
# "main loop" to route events to currently active widget, and
|
|
||||||
# switch the active one based on special events.
|
|
||||||
def main_loop():
|
|
||||||
while 1:
|
|
||||||
key = m.get_input()
|
|
||||||
|
|
||||||
if isinstance(key, list):
|
|
||||||
# Mouse click
|
|
||||||
x, y = key
|
|
||||||
if m.inside(x, y):
|
|
||||||
m.focus = True
|
|
||||||
|
|
||||||
if m.focus:
|
|
||||||
# If menu is focused, it gets events. If menu is cancelled,
|
|
||||||
# it loses focus. Otherwise, if menu selection is made, we
|
|
||||||
# quit with with menu result.
|
|
||||||
res = m.handle_input(key)
|
|
||||||
if res == ACTION_CANCEL:
|
|
||||||
m.focus = False
|
|
||||||
elif res is not None and res is not True:
|
|
||||||
return res
|
|
||||||
else:
|
|
||||||
# If menu isn't focused, it can be focused by pressing F9.
|
|
||||||
if key == KEY_F9:
|
|
||||||
m.focus = True
|
|
||||||
m.redraw()
|
|
||||||
continue
|
|
||||||
# Otherwise, dialog gets input
|
|
||||||
res = d.handle_input(key)
|
|
||||||
if res is not None and res is not True:
|
|
||||||
return res
|
|
||||||
|
|
||||||
with Context():
|
|
||||||
|
|
||||||
d = Dialog(10, 5, 80, 24)
|
|
||||||
d.add(2, 21, WLabel("Press F9 for menu"))
|
|
||||||
d.add(2, 22, WLabel("Press Esc to Exit"))
|
|
||||||
|
|
||||||
# Get all files in the current directory that are YAML files
|
|
||||||
d.add(4, 2, WLabel("Available YAML Files:"))
|
|
||||||
# dir_list = list(filter(yamlFilter, os.listdir('.')))
|
|
||||||
dir_list = os.listdir('.')
|
|
||||||
print( dir_list )
|
|
||||||
# Draw a list box with all those files in it
|
|
||||||
filelist = WListBox(26, 10, dir_list )
|
|
||||||
d.add(4, 3, filelist )
|
|
||||||
|
|
||||||
b = WButton(8, "OK")
|
|
||||||
d.add(10, 19, b)
|
|
||||||
b.finish_dialog = ACTION_OK
|
|
||||||
|
|
||||||
b = WButton(8, "Cancel")
|
|
||||||
d.add(23, 19, b)
|
|
||||||
b.finish_dialog = ACTION_CANCEL
|
|
||||||
|
|
||||||
screen_redraw(Screen)
|
|
||||||
Screen.set_screen_redraw(screen_redraw)
|
|
||||||
|
|
||||||
menu_file = WMenuBox([("Open...", "Open"), ("Save", "S"), ("Save as...", "Sa"), ("Exit", "ex")])
|
|
||||||
menu_edit = WMenuBox([("Copy", "copy"), ("Paste", "paste")])
|
|
||||||
m = WMenuBar([("File", menu_file), ("Edit", menu_edit), ("About", "About")])
|
|
||||||
m.permanent = True
|
|
||||||
m.redraw()
|
|
||||||
|
|
||||||
res = main_loop()
|
|
||||||
# We get here when the user finishes.
|
|
||||||
if( res != ACTION_CANCEL ):
|
|
||||||
fileToDo = filelist.content[filelist.choice]
|
|
||||||
|
|
||||||
if( fileToDo != None ):
|
|
||||||
configfile = open( fileToDo, 'r', encoding='utf8')
|
|
||||||
cli.parseFile(configfile)
|
|
||||||
else:
|
|
||||||
print( "Cancelled" )
|
|
Loading…
Reference in New Issue