Skip to content

Commit 2c0735a

Browse files
authored
Merge pull request #79 from jtpio/lab-based-apps
Support other lab-based applications
2 parents 74b9ec2 + da190ec commit 2c0735a

File tree

9 files changed

+390
-202
lines changed

9 files changed

+390
-202
lines changed

.binder/environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ dependencies:
55
- bqplot=0.12
66
- ipytree=0.2
77
- jupyterlab=3
8+
- retrolab=0.3
89
- nodejs
910
- numpy

docs/environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ipylab_docs
33
channels:
44
- conda-forge
55
dependencies:
6-
- python=3.5
6+
- python=3.9
77
- nodejs
88
- numpy
99
- sphinx

docs/source/conf.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929
"sphinx.ext.napoleon",
3030
"sphinx.ext.todo",
3131
"nbsphinx",
32-
"jupyter_sphinx.embed_widgets",
33-
"nbsphinx_link",
3432
]
3533

3634
# Ensure our extension is available:
35+
import json
3736
import sys
3837
from os.path import dirname, join as pjoin
3938

@@ -71,15 +70,16 @@
7170

7271
here = os.path.dirname(__file__)
7372
repo = os.path.join(here, "..", "..")
74-
_version_py = os.path.join(repo, "ipylab", "_version.py")
75-
version_ns = {}
76-
with open(_version_py) as f:
77-
exec(f.read(), version_ns)
73+
with open(os.path.join(repo, "package.json")) as f:
74+
package = json.load(f)
75+
_version_js = package["version"]
7876

7977
# The short X.Y version.
80-
version = "%i.%i" % version_ns["version_info"][:2]
78+
version = "%i.%i" % tuple(int(part) for part in _version_js.split("."))[:2]
8179
# The full version, including alpha/beta/rc tags.
82-
release = version_ns["__version__"]
80+
release = (
81+
_version_js.replace("-alpha.", "a").replace("-beta.", "b").replace("-rc.", "rc")
82+
)
8383

