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


Python QCoreApplication.sendPostedEvents方法代码示例

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


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

示例1: test_threadsafe

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import sendPostedEvents [as 别名]
    def test_threadsafe(self):
        output = OutputView()
        output.resize(500, 300)
        output.show()

        blue_formater = output.formated(color=Qt.blue)
        red_formater = output.formated(color=Qt.red)

        correct = []

        def check_thread(*args):
            correct.append(QThread.currentThread() == self.app.thread())

        blue = TextStream()
        blue.stream.connect(blue_formater.write)
        blue.stream.connect(check_thread)

        red = TextStream()
        red.stream.connect(red_formater.write)
        red.stream.connect(check_thread)

        def printer(i):
            if i % 12 == 0:
                fizzbuz = "fizzbuz"
            elif i % 4 == 0:
                fizzbuz = "buz"
            elif i % 3 == 0:
                fizzbuz = "fizz"
            else:
                fizzbuz = str(i)

            if i % 2:
                writer = blue
            else:
                writer = red

            writer.write("Greetings from thread {0}. "
                         "This is {1}\n".format(current_thread().name,
                                                fizzbuz))

        pool = multiprocessing.pool.ThreadPool(100)
        res = pool.map_async(printer, range(10000))

        self.app.exec_()

        res.wait()

        # force all pending enqueued emits
        QCoreApplication.sendPostedEvents(blue, QEvent.MetaCall)
        QCoreApplication.sendPostedEvents(red, QEvent.MetaCall)
        self.app.processEvents()

        self.assertTrue(all(correct))
        self.assertEqual(len(correct), 10000)
开发者ID:ales-erjavec,项目名称:orange-canvas,代码行数:56,代码来源:test_outputview.py

示例2: flush

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import sendPostedEvents [as 别名]
    def flush(self):
        """
        Flush all pending signal emits currently enqueued.

        Must only ever be called from the thread this object lives in
        (:func:`QObject.thread()`).
        """
        if QThread.currentThread() is not self.thread():
            raise RuntimeError("`flush()` called from a wrong thread.")
        # NOTE: QEvent.MetaCall is the event implementing the
        # `Qt.QueuedConnection` method invocation.
        QCoreApplication.sendPostedEvents(self, QEvent.MetaCall)
开发者ID:astaric,项目名称:orange3,代码行数:14,代码来源:concurrent.py

示例3: flush

# 需要导入模块: from AnyQt.QtCore import QCoreApplication [as 别名]
# 或者: from AnyQt.QtCore.QCoreApplication import sendPostedEvents [as 别名]
 def flush(self):
     """
     Flush all pending signal emits currently enqueued.
     """
     assert QThread.currentThread() is self.thread()
     QCoreApplication.sendPostedEvents(self, QEvent.MetaCall)
开发者ID:benzei,项目名称:orange3,代码行数:8,代码来源:concurrent.py


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