From db9663979e18e2eecd276ce7139d9fea74c8201c 2018-09-07 10:53:52 From: Christoph Date: 2018-09-07 10:53:52 Subject: [PATCH] Disable qt inputhook backend when DISPLAY is not set on linux, because the qt lib does not handle this correct --- diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py index 0de9c3d..5b05ac9 100644 --- a/IPython/terminal/pt_inputhooks/qt.py +++ b/IPython/terminal/pt_inputhooks/qt.py @@ -1,15 +1,32 @@ import sys +import os 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 - +_already_warned = False def inputhook(context): global _appref app = QtCore.QCoreApplication.instance() if not app: + if sys.platform == 'linux': + try: + os.environ['DISPLAY'] # DISPLAY is set + assert os.environ['DISPLAY'] != '' # DISPLAY is not empty + except Exception: + import warnings + global _already_warned + if not _already_warned: + _already_warned = True + warnings.warn( + 'The DISPLAY enviroment variable is not set or empty ' + 'and qt requires this enviroment variable. ' + 'Deaktivate qt code.\n' + 'Backend: {}'.format(QtGui) + ) + return _appref = app = QtGui.QApplication([" "]) event_loop = QtCore.QEventLoop(app)