How to use the traitlets.Unicode function in traitlets

To help you get started, we’ve selected a few traitlets 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 altair-viz / altair / altair / schema / _interface / rangefilter.py View on Github external
from .timeunit import TimeUnit


class RangeFilter(BaseObject):
    """Wrapper for Vega-Lite RangeFilter definition.
    
    Attributes
    ----------
    field: Unicode
        Field to be filtered.
    range: List(Union(CFloat, DateTime))
        Array of inclusive minimum and maximum values for a field value of a data item to be included in the filtered data.
    timeUnit: TimeUnit
        time unit for the field to be filtered.
    """
    field = T.Unicode(allow_none=True, default_value=None, help="""Field to be filtered.""")
    range = T.List(T.Union([T.CFloat(allow_none=True, default_value=None), T.Instance(DateTime, allow_none=True, default_value=None)]), allow_none=True, default_value=None, maxlen=2, minlen=2, help="""Array of inclusive minimum and maximum values for a field value of a data item to be included in the filtered data.""")
    timeUnit = TimeUnit(allow_none=True, default_value=None, help="""time unit for the field to be filtered.""")
    
    def __init__(self, field=None, range=None, timeUnit=None, **kwargs):
        kwds = dict(field=field, range=range, timeUnit=timeUnit)
        kwargs.update({k:v for k, v in kwds.items() if v is not None})
        super(RangeFilter, self).__init__(**kwargs)
github InsightSoftwareConsortium / itkwidgets / itkwidgets / widget_line_profiler.py View on Github external
import ipywidgets as widgets
from .widget_viewer import Viewer
from ipydatawidgets import NDArray, array_serialization, shape_constraints
from traitlets import CBool
import matplotlib.pyplot as plt
import matplotlib
import IPython
import itk
from ._transform_types import to_itk_image


@widgets.register
class LineProfiler(Viewer):
    """LineProfiler widget class."""
    _view_name = Unicode('LineProfilerView').tag(sync=True)
    _model_name = Unicode('LineProfilerModel').tag(sync=True)
    _view_module = Unicode('itkwidgets').tag(sync=True)
    _model_module = Unicode('itkwidgets').tag(sync=True)
    _view_module_version = Unicode('^0.25.0').tag(sync=True)
    _model_module_version = Unicode('^0.25.0').tag(sync=True)
    point1 = NDArray(dtype=np.float64, default_value=np.zeros((3,), dtype=np.float64),
                     help="First point in physical space that defines the line profile")\
        .tag(sync=True, **array_serialization)\
        .valid(shape_constraints(3,))
    point2 = NDArray(dtype=np.float64, default_value=np.ones((3,), dtype=np.float64),
                     help="First point in physical space that defines the line profile")\
        .tag(sync=True, **array_serialization)\
        .valid(shape_constraints(3,))
    _select_initial_points = CBool(
        default_value=False, help="We will select the initial points for the line profile.").tag(sync=True)

    def __init__(self, image, order, **kwargs):
github pbugnion / gmaps / gmaps / maps.py View on Github external
class ConfigurationMixin(HasTraits):
    configuration = Dict(
        traits={'api_key': Unicode(allow_none=True)}).tag(sync=True)

    @default('configuration')
    def _configuration_default(self):
        return _default_configuration


class GMapsWidgetMixin(HasTraits):
    """
    Traitlets that are constant across all of gmaps
    """
    _model_module = Unicode('jupyter-gmaps').tag(sync=True)
    _view_module = Unicode('jupyter-gmaps').tag(sync=True)
    _model_module_version = Unicode(CLIENT_VERSION).tag(sync=True)
    _view_module_version = Unicode(CLIENT_VERSION).tag(sync=True)


class InitialViewport(Union):
    """
    Traitlet defining the initial viewport for a map.
    """
    def __init__(self, **metadata):
        trait_types = [
                Enum(['DATA_BOUNDS']),
                Instance(_ZoomCenter)
        ]
        super(InitialViewport, self).__init__(trait_types, **metadata)

    @staticmethod
github pbugnion / gmaps / gmaps / maps.py View on Github external
def configure(api_key=None):
    """
    Configure access to the GoogleMaps API.

    :param api_key: String denoting the key to use when accessing Google maps,
        or None to not pass an API key.
    """
    configuration = {'api_key': api_key}
    global _default_configuration
    _default_configuration = configuration


class ConfigurationMixin(HasTraits):
    configuration = Dict(
        traits={'api_key': Unicode(allow_none=True)}).tag(sync=True)

    @default('configuration')
    def _configuration_default(self):
        return _default_configuration


class GMapsWidgetMixin(HasTraits):
    """
    Traitlets that are constant across all of gmaps
    """
    _model_module = Unicode('jupyter-gmaps').tag(sync=True)
    _view_module = Unicode('jupyter-gmaps').tag(sync=True)
    _model_module_version = Unicode(CLIENT_VERSION).tag(sync=True)
    _view_module_version = Unicode(CLIENT_VERSION).tag(sync=True)
github jupyter-widgets / ipyleaflet / ipyleaflet / leaflet.py View on Github external
def on_mouseover(self, callback, remove=False):
        self._mouseover_callbacks.register_callback(callback, remove=remove)

    def on_mouseout(self, callback, remove=False):
        self._mouseout_callbacks.register_callback(callback, remove=remove)


class UILayer(Layer):
    _view_name = Unicode('LeafletUILayerView').tag(sync=True)
    _model_name = Unicode('LeafletUILayerModel').tag(sync=True)


