Python ipywidgets.Widget() Examples

The following are 3 code examples of ipywidgets.Widget(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ipywidgets , or try the search function .
Example #1
Source File: ros_widgets.py    From jupyter-ros with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def widget_dict_to_msg(msg_instance, d):
    for key in d:
        if isinstance(d[key], widgets.Widget):
            if key == 'img':
                img_msg = img_to_msg(d[key].value)
                for slot in img_msg.__slots__:
                    setattr(msg_instance, slot, getattr(img_msg, slot))
                return
            else:
                setattr(msg_instance, key, d[key].value)
        else:
            submsg = getattr(msg_instance, key)
            widget_dict_to_msg(submsg, d[key]) 
Example #2
Source File: easy.py    From ipysheet with MIT License 5 votes vote down vote up
def _assign(object, value):
    if isinstance(object, widgets.Widget):
        object, trait = object, 'value'
    else:
        object, trait = object
    setattr(object, trait, value) 
Example #3
Source File: easy.py    From ipysheet with MIT License 4 votes vote down vote up
def cell(row, column, value=0., type=None, color=None, background_color=None,
         font_style=None, font_weight=None, style=None, label_left=None, choice=None,
         read_only=False, numeric_format='0.000', date_format='YYYY/MM/DD', renderer=None, **kwargs):
    """Adds a new ``Cell`` widget to the current ``Sheet``

    Args:
        row (int): Zero based row index where to put the cell in the sheet
        column (int): Zero based column index where to put the cell in the sheet
        value (int, float, string, bool, Widget): The value of the cell
        {args}

    Returns:
        The new ``Cell`` widget.

    Example:
        >>> from ipysheet import sheet, cell
        >>>
        >>> s1 = sheet()
        >>> cell(0, 0, 36.)            # The Cell type will be 'numeric'
        >>> cell(1, 0, True)           # The Cell type will be 'checkbox'
        >>> cell(0, 1, 'Hello World!') # The Cell type will be 'text'
        >>> c = cell(1, 1, True)
        >>> c.value = False            # Dynamically changing the cell value at row=1, column=1
    """
    global _cells
    if type is None:
        if isinstance(value, bool):
            type = 'checkbox'
        elif isinstance(value, numbers.Number):
            type = 'numeric'
        elif isinstance(value, widgets.Widget):
            type = 'widget'
        else:
            type = 'text'
        if choice is not None:
            type = 'dropdown'

    style = style or {}
    if color is not None:
        style['color'] = color
    if background_color is not None:
        style['backgroundColor'] = background_color
    if font_style is not None:
        style['fontStyle'] = font_style
    if font_weight is not None:
        style['fontWeight'] = font_weight
    c = Cell(value=value, row_start=row, column_start=column, row_end=row, column_end=column,
             squeeze_row=True, squeeze_column=True, type=type, style=style, choice=choice,
             read_only=read_only, numeric_format=numeric_format, date_format=date_format,
             renderer=renderer, **kwargs)
    if _hold_cells:
        _cells += (c,)
    else:
        _last_sheet.cells = _last_sheet.cells+(c,)
    if label_left:
        if column-1 < 0:
            raise IndexError("cannot put label to the left of column 0")
        cell(row, column-1, value=label_left, font_weight='bold')
    return c