Start a config editor with an extract from the urwid tour
This commit is contained in:
82
site_ansto/instrument/util/config_edit.py
Normal file
82
site_ansto/instrument/util/config_edit.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import urwid
|
||||
import urwid.raw_display
|
||||
import urwid.web_display
|
||||
|
||||
def main():
|
||||
text_header = (u"Welcome to the urwid tour! "
|
||||
u"UP / DOWN / PAGE UP / PAGE DOWN scroll. F8 exits.")
|
||||
text_button_list = [u"Yes", u"No", u"Perhaps", u"Certainly", u"Partially",
|
||||
u"Tuesdays Only", u"Help"]
|
||||
text_cb_list = [u"Wax", u"Wash", u"Buff", u"Clear Coat", u"Dry",
|
||||
u"Racing Stripe"]
|
||||
text_rb_list = [u"Morning", u"Afternoon", u"Evening", u"Weekend"]
|
||||
|
||||
|
||||
def button_press(button):
|
||||
frame.footer = urwid.AttrWrap(urwid.Text(
|
||||
[u"Pressed: ", button.get_label()]), 'header')
|
||||
|
||||
radio_button_group = []
|
||||
|
||||
blank = urwid.Divider()
|
||||
listbox_content = [
|
||||
urwid.Padding(urwid.GridFlow(
|
||||
[urwid.AttrWrap(urwid.Button(txt, button_press),
|
||||
'buttn','buttnf') for txt in text_button_list],
|
||||
13, 3, 1, 'left'),
|
||||
left=4, right=3, min_width=13),
|
||||
blank,
|
||||
urwid.Padding(urwid.GridFlow(
|
||||
[urwid.AttrWrap(urwid.CheckBox(txt),'buttn','buttnf')
|
||||
for txt in text_cb_list],
|
||||
10, 3, 1, 'left') ,
|
||||
left=4, right=3, min_width=10),
|
||||
blank,
|
||||
urwid.Padding(urwid.GridFlow(
|
||||
[urwid.AttrWrap(urwid.RadioButton(radio_button_group,
|
||||
txt), 'buttn','buttnf')
|
||||
for txt in text_rb_list],
|
||||
13, 3, 1, 'left') ,
|
||||
left=4, right=3, min_width=13),
|
||||
blank,
|
||||
]
|
||||
header = urwid.AttrWrap(urwid.Text(text_header), 'header')
|
||||
listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content))
|
||||
frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header)
|
||||
|
||||
palette = [
|
||||
('body','black','light gray', 'standout'),
|
||||
('reverse','light gray','black'),
|
||||
('header','white','dark red', 'bold'),
|
||||
('important','dark blue','light gray',('standout','underline')),
|
||||
('editfc','white', 'dark blue', 'bold'),
|
||||
('editbx','light gray', 'dark blue'),
|
||||
('editcp','black','light gray', 'standout'),
|
||||
('bright','dark gray','light gray', ('bold','standout')),
|
||||
('buttn','black','dark cyan'),
|
||||
('buttnf','white','dark blue','bold'),
|
||||
]
|
||||
|
||||
if urwid.web_display.is_web_request():
|
||||
screen = urwid.web_display.Screen()
|
||||
else:
|
||||
screen = urwid.raw_display.Screen()
|
||||
|
||||
def unhandled(key):
|
||||
if key == 'f8':
|
||||
raise urwid.ExitMainLoop()
|
||||
|
||||
urwid.MainLoop(frame, palette, screen,
|
||||
unhandled_input=unhandled).run()
|
||||
|
||||
def setup():
|
||||
urwid.web_display.set_preferences("Urwid Tour")
|
||||
# try to handle short web requests quickly
|
||||
if urwid.web_display.handle_short_request():
|
||||
return
|
||||
|
||||
main()
|
||||
|
||||
if '__main__'==__name__ or urwid.web_display.is_web_request():
|
||||
setup()
|
||||
|
||||
Reference in New Issue
Block a user