| | import sys |
| | import os |
| | from IPython.external.qt_for_kernel import QtCore, QtGui, enum_helper |
| | from IPython import get_ipython |
| |
|
| | |
| | |
| | _appref = None |
| | _already_warned = False |
| |
|
| |
|
| | def _exec(obj): |
| | |
| | obj.exec() if hasattr(obj, "exec") else obj.exec_() |
| |
|
| |
|
| | def _reclaim_excepthook(): |
| | shell = get_ipython() |
| | if shell is not None: |
| | sys.excepthook = shell.excepthook |
| |
|
| |
|
| | def inputhook(context): |
| | global _appref |
| | app = QtCore.QCoreApplication.instance() |
| | if not app: |
| | if sys.platform == 'linux': |
| | if not os.environ.get('DISPLAY') \ |
| | and not os.environ.get('WAYLAND_DISPLAY'): |
| | import warnings |
| | global _already_warned |
| | if not _already_warned: |
| | _already_warned = True |
| | warnings.warn( |
| | 'The DISPLAY or WAYLAND_DISPLAY environment variable is ' |
| | 'not set or empty and Qt5 requires this environment ' |
| | 'variable. Deactivate Qt5 code.' |
| | ) |
| | return |
| | try: |
| | QtCore.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) |
| | except AttributeError: |
| | pass |
| | try: |
| | QtCore.QApplication.setHighDpiScaleFactorRoundingPolicy( |
| | QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough |
| | ) |
| | except AttributeError: |
| | pass |
| | _appref = app = QtGui.QApplication([" "]) |
| |
|
| | |
| | |
| | |
| | |
| | QtCore.QTimer.singleShot(0, _reclaim_excepthook) |
| |
|
| | event_loop = QtCore.QEventLoop(app) |
| |
|
| | if sys.platform == 'win32': |
| | |
| | |
| | timer = QtCore.QTimer() |
| | timer.timeout.connect(event_loop.quit) |
| | while not context.input_is_ready(): |
| | |
| | timer.start(50) |
| | _exec(event_loop) |
| | timer.stop() |
| | else: |
| | |
| | |
| | notifier = QtCore.QSocketNotifier( |
| | context.fileno(), enum_helper("QtCore.QSocketNotifier.Type").Read |
| | ) |
| | try: |
| | |
| | |
| | |
| | notifier.activated.connect(lambda: event_loop.exit()) |
| | notifier.setEnabled(True) |
| | |
| | if not context.input_is_ready(): |
| | _exec(event_loop) |
| | finally: |
| | notifier.setEnabled(False) |
| |
|