diff --git a/spyder_notebook/notebookplugin.py b/spyder_notebook/notebookplugin.py index 35c4162..ff95bf3 100644 --- a/spyder_notebook/notebookplugin.py +++ b/spyder_notebook/notebookplugin.py @@ -6,6 +6,7 @@ """Notebook plugin.""" # Standard library imports +import logging import os.path as osp # Spyder imports @@ -20,6 +21,8 @@ from spyder_notebook.widgets.main_widget import NotebookMainWidget from spyder_notebook.utils.localization import _ +logger = logging.getLogger(__name__) + class NotebookPlugin(SpyderDockablePlugin): """Spyder Notebook plugin.""" @@ -94,10 +97,11 @@ def open_notebook(self, filenames=None): self.get_widget().open_notebook(filenames) # ------ Private API ------------------------------------------------------ - def _open_console(self, kernel_id, tab_name): + def _open_console(self, connection_file, tab_name): """Open an IPython console as requested.""" + logger.info(f'Opening console with {connection_file=}') ipyconsole = self.get_plugin(Plugins.IPythonConsole) - ipyconsole.create_client_for_kernel(kernel_id) + ipyconsole.create_client_for_kernel(connection_file) ipyclient = ipyconsole.get_current_client() ipyclient.allow_rename = False ipyconsole.rename_client_tab(ipyclient, tab_name) diff --git a/spyder_notebook/widgets/main_widget.py b/spyder_notebook/widgets/main_widget.py index e403d36..e76c739 100644 --- a/spyder_notebook/widgets/main_widget.py +++ b/spyder_notebook/widgets/main_widget.py @@ -4,7 +4,11 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# Standard library imports +import os.path as osp + # Third-party imports +from jupyter_core.paths import jupyter_runtime_dir from qtpy.QtCore import Signal from qtpy.QtWidgets import QMessageBox, QVBoxLayout @@ -55,8 +59,8 @@ class NotebookMainWidget(PluginMainWidget): Parameters ----------- - kernel_id: str - Id of the kernel to open a console for. + connection_file: str + Name of the connection file for the kernel to open a console for. tab_name: str Tab name to set for the created console. """ @@ -317,8 +321,10 @@ def open_console(self, client=None): ) return + connection_file = f'kernel-{kernel_id}.json' + connection_file = osp.join(jupyter_runtime_dir(), connection_file) self.sig_open_console_requested.emit( - kernel_id, + connection_file, client.get_short_name() )