https://github.com/meyer1994/ugh
Use JSON templates to create terminal UI with urwid
https://github.com/meyer1994/ugh
curses template terminal ui urwid xml
Last synced: 19 days ago
JSON representation
Use JSON templates to create terminal UI with urwid
- Host: GitHub
- URL: https://github.com/meyer1994/ugh
- Owner: meyer1994
- License: gpl-3.0
- Created: 2017-12-13T16:18:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-20T18:17:06.000Z (about 5 years ago)
- Last Synced: 2025-09-22T23:23:38.279Z (8 months ago)
- Topics: curses, template, terminal, ui, urwid, xml
- Language: Python
- Size: 72.3 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UGH
Use JSON templates to create terminal UI with urwid
[](https://travis-ci.org/meyer1994/ugh)
[](https://codecov.io/gh/meyer1994/ugh)
PS: UGH does not mean anything. It is what I think when I need to use urwid (still better than curses).
## Usage:
1. Define the `class` attribute with the name of the class you want to use;
2. Define the variables of the constructor as if you were coding it normally;
3. ????
4. Profit?
---
Simple example used to show a centered Text widget written 'nice' with red
background.
[text.py](examples/text.py)
```python
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()
```
## TODO
- ~~Handle lists and tuples.~~
- ~~Better way to handle tuples.~~
- ~~Handle callbacks (it breaks everything, for now).~~