Skip to content
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

Shaperilio/gui msg #14067

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Conversation

shaperilio
Copy link
Contributor

@shaperilio shaperilio commented May 2, 2023

Addresses the annoying extra messages as detailed in #14006.

Behavior

The intent is to:

  • Communicate when the user installs a hook
  • Communicate when the user tries to install a different hook and cannot.
  • Communicate when the user uninstalls a hook
  • Not communicate when the user tries to install the same hook multiple times, with special care for the "latest version" 'qt' hook request.

Take a system with both PyQt5 and pyside6 installed:

(venv) > ipython
Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0.dev -- An enhanced Interactive Python. Type '?' for help.

In [1]: %gui qt
Installed qt6 event loop hook.

In [2]: %gui qt5
Cannot switch Qt versions for this session; will use qt6.
Installed qt6 event loop hook.

In [3]: %gui qt

In [4]: %gui qt6

In [5]: %gui tk
Shell is already running a gui event loop for qt6. Call with no arguments to disable the current loop.

In [6]: %gui
GUI event loop hook for tk removed.

In [7]: %gui tk
Installed tk event loop hook.

In [8]: %gui qt
Shell is already running a gui event loop for tk. Call with no arguments to disable the current loop.

In [9]: %gui qt6
Shell is already running a gui event loop for tk. Call with no arguments to disable the current loop.

In [10]: %gui qt5
Shell is already running a gui event loop for tk. Call with no arguments to disable the current loop.

In [11]: %gui
GUI event loop hook for qt5 removed.

In [12]: %gui tk
Installed tk event loop hook.

In [13]: %gui
GUI event loop hook for tk removed.

In [14]: %gui qt5
Cannot switch Qt versions for this session; will use qt6.
Installed qt6 event loop hook.

In [15]: 

This means when you run ipython --matplotlib=tk, for example, you'll see this:

Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0.dev -- An enhanced Interactive Python. Type '?' for help.
Installed tk event loop hook.

In [1]:

Notes

Working on this has uncovered some interesting dynamics; qt is taken to mean "the latest Qt available" and the current code appears to force, in some cases, what is effectively a %gui qt command before command line or config args are processed (see this issue), so that executing

ipython --matplotlib=qt5

effectively runs

%gui qt
%gui qt5

and if both pyside6 and PyQt5 are installed, the %gui qt5 will trigger a message about not being able to change Qt versions in the session.

I see no difference in e.g. Jupyter notebook. Removing this call
prevents the unnecessary installation of a
gui event loop hook.
from matplotlib_inline.backend_inline import configure_inline_support
# NOTE: this import triggers `enable_gui('qt')` and occurs before the users' config (e.g.
# `--matplotlib=qt5`) is procssed.
# from matplotlib_inline.backend_inline import configure_inline_support
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this import (and the function call that requires it) prevents the unnecessary installation of a qt event loop hook, and as far as I can tell, has no negative effects - I still get inline figures in a Jupyter notebook, for example. I'll need someone with more expertise to chime in on this.

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

Successfully merging this pull request may close these issues.

None yet

1 participant