def start(self, job): job.setParent(self.local) job = Job(job) job.moveToThread(self.thread) job.setParent(self.remote) QMetaObject.invokeMethod( job, 'run', Qt.QueuedConnection )
def run(self): try: self.impl() if self.main: self.finished() else: QMetaObject.invokeMethod(self, 'finished', Qt.QueuedConnection) except Exception as e: if self.main: self.failed(e) else: QMetaObject.invokeMethod(self, 'failed', Qt.QueuedConnection, Q_ARG(object, e))
def run(self): """Use mutex to protect self.d.""" with QMutexLocker(self.p.mutex): for runnable in self.p.d.values(): runnable.query.update(self.query.lower()) def f(runnable): """Don't calculate editing distance if job stopped.""" if self.canceled: return 0 elif not self.query: return runnable.order else: return runnable.query.distance_to(runnable.name.lower()) QMetaObject.invokeMethod( self, '_make_model', Qt.QueuedConnection, Q_ARG(object, sorted(self.p.d.values(), key=f)[:self.upper_bound]))
def run(self): try: self.impl() if self.main: self.finished() else: QMetaObject.invokeMethod( self, 'finished', Qt.QueuedConnection ) except Exception as e: if self.main: self.failed(e) else: QMetaObject.invokeMethod( self, 'failed', Qt.QueuedConnection, Q_ARG(object, e) )
def run(self): """Use mutex to protect self.d.""" with QMutexLocker(self.p.mutex): for runnable in self.p.d.values(): runnable.query.update(self.query.lower()) def f(runnable): """Don't calculate editing distance if job stopped.""" if self.canceled: return 0 elif not self.query: return runnable.order else: return runnable.query.distance_to(runnable.name.lower()) QMetaObject.invokeMethod( self, '_make_model', Qt.QueuedConnection, Q_ARG(object, sorted(self.p.d.values(), key=f)[:self.upper_bound]) )
def delay_deal(self): QMetaObject.invokeMethod( self, 'deal', Qt.QueuedConnection )
self.hotkey = Hotkey(self.handle_hotkey) def handle_hotkey(self): self.fire.emit() def stop(self): self.hotkey.stop() def run(self): self.hotkey.start() if __name__ == '__main__': import sys import os logging.basicConfig( filename=os.path.expanduser('~/.lit.server.log'), filemode='w', format='%(asctime)s - %(levelname)s - %(message)s', level=logging.DEBUG ) app = QCoreApplication(sys.argv) set_app_info(app, 'litserver') server = Server() QMetaObject.invokeMethod( server, 'start', Qt.QueuedConnection ) sys.exit(app.exec_())
app = QApplication(argv) STYLESHEET = 'style.css' set_app_info(app, 'lit') app.setQuitOnLastWindowClosed(False) # style with open(STYLESHEET, 'r') as f: app.setStyleSheet(f.read()) worker = Worker() from client import Client client = Client() QMetaObject.invokeMethod( client, 'start', Qt.QueuedConnection ) lit = Lit(worker, client) lit.show() #QMetaObject.invokeMethod( #lit, #'show_window', #Qt.QueuedConnection #) client.toggle.connect(lit.handle_hotkey) #return app.exec_() app.exec_()
from qt.QtCore import (QThread, QObject, QCoreApplication, QMetaObject, Qt, Slot, Signal, QRunnable, QThreadPool) class Job(QObject): finished = Signal() @Slot() def run(self): print("job thread: %d" % QThread.currentThreadId()) self.finished.emit() def finished(): print("post thread: %d" % QThread.currentThreadId()) if __name__ == '__main__': import sys app = QCoreApplication(sys.argv) print("main thread: %d" % QThread.currentThreadId()) thread = QThread() thread.start() job = Job() job.finished.connect(finished, Qt.QueuedConnection) job.moveToThread(thread) QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection) app.exec_() thead.wait()
QThreadPool ) class Job(QObject): finished = Signal() @Slot() def run(self): print("job thread: %d" % QThread.currentThreadId()) self.finished.emit() def finished(): print("post thread: %d" % QThread.currentThreadId()) if __name__ == '__main__': import sys app = QCoreApplication(sys.argv) print("main thread: %d" % QThread.currentThreadId()) thread = QThread() thread.start() job = Job() job.finished.connect(finished, Qt.QueuedConnection) job.moveToThread(thread) QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection) app.exec_() thead.wait()
def delay_deal(self): QMetaObject.invokeMethod(self, 'deal', Qt.QueuedConnection)
def start(self, job): job.setParent(self.local) job = Job(job) job.moveToThread(self.thread) job.setParent(self.remote) QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection)