-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
56 lines (45 loc) · 1.43 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import curses
import urwid
class Screen:
def __init__(self, stdscr):
self.stdscr = stdscr
def tick(self):
self.stdscr.clear()
rows, cols = self.stdscr.getmaxyx()
x = (cols - len("Hello World!")) // 2
y = rows // 2
self.stdscr.addstr(y, x, "Hello World!")
self.stdscr.addstr(0, 0, str(curses.LINES))
self.stdscr.refresh()
def main(stdscr):
# Clear screen
screen = Screen(stdscr)
while True:
#window = curses.newwin(10, curses.COLS, 0, 0)
#window.clear()
#window.addstr(0, 0, "Hello World!")
#stdscr.refresh()
#window.refresh()
screen.tick()
code = stdscr.getch()
#if code == curses.KEY_RESIZE:
#curses.endwin()
#stdscr = curses.initscr()
#stdscr.refresh()
#stdscr.clear()
#screen = Screen(stdscr)
if __name__ == "__main__":
#curses.wrapper(main)
def exit_on_q(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
palette = [
('banner', 'black', 'light gray'),
('streak', 'black', 'dark red'),
('bg', 'black', 'dark blue'),]
txt = urwid.Text(('banner', u" Hello World "), align='center')
map1 = urwid.AttrMap(txt, 'streak')
fill = urwid.Filler(map1)
map2 = urwid.AttrMap(fill, 'bg')
loop = urwid.MainLoop(map2, palette, unhandled_input=exit_on_q)
loop.run()