##// END OF EJS Templates
Always run the OS X loop even if no windows....
Always run the OS X loop even if no windows. Otherwise this can trigger infinite Python-Icon-In-Dock bouncing. See #10137. I will guess that this is because application on OS X may not have windows and still need to process events. It may be that an alternative is to run the loop only once the first time, but I'm unsure. at_least_once = False def inputhook(context): """Inputhook for Cocoa (NSApp)""" NSApp = _NSApp() window_count = msg( msg(NSApp, n('windows')), n('count') ) if not window_count and not at_least_once: at_least_once = True return _stop_on_read(context.fileno()) msg(NSApp, n('run')) if not _triggered.is_set(): # app closed without firing callback, # probably due to last window being closed. # Run the loop manually in this case, # since there may be events still to process (#9734) CoreFoundation.CFRunLoopRun() Closes #10137

File last commit:

r22707:3a42b331
r23167:260e9884
Show More
qt.py
30 lines | 1.0 KiB | text/x-python | PythonLexer
import sys
from IPython.external.qt_for_kernel import QtCore, QtGui
# If we create a QApplication, keep a reference to it so that it doesn't get
# garbage collected.
_appref = None
def inputhook(context):
global _appref
app = QtCore.QCoreApplication.instance()
if not app:
_appref = app = QtGui.QApplication([" "])
event_loop = QtCore.QEventLoop(app)
if sys.platform == 'win32':
# The QSocketNotifier method doesn't appear to work on Windows.
# Use polling instead.
timer = QtCore.QTimer()
timer.timeout.connect(event_loop.quit)
while not context.input_is_ready():
timer.start(50) # 50 ms
event_loop.exec_()
timer.stop()
else:
# On POSIX platforms, we can use a file descriptor to quit the event
# loop when there is input ready to read.
notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read)
notifier.setEnabled(True)
notifier.activated.connect(event_loop.exit)
event_loop.exec_()