From f872d8bb30a9daffb68ffdabd9d0b6b3cdc92213 Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Sun, 28 Nov 2021 21:12:02 +0100 Subject: [PATCH] Optimized filelist progress updates --- soundconverter/interface/filelist.py | 19 +++++++++++++++---- soundconverter/interface/ui.py | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/soundconverter/interface/filelist.py b/soundconverter/interface/filelist.py index 0448ec7..8ee0ab6 100644 --- a/soundconverter/interface/filelist.py +++ b/soundconverter/interface/filelist.py @@ -61,6 +61,7 @@ def __init__(self, window, builder): self.filelist = set() self.model = Gtk.ListStore(*MODEL) + self.progress_cache = {} self.widget = builder.get_object('filelist') self.widget.props.fixed_height_mode = True @@ -133,6 +134,8 @@ def add_uris(self, uris, base=None, extensions=None): are inside a directory and only some of them should be converted. Default:None which accepts all types. """ + self.progress_cache = {} + if len(uris) == 0: return @@ -369,15 +372,23 @@ def format_cell(self, sound_file): def set_row_progress(self, number, progress): """Update the progress bar of a single row/file.""" - self.progress_column.set_visible(True) - if self.model[number][2] == progress * 100: + # when convertin a lot of files updating all progress bars really becomes + # quite an expensive task + cached = self.progress_cache.get(number, 0) + # - progress_cache is faster than self.model for this optimization + # - skip small changes + # - make sure it will be set to 1 even if the change is small + if (progress == 1 and cached != 1) or abs(cached - progress) > 0.02: + self.model[number][2] = progress * 100.0 + self.progress_cache[number] = progress return - self.model[number][2] = progress * 100.0 - def hide_row_progress(self): self.progress_column.set_visible(False) + def show_row_progress(self): + self.progress_column.set_visible(True) + def append_file(self, sound_file): """Add a valid SoundFile object to the list of files in the GUI. diff --git a/soundconverter/interface/ui.py b/soundconverter/interface/ui.py index f5960a0..d442382 100644 --- a/soundconverter/interface/ui.py +++ b/soundconverter/interface/ui.py @@ -342,6 +342,8 @@ def update_progress(self): self.filelist.hide_row_progress() return False + self.filelist.show_row_progress() + if not paused and running: # if paused, don't refresh the progress total_progress, task_progress = self.converter_queue.get_progress()