Python ipywidgets.Image() Examples
The following are 6
code examples of ipywidgets.Image().
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: qubit_widget.py From scqubits with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #2
Source File: __init__.py From paramnb with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #3
Source File: canvas.py From ipycanvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #4
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))
Example #5
Source File: plot.py From QuLab with MIT License | 5 votes |
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)
Example #6
Source File: interactive_view_widget.py From SlicerJupyter with MIT License | 5 votes |
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())