Python ipywidgets.widget_serialization() Examples
The following are 3
code examples of ipywidgets.widget_serialization().
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: serializer.py From ipysheet with MIT License | 6 votes |
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 }
Example #2
Source File: serialize.py From ipyvolume with MIT License | 5 votes |
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)
Example #3
Source File: canvas.py From ipycanvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))