Skip to content

Commit

Permalink
chore: lumino example and heigh
Browse files Browse the repository at this point in the history
  • Loading branch information
echarles committed Oct 23, 2023
1 parent 03d9633 commit a463ab9
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 17 deletions.
2 changes: 2 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"@jupyterlab/builder": "4.0.3",
"@jupyterlab/geojson-extension": "3.4.0",
"@jupyterlab/launcher": "4.0.3",
"@jupyterlab/running": "4.0.3",
"@jupyterlab/running-extension": "4.0.3",
"@jupyterlab/testutils": "4.0.3",
"@jupyterlab/vega3-extension": "3.3.0",
"@types/codemirror": "5.60.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/jupyterlab/JupyterLabApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import JupyterLabAppCss from "./JupyterLabAppCss";
let _adapter: JupyterLabAppAdapter | undefined = undefined;

// The webpack public path needs to be set before loading the CSS assets.
(global as any).__webpack_public_path__ = PageConfig.getOption('fullStaticUrl') + '/';
(globalThis as any).__webpack_public_path__ = PageConfig.getOption('fullStaticUrl') + '/';
(window as any).__webpack_public_path__ = PageConfig.getOption('fullStaticUrl') + '/';

export type JupyterLabAppProps = {
devMode: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/output/OutputIPyWidgets.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IPyWidgetsAttached from '../../jupyter/lumino/IPyWidgetsAttached';
import IPyWidgetsAttached from '../../jupyter/ipywidgets/IPyWidgetsAttached';

import './OutputIPyWidgets.css';

Expand Down
25 changes: 18 additions & 7 deletions packages/react/src/examples/JupyterLabHeadlessApp.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState } from 'react';
import { createRoot } from 'react-dom/client';
import { Box, Text, ToggleSwitch, ThemeProvider, useTheme } from "@primer/react";
import { BoxPanel } from '@lumino/widgets';
import { BoxPanel, Widget } from '@lumino/widgets';
import { ThemeManager } from '@jupyterlab/apputils';
import { NotebookPanel } from '@jupyterlab/notebook';
import { RunningSessions } from '@jupyterlab/running';
// import { NotebookTracker } from '@jupyterlab/notebook';
import { ThemeManager } from '@jupyterlab/apputils';
import { Widget } from '@lumino/widgets';
import Jupyter from '../jupyter/Jupyter';
import Lumino from '../jupyter/lumino/Lumino';
import { JupyterLabTheme } from '../jupyter/lab/JupyterLabTheme';
Expand All @@ -14,6 +14,7 @@ import JupyterLabAppAdapter from "../components/jupyterlab/JupyterLabAppAdapter"

