当前位置: 首页>>代码示例>>Python>>正文


Python ipywidgets.widget_serialization方法代码示例

本文整理汇总了Python中ipywidgets.widget_serialization方法的典型用法代码示例。如果您正苦于以下问题:Python ipywidgets.widget_serialization方法的具体用法?Python ipywidgets.widget_serialization怎么用?Python ipywidgets.widget_serialization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ipywidgets的用法示例。


在下文中一共展示了ipywidgets.widget_serialization方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_value_serializer

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import widget_serialization [as 别名]
def create_value_serializer(name):
    """Create a serializer that support widgets, and anything json accepts while preserving type"""
    def value_to_json(value, widget):
        # first take out all widgets
        value = widgets.widget_serialization['to_json'](value, widget)
        return adapt_value(value)

    def json_to_value(data, widget):
        # first put pack widgets in
        value = widgets.widget_serialization['from_json'](data, widget)
        original = getattr(widget, name)
        if hasattr(original, 'copy'):  # this path will try to preserve the type
            # numpy arrays and dataframs follow this path
            try:
                copy = original.copy()
                copy[:] = value
                value = copy
            except TypeError:
                pass  # give up for instance when we set Widgets into a float array
        return value

    return {
        'to_json': value_to_json,
        'from_json': json_to_value
    } 
开发者ID:QuantStack,项目名称:ipysheet,代码行数:27,代码来源:serializer.py

示例2: texture_to_json

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import widget_serialization [as 别名]
def texture_to_json(texture, widget):
    if isinstance(texture, ipywebrtc.HasStream):
        return ipywidgets.widget_serialization['to_json'](texture, widget)
    else:
        return image_to_url(texture, widget) 
开发者ID:maartenbreddels,项目名称:ipyvolume,代码行数:7,代码来源:serialize.py

示例3: draw_image

# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import widget_serialization [as 别名]
def draw_image(self, image, x=0, y=0, width=None, height=None):
        """Draw an ``image`` on the Canvas at the coordinates (``x``, ``y``) and scale it to (``width``, ``height``)."""
        if (not isinstance(image, (Canvas, Image))):
            raise TypeError('The image argument should be an Image widget or a Canvas widget')

        if width is not None and height is None:
            height = width

        serialized_image = widget_serialization['to_json'](image, None)

        self._send_canvas_command('drawImage', (serialized_image, x, y, width, height)) 
开发者ID:martinRenou,项目名称:ipycanvas,代码行数:13,代码来源:canvas.py


注:本文中的ipywidgets.widget_serialization方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。