From f9957b5f86f4a372dec2f4c37666e33995e149dc Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 7 Nov 2016 21:44:31 -0800 Subject: [PATCH] support transient field, update_display_data --- ipykernel/zmqshell.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 9d59e9996..b4cc25e52 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -91,20 +91,42 @@ def _hooks(self): self._thread_local.hooks = [] return self._thread_local.hooks - def publish(self, data, metadata=None, source=None): + 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( - u'display_data', json_clean(content), + msg_type, json_clean(content), parent=self.parent_header ) @@ -117,10 +139,20 @@ def publish(self, data, metadata=None, source=None): return self.session.send( - self.pub_socket, msg, ident=self.topic + self.pub_socket, msg, ident=self.topic, ) def clear_output(self, wait=False): + """Clear output associated with the current execution (cell). + + Parameters + ---------- + wait: bool (default: False) + If True, the output will not be cleared immediately, + instead waiting for the next display before clearing. + This reduces bounce during repeated clear & display loops. + + """ content = dict(wait=wait) self._flush_streams() self.session.send(