class Icon(UILayer):
    _view_name = Unicode('LeafletIconView').tag(sync=True)
    _model_name = Unicode('LeafletIconModel').tag(sync=True)

    icon_url = Unicode('').tag(sync=True, o=True)
    shadow_url = Unicode(None, allow_none=True).tag(sync=True, o=True)
    icon_size = Tuple((10, 10), allow_none=True).tag(sync=True, o=True)
    shadow_size = Tuple((10, 10), allow_none=True).tag(sync=True, o=True)
    icon_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)
    shadow_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)
    popup_anchor = Tuple((0, 0), allow_none=True).tag(sync=True, o=True)


class AwesomeIcon(UILayer):
    _view_name = Unicode('LeafletAwesomeIconView').tag(sync=True)
    _model_name = Unicode('LeafletAwesomeIconModel').tag(sync=True)

    name = Unicode('home').tag(sync=True)
    marker_color = Enum(
github glue-viz / glue-jupyter / glue_jupyter / widgets / subset_select_vuetify.py View on Github external
def subset_to_dict(subset):
    return {
        'label': subset.label,
        'color': subset.style.color
    }


class SubsetSelect(v.VuetifyTemplate, HubListener):
    """
    Widget responsible for selecting which subsets are active, sync state between UI and glue.
    """

    selected = traitlets.List().tag(sync=True)
    available = traitlets.List().tag(sync=True)
    no_selection_text = traitlets.Unicode('No selection (create new)').tag(sync=True)
    multiple = traitlets.Bool(False).tag(sync=True)
    nr_of_full_names = traitlets.Int(2).tag(sync=True)
    show_allow_multiple_subsets = traitlets.Bool(False).tag(sync=True)

    methods = traitlets.Unicode('''{
        toSubsets(indices) {
            return indices.map(i => this.available[i]);
        },
        deselect() {
            this.multiple = false;
            this.selected = [];
        },
        toggleSubset(index) {
            this.selected = this.selected.includes(index)
                ? this.selected.filter(x => x != index)
                : this.selected.concat(index);
github jupyterhub / kubespawner / kubespawner / spawner.py View on Github external
Provide either a string or a list containing the path to the startup script command. Extra arguments,
        other than this path, should be provided via `args`.

        This is usually set if you want to start the single-user server in a different python
        environment (with virtualenv/conda) than JupyterHub itself.

        Some spawners allow shell-style expansion here, allowing you to use environment variables.
        Most, including the default, do not. Consult the documentation for your spawner to verify!

        If set to `None`, Kubernetes will start the `CMD` that is specified in the Docker image being started.
        """
    )

    # FIXME: Don't override 'default_value' ("") or 'allow_none' (False) (Breaking change)
    working_dir = Unicode(
        None,
        allow_none=True,
        config=True,
        help="""
        The working directory where the Notebook server will be started inside the container.
        Defaults to `None` so the working directory will be the one defined in the Dockerfile.

        `{username}` is expanded to the escaped, dns-label safe username.
        """
    )

    # FIXME: Don't override 'default_value' ("") or 'allow_none' (False) (Breaking change)
    service_account = Unicode(
        None,
        allow_none=True,
        config=True,
github jupyter / notebook / notebook / notebookapp.py View on Github external
help='''The base URL for the notebook server.

                               Leading and trailing slashes can be omitted,
                               and will automatically be added.
                               ''')

    @validate('base_url')
    def _update_base_url(self, proposal):
        value = proposal['value']
        if not value.startswith('/'):
            value = '/' + value
        if not value.endswith('/'):
            value = value + '/'
        return value
    
    base_project_url = Unicode('/', config=True, help=_("""DEPRECATED use base_url"""))

    @observe('base_project_url')
    def _update_base_project_url(self, change):
        self.log.warning(_("base_project_url is deprecated, use base_url"))
        self.base_url = change['new']

    extra_static_paths = List(Unicode(), config=True,
        help="""Extra paths to search for serving static files.
        
        This allows adding javascript/css to be available from the notebook server machine,
        or overriding individual files in the IPython"""
    )
    
    @property
    def static_file_path(self):
        """return extra paths + the default location"""
github Autodesk / notebook-molecular-visualization / nbmolviz / base / molviz2d.py View on Github external
from traitlets import Unicode
from .base_widget import MessageWidget
from ..utils import translate_color


class MolViz2D(MessageWidget):
    """
    Draws 2D molecular representations with D3.js
    """
    _view_name = Unicode('MolWidget2DView').tag(sync=True)
    _model_name = Unicode('MolWidget2DModel').tag(sync=True)
    _view_module = Unicode('nbmolviz-js').tag(sync=True)
    _model_module = Unicode('nbmolviz-js').tag(sync=True)

    charge = traitlets.Float().tag(sync=True)
    uuid = traitlets.Unicode().tag(sync=True)
    graph = traitlets.Dict().tag(sync=True)
    clicked_bond_indices = traitlets.Tuple((-1, -1)).tag(sync=True)
    _atom_colors = traitlets.Dict({}).tag(sync=True)
    width = traitlets.Float().tag(sync=True)
    height = traitlets.Float().tag(sync=True)
    selected_atom_indices = traitlets.Set(set()).tag(sync=True)

    def __init__(self, atoms,
                 charge=-150,
                 width=400, height=350,
                 **kwargs):

        kwargs.update(width=width, height=height)
        super(MolViz2D, self).__init__(**kwargs)

        try: