本文整理匯總了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))