-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
37 lines (31 loc) · 995 Bytes
/
worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This file is part of "github actions gui" project
#
# Author: Roman Gladyshev <[email protected]>
# License: MIT License
#
# SPDX-License-Identifier: MIT
# License text is available in the LICENSE file and online:
# http://www.opensource.org/licenses/MIT
#
# Copyright (c) 2020 remico
from threading import Thread
from .pyside2 import *
__all__ = ['WorkerThread']
class WorkerThread(QObject):
def __init__(self, jobCollable, parent=None) -> None:
super().__init__(parent)
self.delay = 0
def _job():
jobCollable()
QMetaObject.invokeMethod(self, "_on_done") # QueuedConnection
Thread(target=_job).start()
def callback(self, callback, delay_ms=0):
self.delay = delay_ms
self._done.connect(callback)
_done = PS2Signal()
@PS2Slot()
def _on_done(self):
QTimer.singleShot(self.delay, lambda: self._done.emit() and self.deleteLater())