8484
# The language for content autogenerated by Sphinx. Refer to documentation
8585
# for a list of supported languages.
@@ -192,15 +192,3 @@
192192
# that nbsphinx complains about:
193193
#
194194
nbsphinx_allow_errors = True # exception ipstruct.py ipython_genutils
195-
196-
197-
def setup(app):
198-
app.setup_extension("jupyter_sphinx.embed_widgets")
199-
200-
def add_scripts(app):
201-
for fname in ["helper.js", "embed-bundle.js"]:
202-
if not os.path.exists(os.path.join(here, "_static", fname)):
203-
app.warn("missing javascript file: %s" % fname)
204-
app.add_javascript(fname)
205-
206-
app.connect("builder-inited", add_scripts)

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@
7272
"dependencies": {
7373
"@jupyter-widgets/base": "^1 || ^2 || ^3 || ^4",
7474
"@jupyter-widgets/controls": "^3.0.0",
75-
"@jupyterlab/builder": "^3.0.0",
76-
"@jupyterlab/application": "^3.0.0",
77-
"@jupyterlab/apputils": "^3.0.0",
78-
"@jupyterlab/observables": "^4.0.0",
79-
"@lumino/algorithm": "^1.3.3",
75+
"@jupyterlab/application": "^3.2.3",
76+
"@jupyterlab/apputils": "^3.2.3",
77+
"@jupyterlab/observables": "^4.2.3",
78+
"@lumino/algorithm": "^1.9.1",
8079
"@lumino/commands": "^1.12.0",
81-
"@lumino/disposable": "^1.4.3",
82-
"@lumino/messaging": "^1.4.3",
83-
"@lumino/widgets": "^1.17.0"
80+
"@lumino/disposable": "^1.10.1",
81+
"@lumino/messaging": "^1.10.1",
82+
"@lumino/widgets": "^1.30.0"
8483
},
8584
"devDependencies": {
85+
"@jupyterlab/builder": "^3.2.3",
8686
"@types/expect.js": "^0.3.29",
8787
"@types/node": "^10.11.6",
8888
"@typescript-eslint/eslint-plugin": "^2.26.0",
@@ -100,7 +100,7 @@
100100
"npm-run-all": "^4.1.3",
101101
"prettier": "^2.0.2",
102102
"rimraf": "^2.6.2",
103-
"typescript": "~4.1.3"
103+
"typescript": "~4.4.4"
104104
},
105105
"jupyterlab": {
106106
"extension": "lib/plugin",

readthedocs.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
type: sphinx
1+
version: 2
22
python:
3-
version: 3.5
4-
pip_install: true
5-
extra_requirements:
6-
- examples
7-
- docs
3+
version: "3.7"
4+
install:
5+
- method: pip
6+
path: .
87
conda:
9-
file: docs/environment.yml
8+
environment: docs/environment.yml

src/plugin.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ const EXTENSION_ID = 'ipylab:plugin';
2323
const extension: JupyterFrontEndPlugin<void> = {
2424
id: EXTENSION_ID,
2525
autoStart: true,
26-
requires: [IJupyterWidgetRegistry, ILabShell],
27-
optional: [ICommandPalette],
26+
requires: [IJupyterWidgetRegistry],
27+
optional: [ICommandPalette, ILabShell],
2828
activate: (
2929
app: JupyterFrontEnd,
3030
registry: IJupyterWidgetRegistry,
31-
shell: ILabShell,
32-
palette: ICommandPalette
31+
palette: ICommandPalette,
32+
labShell: ILabShell | null
3333
): void => {
3434
// add globals
3535
widgetExports.JupyterFrontEndModel.app = app;
36-
widgetExports.ShellModel.shell = shell;
36+
widgetExports.ShellModel.shell = app.shell;
37+
widgetExports.ShellModel.labShell = labShell;
3738
widgetExports.CommandRegistryModel.commands = app.commands;
3839
widgetExports.CommandPaletteModel.palette = palette;
3940
widgetExports.SessionManagerModel.sessions = app.serviceManager.sessions;
40-
widgetExports.SessionManagerModel.shell = shell;
41+
widgetExports.SessionManagerModel.shell = app.shell;
42+
widgetExports.SessionManagerModel.labShell = labShell;
4143

4244
registry.registerWidget({
4345
name: MODULE_NAME,

src/widgets/sessions.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ISerializers, WidgetModel } from '@jupyter-widgets/base';
88
import { toArray } from '@lumino/algorithm';
99
import { MODULE_NAME, MODULE_VERSION } from '../version';
1010
import { Session } from '@jupyterlab/services';
11-
import { ILabShell } from '@jupyterlab/application';
11+
import { ILabShell, JupyterFrontEnd } from '@jupyterlab/application';
1212

1313
/**
1414
* The model for a Session Manager
@@ -35,15 +35,23 @@ export class SessionManagerModel extends WidgetModel {
3535
* @param options The initialization options.
3636
*/
3737
initialize(attributes: any, options: any): void {
38-
const { sessions, shell } = SessionManagerModel;
38+
const { labShell, sessions, shell } = SessionManagerModel;
3939
this._sessions = sessions;
4040
this._shell = shell;
41+
this._labShell = labShell;
42+
4143
sessions.runningChanged.connect(this._sendSessions, this);
42-
shell.currentChanged.connect(this._currentChanged, this);
4344

4445
super.initialize(attributes, options);
4546
this.on('msg:custom', this._onMessage.bind(this));
46-
this._shell.activeChanged.connect(this._currentChanged, this);
47+
48+
if (this._labShell) {
49+
this._labShell.currentChanged.connect(this._currentChanged, this);
50+
this._labShell.activeChanged.connect(this._currentChanged, this);
51+
} else {
52+
this._currentChanged();
53+
}
54+
4755
this._sendSessions();
4856
this._sendCurrent();
4957
this.send({ event: 'sessions_initialized' }, {});
@@ -124,6 +132,8 @@ export class SessionManagerModel extends WidgetModel {
124132
private _current_session: Session.IModel | {};
125133
private _sessions: SessionManager;
126134
static sessions: SessionManager;
127-
private _shell: ILabShell;
128-
static shell: ILabShell;
135+
private _shell: JupyterFrontEnd.IShell;
136+
private _labShell: ILabShell | null;
137+
static shell: JupyterFrontEnd.IShell;
138+
static labShell: ILabShell | null;
129139
}

src/widgets/shell.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) ipylab contributors
22
// Distributed under the terms of the Modified BSD License.
33

4-
import { ILabShell } from '@jupyterlab/application';
4+
import { JupyterFrontEnd, ILabShell } from '@jupyterlab/application';
55

66
import { DOMUtils } from '@jupyterlab/apputils';
77

@@ -42,6 +42,8 @@ export class ShellModel extends WidgetModel {
4242
*/
4343
initialize(attributes: any, options: any): void {
4444
this._shell = ShellModel.shell;
45+
this._labShell = ShellModel.labShell;
46+
4547
super.initialize(attributes, options);
4648
this.on('msg:custom', this._onMessage.bind(this));
4749

@@ -86,12 +88,12 @@ export class ShellModel extends WidgetModel {
8688
title.on('change', updateTitle);
8789
updateTitle();
8890

89-
if (area === 'left' || area === 'right') {
91+
if ((area === 'left' || area === 'right') && this._labShell) {
9092
let handler;
9193
if (area === 'left') {
92-
handler = this._shell['_leftHandler'];
94+
handler = this._labShell['_leftHandler'];
9395
} else {
94-
handler = this._shell['_rightHandler'];
96+
handler = this._labShell['_rightHandler'];
9597
}
9698

9799
// handle tab closed event
@@ -128,11 +130,15 @@ export class ShellModel extends WidgetModel {
128130
break;
129131
}
130132
case 'expandLeft': {
131-
this._shell.expandLeft();
133+
if (this._labShell) {
134+
this._labShell.expandLeft();
135+
}
132136
break;
133137
}
134138
case 'expandRight': {
135-
this._shell.expandRight();
139+
if (this._labShell) {
140+
this._labShell.expandRight();
141+
}
136142
break;
137143
}
138144
default:
@@ -151,7 +157,9 @@ export class ShellModel extends WidgetModel {
151157
static view_module: string = null;
152158
static view_module_version = MODULE_VERSION;
153159

154-
private _shell: ILabShell;
160+
private _shell: JupyterFrontEnd.IShell;
161+
private _labShell: ILabShell;
155162

156-
static shell: ILabShell;
163+
static shell: JupyterFrontEnd.IShell;
164+
static labShell: ILabShell;
157165
}

0 commit comments

Comments
 (0)