本文整理汇总了Python中ipywidgets.Image方法的典型用法代码示例。如果您正苦于以下问题:Python ipywidgets.Image方法的具体用法?Python ipywidgets.Image怎么用?Python ipywidgets.Image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipywidgets
的用法示例。
在下文中一共展示了ipywidgets.Image方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_trait
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [as 别名]
def _update_trait(self, p_name, p_value, widget=None):
p_obj = self.parameterized.params(p_name)
widget = self._widgets[p_name] if widget is None else widget
if isinstance(p_value, tuple):
p_value, size = p_value
if isinstance(size, tuple) and len(size) == 2:
if isinstance(widget, ipywidgets.Image):
widget.width = size[0]
widget.height = size[1]
else:
widget.layout.min_width = '%dpx' % size[0]
widget.layout.min_height = '%dpx' % size[1]
if isinstance(widget, Output):
if isinstance(p_obj, HTMLView) and p_value:
p_value = HTML(p_value)
with widget:
# clear_output required for JLab support
# in future handle.update(p_value) should be sufficient
handle = self._display_handles.get(p_name)
if handle:
clear_output(wait=True)
handle.display(p_value)
else:
handle = display(p_value, display_id=p_name+self._id)
self._display_handles[p_name] = handle
else:
widget.value = p_value
示例2: create_widget
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [as 别名]
def create_widget(callback_func, init_params, image_filename=None):
"""
Displays ipywidgets for initialization of a QuantumSystem object.
Parameters
----------
callback_func: function
callback_function depends on all the parameters provided as keys (str) in the parameter_dict, and is called upon
changes of values inside the widgets
init_params: {str: value, str: value, ...}
names and values of initialization parameters
image_filename: str, optional
file name for circuit image to be displayed alongside the qubit
Returns
-------
"""
widgets = {}
box_list = []
for name, value in init_params.items():
label = ipywidgets.Label(value=name)
if isinstance(value, float):
enter_widget = ipywidgets.FloatText
else:
enter_widget = ipywidgets.IntText
widgets[name] = enter_widget(value=value, description='', disabled=False)
box_list.append(ipywidgets.HBox([label, widgets[name]], layout=ipywidgets.Layout(justify_content='flex-end')))
if image_filename:
file = open(image_filename, "rb")
image = file.read()
image_widget = ipywidgets.Image(value=image, format='png', layout=ipywidgets.Layout(width='400px'))
ui_widget = ipywidgets.HBox([ipywidgets.VBox(box_list), ipywidgets.VBox([image_widget])])
else:
ui_widget = ipywidgets.VBox(box_list)
out = ipywidgets.interactive_output(callback_func, widgets)
display(ui_widget, out)
示例3: set_line_dash
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [as 别名]
def set_line_dash(self, segments):
"""Set the current line dash pattern."""
if len(segments) % 2:
self._line_dash = segments + segments
else:
self._line_dash = segments
self._send_canvas_command('setLineDash', (self._line_dash, ))
# Image methods
示例4: draw_image
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [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))
示例5: __init__
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [as 别名]
def __init__(self,
fig_format='png',
figsize=None,
dpi=None,
facecolor=None,
edgecolor=None,
frameon=True):
#self.image = widgets.Image(format='svg+xml')
self.image = widgets.Image(format=fig_format)
self.kwds = dict(figsize=figsize,
dpi=dpi,
facecolor=facecolor,
edgecolor=edgecolor,
frameon=frameon,
fig_format=fig_format)
示例6: getImage
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import Image [as 别名]
def getImage(self, compress=True, forceRender=True):
from ipywidgets import Image
slicer.app.processEvents()
if forceRender:
self.renderView.forceRender()
screenshot = self.renderView.grab()
bArray = qt.QByteArray()
buffer = qt.QBuffer(bArray)
buffer.open(qt.QIODevice.WriteOnly)
if compress:
screenshot.save(buffer, "JPG", self.compressionQuality)
else:
screenshot.save(buffer, "PNG")
return Image(value=bArray.data(), width=screenshot.width(), height=screenshot.height())