|
|
|
|
@ -2,6 +2,7 @@ import urwid
|
|
|
|
|
import yaml
|
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
from API import Fetcher
|
|
|
|
|
from Render import Article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LeftPane(urwid.ListBox):
|
|
|
|
|
@ -14,6 +15,9 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
self.categoryPosition = 0
|
|
|
|
|
self.isCategoryView = True
|
|
|
|
|
self.currentCategory = ""
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
if self.isCategoryView:
|
|
|
|
|
self.currentCategory = focus_widget.attr_map[None][0]
|
|
|
|
|
|
|
|
|
|
def getArticlesFromCategory(self, category, number):
|
|
|
|
|
tui.fetcher.articlesFromCategory(category[13:], str(number))
|
|
|
|
|
@ -41,8 +45,10 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
idx = idx + 1
|
|
|
|
|
self.set_focus(idx)
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articles.fill(articles)
|
|
|
|
|
if self.isCategoryView:
|
|
|
|
|
self.currentCategory = focus_widget.attr_map[None][0]
|
|
|
|
|
tui.articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articleView.fill(tui.articles)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("k", "up"):
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
@ -50,8 +56,10 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
idx = idx - 1
|
|
|
|
|
self.set_focus(idx)
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articles.fill(articles)
|
|
|
|
|
if self.isCategoryView:
|
|
|
|
|
self.currentCategory = focus_widget.attr_map[None][0]
|
|
|
|
|
tui.articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articleView.fill(tui.articles)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("l", "right"):
|
|
|
|
|
if self.isCategoryView:
|
|
|
|
|
@ -59,7 +67,6 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
self.categoryPosition = idx
|
|
|
|
|
categoryId = focus_widget.attr_map[None][0]
|
|
|
|
|
self.currentCategory = categoryId
|
|
|
|
|
feeds = tui.fetcher.feedsFromCategory(categoryId)
|
|
|
|
|
feedItems = [urwid.AttrMap(urwid.Columns([(5, urwid.Text(str(tui.fetcher.unreadCounts[feed["id"]][0]))),
|
|
|
|
|
urwid.Text(feed["title"])]), feed["id"], "reveal focus") for feed in feeds]
|
|
|
|
|
@ -67,8 +74,10 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
self.body = walker
|
|
|
|
|
tui.leftBox.set_title(categoryId[13:])
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articles.fill(articles)
|
|
|
|
|
if self.isCategoryView:
|
|
|
|
|
self.currentCategory = focus_widget.attr_map[None][0]
|
|
|
|
|
tui.articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articleView.fill(tui.articles)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("h", "left"):
|
|
|
|
|
if not self.isCategoryView:
|
|
|
|
|
@ -80,8 +89,8 @@ class LeftPane(urwid.ListBox):
|
|
|
|
|
tui.leftBox.set_title("Categories")
|
|
|
|
|
self.set_focus(self.categoryPosition)
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articles.fill(articles)
|
|
|
|
|
tui.articles = self.getArticles(focus_widget.attr_map[None])
|
|
|
|
|
tui.articleView.fill(tui.articles)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
@ -92,6 +101,8 @@ class RightPane(urwid.ListBox):
|
|
|
|
|
super().__init__(self)
|
|
|
|
|
walker = urwid.SimpleListWalker([])
|
|
|
|
|
self.body = walker
|
|
|
|
|
self.isList = True
|
|
|
|
|
self.articlePosition = 0
|
|
|
|
|
|
|
|
|
|
def fill(self, articles):
|
|
|
|
|
items = [urwid.AttrMap(urwid.Columns([(2, urwid.Text("N")), urwid.Text(article["title"])]),
|
|
|
|
|
@ -99,6 +110,10 @@ class RightPane(urwid.ListBox):
|
|
|
|
|
walker = urwid.SimpleListWalker(items)
|
|
|
|
|
self.body = walker
|
|
|
|
|
|
|
|
|
|
def getArticle(self, articleId):
|
|
|
|
|
article = [item for item in tui.fetcher.articles[tui.feedView.currentCategory[13:]] if item["id"] == articleId][0]
|
|
|
|
|
return article
|
|
|
|
|
|
|
|
|
|
def keypress(self, size, key):
|
|
|
|
|
if key in ("j", "down"):
|
|
|
|
|
item_size = len(self.body)
|
|
|
|
|
@ -114,20 +129,23 @@ class RightPane(urwid.ListBox):
|
|
|
|
|
self.set_focus(idx)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("l", "right"):
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
value = next(focus_widget.render((100,), focus=False).content())[1][2].decode().strip()
|
|
|
|
|
feeds = tui.leftPaneItems[value]["feeds"]
|
|
|
|
|
feedItems = [urwid.Columns([(4, urwid.Text(item["count"])), urwid.Text(item["name"])])
|
|
|
|
|
for item in feeds]
|
|
|
|
|
walker = urwid.SimpleListWalker([urwid.AttrMap(item, None, 'reveal focus') for item in feedItems])
|
|
|
|
|
self.body = walker
|
|
|
|
|
tui.leftBox.set_title(value)
|
|
|
|
|
if self.isList is True:
|
|
|
|
|
self.isList = False
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
self.articlePosition = idx
|
|
|
|
|
articleId = focus_widget.attr_map[None]
|
|
|
|
|
article = Article(self.getArticle(articleId))
|
|
|
|
|
walker = urwid.SimpleListWalker([urwid.Text(""), urwid.Text(article.text), urwid.Text("")])
|
|
|
|
|
self.body = walker
|
|
|
|
|
self.set_focus(1)
|
|
|
|
|
tui.rightBox.set_title(article.title)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("h", "left"):
|
|
|
|
|
feedItems = tui.feedItems
|
|
|
|
|
walker = urwid.SimpleListWalker([urwid.AttrMap(item, None, 'reveal focus') for item in feedItems])
|
|
|
|
|
self.body = walker
|
|
|
|
|
tui.leftBox.set_title("Categories")
|
|
|
|
|
if self.isList is False:
|
|
|
|
|
self.isList = True
|
|
|
|
|
self.fill(tui.articles)
|
|
|
|
|
tui.rightBox.set_title("Articles")
|
|
|
|
|
self.set_focus(self.articlePosition)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
@ -164,23 +182,24 @@ class TUI(urwid.Frame):
|
|
|
|
|
self.executor = ThreadPoolExecutor(max_workers=1)
|
|
|
|
|
self.loop = None
|
|
|
|
|
self.articleItems = [urwid.Text("Article# " + str(i)) for i in range(0, 10)]
|
|
|
|
|
self.feeds = LeftPane(self.fetcher.categories)
|
|
|
|
|
self.articles = RightPane([])
|
|
|
|
|
self.leftBox = urwid.LineBox(self.feeds, title="Categories")
|
|
|
|
|
self.feedView = LeftPane(self.fetcher.categories)
|
|
|
|
|
self.articleView = RightPane([])
|
|
|
|
|
self.leftBox = urwid.LineBox(self.feedView, title="Categories")
|
|
|
|
|
self.rightBox = urwid.LineBox(self.articleView, title="Articles")
|
|
|
|
|
self.container = urwid.Columns(
|
|
|
|
|
[(40, self.leftBox),
|
|
|
|
|
urwid.LineBox(self.articles, title="Articles")])
|
|
|
|
|
[(40, self.leftBox), self.rightBox])
|
|
|
|
|
self.body = self.container
|
|
|
|
|
self.articles = []
|
|
|
|
|
|
|
|
|
|
super().__init__(self.body)
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
focus_widget, idx = self.feeds.get_focus()
|
|
|
|
|
focus_widget, idx = self.feedView.get_focus()
|
|
|
|
|
itemId = focus_widget.attr_map[None][0]
|
|
|
|
|
number = focus_widget.attr_map[None][1]
|
|
|
|
|
tui.fetcher.articlesFromCategory(itemId[13:], str(number))
|
|
|
|
|
articles = tui.fetcher.articles[itemId[13:]]
|
|
|
|
|
self.articles.fill(articles)
|
|
|
|
|
self.articles = tui.fetcher.articles[itemId[13:]]
|
|
|
|
|
self.articleView.fill(self.articles)
|
|
|
|
|
self.loop.run()
|
|
|
|
|
self.executor.shutdown(wait=False)
|
|
|
|
|
|
|
|
|
|
|