def subreddit_page(reddit, terminal, config, oauth): subreddit = '/r/python' with terminal.loader(): page = SubredditPage(reddit, terminal, config, oauth, subreddit) assert not terminal.loader.exception page.draw() return page
def test_subreddit_page_construct(reddit, terminal, config, oauth): window = terminal.stdscr.subwin with terminal.loader(): page = SubredditPage(reddit, terminal, config, oauth, '/r/python') assert terminal.loader.exception is None page.draw() # Title title = '/r/python'.encode('utf-8') window.addstr.assert_any_call(0, 0, title) # Banner menu = ('[1]hot ' '[2]top ' '[3]rising ' '[4]new ' '[5]controversial').encode('utf-8') window.addstr.assert_any_call(0, 0, menu) # Submission text = page.content.get(0)['split_title'][0].encode('utf-8') window.subwin.addstr.assert_any_call(0, 1, text, 2097152) # Cursor should have been drawn assert window.subwin.chgat.called # Reload with a smaller terminal window terminal.stdscr.ncols = 20 terminal.stdscr.nlines = 10 with terminal.loader(): page = SubredditPage(reddit, terminal, config, oauth, '/r/python') assert terminal.loader.exception is None page.draw()
def draw_screen(stdscr, reddit, config, theme, oauth): threads = [] max_y, max_x = stdscr.getmaxyx() mid_x = int(max_x / 2) tall_y, short_y = int(max_y / 3 * 2), int(max_y / 3) stdscr.clear() stdscr.refresh() # =================================================================== # Submission Page # =================================================================== win1 = stdscr.derwin(tall_y - 1, mid_x - 1, 0, 0) term = Terminal(win1, config) term.set_theme(theme) oauth.term = term url = 'https://www.reddit.com/r/Python/comments/4dy7xr' with term.loader('Loading'): page = SubmissionPage(reddit, term, config, oauth, url=url) # Tweak the data in order to demonstrate the full range of settings data = page.content.get(-1) data['object'].link_flair_text = 'flair' data['object'].guilded = 1 data['object'].over_18 = True data['object'].saved = True data.update(page.content.strip_praw_submission(data['object'])) data = page.content.get(0) data['object'].author.name = 'kafoozalum' data['object'].stickied = True data['object'].author_flair_text = 'flair' data['object'].likes = True data.update(page.content.strip_praw_comment(data['object'])) data = page.content.get(1) data['object'].saved = True data['object'].likes = False data['object'].score_hidden = True data['object'].guilded = 1 data.update(page.content.strip_praw_comment(data['object'])) data = page.content.get(2) data['object'].author.name = 'kafoozalum' data['object'].body = data['object'].body[:100] data.update(page.content.strip_praw_comment(data['object'])) page.content.toggle(9) page.content.toggle(5) page.draw() # =================================================================== # Subreddit Page # =================================================================== win2 = stdscr.derwin(tall_y - 1, mid_x - 1, 0, mid_x + 1) term = Terminal(win2, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubredditPage(reddit, term, config, oauth, '/u/saved') # Tweak the data in order to demonstrate the full range of settings data = page.content.get(3) data['object'].hide_score = True data['object'].author = None data['object'].saved = False data.update(page.content.strip_praw_submission(data['object'])) page.content.order = 'rising' page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Success',), kwargs={'style': 'Success'}) thread.start() threads.append((thread, term)) # =================================================================== # Subscription Page # =================================================================== win3 = stdscr.derwin(short_y, mid_x - 1, tall_y, 0) term = Terminal(win3, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubscriptionPage(reddit, term, config, oauth, 'popular') page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Error',), kwargs={'style': 'Error'}) thread.start() threads.append((thread, term)) # =================================================================== # Multireddit Page # =================================================================== win4 = stdscr.derwin(short_y, mid_x - 1, tall_y, mid_x + 1) term = Terminal(win4, config) term.set_theme(theme) oauth.term = term with term.loader('Loading'): page = SubscriptionPage(reddit, term, config, oauth, 'multireddit') page.nav.cursor_index = 1 page.draw() term.pause_getch = True term.getch = MethodType(notification_getch, term) thread = threading.Thread(target=term.show_notification, args=('Info',), kwargs={'style': 'Info'}) thread.start() threads.append((thread, term)) term = Terminal(win4, config) term.set_theme(theme) term.pause_getch = True term.getch = MethodType(prompt_getch, term) thread = threading.Thread(target=term.prompt_y_or_n, args=('Prompt: ',)) thread.start() threads.append((thread, term)) time.sleep(0.5) curses.curs_set(0) return threads