Added loading dialog when opening submissions.

This commit is contained in:
Michael Lazar
2015-01-28 01:53:51 -08:00
parent aa9ec95da4
commit 86e0a94473
5 changed files with 37 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import praw import praw
import curses import curses
import sys
from content_generators import SubmissionContent, SubredditContent from content_generators import SubmissionContent, SubredditContent
from utils import curses_session from utils import curses_session
@@ -37,9 +38,13 @@ class SubmissionViewer(BaseViewer):
elif cmd == curses.KEY_RESIZE: elif cmd == curses.KEY_RESIZE:
self.draw() self.draw()
# Go back
elif cmd in (ord('b'), curses.KEY_LEFT):
break
# Quit # Quit
elif cmd == ord('q'): elif cmd == ord('q'):
break sys.exit()
else: else:
curses.beep() curses.beep()

View File

@@ -1,10 +1,12 @@
import praw import praw
import textwrap import textwrap
import curses import curses
import sys
from content_generators import SubredditContent from content_generators import SubredditContent, SubmissionContent
from utils import curses_session from submission_viewer import SubmissionViewer
from viewer import BaseViewer from viewer import BaseViewer
from utils import curses_session
class SubredditViewer(BaseViewer): class SubredditViewer(BaseViewer):
@@ -24,7 +26,8 @@ class SubredditViewer(BaseViewer):
# View submission # View submission
elif cmd in (curses.KEY_RIGHT, ord(' ')): elif cmd in (curses.KEY_RIGHT, ord(' ')):
pass self.open_submission()
self.draw()
# Enter edit mode to change subreddit # Enter edit mode to change subreddit
elif cmd == ord('/'): elif cmd == ord('/'):
@@ -41,11 +44,21 @@ class SubredditViewer(BaseViewer):
# Quit # Quit
elif cmd == ord('q'): elif cmd == ord('q'):
break sys.exit()
else: else:
curses.beep() curses.beep()
def open_submission(self):
"Select the current submission to view posts"
self.add_loading()
submission = self.content.get(self.nav.absolute_index)['object']
content = SubmissionContent(submission)
viewer = SubmissionViewer(self.stdscr, content)
viewer.loop()
def draw(self): def draw(self):
n_rows, n_cols = self.stdscr.getmaxyx() n_rows, n_cols = self.stdscr.getmaxyx()

View File

@@ -106,6 +106,20 @@ class BaseViewer(object):
continue continue
self.stdscr.nodelay(0) self.stdscr.nodelay(0)
def add_loading(self):
"Draw a `loading` popup dialog in the center of the screen"
message = 'Loading...'
n_rows, n_cols = self.stdscr.getmaxyx()
win_rows, win_cols = 3, len(message)+2
start_row = (n_rows - win_rows) / 2
start_col = (n_cols - win_cols) / 2
window = self.stdscr.derwin(win_rows, win_cols, start_row, start_col)
window.border()
window.addstr(1, 1, message)
window.refresh()
def draw_header(self): def draw_header(self):
n_rows, n_cols = self._header_window.getmaxyx() n_rows, n_cols = self._header_window.getmaxyx()

0
scripts/__init__.py Normal file
View File