8000 Do not create a QApplication in Qt input hook · Issue #13617 · ipython/ipython · GitHub
[go: up one dir, main page]

Skip to content

Do not create a QApplication in Qt input hook #13617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tacaswell opened this issue Apr 1, 2022 · 1 comment
Open

Do not create a QApplication in Qt input hook #13617

tacaswell opened this issue Apr 1, 2022 · 1 comment

Comments

@tacaswell
Copy link
Contributor

Currently if the Qt input hook runs and there is not as exiting QApplication IPython will create one for the user and then spin it. On one hand this is convenient for doing Qt work as the Application is automatically created after the first cell runs. However, this can lead to weird behavior where running commands in one line vs serval cells leads to different results (see DeepLabCut/DeepLabCut#1730).

Although I advocated for the current state of affairs, I now think that it is more confusing this way. I propose that basically this entire block of code is removed and replaced with return

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: # Only for Qt>=5.6, <6.
pass
try:
QtCore.QApplication.setHighDpiScaleFactorRoundingPolicy(
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
except AttributeError: # Only for Qt>=5.14.
pass
_appref = app = QtGui.QApplication([" "])
# "reclaim" IPython sys.excepthook after event loop starts
# without this, it defaults back to BaseIPythonApplication.excepthook
# and exceptions in the Qt event loop are rendered without traceback
# formatting and look like "bug in IPython".
QtCore.QTimer.singleShot(0, _reclaim_excepthook)

A bulk of the work on this issue will be documenting the consequences and thinking through what the consequences might be.

@tacaswell
Copy link
Contributor Author
tacaswell commented Apr 30, 2022

https://gist.github.com/pag/f7d1ebbd1b14fe9058bf68d73a52bc84 is a patch that implements this a related idea that does not spin the event loop until it is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0