Missed some changes.
This commit is contained in:
75
rtv/subscription.py
Normal file
75
rtv/subscription.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import curses
|
||||
|
||||
from .page import Page, PageController
|
||||
from .content import SubscriptionContent
|
||||
from .objects import Color, Navigator, Command
|
||||
|
||||
|
||||
class SubscriptionController(PageController):
|
||||
character_map = {}
|
||||
|
||||
|
||||
class SubscriptionPage(Page):
|
||||
|
||||
def __init__(self, reddit, name, func, term, config, oauth):
|
||||
super(SubscriptionPage, self).__init__(reddit, term, config, oauth)
|
||||
|
||||
self.controller = SubscriptionController(self, keymap=config.keymap)
|
||||
self.name = name
|
||||
self.func = func
|
||||
self.content = SubscriptionContent.from_func(name, func, term.loader)
|
||||
self.nav = Navigator(self.content.get)
|
||||
self.reddit_data = None
|
||||
|
||||
@SubscriptionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download all reddits and reset the page index"
|
||||
|
||||
# reddit listings does not support sorting by order
|
||||
if order:
|
||||
self.term.flash()
|
||||
return
|
||||
|
||||
with self.term.loader():
|
||||
self.content = SubscriptionContent.from_func(
|
||||
self.name, self.func, self.term.loader)
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_SELECT'))
|
||||
def select_reddit(self):
|
||||
"Store the selected reddit and return to the subreddit page"
|
||||
|
||||
self.reddit_data = self.content.get(self.nav.absolute_index)
|
||||
self.active = False
|
||||
|
||||
@SubscriptionController.register(Command('SUBSCRIPTION_EXIT'))
|
||||
def close_subscriptions(self):
|
||||
"Close subscriptions and return to the subreddit page"
|
||||
|
||||
self.active = False
|
||||
|
||||
def _draw_banner(self):
|
||||
# Subscriptions can't be sorted, so disable showing the order menu
|
||||
pass
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
n_cols -= 1 # Leave space for the cursor in the first column
|
||||
|
||||
# Handle the case where the window is not large enough to fit the data.
|
||||
valid_rows = range(0, n_rows)
|
||||
offset = 0 if not inverted else -(data['n_rows'] - n_rows)
|
||||
|
||||
row = offset
|
||||
if row in valid_rows:
|
||||
attr = curses.A_BOLD | Color.YELLOW
|
||||
self.term.add_line(win, '{name}'.format(**data), row, 1, attr)
|
||||
|
||||
row = offset + 1
|
||||
for row, text in enumerate(data['split_title'], start=row):
|
||||
if row in valid_rows:
|
||||
self.term.add_line(win, text, row, 1)
|
||||
Reference in New Issue
Block a user