widget_image.py
35 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
|
r16378 | """ImageWidget class. | ||
|
r14449 | |||
|
r16378 | Represents an image in the frontend using a widget. | ||
|
r14449 | """ | ||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
import base64 | ||||
|
r14540 | from .widget import DOMWidget | ||
|
r14669 | from IPython.utils.traitlets import Unicode, CUnicode, Bytes | ||
|
r14449 | |||
#----------------------------------------------------------------------------- | ||||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
|
r14540 | class ImageWidget(DOMWidget): | ||
|
r14701 | _view_name = Unicode('ImageView', sync=True) | ||
|
r14449 | |||
# Define the custom state properties to sync with the front-end | ||||
|
r14588 | format = Unicode('png', sync=True) | ||
|
r14669 | width = CUnicode(sync=True) | ||
height = CUnicode(sync=True) | ||||
|
r14588 | _b64value = Unicode(sync=True) | ||
|
r14449 | |||
value = Bytes() | ||||
def _value_changed(self, name, old, new): | ||||
|
r16378 | self._b64value = base64.b64encode(new) | ||