本文整理汇总了Python中qtpy.QtWidgets.QApplication.exit方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.exit方法的具体用法?Python QApplication.exit怎么用?Python QApplication.exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.exit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModalTester
# 需要导入模块: from qtpy.QtWidgets import QApplication [as 别名]
# 或者: from qtpy.QtWidgets.QApplication import exit [as 别名]
class ModalTester(object):
"""
Helper class for testing modal widgets (dialogs).
"""
def __init__(self, creator, tester):
"""
Initialise ModalTester.
:param creator: Function without arguments that creates a modal widget. Can be a class name.
A modal widget must have exec_() method.
:param tester: A function taking a widget as its argument that does testing.
"""
self.app = QApplication.instance()
if self.app is None:
self.app = QApplication([''])
self.creator = creator
self.tester = tester
self.widget = None
self.timer = None
self.passed = False
def __call__(self):
"""
Initialise testing.
"""
try:
self.widget = self.creator()
except:
traceback.print_exc()
self.app.exit(0)
if self.widget is not None:
self.widget.exec_()
def _idle(self):
"""
This function runs every time in QApplication's event loop.
Call the testing function.
"""
modal_widget = self.app.activeModalWidget()
if modal_widget is not None:
if self.widget is modal_widget:
try:
self.tester(self.widget)
self.passed = True
except:
traceback.print_exc()
if modal_widget.isVisible():
modal_widget.close()
def start(self):
"""
Start this tester.
"""
self.timer = QTimer()
# Connecting self.idle to a QTimer with 0 time delay
# makes it called when there are no events to process
self.timer.timeout.connect(self._idle)
self.timer.start()
# This calls __call__() method
QTimer.singleShot(0, self)
# Start the event loop
self.app.exec_()