86
86
app.processEvents(QtCore.QEventLoop.AllEvents, 300)
87
87
if not stdin_ready():
88
# Generally a program would run QCoreApplication::exec()
89
# from main() to enter and process the Qt event loop until
90
# quit() or exit() is called and the program terminates.
92
# For our input hook integration, we need to repeatedly
93
# enter and process the Qt event loop for only a short
94
# amount of time (say 50ms) to ensure that Python stays
95
# responsive to other user inputs.
97
# A naive approach would be to repeatedly call
98
# QCoreApplication::exec(), using a timer to quit after a
99
# short amount of time. Unfortunately, QCoreApplication
100
# emits an aboutToQuit signal before stopping, which has
101
# the undesirable effect of closing all modal windows.
103
# To work around this problem, we instead create a
104
# QEventLoop and call QEventLoop::exec(). Other than
105
# setting some state variables which do not seem to be
106
# used anywhere, the only thing QCoreApplication adds is
107
# the aboutToQuit signal which is precisely what we are
88
109
timer = QtCore.QTimer()
89
timer.timeout.connect(app.quit)
110
event_loop = QtCore.QEventLoop()
111
timer.timeout.connect(event_loop.quit)
90
112
while not stdin_ready():
94
116
except KeyboardInterrupt: