From 7da0159b22ff3200ee1a80c6fbb22e84fe63e1dd Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Sun, 22 Mar 2020 00:22:39 +0100 Subject: [PATCH] Make progress show a name of current operation (#682) --- plugin/utils/progress_status.py | 30 +++++++++++++++------------ plugin/utils/singleton_thread_pool.py | 7 +++++-- plugin/utils/thread_job.py | 12 +++++------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/plugin/utils/progress_status.py b/plugin/utils/progress_status.py index 71f5f160..b6d861e5 100644 --- a/plugin/utils/progress_status.py +++ b/plugin/utils/progress_status.py @@ -19,7 +19,9 @@ class BaseProgressStatus(object): """A base class for progress status.""" MSG_TAG = '000_ECC' - MSG_MASK = 'ECC: [{}]' + MSG_MASK = ' | {msg} |' + PROGRESS_MASK = 'ECC: [{progress}]' + FULL_MASK = PROGRESS_MASK + MSG_MASK def __init__(self): """Initialize progress status.""" @@ -39,14 +41,14 @@ def erase_status(self): view = sublime.active_window().active_view() view.erase_status(BaseProgressStatus.MSG_TAG) - def show_ready_message(self): - """Show ready message.""" + def show_as_ready(self): + """Show ready state.""" if not self.showing: return BaseProgressStatus.set_status( - BaseProgressStatus.MSG_MASK.format(self.msg_ready)) + BaseProgressStatus.PROGRESS_MASK.format(progress=self.msg_ready)) - def show_next_message(self): + def update_progress(self, message=''): """Abstract method. Generate next message.""" raise NotImplementedError("abstract method is called") @@ -61,15 +63,16 @@ def __init__(self): self.msg_chars = MSG_CHARS_MOON self.msg_ready = MSG_READY_MOON - def show_next_message(self): - """Show next moon phase message.""" + def update_progress(self, message): + """Show next moon phase and a custom message.""" if not self.showing: return chars = self.msg_chars mod = len(chars) self.idx = (self.idx + 1) % mod BaseProgressStatus.set_status( - BaseProgressStatus.MSG_MASK.format(chars[self.idx])) + BaseProgressStatus.FULL_MASK.format( + progress=chars[self.idx], msg=message)) class ColorSublimeProgressStatus(BaseProgressStatus): @@ -81,15 +84,16 @@ def __init__(self): self.msg_chars = MSG_CHARS_COLOR_SUBLIME self.msg_ready = MSG_READY_COLOR_SUBLIME - def show_next_message(self): - """Show next random progress message.""" + def update_progress(self, message): + """Show next random progress indicator and a custom message.""" if not self.showing: return from random import sample mod = len(self.msg_chars) rands = [self.msg_chars[x % mod] for x in sample(range(100), 10)] BaseProgressStatus.set_status( - BaseProgressStatus.MSG_MASK.format(''.join(rands))) + BaseProgressStatus.FULL_MASK.format( + progress=''.join(rands), msg=message)) class NoneSublimeProgressStatus(BaseProgressStatus): @@ -100,10 +104,10 @@ def __init__(self): super().__init__() self.showing = False - def show_ready_message(self): + def show_as_ready(self): """Empty implementation.""" pass - def show_next_message(self): + def update_progress(self, message): """Empty implementation.""" pass diff --git a/plugin/utils/singleton_thread_pool.py b/plugin/utils/singleton_thread_pool.py index 1a55ea41..6a6a5a32 100644 --- a/plugin/utils/singleton_thread_pool.py +++ b/plugin/utils/singleton_thread_pool.py @@ -47,6 +47,7 @@ def __init__(self, max_workers=1): self.__progress_lock = Lock() self.__show_animation = False + self.__current_operation_name = '' self.__progress_update_delay = 0.1 self.__progress_idle_delay = 0.3 @@ -91,6 +92,7 @@ def new_job(self, job): job.future = future # Set the future for this job. with self.__lock: self.__active_jobs.append(job) + self.__current_operation_name = job.name self.__show_animation = True def __on_job_done(self, future): @@ -111,10 +113,11 @@ def __animate_progress(self): if not self.__progress_status: sleep_time = self.__progress_idle_delay elif self.__show_animation: - self.__progress_status.show_next_message() + self.__progress_status.update_progress( + self.__current_operation_name) sleep_time = self.__progress_update_delay else: - self.__progress_status.show_ready_message() + self.__progress_status.show_as_ready() sleep_time = self.__progress_idle_delay # Allow some time for progress status to be updated. time.sleep(sleep_time) diff --git a/plugin/utils/thread_job.py b/plugin/utils/thread_job.py index 98f8200e..244dc1ac 100644 --- a/plugin/utils/thread_job.py +++ b/plugin/utils/thread_job.py @@ -19,12 +19,12 @@ class ThreadJob: args (object[]): Sequence of additional arguments for `function`. """ - UPDATE_TAG = "update" - CLEAR_TAG = "clear" - COMPLETE_TAG = "complete" - COMPLETE_INCLUDES_TAG = "complete_includes" - GENERATE_DB_TAG = "generate_db" - INFO_TAG = "info" + UPDATE_TAG = "Updating translation unit" + CLEAR_TAG = "Clearing" + COMPLETE_TAG = "Completing" + COMPLETE_INCLUDES_TAG = "Competing includes" + GENERATE_DB_TAG = "Generating compilation database" + INFO_TAG = "Showing info" def __init__(self, name, callback, function, args): """Initialize a job.