Example #1
0
 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
     )
Example #2
0
 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))
Example #3
0
    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]))
Example #4
0
 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)
             )
Example #5
0
    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])
            )
Example #6
0
 def delay_deal(self):
     QMetaObject.invokeMethod(
         self,
         'deal',
         Qt.QueuedConnection
     )
Example #7
0
        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_())
Example #8
0
        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_()
Example #9
0
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()
Example #10
0
    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()
Example #11
0
 def delay_deal(self):
     QMetaObject.invokeMethod(self, 'deal', Qt.QueuedConnection)
Example #12
0
 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)