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