Refactored page initialization, content initialization, and loading.

This commit is contained in:
Michael Lazar
2015-02-01 02:02:22 -08:00
parent 66dd4c5bd4
commit b8794e3599
6 changed files with 91 additions and 80 deletions

View File

@@ -1,18 +1,25 @@
import praw
import curses
import sys
from content import SubmissionContent
from page import BasePage
from utils import curses_session
from utils import LoadScreen
class SubmissionPage(BasePage):
def __init__(self, stdscr, content):
def __init__(self, stdscr, reddit, url=None, submission=None):
self.loader = LoadScreen(stdscr)
if url is not None:
content = SubmissionContent.from_url(reddit, url, self.loader)
elif submission is not None:
content = SubmissionContent(submission, self.loader)
else:
raise ValueError('Must specify url or submission')
page_index, cursor_index = -1, 1
super(SubmissionPage, self).__init__(
stdscr, content,
page_index=page_index, cursor_index=cursor_index)
stdscr, content, page_index=-1, cursor_index=1)
def loop(self):
@@ -61,16 +68,6 @@ class SubmissionPage(BasePage):
self.stdscr.clear()
self.draw()
def draw(self):
n_rows, n_cols = self.stdscr.getmaxyx()
self._header_window = self.stdscr.derwin(1, n_cols, 0, 0)
self._content_window = self.stdscr.derwin(1, 0)
self.draw_header()
self.draw_content()
self.add_cursor()
def draw_item(self, win, data, inverted=False):
if data['type'] == 'MoreComments':