How to use the @jupyter-widgets/base.ManagerBase function in @jupyter-widgets/base

To help you get started, we’ve selected a few @jupyter-widgets/base examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / deck.gl / test / modules / jupyter-widget / utils.spec.js View on Github external
close() {
    if (this._on_close) {
      this._on_close();
    }
    return 'dummy';
  }
  send() {
    return 'dummy';
  }

  open() {
    return 'dummy';
  }
}

export class DummyManager extends widgets.ManagerBase {
  constructor() {
    super();
    this.el = window.document.createElement('div');
  }

  display_view(msg, view, options) {
    // TODO: make this a spy
    // TODO: return an html element
    return Promise.resolve(view).then(v => {
      this.el.appendChild(v.el);
      v.on('remove', () => console.log('view removed', v)); //eslint-disable-line
      return v.el;
    });
  }

  loadClass(className, moduleName, moduleVersion) {
github jupyter-widgets / jupyterlab-sidecar / tests / src / utils.spec.ts View on Github external
return 'dummy';
    }
    send(): string {
        return 'dummy';
    }

    open(): string {
        return 'dummy';
    }
    comm_id: string;
    _on_msg: Function | null = null;
    _on_close: Function | null = null;
}

export
class DummyManager extends widgets.ManagerBase {
    constructor() {
        super();
        this.el = window.document.createElement('div');
    }

    display_view(msg: services.KernelMessage.IMessage, view: Backbone.View, options: any) {
        // TODO: make this a spy
        // TODO: return an html element
        return Promise.resolve(view).then(view => {
            this.el.appendChild(view.el);
            view.on('remove', () => console.log('view removed', view));
            return view.el;
        });
    }

    protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise {
github vidartf / jupyter-vtk-datawidgets / tests / src / utils.spec.ts View on Github external
return 'dummy';
    }
    send(): string {
        return 'dummy';
    }

    open(): string {
        return 'dummy';
    }
    comm_id: string;
    _on_msg: Function | null = null;
    _on_close: Function | null = null;
}

export
class DummyManager extends widgets.ManagerBase {
    constructor() {
        super();
        this.el = window.document.createElement('div');
    }

    display_view(msg: services.KernelMessage.IMessage, view: Backbone.View, options: any) {
        // TODO: make this a spy
        // TODO: return an html element
        return Promise.resolve(view).then(view => {
            this.el.appendChild(view.el);
            view.on('remove', () => console.log('view removed', view));
            return view.el;
        });
    }

    protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise {
github jupyter-widgets / ipywidgets / examples / web1 / manager.js View on Github external
var widgets = require('@jupyter-widgets/base');
var PhosphorWidget = require('@phosphor/widgets').Widget;
var ManagerBase = widgets.ManagerBase;

var WidgetManager = exports.WidgetManager = function(el) {
    //  Call the base class.
    ManagerBase.call(this);
    this.el = el;
};
WidgetManager.prototype = Object.create(ManagerBase.prototype);

WidgetManager.prototype.display_view = function(msg, view, options) {
    var that = this;
    return Promise.resolve(view).then(function(view) {
        PhosphorWidget.attach(view.pWidget, that.el);
        view.on('remove', function() {
            console.log('View removed', view);
        });
        return view;
github jupyter-widgets / ipywidgets / widgetsnbextension / src / manager.js View on Github external
// Checks whether new_comm needs a polyfill, and calls the correct version
    // Polyfill needed for notebook <5.1, in which the new_comm method does not support a buffers argument.
    // See https://github.com/jupyter-widgets/ipywidgets/pull/1817
    var need_polyfill = manager.new_comm.length < 6;
    if (need_polyfill) {
        return polyfill_new_comm_buffers.apply(null, arguments);
    }
    return manager.new_comm.apply(manager, Array.prototype.slice.call(arguments, 1));
}

//--------------------------------------------------------------------
// WidgetManager class
//--------------------------------------------------------------------


export class WidgetManager extends base.ManagerBase {
    constructor(comm_manager, notebook) {
        super();
        // Managers are stored in *reverse* order, so that _managers[0] is the most recent.
        WidgetManager._managers.unshift(this);

        // Attach a comm manager
        this.notebook = notebook;
        this.keyboard_manager = notebook.keyboard_manager;
        this.comm_manager = comm_manager;

        var widget_md = notebook.metadata.widgets

        // Steps that needs to be done:
        // 1. Register comm target
        // 2. Get any widget state from the kernel and open comms with existing state
        // 3. Check saved state for widgets, and restore any that would not overwrite
github jupyter-widgets / ipywidgets / packages / html-manager / src / htmlmanager.ts View on Github external
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import * as widgets from '@jupyter-widgets/controls';
import * as base from '@jupyter-widgets/base';
import * as outputWidgets from './output';

import * as PhosphorWidget from '@phosphor/widgets';
import { RenderMimeRegistry, standardRendererFactories } from '@jupyterlab/rendermime';

import { WidgetRenderer, WIDGET_MIMETYPE } from './output_renderers';

export
class HTMLManager extends base.ManagerBase {

    constructor(options?: {loader?: (moduleName: string, moduleVersion: string) => Promise}) {
        super();
        this.loader = options && options.loader;
        this.renderMime = new RenderMimeRegistry({
            initialFactories: standardRendererFactories
        });
        this.renderMime.addFactory({
            safe: false,
            mimeTypes: [WIDGET_MIMETYPE],
             createRenderer: (options) => new WidgetRenderer(options, this)
        }, 0);
    }
    /**
     * Display the specified view. Element where the view is displayed
     * is specified in the `options.el` argument.
github jupyter-widgets / ipywidgets / examples / web2 / manager.js View on Github external
var base = require('@jupyter-widgets/base');
var controls = require('@jupyter-widgets/controls');
var PhosphorWidget = require('@phosphor/widgets').Widget;

class WidgetManager extends base.ManagerBase {
    constructor(el) {
        super();
        this.el = el;
    }

    loadClass(className, moduleName, moduleVersion) {
        return new Promise(function(resolve, reject) {
            if (moduleName === '@jupyter-widgets/controls') {
                resolve(controls);
            } else if (moduleName === '@jupyter-widgets/base') {
                resolve(base)
            } else {
                var fallback = function(err) {
                    let failedId = err.requireModules && err.requireModules[0];
                    if (failedId) {
                        console.log(`Falling back to unpkg.com for ${moduleName}@${moduleVersion}`);
github jupyter-widgets / ipywidgets / examples / web-tmpnb / src / manager.ts View on Github external
} from '@jupyterlab/services';

import '@jupyter-widgets/controls/css/widgets.css';
import { DOMWidgetView } from '@jupyter-widgets/base';

let requirePromise = function(module: string): Promise {
    return new Promise((resolve, reject) => {
        if ((window as any).require === void 0) {
            reject('requirejs not loaded');
        }
        (window as any).require([module], resolve, reject);
    });
};

export
class WidgetManager extends base.ManagerBase {
    constructor(kernel: Kernel.IKernelConnection, el: HTMLElement) {
        super();
        this.kernel = kernel;
        this.el = el;

        kernel.registerCommTarget(this.comm_target_name, async (comm, msg) => {
            let oldComm = new base.shims.services.Comm(comm);
            await this.handle_comm_open(oldComm, msg);
        });
    }

    display_view(msg: any, view: DOMWidgetView, options: any) {
        return Promise.resolve(view).then((view) => {
            pWidget.Widget.attach(view.pWidget, this.el);
            view.on('remove', function() {
                console.log('view removed', view);
github nteract / nteract / packages / jupyter-widgets / src / manager / manager.ts View on Github external
interface IDomWidgetModel extends DOMWidgetModel {
  _model_name: string;
  _model_module: string;
  _module_version: string;
  _view_name: string;
  _view_module: string;
  _view_module_version: string;
}

/**
 * The WidgetManager extends the ManagerBase class and is required
 * by the ipywidgets implementation for rendering all models. This
 * WidgetManager contains some overrides to get it to play nice
 * with our RxJS-based kernel communication.
 */
export class WidgetManager extends base.ManagerBase {
  el: HTMLElement;

  constructor(el: HTMLElement) {
    super();
    this.el = el;
  }

  /**
   * Given a class name and module reference, this method will
   * attempt to resolve a reference to that module if it is found.
   * For non-supported widget models, this method will through
   * an error.
   *
   * @param className     The name of the WidgetView to load
   * @param moduleName    The module to load the widget from
   * @param moduleVersion The module version to laod from
github jupyter-widgets / ipywidgets / widgetsnbextension / src / manager.js View on Github external
callbacks(view) {
        var callbacks = base.ManagerBase.prototype.callbacks.call(this, view);
        if (view && view.options.iopub_callbacks) {
            callbacks.iopub = view.options.iopub_callbacks
        }
        return callbacks;
    };
}