Use JSON templates to create terminal UI with urwid
PS: UGH does not mean anything. It is what I think when I need to use urwid (still better than curses).
- Define the
class
attribute with the name of the class you want to use; - Define the variables of the constructor as if you were coding it normally;
- ????
- Profit?
Simple example used to show a centered Text widget written 'nice' with red background.
import urwid
import json
import ugh
def exit_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
json_string = '''
{
"class": "Filler",
"body": {
"class": "AttrMap",
"w": {
"class": "Text",
"markup": "nice",
"align": "center"
},
"attr_map": "streak"
}
}
'''
palette = [('streak', 'black', 'dark red')]
w_dict = json.loads(json_string)
t = ugh.construct(w_dict)
loop = urwid.MainLoop(t, palette, unhandled_input=exit_q)
loop.run()
-
Handle lists and tuples.Better way to handle tuples.
-
Handle callbacks (it breaks everything, for now).