Use the jupyterlab command to create a console, to also have the console tracker updated (required to execute code)

pull/7790/head
Nicolas Brichet 5 months ago
parent c1fac6d646
commit 57b3c12989

@ -41,15 +41,13 @@
"@jupyter-notebook/application": "^7.6.0-alpha.0",
"@jupyterlab/application": "~4.6.0-alpha.0",
"@jupyterlab/apputils": "~4.7.0-alpha.0",
"@jupyterlab/codeeditor": "~4.6.0-alpha.0",
"@jupyterlab/console": "~4.6.0-alpha.0",
"@jupyterlab/coreutils": "~6.6.0-alpha.0",
"@jupyterlab/notebook": "~4.6.0-alpha.0",
"@jupyterlab/rendermime": "~4.6.0-alpha.0",
"@jupyterlab/settingregistry": "~4.6.0-alpha.0",
"@jupyterlab/translation": "~4.6.0-alpha.0",
"@jupyterlab/ui-components": "~4.6.0-alpha.0",
"@lumino/algorithm": "^2.0.4",
"@lumino/coreutils": "^2.2.2",
"@lumino/widgets": "^2.7.2"
},
"devDependencies": {

@ -12,7 +12,7 @@
"id": "jp-mainmenu-file-new",
"items": [
{
"command": "console:scratch-pad",
"command": "scratch-pad-console:open",
"rank": 2
}
]
@ -24,7 +24,7 @@
},
"jupyter.lab.shortcuts": [
{
"command": "console:scratch-pad",
"command": "scratch-pad-console:open",
"keys": ["Accel B"],
"selector": "body"
}

@ -9,24 +9,14 @@ import {
import { ICommandPalette } from '@jupyterlab/apputils';
import { IEditorServices } from '@jupyterlab/codeeditor';
import {
ConsolePanel,
IConsoleCellExecutor,
IConsoleTracker,
} from '@jupyterlab/console';
import { IConsoleTracker } from '@jupyterlab/console';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { INotebookTracker } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { consoleIcon } from '@jupyterlab/ui-components';
import {
@ -37,6 +27,8 @@ import {
import { find } from '@lumino/algorithm';
import { ReadonlyJSONObject } from '@lumino/coreutils';
import { Widget } from '@lumino/widgets';
/**
@ -79,18 +71,33 @@ const opener: JupyterFrontEndPlugin<void> = {
const redirect: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/console-extension:redirect',
requires: [IConsoleTracker],
optional: [INotebookPathOpener],
optional: [INotebookPathOpener, INotebookShell],
autoStart: true,
description: 'Open consoles in a new tab',
activate: (
app: JupyterFrontEnd,
tracker: IConsoleTracker,
notebookPathOpener: INotebookPathOpener | null
notebookPathOpener: INotebookPathOpener | null,
notebookShell: INotebookShell | null
) => {
const baseUrl = PageConfig.getBaseUrl();
const opener = notebookPathOpener ?? defaultNotebookPathOpener;
tracker.widgetAdded.connect(async (send, console) => {
if (notebookShell) {
notebookShell.add(console, 'right');
notebookShell.expandRight(console.id);
app.commands
.listCommands()
.filter((id) => id.startsWith('console:'))
.forEach((id) => {
(app.commands as any)._commands.get(id).isEnabled = () =>
tracker.currentWidget !== null &&
tracker.currentWidget.node.contains(document.activeElement);
});
return;
}
const { sessionContext } = console;
await sessionContext.ready;
const widget = find(
@ -118,34 +125,23 @@ const redirect: JupyterFrontEndPlugin<void> = {
*/
const scratchPadConsole: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/console-extension:scratch-pad',
requires: [
ConsolePanel.IContentFactory,
IConsoleCellExecutor,
IEditorServices,
IRenderMimeRegistry,
INotebookTracker,
],
optional: [INotebookShell, ICommandPalette, ITranslator, ISettingRegistry],
requires: [INotebookTracker],
optional: [INotebookShell, ICommandPalette, ITranslator],
autoStart: true,
description: 'Open consoles in a new tab',
activate: (
app: JupyterFrontEnd,
contentFactory: ConsolePanel.IContentFactory,
executor: IConsoleCellExecutor,
editorServices: IEditorServices,
rendermime: IRenderMimeRegistry,
tracker: INotebookTracker,
notebookShell: INotebookShell | null,
palette: ICommandPalette | null,
translator: ITranslator | null,
settingRegistry: ISettingRegistry | null
translator: ITranslator | null
) => {
const { commands } = app;
const manager = app.serviceManager;
const trans = (translator ?? nullTranslator).load('notebook');
const command = 'console:scratch-pad';
const command = 'scratch-pad-console:open';
commands.addCommand(command, {
label: (args) =>
args['isPalette']
@ -183,30 +179,21 @@ const scratchPadConsole: JupyterFrontEndPlugin<void> = {
const id = notebookSessionContext.session?.kernel?.id;
const kernelPref = notebookSessionContext.kernelPreference;
panel = new ConsolePanel({
manager,
contentFactory,
mimeTypeService: editorServices.mimeTypeService,
rendermime,
executor,
kernelPreference: { ...kernelPref, id },
panel = await commands.execute('console:create', {
kernelPreference: { ...kernelPref, id } as ReadonlyJSONObject,
});
panel.title.caption = trans.__('Console');
panel.id = consoleId;
const interactionMode: string = ((
await settingRegistry?.get(
'@jupyterlab/console-extension:tracker',
'interactionMode'
)
)?.composite ?? 'notebook') as string;
(panel as ConsolePanel).console.node.dataset.jpInteractionMode =
interactionMode;
if (!panel) {
console.log('An error occurred during console widget creation');
return;
}
notebookShell.add(panel, 'right');
panel.title.caption = trans.__('Console');
panel.id = consoleId;
} else {
notebookShell.expandRight(consoleId);
}
notebookShell.expandRight(consoleId);
},
describedBy: {
args: {

@ -2384,15 +2384,13 @@ __metadata:
"@jupyter-notebook/application": ^7.6.0-alpha.0
"@jupyterlab/application": ~4.6.0-alpha.0
"@jupyterlab/apputils": ~4.7.0-alpha.0
"@jupyterlab/codeeditor": ~4.6.0-alpha.0
"@jupyterlab/console": ~4.6.0-alpha.0
"@jupyterlab/coreutils": ~6.6.0-alpha.0
"@jupyterlab/notebook": ~4.6.0-alpha.0
"@jupyterlab/rendermime": ~4.6.0-alpha.0
"@jupyterlab/settingregistry": ~4.6.0-alpha.0
"@jupyterlab/translation": ~4.6.0-alpha.0
"@jupyterlab/ui-components": ~4.6.0-alpha.0
"@lumino/algorithm": ^2.0.4
"@lumino/coreutils": ^2.2.2
"@lumino/widgets": ^2.7.2
rimraf: ^3.0.2
typescript: ~5.5.4

Loading…
Cancel
Save