From fdba32726b77f93d2a42c75acbed3efa2a25d136 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari <ayush.tiwari@nexedi.com> Date: Wed, 4 Nov 2015 19:39:33 +0100 Subject: [PATCH] erp5_data_notebook bt5: Close plot object and after every call to Base_dispalyImage with matplotlib object --- .../portal_components/extension.erp5.JupyterCompile.py | 9 +++++++-- .../portal_components/extension.erp5.JupyterCompile.xml | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py index fc548c4a51..fd8d4ba465 100644 --- a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py +++ b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py @@ -190,8 +190,11 @@ def Base_displayImage(self, image_object=None): """ External function to display Image objects to jupyter frontend. - XXX: This function is intented to be called from Base_executeJupyter - or Jupyter frontend.That's why printing string and returning None + XXX: This function is intented to be called from Base_executeJupyter + or Jupyter frontend.That's why printing string and returning None. + Also, it clears the plot for Matplotlib object after every call, so + in case of saving the plot, its essential to call Base_savePlot before + calling Base_displayImage. Parameters ---------- @@ -228,6 +231,8 @@ def Base_displayImage(self, image_object=None): # Encode the value in figfile to base64 string so as to serve it jupyter frontend figdata = base64.b64encode(figfile.getvalue()) mime_type = 'image/png' + # Clear the plot figures after every execution + image_object.close() # XXX: We are not returning anything because we want this function to be called # by Base_executeJupyter , inside exec(), and its better to get the printed string diff --git a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml index ecc961fb03..9edc41d083 100644 --- a/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml +++ b/bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml @@ -50,7 +50,7 @@ <string>W: 91, 8: Use of exec (exec-used)</string> <string>W:115, 8: Use of exec (exec-used)</string> <string>W:121, 8: Use of exec (exec-used)</string> - <string>W:213, 4: Using the global statement (global-statement)</string> + <string>W:216, 4: Using the global statement (global-statement)</string> </tuple> </value> </item> -- 2.30.9