import * as darkThemeExtension from '@jupyterlab/theme-dark-extension';
import * as lightThemeExtension from '@jupyterlab/theme-light-extension';
import * as runningExtension from '@jupyterlab/running-extension';
import * as ipywidgetsExtension from '@jupyter-widgets/jupyterlab-manager';
import * as plotlyExtension from 'jupyterlab-plotly/lib/jupyterlab-plugin';
import * as mimePlotlyExtension from 'jupyterlab-plotly/lib/plotly-renderer';
Expand All @@ -28,7 +29,8 @@ const PATHS = [
const PATH_INDEX = 1;

const JupyterLabHeadlessAppExample = () => {
const [boxPanel, setBoxPanel] = useState<BoxPanel>();
const [notebookBoxPanel, setNotebookBoxPanel] = useState<BoxPanel>();
const [runningSessions, setRunningSessions] = useState<BoxPanel>();
const [theme, setTheme] = useState<JupyterLabTheme>('light');
const [jupyterLabAdapter, setJupyterlabAdapter] = useState<JupyterLabAppAdapter>();
const { setColorMode } = useTheme();
Expand Down Expand Up @@ -63,7 +65,10 @@ const JupyterLabHeadlessAppExample = () => {
boxPanel.addClass('dla-Jupyter-Notebook');
boxPanel.spacing = 0;
boxPanel.addWidget(notebookPanel);
setBoxPanel(boxPanel);
setNotebookBoxPanel(boxPanel);
const runningSessionManagers = jupyterLabAdapter.service('@jupyterlab/running-extension:plugin');
const runningSessions = new RunningSessions(runningSessionManagers);
setRunningSessions(runningSessions);
}
const onPlugin = (themeManager: ThemeManager) => {
// const notebookTracker = jupyterlabAdapter.service("@jupyterlab/notebook-extension:tracker") as NotebookTracker;
Expand Down Expand Up @@ -94,7 +99,12 @@ const JupyterLabHeadlessAppExample = () => {
</Box>
</Box>
</ThemeProvider>
{ boxPanel &&
{ runningSessions &&
<Lumino height="300px">
{runningSessions}
</Lumino>
}
{ notebookBoxPanel &&
<div style={{ position: "relative" }}>
<Box className="jp-LabShell"
sx={{
Expand All @@ -106,14 +116,15 @@ const JupyterLabHeadlessAppExample = () => {
},
}}
>
<Lumino>{boxPanel}</Lumino>
<Lumino>{notebookBoxPanel}</Lumino>
</Box>
</div>
}
<JupyterLabApp
extensions={[
lightThemeExtension,
darkThemeExtension,
runningExtension,
ipywidgetsExtension,
plotlyExtension,
]}
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/examples/Lumino.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useMemo } from 'react';
import { createRoot } from 'react-dom/client';
import LuminoBox from './../jupyter/lumino/LuminoBox';
import LuminoWidget from './lumino/LuminoWidget';

export const LuminoExample = () => {
const luminoWidget = useMemo(() => new LuminoWidget(), []);
return (
<LuminoBox height="100px">
{luminoWidget.panel}
</LuminoBox>
)
}

const div = document.createElement('div');
document.body.appendChild(div);
const root = createRoot(div)

root.render(
<>
<LuminoExample/>
</>
);
4 changes: 2 additions & 2 deletions packages/react/src/examples/NotebookKernelChange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CellSidebar from '../components/notebook/cell/sidebar/CellSidebar';

const NOTEBOOK_UID = 'notebook-kernel-id';

const NEW_KERNEL_NAME = "python-slow"
const NEW_KERNEL_NAME = "python-bis"

const NotebookKernelChange = () => {
const { kernelManager, serverSettings } = useJupyter();
Expand All @@ -26,7 +26,7 @@ const NotebookKernelChange = () => {
});
kernel.ready.then(() => {
dispatch(notebookActions.changeKernel({ uid: NOTEBOOK_UID, kernel }));
alert('The kernel is changed.')
alert('The kernel is changed (was python3, now is python-bis). Bummer, all your variables are lost!')
});
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/react/src/examples/lumino/LuminoWidget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.content {
min-width: 50px;
min-height: 50px;
display: block;
padding: 8px;
border: 1px solid #C0C0C0;
border-top: none;
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.content > div {
border: 1px solid #505050;
overflow: auto;
}

.content input {
margin: 8px;
}

.red > div {
background: #E74C3C;
}

.yellow > div {
background: #F1C40F;
}

.green > div {
background: #27AE60;
}

.blue > div {
background: #3498DB;
}
90 changes: 90 additions & 0 deletions packages/react/src/examples/lumino/LuminoWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Message } from '@lumino/messaging';
import { DockPanel, BoxPanel, Widget } from '@lumino/widgets';

import '@lumino/default-theme/style/index.css';

import './LuminoWidget.css'

class LuminoWidget extends Widget {

constructor(name: string) {
super({ node: LuminoWidget.createNode() });
this.setFlag(Widget.Flag.DisallowLayout);
this.addClass('content');
this.addClass(name.toLowerCase());
this.title.label = name;
this.title.closable = true;
this.title.caption = `Long description for: ${name}`;
}

static createNode(): HTMLElement {
let node = document.createElement('div');
let content = document.createElement('div');
let input = document.createElement('input');
input.placeholder = 'Placeholder...';
content.appendChild(input);
node.appendChild(content);
return node;
}

get inputNode(): HTMLInputElement {
return this.node.getElementsByTagName('input')[0] as HTMLInputElement;
}

protected onActivateRequest(msg: Message): void {
if (this.isAttached) {
this.inputNode.focus();
}
}

}

class SimpleAdapter {
private simplePanel: BoxPanel;

constructor() {
const colors = [
'Red',
'Yellow',
'Green',
'Blue'
];

this.simplePanel = new BoxPanel();
this.simplePanel.id = 'simple-panel';
// this.simplePanel.direction = 'top-to-bottom';
this.simplePanel.spacing = 0;

// Dock Panel
const r1 = new LuminoWidget('Red');
const b1 = new LuminoWidget('Blue');
const g1 = new LuminoWidget('Green');
const y1 = new LuminoWidget('Yellow');
const r2 = new LuminoWidget('Red');
const b2 = new LuminoWidget('Blue');

const dockPanel = new DockPanel();
dockPanel.addWidget(r1);
dockPanel.addWidget(b1, { mode: 'split-right', ref: r1 });
dockPanel.addWidget(y1, { mode: 'split-bottom', ref: b1 });
dockPanel.addWidget(g1, { mode: 'split-left', ref: y1 });
dockPanel.addWidget(r2, { ref: b1 });
dockPanel.addWidget(b2, { mode: 'split-right', ref: y1 });
dockPanel.id = 'simple-dock-panel';

this.simplePanel.addWidget(dockPanel);

for (let i = 0; i < 20; i++) {
const c = new LuminoWidget(colors[Math.floor(Math.random() * 4)]);
this.simplePanel.addWidget(c);
}

}

get panel(): BoxPanel {
return this.simplePanel;
}

}

export default SimpleAdapter;
8 changes: 5 additions & 3 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export * from './components/notebook/cell/sidebar/CellSidebar';
export * from './components/notebook/cell/sidebar/CellSidebarRun';

// IPyWidgets.
export * from './jupyter/ipywidgets/IPyWidgetsAttached';
export * from './jupyter/ipywidgets/IPyWidgetsViewManager';
export * from './jupyter/ipywidgets/IPyWidgetsViewManager';

// Commands.
Expand All @@ -60,13 +62,13 @@ export * from './components/console/ConsoleState';
// Dialog.
export * from './components/dialog/Dialog';

// FileBrowser.
// File Browser.
export * from './components/filebrowser/FileBrowser';

// FileManager.
// File Manager.
export * from './components/filemanager/FileManagerState';

// FileManager (JupyterLab variant).
// File Manager (JupyterLab variant).
export * from './components/filemanager/FileManagerJupyterLab';

// Outputs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IPyWidgetsViewManager from '../ipywidgets/IPyWidgetsViewManager';
import IPyWidgetsViewManager from './IPyWidgetsViewManager';

type Props = {
view: any,
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/jupyter/lumino/Lumino.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Widget } from '@lumino/widgets';

type LuminoProps = {
id?: string;
height?: string | number;
children: Widget;
}

export const Lumino = (props: LuminoProps) => {
const ref = useRef<HTMLDivElement>(null);
const { children, id } = props;
const { children, id, height } = props;
useEffect(() => {
if (ref && ref.current) {
try {
Expand All @@ -31,11 +32,12 @@ export const Lumino = (props: LuminoProps) => {
}
}
}, [ref, children]);
return <div ref={ref} id={id}/>
return <div ref={ref} id={id} style={{ height: height, minHeight: height }} />
}

Lumino.defaultProps = {
id: "lumino-id",
height: "100%",
}

export default Lumino;
1 change: 1 addition & 0 deletions packages/react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ENTRY =
// "./src/app/App";
// "./src/examples/JupyterLabApp";
"./src/examples/JupyterLabHeadlessApp";
// "./src/examples/Lumino";
// "./src/examples/Matplotlib";
// "./src/examples/Notebook";
// "./src/examples/NotebookKernelChange";
Expand Down

0 comments on commit a463ab9

Please sign in to comment.