当前位置: 首页>>代码示例>>Python>>正文


Python QCoreApplication.processEvents方法代码示例

本文整理汇总了Python中AnyQt.QtCore.QCoreApplication.processEvents方法的典型用法代码示例。如果您正苦于以下问题:Python QCoreApplication.processEvents方法的具体用法?Python QCoreApplication.processEvents怎么用?Python QCoreApplication.processEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AnyQt.QtCore.QCoreApplication的用法示例。


在下文中一共展示了QCoreApplication.processEvents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_methodinvoke

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import processEvents [as 别名]
    def test_methodinvoke(self):
        executor = ThreadExecutor()
        state = [None, None]

        class StateSetter(QObject):
            @Slot(object)
            def set_state(self, value):
                state[0] = value
                state[1] = QThread.currentThread()

        def func(callback):
            callback(QThread.currentThread())

        obj = StateSetter()
        f1 = executor.submit(func, methodinvoke(obj, "set_state", (object,)))
        f1.result()

        # So invoked method can be called
        QCoreApplication.processEvents()

        self.assertIs(state[1], QThread.currentThread(),
                      "set_state was called from the wrong thread")

        self.assertIsNot(state[0], QThread.currentThread(),
                         "set_state was invoked in the main thread")

        executor.shutdown(wait=True)
开发者ID:RachitKansal,项目名称:orange3,代码行数:29,代码来源:concurrent.py

示例2: TestTask

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import processEvents [as 别名]
class TestTask(unittest.TestCase):
    def setUp(self):
        self.app = QCoreApplication([])

    def test_task(self):
        results = []

        task = Task(function=QThread.currentThread)
        task.resultReady.connect(results.append)

        task.start()
        self.app.processEvents()

        self.assertSequenceEqual(results, [QThread.currentThread()])

        results = []

        thread = QThread()
        thread.start()

        task = Task(function=QThread.currentThread)

        task.moveToThread(thread)

        self.assertIsNot(task.thread(), QThread.currentThread())
        self.assertIs(task.thread(), thread)

        task.resultReady.connect(results.append, Qt.DirectConnection)
        task.start()

        f = task.future()

        self.assertIsNot(f.result(3), QThread.currentThread())

        self.assertIs(f.result(3), results[-1])

    def test_executor(self):
        executor = ThreadExecutor()

        f = executor.submit(QThread.currentThread)

        self.assertIsNot(f.result(3), QThread.currentThread())

        f = executor.submit(lambda: 1 / 0)

        with self.assertRaises(ZeroDivisionError):
            f.result()

        results = []
        task = Task(function=QThread.currentThread)
        task.resultReady.connect(results.append, Qt.DirectConnection)

        f = executor.submit(task)

        self.assertIsNot(f.result(3), QThread.currentThread())

        executor.shutdown()
开发者ID:RachitKansal,项目名称:orange3,代码行数:59,代码来源:concurrent.py

示例3: CoreAppTestCase

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import processEvents [as 别名]
class CoreAppTestCase(unittest.TestCase):
    def setUp(self):
        self.app = QCoreApplication.instance()
        if self.app is None:
            self.app = QCoreApplication([])

    def tearDown(self):
        self.app.processEvents()
        del self.app
开发者ID:PrimozGodec,项目名称:orange3,代码行数:11,代码来源:test_concurrent.py


注:本文中的AnyQt.QtCore.QCoreApplication.processEvents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。