-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtui.py
76 lines (56 loc) · 2.78 KB
/
tui.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import urwid
from summnews import SummNews
class SummNewsTui:
def __init__(self):
self.palette = [
("title", "black, bold", "white"),
("body", "black", "white"),
("bar", "black", "white"),
("content_box", "black", "white"),
("bg", "black", "white")]
self.summed_articles = SummNews(5).get_summed_news()
#[{"title": "Test Num: " + str(x), "body": "This is just a test, number " + str(x) + "."} for x in range(60)]
pre_div = urwid.Divider()
self.div = urwid.AttrMap(pre_div, "bar")
self.start_up()
def title_menu(self):
title_list = [self.div]
for article in self.summed_articles:
pre_title_btn = urwid.Button(article["title"])
urwid.connect_signal(pre_title_btn, "click", self.display_article, article)
title_btn = urwid.AttrMap(pre_title_btn, "body", focus_map="reversed")
title_list.extend([title_btn])
scene = urwid.Pile(title_list)
return urwid.Filler(scene)
def re_title_menu(self, button):
self.contents.original_widget = self.title_menu()
def display_article(self, button, article):
title = urwid.Text(("title", article["title"]), align="center")
body = urwid.Text(("body", article["body"]), align="left")
pre_close_btn = urwid.Button("Close")
urwid.connect_signal(pre_close_btn, "click", self.re_title_menu)
close_btn = urwid.AttrMap(pre_close_btn, "body", focus_map="reversed")
scene = urwid.Pile([title, self.div, body, self.div, close_btn])
self.contents.original_widget = urwid.Filler(scene)
def display_all_articles(self):
interface_articles = []
for article in self.summed_articles:
title = urwid.Text(("title", article["title"]), align="center")
div = urwid.Divider()
div_mapped = urwid.AttrMap(div, "bar")
body = urwid.Text(("body", article["body"]), align="left")
interface_articles.extend([title, body, div_mapped])
return urwid.Pile(interface_articles)
def read_key(self, key):
if key in ("q", "Q"):
raise urwid.ExitMainLoop()
def start_up(self):
pre_contents = self.title_menu()
self.contents = urwid.AttrMap(pre_contents, "content_box")
pre_frame = urwid.Padding(self.contents, "center", left=2, right=2)
self.frame = urwid.AttrMap(pre_frame, "bar")
self.overlay = urwid.Overlay(self.frame, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
align="center", width=("relative", 60),
valign="middle", height=("relative", 60))
urwid.MainLoop(self.overlay, self.palette, unhandled_input=self.read_key).run()
#SummNewsTui()