Merge pull request #3 from pypeclub/pyblish_pype_update_mod2

Avoid using processEvents
This commit is contained in:
Roy Nieterau 2022-02-12 10:03:31 +01:00 committed by GitHub
commit 6a26813f8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
@ -71,13 +75,15 @@ class MainThreadProcess(QtCore.QObject):
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()