Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-936: Allow UI to be more responsive when loading files #616

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Load files in a seperate thread to allow UI to be more responsive
  • Loading branch information
samj1912 committed Feb 3, 2017
commit 161badcc506f08fc7513cfddff35025d2f03091c
3 changes: 2 additions & 1 deletion picard/file.py
Expand Up @@ -100,7 +100,8 @@ def load(self, callback):
thread.run_task(
partial(self._load, self.filename),
partial(self._loading_finished, callback),
priority=1)
priority=1,
thread_pool=self.tagger.load_thread_pool)

def _loading_finished(self, callback, result=None, error=None):
if self.state != self.PENDING:
Expand Down
24 changes: 18 additions & 6 deletions picard/tagger.py
Expand Up @@ -122,6 +122,10 @@ def __init__(self, picard_args, unparsed_args, localedir, autoupdate):
self.save_thread_pool = QtCore.QThreadPool(self)
self.save_thread_pool.setMaxThreadCount(1)

# Use a seperate thread pool for loading to allow UI to be responsonsive
self.load_thread_pool = QtCore.QThreadPool(self)
self.load_thread_pool.setMaxThreadCount(1)

if not sys.platform == "win32":
# Set up signal handling
# It's not possible to call all available functions from signal
Expand Down Expand Up @@ -347,13 +351,18 @@ def move_files(self, files, target):

def add_files(self, filenames, target=None):
"""Add files to the tagger."""
thread.run_task(partial(self._open_files, filenames),
partial(self._file_opening_finsished, target),
priority=1,
thread_pool=self.load_thread_pool)

def _open_files(self, filenames):
ignoreregex = None
pattern = config.setting['ignore_regex']
if pattern:
ignoreregex = re.compile(pattern)
ignore_hidden = config.setting["ignore_hidden_files"]
new_files = []
tmp_files = {}
temp_files = dict()
for filename in filenames:
filename = os.path.normpath(os.path.realpath(filename))
if ignore_hidden and is_hidden(filename):
Expand All @@ -365,11 +374,14 @@ def add_files(self, filenames, target=None):
if filename not in self.files:
file = open_file(filename)
if file:
tmp_files[filename] = file
if tmp_files and self.check_load(tmp_files):
temp_files[filename] = file
return temp_files

def _file_opening_finsished(self, target=None, result=None, error=None):
if result and self.check_load(result):
new_files = []
for filename in sorted(tmp_files):
file = tmp_files[filename]
for filename in sorted(result):
file = result[filename]
self.files[filename] = file
new_files.append(file)
log.debug("Adding files %r", new_files)
Expand Down