示例#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_()
示例#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 isinstance(self.task.thread(), _TaskDepotThread)
        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.
        # TODO: If the task encounters an critical error it might not emit
        # these signals and this Runnable will never complete.
        self.task.finished.connect(self.eventLoop.quit)
        self.task.cancelled.connect(self.eventLoop.quit)
        self.eventLoop.exec_()
示例#3
0
    def handleRequest(self):
        request = WebServerRequest(self)
        response = WebServerResponse(self)

        for server in servers:
            # verify which server this request is for
            if self.server == server.httpd:
                connectionType = Qt.BlockingQueuedConnection
                if QThread.currentThread() == server.thread():
                    connectionType = Qt.DirectConnection

                QMetaObject.invokeMethod(server, 'newRequest', connectionType,
                                         Q_ARG(WebServerRequest, request),
                                         Q_ARG(WebServerResponse, response))
                break
示例#4
0
 def run(self):
     try:
         result = self.func(*(self.args), **(self.kwargs))
     except Exception as e:
         logger.exception("deferToThread caught exception: %r", e)
         QMetaObject.invokeMethod(DeferCallThread.mainThreadStub,
                                  "_slot_errback", Qt.QueuedConnection,
                                  Q_ARG("PyQt_PyObject", self.done),
                                  Q_ARG("PyQt_PyObject", e))
     else:
         QMetaObject.invokeMethod(DeferCallThread.mainThreadStub,
                                  "_slot_callback", Qt.QueuedConnection,
                                  Q_ARG("PyQt_PyObject", self.done),
                                  Q_ARG("PyQt_PyObject", result))
     finally:
         del self.func, self.done, self.args, self.kwargs
示例#5
0
    def cardScanned(self, card):
        self.statusLabel.setText("Loading ...")

        userid = self.uf.read(card)[1]
        user = InternetClient.getUserDetails(userid)
        status = InternetClient.getUserStatus(userid, 0)
        statusDetails = None
        if status == "in":
            statusDetails = InternetClient.getUserStatus(userid, 1)
        QMetaObject.invokeMethod(self.parent, "startLogin",
                                 Qt.QueuedConnection, Q_ARG(QString, userid),
                                 Q_ARG(QString, user["realname"]),
                                 Q_ARG(QString, status),
                                 Q_ARG(QString, user["last_visit"]))

        self.statusLabel.setText("")
示例#6
0
 def run(self):
     self.eventLoop = QEventLoop()
     self.eventLoop.processEvents()
     QObject.connect(self._call, SIGNAL("finished(QString)"),
                     lambda str: self.eventLoop.quit())
     QMetaObject.invokeMethod(
         self._call, "moveToAndInit", Qt.QueuedConnection,
         Q_ARG("PyQt_PyObject", QThread.currentThread()))
     self.eventLoop.processEvents()
     self.eventLoop.exec_()
示例#7
0
文件: mikro.py 项目: moceap/scribus
 def wrapper(obj, *args):
     # XXX: support kwargs?
     qargs = [Q_ARG(t, v) for t, v in zip(self.args, args)]
     invoke_args = [obj._instance, self.name]
     invoke_args.append(Qt.DirectConnection)
     rtype = self.returnType
     if rtype:
         invoke_args.append(Q_RETURN_ARG(rtype))
     invoke_args.extend(qargs)
     try:
         result = QMetaObject.invokeMethod(*invoke_args)
         error_msg = str(qApp.property("MIKRO_EXCEPTION").toString())
         if error_msg:
             # clear message
             qApp.setProperty("MIKRO_EXCEPTION", QVariant())
             raise Error(error_msg)
     except RuntimeError, e:
         raise TypeError, \
             "%s.%s(%r) call failed: %s" % (obj, self.name, args, e)
示例#8
0
 def call(*args):
     args = [Q_ARG(atype, arg) for atype, arg in zip(sig, args)]
     return QMetaObject.invokeMethod(obj, name, conntype, *args)
示例#9
0
    def _load(self):
        url = self._url
        config = get_config()
        searcher_hp = self._searcher_hp
        searcher_de = self._searcher_de
        mime = None
        error = False

        if url.scheme() == 'static':
            try:
                self._data = _load_static_data(url.path().lstrip('/'))
            except EnvironmentError:
                self._data = '<h2>Static File Not Found</h2>'
                mime = 'text/html'
                error = True

        elif url.scheme() == 'dict':
            try:
                path = url.path().split('#', 1)[0]
                ldoce5 = LDOCE5(config.get('dataDir', ''), config.filemap_path)
                (self._data, mime) = ldoce5.get_content(path)
            except NotFoundError:
                self._data = '<h2>Content Not Found</h2>'
                mime = 'text/html'
                error = True
            except FilemapError:
                self._data = '<h2>File-Location Map Not Available</h2>'
                mime = 'text/html'
                error = True
            except ArchiveError:
                self._data = '<h2>Dictionary Data Not Available</h2>'
                mime = 'text/html'
                error = True

        elif url.scheme() == 'search':
            if searcher_hp and searcher_de:
                try:
                    self._data = enc_utf8(
                        search_and_render(url, searcher_hp, searcher_de))
                    mime = 'text/html'
                except:
                    s = u"<h2>Error</h2><div>{0}</div>".format('<br>'.join(
                        traceback.format_exc().splitlines()))
                    self._data = enc_utf8(s)
                    mime = 'text/html'
                    error = True
            else:
                mime = 'text/html'
                self._data = ("""<p>The full-text search index """
                              """has not been created yet or broken.</p>""")
                error = True

        if mime:
            self.setHeader(QNetworkRequest.ContentTypeHeader, mime)
        self.setHeader(QNetworkRequest.ContentLengthHeader, len(self._data))
        self.setOpenMode(self.ReadOnly | self.Unbuffered)

        if error:
            nwerror = QNetworkReply.ContentNotFoundError
            error_msg = u'Content Not Found'
            self.setError(nwerror, error_msg)
            QMetaObject.invokeMethod(
                self, 'error', Qt.QueuedConnection,
                Q_ARG(QNetworkReply.NetworkError, nwerror))

        QMetaObject.invokeMethod(self, 'metaDataChanged', Qt.QueuedConnection)
        QMetaObject.invokeMethod(self, 'downloadProgress', Qt.QueuedConnection,
                                 Q_ARG('qint64', len(self._data)),
                                 Q_ARG('qint64', len(self._data)))
        QMetaObject.invokeMethod(self, 'readyRead', Qt.QueuedConnection)
        QMetaObject.invokeMethod(self, 'finished', Qt.QueuedConnection)

        self._finished = True
示例#10
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)