def run(self): """ Reimplemented from `QRunnable.run` """ self.eventLoop = QEventLoop() self.eventLoop.processEvents() # Move the task to the current thread so it's events, signals, slots # are triggered from this thread. assert self.task.thread() is _TaskDepotThread.instance() QMetaObject.invokeMethod( self.task.thread(), "transfer", Qt.BlockingQueuedConnection, Q_ARG(object, self.task), Q_ARG(object, QThread.currentThread()) ) self.eventLoop.processEvents() # Schedule task.run from the event loop. self.task.start() # Quit the loop and exit when task finishes or is cancelled. self.task.finished.connect(self.eventLoop.quit) self.task.cancelled.connect(self.eventLoop.quit) self.eventLoop.exec_()
def run(self): """ Reimplemented from `QRunnable.run` """ self.eventLoop = QEventLoop() self.eventLoop.processEvents() # Move the task to the current thread so it's events, signals, slots # are triggered from this thread. assert self.task.thread() is _TaskDepotThread.instance() QMetaObject.invokeMethod( self.task.thread(), "transfer", Qt.BlockingQueuedConnection, Q_ARG(object, self.task), Q_ARG(object, QThread.currentThread()), ) self.eventLoop.processEvents() # Schedule task.run from the event loop. self.task.start() # Quit the loop and exit when task finishes or is cancelled. self.task.finished.connect(self.eventLoop.quit) self.task.cancelled.connect(self.eventLoop.quit) self.eventLoop.exec_()
def progress_callback(finished): if task.cancelled: raise UserInterrupt() QMetaObject.invokeMethod( self, "setProgressValue", Qt.QueuedConnection, Q_ARG(float, 100 * finished) )
def callback(progress): nonlocal task # update progress bar QMetaObject.invokeMethod( self, "set_progress_value", Qt.QueuedConnection, Q_ARG(int, progress)) if task.canceled: return True return False
def callback(progress): nonlocal task # update progress bar QMetaObject.invokeMethod( self, "set_progress_value", Qt.QueuedConnection, Q_ARG(int, progress)) if task.canceled: return True return False
def func(): try: QMetaObject.invokeMethod(self, "_on_start", Qt.QueuedConnection) if allow_partial_results: kwargs['should_break'] = should_break res = method(self, *args, on_progress=on_progress, **kwargs) except StopExecution: res = None QMetaObject.invokeMethod(self, "_on_result", Qt.QueuedConnection, Q_ARG(object, res)) self.running = False
def run(self, *args, **kwargs): if self.im_func.start_callback: QMetaObject.invokeMethod(self.im_self, self.im_func.start_callback, Qt.QueuedConnection) if self.im_self: args = (self.im_self,) + args try: result = self.im_func.method(*args, **kwargs) except StopExecution: result = None if self.im_func.finish_callback: QMetaObject.invokeMethod(self.im_self, self.im_func.finish_callback, Qt.QueuedConnection, Q_ARG(object, result)) self.running = False
def endEdit(self): """End the annotation edit. """ content = self.__textItem.toPlainText() self.__textItem.setTextInteractionFlags(self.__defaultInteractionFlags) self.__textItem.document().contentsChanged.disconnect(self.textEdited) cursor = self.__textItem.textCursor() cursor.clearSelection() self.__textItem.setTextCursor(cursor) self.__content = content self.editingFinished.emit() # Cannot change the textItem's html immediately, this method is # invoked from it. # TODO: Separate the editor from the view. QMetaObject.invokeMethod(self, "__updateRenderedContent", Qt.QueuedConnection)
def endEdit(self): """End the annotation edit. """ content = self.__textItem.toPlainText() self.__textItem.setTextInteractionFlags(self.__defaultInteractionFlags) self.__textItem.document().contentsChanged.disconnect( self.textEdited ) cursor = self.__textItem.textCursor() cursor.clearSelection() self.__textItem.setTextCursor(cursor) self.__content = content self.editingFinished.emit() # Cannot change the textItem's html immediately, this method is # invoked from it. # TODO: Separate the editor from the view. QMetaObject.invokeMethod( self, "__updateRenderedContent", Qt.QueuedConnection)
def ondone(_): QMetaObject.invokeMethod( self, "__task_complete", Qt.QueuedConnection, Q_ARG(object, task))
def __call__(self, *args): args = [Q_ARG(atype, arg) for atype, arg in zip(self.arg_types, args)] return QMetaObject.invokeMethod(self.obj, self.method, self.conntype, *args)
def __call__(self, *args, **kwargs): QMetaObject.invokeMethod(self.master, 'call', Qt.QueuedConnection, Q_ARG(object, (self.instance, args, kwargs)))
def call(*args): args = [Q_ARG(atype, arg) for atype, arg in zip(sig, args)] return QMetaObject.invokeMethod(obj, name, conntype, *args)
def update(f): QMetaObject.invokeMethod( self, "_update_info", Qt.QueuedConnection)
def call(*args): args = [Q_ARG(atype, arg) for atype, arg in zip(sig, args)] return QMetaObject.invokeMethod(obj, name, conntype, *args)
def callback_update(table): QMetaObject.invokeMethod( self, "update_view", Qt.QueuedConnection, Q_ARG(Orange.data.Table, table))
def __call__(self, *args): args = [Q_ARG(atype, arg) for atype, arg in zip(self.arg_types, args)] return QMetaObject.invokeMethod( self.obj, self.method, self.conntype, *args)
def callback_prediction(class_value): QMetaObject.invokeMethod( self, "update_model_prediction", Qt.QueuedConnection, Q_ARG(float, class_value))
def __call__(self, *args): args = [Q_ARG(atype, arg) for atype, arg in zip(self.arg_types, args)] QMetaObject.invokeMethod( self.obj, self.method, Qt.QueuedConnection, *args )
def ondone(_): QMetaObject.invokeMethod(self, "__task_complete", Qt.QueuedConnection, Q_ARG(object, task))
def callback_prediction(class_value): QMetaObject.invokeMethod( self, "update_model_prediction", Qt.QueuedConnection, Q_ARG(float, class_value))
def callback_update(table): QMetaObject.invokeMethod( self, "update_view", Qt.QueuedConnection, Q_ARG(Orange.data.Table, table))
def __call__(self, *args): args = [Q_ARG(atype, arg) for atype, arg in zip(self.arg_types, args)] QMetaObject.invokeMethod(self.obj, self.method, Qt.QueuedConnection, *args)
def on_progress(i): if not self.running and not allow_partial_results: raise StopExecution QMetaObject.invokeMethod(self, "_on_progress", Qt.QueuedConnection, Q_ARG(float, i))
def update(_): QMetaObject.invokeMethod( self, "_update_info", Qt.QueuedConnection)
def safe_invoke(obj, method_name, *args): try: QMetaObject.invokeMethod(obj, method_name, Qt.QueuedConnection, *args) except RuntimeError: # C++ object wrapped by `obj` may be already destroyed pass