本文整理汇总了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)
示例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)
示例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)