def write_format_data(self, format_dict, md_dict=None): # print("WRITING FORMAT DATA:", format_dict) if 0 in format_dict: # have multiple outputs new_format_dict = {} for i in format_dict: new_format_dict[i] = json_clean(encode_images(format_dict[i])) self.msg['content']['data'] = new_format_dict else: self.msg['content']['data'] = json_clean( encode_images(format_dict)) self.msg['content']['metadata'] = md_dict
def publish(self, data, metadata=None, source=None): self._flush_streams() if metadata is None: metadata = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata # Use 2-stage process to send a message, # in order to put it through the transform # hooks before potentially sending. msg = self.session.msg(u'display_data', json_clean(content), parent=self.parent_header) # Each transform either returns a new # message or None. If None is returned, # the message has been 'used' and we return. for hook in self._hooks: msg = hook(msg) if msg is None: return self.session.send(self.pub_socket, msg, ident=self.topic)
def publish(self, data, metadata=None, source=None): self._flush_streams() if metadata is None: metadata = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata # Use 2-stage process to send a message, # in order to put it through the transform # hooks before potentially sending. msg = self.session.msg( u'display_data', json_clean(content), parent=self.parent_header ) # Each transform either returns a new # message or None. If None is returned, # the message has been 'used' and we return. for hook in self.thread_local.hooks: msg = hook(msg) if msg is None: return self.session.send( self.pub_socket, msg, ident=self.topic )
def publish(self, data, metadata=None, source=None): if not isinstance(data, dict): raise TypeError('data must be a dict, got: %r' % data) if metadata is not None and not isinstance(metadata, dict): raise TypeError('metadata must be a dict, got: %r' % data) content = {} content['data'] = encode_images(data) content['metadata'] = metadata print(json.dumps(json_clean(content)))
def publish( self, data, metadata=None, source=None, transient=None, update=False, ): """Publish a display-data message Parameters ---------- data: dict A mime-bundle dict, keyed by mime-type. metadata: dict, optional Metadata associated with the data. transient: dict, optional, keyword-only Transient data that may only be relevant during a live display, such as display_id. Transient data should not be persisted to documents. update: bool, optional, keyword-only If True, send an update_display_data message instead of display_data. """ self._flush_streams() if metadata is None: metadata = {} if transient is None: transient = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata content['transient'] = transient msg_type = 'update_display_data' if update else 'display_data' # Use 2-stage process to send a message, # in order to put it through the transform # hooks before potentially sending. msg = self.session.msg(msg_type, json_clean(content), parent=self.parent_header) # Each transform either returns a new # message or None. If None is returned, # the message has been 'used' and we return. for hook in self._hooks: msg = hook(msg) if msg is None: return self.session.send( self.pub_socket, msg, ident=self.topic, )
def publish(self, data, metadata=None, source=None): self._flush_streams() if metadata is None: metadata = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata self.session.send( self.pub_socket, u'display_data', json_clean(content), parent=self.parent_header, ident=self.topic, )
def matplotlib_post_run(data_list): png_data = None figure = plt.gcf() # Always try to get the current figure. # This is not efficient, but we can support any libraries # that use matplotlib. png_data = print_figure(figure, fmt='png') figure.clear() if png_data is not None: width, height = _pngxy(png_data) data = encode_images({'image/png':png_data}) metadata = {'image/png':dict(width=width, height=height)} data_list.append(json_clean(dict(data=data, metadata=metadata)))
def publish(self, data, metadata=None, source=None, transient=None, update=False, ): """Publish a display-data message Parameters ---------- data: dict A mime-bundle dict, keyed by mime-type. metadata: dict, optional Metadata associated with the data. transient: dict, optional, keyword-only Transient data that may only be relevant during a live display, such as display_id. Transient data should not be persisted to documents. update: bool, optional, keyword-only If True, send an update_display_data message instead of display_data. """ self._flush_streams() if metadata is None: metadata = {} if transient is None: transient = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata content['transient'] = transient msg_type = 'update_display_data' if update else 'display_data' # Use 2-stage process to send a message, # in order to put it through the transform # hooks before potentially sending. msg = self.session.msg( msg_type, json_clean(content), parent=self.parent_header ) # Each transform either returns a new # message or None. If None is returned, # the message has been 'used' and we return. for hook in self._hooks: msg = hook(msg) if msg is None: return self.session.send( self.pub_socket, msg, ident=self.topic, )
def write_format_data(self, format_dict, md_dict=None): self.msg["content"]["data"] = json_clean(encode_images(format_dict)) self.msg["content"]["metadata"] = md_dict
def write_format_data(self, format_dict, md_dict=None): self.msg['content']['data'] = encode_images(format_dict) self.msg['content']['metadata'] = md_dict
def publish( self, data, metadata=None, source=_sentinel, transient=None, update=False, ): """Publish a display-data message Parameters ---------- data : dict A mime-bundle dict, keyed by mime-type. metadata : dict, optional Metadata associated with the data. transient : dict, optional, keyword-only Transient data that may only be relevant during a live display, such as display_id. Transient data should not be persisted to documents. update : bool, optional, keyword-only If True, send an update_display_data message instead of display_data. source : unused Value will have no effect on function behavior. Parameter is still present for backward compatibility but will be removed in the future. .. deprecated:: 4.0.1 `source` has been deprecated and no-op since ipykernel 4.0.1 (2015) """ if source is not _sentinel: warnings.warn( "`source` has been deprecated since ipykernel 4.0.1 " "and will have no effect", DeprecationWarning, stacklevel=2, ) self._flush_streams() if metadata is None: metadata = {} if transient is None: transient = {} self._validate_data(data, metadata) content = {} content['data'] = encode_images(data) content['metadata'] = metadata content['transient'] = transient msg_type = 'update_display_data' if update else 'display_data' # Use 2-stage process to send a message, # in order to put it through the transform # hooks before potentially sending. msg = self.session.msg(msg_type, json_clean(content), parent=self.parent_header) # Each transform either returns a new # message or None. If None is returned, # the message has been 'used' and we return. for hook in self._hooks: msg = hook(msg) if msg is None: return self.session.send( self.pub_socket, msg, ident=self.topic, )
def write_format_data(self, format_dict, md_dict=None): self.msg["content"]["data"] = encode_images(format_dict) self.msg["content"]["metadata"] = md_dict