Added better descriptions to loader messages.
This commit is contained in:
@@ -64,7 +64,7 @@ def main():
|
||||
try:
|
||||
with curses_session() as stdscr:
|
||||
term = Terminal(stdscr, config['ascii'])
|
||||
with term.loader(catch_exception=False):
|
||||
with term.loader('Initializing', catch_exception=False):
|
||||
reddit = praw.Reddit(user_agent=user_agent,
|
||||
decode_html_entities=False,
|
||||
disable_update_check=True)
|
||||
@@ -74,9 +74,9 @@ def main():
|
||||
if config.refresh_token:
|
||||
oauth.authorize()
|
||||
|
||||
with term.loader():
|
||||
page = SubredditPage(reddit, term, config, oauth,
|
||||
config['subreddit'])
|
||||
name = config['subreddit']
|
||||
with term.loader('Loading subreddit'):
|
||||
page = SubredditPage(reddit, term, config, oauth, name)
|
||||
if term.loader.exception:
|
||||
return
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ class SubmissionContent(Content):
|
||||
self._comment_data[index:index + 1] = data['cache']
|
||||
|
||||
elif data['type'] == 'MoreComments':
|
||||
with self._loader():
|
||||
with self._loader('Loading comments'):
|
||||
# Undefined behavior if using a nested loader here
|
||||
assert self._loader.depth == 1
|
||||
comments = data['object'].comments(update=True)
|
||||
@@ -424,7 +424,7 @@ class SubredditContent(Content):
|
||||
|
||||
while index >= len(self._submission_data):
|
||||
try:
|
||||
with self._loader():
|
||||
with self._loader('Loading more submissions'):
|
||||
submission = next(self._submissions)
|
||||
if self._loader.exception:
|
||||
raise IndexError
|
||||
@@ -477,7 +477,7 @@ class SubscriptionContent(Content):
|
||||
|
||||
while index >= len(self._subscription_data):
|
||||
try:
|
||||
with self._loader():
|
||||
with self._loader('Loading subscriptions'):
|
||||
subscription = next(self._subscriptions)
|
||||
if self._loader.exception:
|
||||
raise IndexError
|
||||
|
||||
@@ -72,7 +72,7 @@ class OAuthHelper(object):
|
||||
|
||||
# If we already have a token, request new access credentials
|
||||
if self.config.refresh_token:
|
||||
with self.term.loader(message='Logging in'):
|
||||
with self.term.loader('Logging in'):
|
||||
self.reddit.refresh_access_information(
|
||||
self.config.refresh_token)
|
||||
return
|
||||
@@ -93,7 +93,7 @@ class OAuthHelper(object):
|
||||
# Open a background browser (e.g. firefox) which is non-blocking.
|
||||
# Stop the iloop when the user hits the auth callback, at which
|
||||
# point we continue and check the callback params.
|
||||
with self.term.loader(message='Opening browser for authorization'):
|
||||
with self.term.loader('Opening browser for authorization'):
|
||||
self.term.open_browser(authorize_url)
|
||||
io.start()
|
||||
if self.term.loader.exception:
|
||||
@@ -103,7 +103,7 @@ class OAuthHelper(object):
|
||||
# while for the user to close the process. Once the process is
|
||||
# closed, the iloop is stopped and we can check if the user has
|
||||
# hit the callback URL.
|
||||
with self.term.loader(delay=0, message='Redirecting to reddit'):
|
||||
with self.term.loader('Redirecting to reddit', delay=0):
|
||||
# This load message exists to provide user feedback
|
||||
time.sleep(1)
|
||||
io.add_callback(self._async_open_browser, authorize_url)
|
||||
@@ -122,7 +122,7 @@ class OAuthHelper(object):
|
||||
self.term.show_notification('UUID mismatch')
|
||||
return
|
||||
|
||||
with self.term.loader(message='Logging in'):
|
||||
with self.term.loader('Logging in'):
|
||||
info = self.reddit.get_access_information(self.params['code'])
|
||||
if self.term.loader.exception:
|
||||
return
|
||||
|
||||
@@ -121,8 +121,13 @@ class LoadScreen(object):
|
||||
self._animator = None
|
||||
self._is_running = None
|
||||
|
||||
def __call__(self, delay=0.5, interval=0.4, message='Downloading',
|
||||
trail='...', catch_exception=True):
|
||||
def __call__(
|
||||
self,
|
||||
message='Downloading',
|
||||
trail='...',
|
||||
delay=0.5,
|
||||
interval=0.4,
|
||||
catch_exception=True):
|
||||
"""
|
||||
Params:
|
||||
delay (float): Length of time that the loader will wait before
|
||||
|
||||
12
rtv/page.py
12
rtv/page.py
@@ -129,12 +129,12 @@ class Page(object):
|
||||
if 'likes' not in data:
|
||||
self.term.flash()
|
||||
elif data['likes']:
|
||||
with self.term.loader():
|
||||
with self.term.loader('Clearing vote'):
|
||||
data['object'].clear_vote()
|
||||
if not self.term.loader.exception:
|
||||
data['likes'] = None
|
||||
else:
|
||||
with self.term.loader():
|
||||
with self.term.loader('Voting'):
|
||||
data['object'].upvote()
|
||||
if not self.term.loader.exception:
|
||||
data['likes'] = True
|
||||
@@ -146,12 +146,12 @@ class Page(object):
|
||||
if 'likes' not in data:
|
||||
self.term.flash()
|
||||
elif data['likes'] or data['likes'] is None:
|
||||
with self.term.loader():
|
||||
with self.term.loader('Voting'):
|
||||
data['object'].downvote()
|
||||
if not self.term.loader.exception:
|
||||
data['likes'] = False
|
||||
else:
|
||||
with self.term.loader():
|
||||
with self.term.loader('Clearing vote'):
|
||||
data['object'].clear_vote()
|
||||
if not self.term.loader.exception:
|
||||
data['likes'] = None
|
||||
@@ -187,7 +187,7 @@ class Page(object):
|
||||
self.term.show_notification('Aborted')
|
||||
return
|
||||
|
||||
with self.term.loader(message='Deleting', delay=0):
|
||||
with self.term.loader('Deleting', delay=0):
|
||||
data['object'].delete()
|
||||
# Give reddit time to process the request
|
||||
time.sleep(2.0)
|
||||
@@ -223,7 +223,7 @@ class Page(object):
|
||||
self.term.show_notification('Aborted')
|
||||
return
|
||||
|
||||
with self.term.loader(message='Editing', delay=0):
|
||||
with self.term.loader('Editing', delay=0):
|
||||
data['object'].edit(text)
|
||||
time.sleep(2.0)
|
||||
if self.term.loader.exception is None:
|
||||
|
||||
@@ -54,7 +54,7 @@ class SubmissionPage(Page):
|
||||
order = order or self.content.order
|
||||
url = name or self.content.name
|
||||
|
||||
with self.term.loader():
|
||||
with self.term.loader('Refreshing page'):
|
||||
self.content = SubmissionContent.from_url(
|
||||
self.reddit, url, self.term.loader, order=order)
|
||||
if not self.term.loader.exception:
|
||||
@@ -107,7 +107,7 @@ class SubmissionPage(Page):
|
||||
self.term.show_notification('Aborted')
|
||||
return
|
||||
|
||||
with self.term.loader(message='Posting', delay=0):
|
||||
with self.term.loader('Posting', delay=0):
|
||||
reply(comment)
|
||||
# Give reddit time to process the submission
|
||||
time.sleep(2.0)
|
||||
|
||||
@@ -43,7 +43,7 @@ class SubredditPage(Page):
|
||||
if order == 'ignore':
|
||||
order = None
|
||||
|
||||
with self.term.loader():
|
||||
with self.term.loader('Refreshing page'):
|
||||
self.content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader, order=order)
|
||||
if not self.term.loader.exception:
|
||||
@@ -59,7 +59,7 @@ class SubredditPage(Page):
|
||||
if not query:
|
||||
return
|
||||
|
||||
with self.term.loader():
|
||||
with self.term.loader('Searching'):
|
||||
self.content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader, query=query)
|
||||
if not self.term.loader.exception:
|
||||
@@ -82,7 +82,7 @@ class SubredditPage(Page):
|
||||
data = self.content.get(self.nav.absolute_index)
|
||||
url = data['permalink']
|
||||
|
||||
with self.term.loader():
|
||||
with self.term.loader('Loading submission'):
|
||||
page = SubmissionPage(
|
||||
self.reddit, self.term, self.config, self.oauth, url=url)
|
||||
if self.term.loader.exception:
|
||||
@@ -125,7 +125,7 @@ class SubredditPage(Page):
|
||||
return
|
||||
|
||||
title, content = text.split('\n', 1)
|
||||
with self.term.loader(message='Posting', delay=0):
|
||||
with self.term.loader('Posting', delay=0):
|
||||
submission = self.reddit.submit(name, title, text=content,
|
||||
raise_captcha_exception=True)
|
||||
# Give reddit time to process the submission
|
||||
@@ -134,7 +134,7 @@ class SubredditPage(Page):
|
||||
return
|
||||
|
||||
# Open the newly created post
|
||||
with self.term.loader():
|
||||
with self.term.loader('Loading submission'):
|
||||
page = SubmissionPage(
|
||||
self.reddit, self.term, self.config, self.oauth,
|
||||
submission=submission)
|
||||
@@ -150,7 +150,7 @@ class SubredditPage(Page):
|
||||
def open_subscriptions(self):
|
||||
"Open user subscriptions page"
|
||||
|
||||
with self.term.loader():
|
||||
with self.term.loader('Loading subscriptions'):
|
||||
page = SubscriptionPage(
|
||||
self.reddit, self.term, self.config, self.oauth)
|
||||
if self.term.loader.exception:
|
||||
|
||||
@@ -295,7 +295,7 @@ class Terminal(object):
|
||||
if self.display:
|
||||
command = "import webbrowser; webbrowser.open_new_tab('%s')" % url
|
||||
args = [sys.executable, '-c', command]
|
||||
with self.loader(message='Opening page in a new window'), \
|
||||
with self.loader('Opening page in a new window'), \
|
||||
open(os.devnull, 'ab+', 0) as null:
|
||||
p = subprocess.Popen(args, stdout=null, stderr=null)
|
||||
# Give the browser 5 seconds to open a new tab. Because the
|
||||
|
||||
Reference in New Issue
Block a user