Show More
@@ -85,11 +85,33 def create_inputhook_qt4(mgr, app=None): | |||
|
85 | 85 | return 0 |
|
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. | |
|
91 | # | |
|
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. | |
|
96 | # | |
|
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. | |
|
102 | # | |
|
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 | |
|
108 | # trying to avoid. | |
|
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(): |
|
91 | 113 | timer.start(50) |
|
92 |
|
|
|
114 | event_loop.exec_() | |
|
93 | 115 | timer.stop() |
|
94 | 116 | except KeyboardInterrupt: |
|
95 | 117 | ignore_CTRL_C() |
General Comments 0
You need to be logged in to leave comments.
Login now