Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
erp5
Commits
1837719b
Commit
1837719b
authored
Nov 03, 2015
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_data_notebook bt5: Image visualization for objects from Image module in erp5
parent
8607a0ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
19 deletions
+40
-19
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
...teItem/portal_components/extension.erp5.JupyterCompile.py
+36
-16
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml
...eItem/portal_components/extension.erp5.JupyterCompile.xml
+4
-3
No files found.
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
View file @
1837719b
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
StringIO
import
StringIO
from
c
StringIO
import
StringIO
from
Products.ERP5Type.Globals
import
PersistentMapping
from
Products.ERP5Type.Globals
import
PersistentMapping
from
OFS.Image
import
Image
as
OFSImage
import
sys
import
sys
import
ast
import
ast
...
@@ -43,6 +44,12 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict):
...
@@ -43,6 +44,12 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict):
out2 = '12'
out2 = '12'
"""
"""
# Updating global variable mime_type to its original value
# Required when call to Base_displayMatplotlibImage is made which is changing
# the value of gloabl mime_type
global
mime_type
mime_type
=
'text/plain'
# Other way would be to use all the globals variables instead of just an empty
# Other way would be to use all the globals variables instead of just an empty
# dictionary, but that might hamper the speed of exec or eval.
# dictionary, but that might hamper the speed of exec or eval.
# Something like -- g = globals(); g['context'] = self;
# Something like -- g = globals(); g['context'] = self;
...
@@ -178,14 +185,15 @@ def UpdateLocalVariableDict(self, existing_dict):
...
@@ -178,14 +185,15 @@ def UpdateLocalVariableDict(self, existing_dict):
new_dict
[
'imports'
][
key
]
=
val
new_dict
[
'imports'
][
key
]
=
val
return
new_dict
return
new_dict
def
Base_displayMatplotlibImage
(
self
,
plot
_object
=
None
):
def
Base_displayMatplotlibImage
(
self
,
image
_object
=
None
):
"""
"""
External function to display Matplotlib Plot objects to jupyter function.
External function to display Matplotlib Plot objects to jupyter function.
Parameters
Parameters
----------
----------
plot_object : Any matplotlib object from which we can create a plot.
image_object :Any image object from ERP5
Any matplotlib object from which we can create a plot.
Can be <matplotlib.lines.Line2D>, <matplotlib.text.Text>, etc.
Can be <matplotlib.lines.Line2D>, <matplotlib.text.Text>, etc.
Output
Output
...
@@ -194,20 +202,32 @@ def Base_displayMatplotlibImage(self, plot_object=None):
...
@@ -194,20 +202,32 @@ def Base_displayMatplotlibImage(self, plot_object=None):
Returns base64 encoded string of the plot on which it has been called.
Returns base64 encoded string of the plot on which it has been called.
"""
"""
if
plot_object
:
if
image_object
:
from
io
import
BytesIO
import
base64
# Create a ByteFile on the server which would be used to save the plot
import
base64
figfile
=
BytesIO
()
# Save plot as 'png' format in the ByteFile
plot_object
.
savefig
(
figfile
,
format
=
'png'
)
figfile
.
seek
(
0
)
# Encode the value in figfile to base64 string so as to serve it jupyter frontend
figdata_png
=
base64
.
b64encode
(
figfile
.
getvalue
())
# Chanage global variable 'mime_type' to 'image/png'
# Chanage global variable 'mime_type' to 'image/png'
global
mime_type
global
mime_type
mime_type
=
'image/png'
return
figdata_png
# Image object in ERP5 is instance of OFS.Image object
if
isinstance
(
image_object
,
OFSImage
):
\ No newline at end of file
figdata
=
base64
.
b64encode
(
image_object
.
getData
())
mime_type
=
image_object
.
getContentType
()
else
:
# For matplotlib objects
# XXX: Needs refactoring to handle cases
# Create a ByteFile on the server which would be used to save the plot
figfile
=
StringIO
()
# Save plot as 'png' format in the ByteFile
image_object
.
savefig
(
figfile
,
format
=
'png'
)
figfile
.
seek
(
0
)
# Encode the value in figfile to base64 string so as to serve it jupyter frontend
figdata
=
base64
.
b64encode
(
figfile
.
getvalue
())
mime_type
=
'image/png'
# 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
# instead of returned string from this function as after exec, we are getting
# value from stdout and using return we would get that value as string inside
# an string which is unfavourable.
print
figdata
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.xml
View file @
1837719b
...
@@ -46,9 +46,10 @@
...
@@ -46,9 +46,10 @@
<key>
<string>
text_content_warning_message
</string>
</key>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<value>
<tuple>
<tuple>
<string>
W: 75, 6: Use of exec (exec-used)
</string>
<string>
W: 50, 2: Using the global statement (global-statement)
</string>
<string>
W:104, 6: Use of exec (exec-used)
</string>
<string>
W: 82, 6: Use of exec (exec-used)
</string>
<string>
W:110, 6: Use of exec (exec-used)
</string>
<string>
W:111, 6: Use of exec (exec-used)
</string>
<string>
W:117, 6: Use of exec (exec-used)
</string>
<string>
W:209, 4: Using the global statement (global-statement)
</string>
<string>
W:209, 4: Using the global statement (global-statement)
</string>
</tuple>
</tuple>
</value>
</value>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment