Exemplo n.º 1
0
    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_()
Exemplo n.º 2
0
    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_()
Exemplo n.º 3
0
 def progress_callback(finished):
     if task.cancelled:
         raise UserInterrupt()
     QMetaObject.invokeMethod(
         self, "setProgressValue", Qt.QueuedConnection,
         Q_ARG(float, 100 * finished)
     )
Exemplo n.º 4
0
 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
Exemplo n.º 6
0
        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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
 def ondone(_):
     QMetaObject.invokeMethod(
         self, "__task_complete", Qt.QueuedConnection,
         Q_ARG(object, task))
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 def __call__(self, *args, **kwargs):
     QMetaObject.invokeMethod(self.master, 'call', Qt.QueuedConnection,
                              Q_ARG(object, (self.instance, args, kwargs)))
Exemplo n.º 13
0
 def call(*args):
     args = [Q_ARG(atype, arg) for atype, arg in zip(sig, args)]
     return QMetaObject.invokeMethod(obj, name, conntype, *args)
Exemplo n.º 14
0
 def update(f):
     QMetaObject.invokeMethod(
         self, "_update_info", Qt.QueuedConnection)
Exemplo n.º 15
0
 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))
Exemplo n.º 17
0
 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))
Exemplo n.º 19
0
 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
     )
Exemplo n.º 20
0
 def ondone(_):
     QMetaObject.invokeMethod(self, "__task_complete",
                              Qt.QueuedConnection, Q_ARG(object, task))
Exemplo n.º 21
0
 def callback_prediction(class_value):
     QMetaObject.invokeMethod(
         self, "update_model_prediction", Qt.QueuedConnection, Q_ARG(float, class_value))
Exemplo n.º 22
0
 def callback_update(table):
     QMetaObject.invokeMethod(
         self, "update_view", Qt.QueuedConnection, Q_ARG(Orange.data.Table, table))
Exemplo n.º 23
0
 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)
Exemplo n.º 24
0
 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))
Exemplo n.º 25
0
 def update(_):
     QMetaObject.invokeMethod(
         self, "_update_info", Qt.QueuedConnection)
Exemplo n.º 26
0
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