Skip to content

Let's just do all the GUI event loops #14089

Open

Description

@shaperilio

I worked on adding support for PySide6 in %gui. Discovering how that whole process worked, and how IPython and matplotlib play with each other was tough, so I put in some messages that some people don't like (#14006).

Without these messages, "weird things happen", because you can only run one GUI event loop at once, and all sorts of things can request hook installation (e.g. selecting a matplotlib backend that requires it). So you might be having a nice flowery day and you run some nice GUI someone wrote and nothing happens; no windows, no nothing, because it was written with Tk and something silently hooked the GUI loop for Qt.

If you factor in trying to support multiple Qt versions (i.e. let a user choose between PyQt5 or pyside6 and things get really complicated. There's a lot of back-and-forth mapping which doesn't immediately make sense. A coworker of mine also magically got a pyside6 program to work just fine with a version of IPython which technically does not support pyside6 in %gui so there may even be some voodoo going on in the Qt side of things that just made that work.

So I suggest a few things:

  • Remove absolutely every mention of qt4 in any GUI<->backend mapping, for completeness.
  • Consider not supporting the specification of a specific Qt version. i.e. only support %gui qt which will choose the latest Qt package you have and that's that (that's effectively done by the backend2gui mapping).
  • Implement a %gui all which just hooks everything in. Tk and Qt at least, but maybe we just come up with an "if installed then hook it" type of thing for every supported GUI event loop. I even dare say IPython should just do that at startup, but easy enough for people to configure it to do so.

Activity

  1. shaperilio commented on May 30, 2023

    @shaperilio
    ContributorAuthor

    I've been playing with this... The following sequence actually runs the Qt and Tk event loops at the same time:

    %gui qt  # request Qt
    %gui     # disable Qt. Verified that Qt apps become unresponsive.
    %gui tk  # request Tk. Qt app starts running again, as do Tk apps.
    

    The reverse order does not work; Tk apps never wake up again.

    In code, I tried to create an input hook like this and then install it in the terminal:

    tk_inputhook = IPython.terminal.pt_inputhooks.tk.inputhook
    qt_inputhook = IPython.terminal.pt_inputhooks.qt.inputhook
    
    def inputhook(context):
        tk_inputhook(context)
        qt_inputhook(context)
    

    That has the same effect as the working %gui sequence above. Inverting the tk/qt calls does not work.

    (this is all in Windows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions