Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from pypeclub/pyblish_pype_update_mod2
Browse files Browse the repository at this point in the history
Avoid using processEvents
  • Loading branch information
BigRoy authored Feb 12, 2022
2 parents 6c12932 + 90ad762 commit 6a26813
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions openpype/tools/pyblish_pype/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ class MainThreadProcess(QtCore.QObject):
This approach gives ability to update UI meanwhile plugin is in progress.
"""
timer_interval = 3
# How many times let pass QtApplication to process events
# - use 2 as resize event can trigger repaint event but not process in
# same loop
count_timeout = 2

def __init__(self):
super(MainThreadProcess, self).__init__()
self._items_to_process = collections.deque()

timer = QtCore.QTimer()
timer.setInterval(self.timer_interval)
timer.setInterval(0)

timer.timeout.connect(self._execute)

self._timer = timer
self._switch_counter = self.count_timeout

def process(self, func, *args, **kwargs):
item = MainThreadItem(func, *args, **kwargs)
Expand All @@ -71,13 +75,15 @@ def _execute(self):
if not self._items_to_process:
return

if self._switch_counter > 0:
self._switch_counter -= 1
return

self._switch_counter = self.count_timeout

item = self._items_to_process.popleft()
item.process()

# Process events directly after the item processed. This allows to
# correctly show "highlighted" state for the next item to process
QtWidgets.QApplication.instance().processEvents()

def start(self):
if not self._timer.isActive():
self._timer.start()
Expand Down

0 comments on commit 6a26813

Please sign in to comment.