本文整理汇总了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
}
示例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)
示例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))