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