##// END OF EJS Templates
Merge pull request #12739 from farisachugthai/conda
Merge pull request #12739 from farisachugthai/conda

File last commit:

r25812:f4206657
r26285:6a7c4880 merge
Show More
qt.py
56 lines | 2.2 KiB | text/x-python | PythonLexer
Thomas Kluyver
Try to fix Qt event loop, take III...
r22654 import sys
Christoph
Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct
r24529 import os
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 from IPython.external.qt_for_kernel import QtCore, QtGui
Thomas Kluyver
Create a QApplication for inputhook if one doesn't already exist...
r22707 # If we create a QApplication, keep a reference to it so that it doesn't get
# garbage collected.
_appref = None
Christoph
Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct
r24529 _already_warned = False
Thomas A Caswell
FIX: re-order qt eventloop hook a bit...
r23367
Thomas A Caswell
FIX: make sure the QSocketNotifier is disabled...
r25035
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 def inputhook(context):
Thomas Kluyver
Create a QApplication for inputhook if one doesn't already exist...
r22707 global _appref
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 app = QtCore.QCoreApplication.instance()
if not app:
Christoph
Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct
r24529 if sys.platform == 'linux':
Christoph
apply comments
r24533 if not os.environ.get('DISPLAY') \
and not os.environ.get('WAYLAND_DISPLAY'):
Christoph
Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct
r24529 import warnings
global _already_warned
if not _already_warned:
_already_warned = True
warnings.warn(
luz.paz
typos...
r24559 'The DISPLAY or WAYLAND_DISPLAY environment variable is '
'not set or empty and Qt5 requires this environment '
Christoph
apply comments
r24533 'variable. Deactivate Qt5 code.'
Christoph
Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct
r24529 )
return
Talley Lambert
enable high dpi
r25726 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
Thomas Kluyver
Create a QApplication for inputhook if one doesn't already exist...
r22707 _appref = app = QtGui.QApplication([" "])
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 event_loop = QtCore.QEventLoop(app)
Thomas Kluyver
Try to fix Qt event loop, take III...
r22654
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.
Thomas A Caswell
FIX: re-order qt eventloop hook a bit...
r23367 notifier = QtCore.QSocketNotifier(context.fileno(),
QtCore.QSocketNotifier.Read)
Thomas A Caswell
FIX: make sure the QSocketNotifier is disabled...
r25035 try:
# connect the callback we care about before we turn it on
Matthias Bussonnier
Add comments to explain the lambda:...
r25812 # lambda is necessary as PyQT inspect the function signature to know
# what arguments to pass to. See https://github.com/ipython/ipython/pull/12355
Talley Lambert
fix notifier.activated connection
r25791 notifier.activated.connect(lambda: event_loop.exit())
Thomas A Caswell
FIX: make sure the QSocketNotifier is disabled...
r25035 notifier.setEnabled(True)
# only start the event loop we are not already flipped
if not context.input_is_ready():
event_loop.exec_()
finally:
notifier.setEnabled(False)