Skip to content

Commit

Permalink
Merge pull request #58 from sezanzeb/filelist-optimization
Browse files Browse the repository at this point in the history
Optimized filelist progress updates
  • Loading branch information
kassoulet authored Nov 29, 2021
2 parents 0d641f3 + f872d8b commit abe6b86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 15 additions & 4 deletions soundconverter/interface/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions soundconverter/interface/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit abe6b86

Please sign in to comment.