當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。