17
17
"""Platform specific constants and functions (for Windows)."""
19
19
PLATFORM_QSS = ":/windows.qss"
21
from twisted.internet import defer
22
from PyQt4.QtCore import QThread, QCoreApplication
25
class DeferredThread(QThread):
26
"""A thread that runs a given function."""
28
def __init__(self, f, *args, **kwargs):
29
"""Initialize this thread."""
30
app = QCoreApplication.instance()
31
super(DeferredThread, self).__init__(app)
32
self.deferred = defer.Deferred()
38
self.finished.connect(self.on_finished)
41
"""This code runs inside the thread."""
43
self.result = self.f(*self.args, **self.kwargs)
44
except Exception as e:
45
self.succeeded = False
48
def on_finished(self):
49
"""The thread has completed."""
51
self.deferred.callback(self.result)
53
self.deferred.errback(self.result)
56
def qtDeferToThread(f, *args, **kwargs):
57
"""A Qt-based implementation of deferToThread."""
58
thread = DeferredThread(f, *args, **kwargs)
60
return thread.deferred