How to use the @jupyter-widgets/base.WidgetModel.serializers 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 vidartf / jupyter-vtk-datawidgets / src / widgets / base.ts View on Github external
}
      if (serializer.deserialize === unpack_models) {
        // There's a widget serializer, but it is not a direct ref
        // Should be nested widget then
        this.nestedKeys.push(key);
      } else if (serializer === data_union_serialization || serializer === array_serialization) {
        this.dataWidgetKeys.push(key);
      }
    }
  }

  nestedKeys: string[];
  dataWidgetKeys: string[];

  static serializers: ISerializers = {
    ...WidgetModel.serializers,
  }

}
github mwcraig / ipyevents / src / events.ts View on Github external
// are supposed to be (and are in chrome) but those event properties have
    // red box warnings in the MDN documentation that they are not part of any
    // standard and are not on any standards tracks, so get what we need here.
    var bounding_rect = view.el.getBoundingClientRect();
    var y_offset = bounding_rect.top;
    var x_offset = bounding_rect.left;
    return {
        'x': Math.round(event.clientX - x_offset),
        'y': Math.round(event.clientY - y_offset)
    }
}

export
class EventModel extends WidgetModel {
    static serializers = {
        ...WidgetModel.serializers,
        source: {deserialize: unpack_models}
    }

    defaults() {
        return _.extend(super.defaults(), {
            _model_name: 'EventModel',
            _model_module: 'ipyevents',
            _model_module_version: EXTENSION_SPEC_VERSION,
            source: null,
            watched_events: [],
            ignore_modifier_key_events: false,
            prevent_default_action: false,
            xy_coordinate_system: null,
            xy: [],
            wait: 0,
            throttle_or_debounce: null,
github vidartf / jupyter-vtk-datawidgets / src / widget.ts View on Github external
}


export
class VtkWidget extends WidgetModel {
  defaults() {
    return {...super.defaults(),
      _model_module: VtkWidget.model_module,
      _model_module_version: VtkWidget.model_module_version,
      _view_module: VtkWidget.view_module,
      _view_module_version: VtkWidget.view_module_version,
    };
  }

  static serializers: ISerializers = {
    ...WidgetModel.serializers,
    // Add any extra serializers here
  }

  static model_module = 'jupyter-vtk-datawidgets';
  static model_module_version = JUPYTER_EXTENSION_VERSION;
  static view_module = 'jupyter-vtk-datawidgets';   // Set to null if no view
  static view_module_version = JUPYTER_EXTENSION_VERSION;
}


export
class DataArray extends VtkWidget {
  defaults() {
    return {...super.defaults(),
      _model_name: DataArray.model_name,
      name: null,
github mariobuikhuizen / ipyvuetify / js / src / Themes.js View on Github external
const themeName = this.get('_theme_name');

        this.keys()
            .filter(prop => !prop.startsWith('_'))
            .forEach((prop) => {
                vuetify.framework.theme.themes[themeName][prop] = convertColor(this.get(prop));
                this.on(`change:${prop}`, () => {
                    vuetify.framework.theme.themes[themeName][prop] = convertColor(this.get(prop));
                });
            });
    }
}

ThemeColorsModel.serializers = {
    ...WidgetModel.serializers,
};

function convertColor(colorStr) {
    if (colorStr == null) {
        return null;
    }

    if (colorStr.startsWith('colors')) {
        const parts = colorStr.split('.').slice(1);
        let result = colors;

        parts.forEach(part => {
            result = result[part];
        });

        return result;
github jtpio / ipylab / src / widgets / commands.ts View on Github external
* @param bundle The command bundle.
   */
  private _removeCommand(bundle: { id: string }): void {
    const { id } = bundle;
    if (Private.customCommands.has(id)) {
      Private.customCommands.get(id).dispose();
    }
    const commands = this.get('_commands').slice();
    ArrayExt.removeAllWhere(commands, (w: any) => w.id === id);
    this.set('_commands', commands);
    this.save_changes();
    this._sendCommandList();
  }

  static serializers: ISerializers = {
    ...WidgetModel.serializers,
  };

  static model_name = 'CommandRegistryModel';
  static model_module = MODULE_NAME;
  static model_module_version = MODULE_VERSION;
  static view_name: string = null;
  static view_module: string = null;
  static view_module_version = MODULE_VERSION;

  private _commands: CommandRegistry;

  static commands: CommandRegistry;
}

/**
 * A namespace for private data
github jtpio / ipylab / src / widgets / shell.ts View on Github external
}
      case 'expandLeft': {
        this._shell.expandLeft();
        break;
      }
      case 'expandRight': {
        this._shell.expandRight();
        break;
      }
      default:
        break;
    }
  }

  static serializers: ISerializers = {
    ...WidgetModel.serializers,
  };

  static model_name = 'ShellModel';
  static model_module = MODULE_NAME;
  static model_module_version = MODULE_VERSION;
  static view_name: string = null;
  static view_module: string = null;
  static view_module_version = MODULE_VERSION;

  private _shell: ILabShell;

  static shell: ILabShell;
}
github jtpio / ipylab / src / widgets / sessions.ts View on Github external
private _sendSessions(): void {
    this.set('sessions', toArray(this._sessions.running()));
    this.save_changes();
  }

  /**
   * send current session to backend
   */
  private _sendCurrent(): void {
    this._current_session = this._getSessionContext(this._shell.currentWidget);
    this.set('current_session', this._current_session);
    this.save_changes();
  }

  static serializers: ISerializers = {
    ...WidgetModel.serializers,
  };

  static model_name = 'SessionManagerModel';
  static model_module = MODULE_NAME;
  static model_module_version = MODULE_VERSION;
  static view_name: string = null;
  static view_module: string = null;
  static view_module_version = MODULE_VERSION;

  private _current_session: Session.IModel | {};
  private _sessions: SessionManager;
  static sessions: SessionManager;
  private _shell: ILabShell;
  static shell: ILabShell;
}