Skip to content

Commit

Permalink
ENH: Don't show message when enable the current eventloop. (ipython#1…
Browse files Browse the repository at this point in the history
…4168)

Should take care of ipython#14006, at least partially.
  • Loading branch information
Carreau authored Sep 25, 2023
2 parents 3b47371 + cf63863 commit 3df4946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions IPython/terminal/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import sys
from warnings import warn
from typing import Union as UnionType
from typing import Union as UnionType, Optional

from IPython.core.async_helpers import get_asyncio_loop
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
Expand Down Expand Up @@ -912,8 +912,9 @@ def inputhook(self, context):
if self._inputhook is not None:
self._inputhook(context)

active_eventloop = None
def enable_gui(self, gui=None):
active_eventloop: Optional[str] = None

def enable_gui(self, gui: Optional[str] = None) -> None:
if self.simple_prompt is True and gui is not None:
print(
f'Cannot install event loop hook for "{gui}" when running with `--simple-prompt`.'
Expand All @@ -928,8 +929,15 @@ def enable_gui(self, gui=None):
return

if self._inputhook is not None and gui is not None:
print(
f"Shell is already running a gui event loop for {self.active_eventloop}. "
newev, newinhook = get_inputhook_name_and_func(gui)
if self._inputhook == newinhook:
# same inputhook, do nothing
self.log.info(
f"Shell is already running the {self.active_eventloop} eventloop. Doing nothing"
)
return
self.log.warning(
f"Shell is already running a different gui event loop for {self.active_eventloop}. "
"Call with no arguments to disable the current loop."
)
return
Expand Down
3 changes: 2 additions & 1 deletion IPython/terminal/pt_inputhooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import os
from typing import Tuple, Callable

aliases = {
'qt4': 'qt',
Expand Down Expand Up @@ -119,7 +120,7 @@ def set_qt_api(gui):
return qt_env2gui[QT_API]


def get_inputhook_name_and_func(gui):
def get_inputhook_name_and_func(gui: str) -> Tuple[str, Callable]:
if gui in registered:
return gui, registered[gui]

Expand Down

0 comments on commit 3df4946

Please sign in to comment.