Skip to content

Commit

Permalink
Merge pull request #32 from pbugnion/fix-accordion-widget
Browse files Browse the repository at this point in the history
Fix accordion widget
  • Loading branch information
pbugnion authored Apr 8, 2018
2 parents 1fa0816 + a3d1156 commit 0391603
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ipywidgets_server/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '0.2.1'
__version__ = '0.2.2-alpha2'
4 changes: 2 additions & 2 deletions js/ErrorView.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

import { OutputAreaModel, OutputArea } from '@jupyterlab/outputarea';
import { renderMime } from './renderMime'
import { createSimpleRenderMimeRegistry } from './renderMime'

// Output view for errors in callbacks
export class ErrorView {
constructor(element) {
this._element = element
this._outputModel = new OutputAreaModel({trusted: true})
this._outputView = new OutputArea({
rendermime: renderMime,
rendermime: createSimpleRenderMimeRegistry(),
model: this._outputModel,
})
this._element.appendChild(this._outputView.node)
Expand Down
3 changes: 2 additions & 1 deletion js/WidgetApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WidgetManager } from './manager'
import { ErrorView } from './ErrorView'

import 'font-awesome/css/font-awesome.css'
import '@phosphor/widgets/style/index.css'
import './widgets.css'


Expand Down Expand Up @@ -69,4 +70,4 @@ export class WidgetApplication {
// terminate kernel process
this._kernel.shutdown()
}
}
}
7 changes: 5 additions & 2 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Signal } from '@phosphor/signaling';
import { HTMLManager } from '@jupyter-widgets/html-manager';

import * as outputWidgets from './output';
import { ShimmedComm } from './services-shim'
import { ShimmedComm } from './services-shim';
import { createRenderMimeRegistryWithWidgets } from './renderMime';

export class WidgetManager extends HTMLManager {
constructor(kernel, el, loader) {
Expand All @@ -16,6 +17,7 @@ export class WidgetManager extends HTMLManager {
this.registerWithKernel(kernel)
this.el = el;
this.loader = loader;
this.renderMime = createRenderMimeRegistryWithWidgets(this);
this._onError = new Signal(this)
}

Expand All @@ -35,8 +37,9 @@ export class WidgetManager extends HTMLManager {
}

display_view(msg, view, options) {
const el = options.el || this.el;
return Promise.resolve(view).then(view => {
pWidget.Widget.attach(view.pWidget, this.el);
pWidget.Widget.attach(view.pWidget, el);
view.on('remove', function() {
console.log('view removed', view);
});
Expand Down
7 changes: 2 additions & 5 deletions js/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { Panel } from '@phosphor/widgets';

import { OutputAreaModel, OutputArea } from '@jupyterlab/outputarea';

import { renderMime } from './renderMime'

const OUTPUT_WIDGET_VERSION = outputBase.OUTPUT_WIDGET_VERSION;

export
Expand Down Expand Up @@ -114,7 +112,7 @@ class JupyterPhosphorPanelWidget extends Panel {
export class OutputView extends outputBase.OutputView {

_createElement(tagName) {
this.pWidget = new JupyterPhosphorPanelWidget({ view: this });
this.pWidget = new Panel()
return this.pWidget.node;
}

Expand All @@ -133,12 +131,11 @@ export class OutputView extends outputBase.OutputView {
render() {
super.render();
this._outputView = new OutputArea({
rendermime: renderMime,
rendermime: this.model.widget_manager.renderMime,
contentFactory: OutputArea.defaultContentFactory,
model: this.model.outputs
});
this.pWidget.insertWidget(0, this._outputView);

this.pWidget.addClass('jupyter-widgets');
this.pWidget.addClass('widget-output');
this.update(); // Set defaults.
Expand Down
12 changes: 6 additions & 6 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "",
"main": "index.js",
"dependencies": {
"@jupyter-widgets/base": "^1.1.4",
"@jupyter-widgets/controls": "^1.0.10",
"@jupyter-widgets/html-manager": "^0.10.2",
"@jupyter-widgets/output": "^1.0.9",
"@jupyterlab/outputarea": "^0.10.0",
"@jupyterlab/rendermime": "^0.10.0",
"@jupyter-widgets/base": "^1.1.8",
"@jupyter-widgets/controls": "^1.1.6",
"@jupyter-widgets/html-manager": "^0.12.0",
"@jupyter-widgets/output": "^1.0.15",
"@jupyterlab/outputarea": "^0.15.0",
"@jupyterlab/rendermime": "^0.15.0",
"@jupyterlab/services": "^0.49.0",
"@phosphor/signaling": "^1.2.2",
"@phosphor/widgets": "^1.5.0",
Expand Down
25 changes: 21 additions & 4 deletions js/renderMime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@

import { RenderMime, defaultRendererFactories } from '@jupyterlab/rendermime';
import { RenderMimeRegistry, standardRendererFactories } from '@jupyterlab/rendermime';

export const renderMime = new RenderMime({
initialFactories: defaultRendererFactories
});
import { WIDGET_MIMETYPE, WidgetRenderer } from '@jupyter-widgets/html-manager/lib/output_renderers';

export function createSimpleRenderMimeRegistry() {
const renderMime = new RenderMimeRegistry({
initialFactories: standardRendererFactories
});
return renderMime
}

export function createRenderMimeRegistryWithWidgets(manager) {
const renderMime = createSimpleRenderMimeRegistry()

renderMime.addFactory({
safe: false,
mimeTypes: [WIDGET_MIMETYPE],
createRenderer: options => new WidgetRenderer(options, manager)
}, 1)

return renderMime;
}
2 changes: 1 addition & 1 deletion js/widgets.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import "@jupyter-widgets/controls/css/widgets.css";
@import "@jupyter-widgets/controls/css/widgets.built.css";

0 comments on commit 0391603

Please sign in to comment.