From a3b15ec444bf171ed78a5ca86431becd59c84076 Mon Sep 17 00:00:00 2001 From: Szymon Jakubczak Date: Thu, 18 Feb 2016 10:40:29 -0800 Subject: [PATCH] update python module to match new command format --- python/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index 31c1880..f78a438 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -29,6 +29,12 @@ def send(**command): return False +def pane(panetype, win, title, content): + win = win or uid() + send(command='pane', type=panetype, id=win, title=title, content=content) + return win + + def normalize(img, opts): minval = opts.get('min') if minval is None: @@ -51,7 +57,6 @@ def to_rgb(img): def image(img, **opts): assert img.ndim == 2 or img.ndim == 3 - win = opts.get('win') or uid() if isinstance(img, list): return images(img, opts) @@ -61,10 +66,11 @@ def image(img, **opts): pngbytes = png.encode(img.tostring(), img.shape[1], img.shape[0]) imgdata = 'data:image/png;base64,' + base64.b64encode(pngbytes).decode('ascii') - send(command='image', id=win, src=imgdata, - labels=opts.get('labels'), - width=opts.get('width'), - title=opts.get('title')) + return pane('image', opts.get('win'), opts.get('title'), content={ + 'src': imgdata, + 'labels': opts.get('labels'), + 'width': opts.get('width'), + }) return win @@ -81,8 +87,6 @@ def plot(data, **opts): labels: list of series names, first series is always the X-axis see http://dygraphs.com/options.html for other supported options """ - win = opts.get('win') or uid() - dataset = {} if type(data).__module__ == numpy.__name__: dataset = data.tolist() @@ -98,6 +102,5 @@ def plot(data, **opts): # Don't pass our options to dygraphs. options.pop('win', None) - send(command='plot', id=win, title=opts.get('title'), options=options) - return win + return pane('plot', opts.get('win'), opts.get('title'), content=options)