Cleaner subscriptions draw_item() implementation
This commit is contained in:
@@ -153,7 +153,7 @@ class BaseContent(object):
|
|||||||
data = {}
|
data = {}
|
||||||
data['object'] = subscription
|
data['object'] = subscription
|
||||||
data['type'] = 'Subscription'
|
data['type'] = 'Subscription'
|
||||||
data['name'] = subscription._case_name
|
data['name'] = "/r/" + subscription._case_name
|
||||||
data['title'] = subscription.title
|
data['title'] = subscription.title
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@@ -404,9 +404,8 @@ class SubscriptionContent(BaseContent):
|
|||||||
self._subscription_data.append(data)
|
self._subscription_data.append(data)
|
||||||
|
|
||||||
data = self._subscription_data[index]
|
data = self._subscription_data[index]
|
||||||
subreddit_info = "/r/" + data['name'] + "\n" + data['title']
|
data['split_title'] = wrap_text(data['name'], width=n_cols)
|
||||||
data['split_title'] = wrap_text(subreddit_info, width=n_cols)
|
data['n_rows'] = len(data['split_title']) + 1
|
||||||
data['n_rows'] = len(data['split_title'])
|
|
||||||
data['offset'] = 0
|
data['offset'] = 0
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import requests
|
|||||||
from .exceptions import SubredditError, AccountError
|
from .exceptions import SubredditError, AccountError
|
||||||
from .page import BasePage, Navigator, BaseController
|
from .page import BasePage, Navigator, BaseController
|
||||||
from .submission import SubmissionPage
|
from .submission import SubmissionPage
|
||||||
|
from .subscriptions import SubscriptionPage
|
||||||
from .content import SubredditContent
|
from .content import SubredditContent
|
||||||
from .helpers import open_browser, open_editor, strip_subreddit_url
|
from .helpers import open_browser, open_editor, strip_subreddit_url
|
||||||
from .docs import SUBMISSION_FILE
|
from .docs import SUBMISSION_FILE
|
||||||
@@ -158,6 +159,19 @@ class SubredditPage(BasePage):
|
|||||||
page.loop()
|
page.loop()
|
||||||
self.refresh_content()
|
self.refresh_content()
|
||||||
|
|
||||||
|
@SubredditController.register('s')
|
||||||
|
def open_subscriptions(self):
|
||||||
|
"Open user subscriptions page"
|
||||||
|
|
||||||
|
if not self.reddit.is_logged_in():
|
||||||
|
show_notification(self.stdscr, ['Not logged in'])
|
||||||
|
return
|
||||||
|
|
||||||
|
with self.safe_call as s:
|
||||||
|
page = SubscriptionPage(self.stdscr, self.reddit)
|
||||||
|
page.loop()
|
||||||
|
self.refresh_content()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def draw_item(win, data, inverted=False):
|
def draw_item(win, data, inverted=False):
|
||||||
|
|
||||||
|
|||||||
@@ -60,4 +60,9 @@ class SubscriptionPage(BasePage):
|
|||||||
n_title = len(data['split_title'])
|
n_title = len(data['split_title'])
|
||||||
for row, text in enumerate(data['split_title'], start=offset):
|
for row, text in enumerate(data['split_title'], start=offset):
|
||||||
if row in valid_rows:
|
if row in valid_rows:
|
||||||
add_line(win, text, row, 1, curses.A_BOLD)
|
attr = curses.A_BOLD | Color.YELLOW
|
||||||
|
add_line(win, u'{name}'.format(**data), row, 1, attr)
|
||||||
|
|
||||||
|
row = n_title + offset
|
||||||
|
if row in valid_rows:
|
||||||
|
add_line(win, u'{title}'.format(**data), row, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user