adding _repr_png_ for ipython #37
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motiviation
When using SolidPython in the IPython Notebook, it would be nice if just typing:
would draw the object. Additionally, it would be nice to have these images persist through to nbviewer.
Integration
This follows the approach from the IPython documentation to add a custom PNG renderer to
OpenSCADObject
, which everything the user sees appears to inherit from... thanks for that!Implementation
The
_repr_png_
basically shells out to openscad to generate a PNG, using two temporary files, then pushes the raw binary out. The notebook then stores this as base64 encoded data. It would be lovely to do some compression up front, but that would introduce icky dependencies...Demo
Here is an example notebook:
http://nbviewer.ipython.org/gist/bollwyvl/dc849c324ba80bdce771
Future Work
When a suitable browser-based, repackageable STL renderer has been discovered, an
_repr_html_
could be added/replace the png one. There would be the question of CDN vs. inlining.Open questions
How would you like to handle configuration? The manpage for openscad has a number of lovely options, like colorscheme, image size and camera stuff... but not axes 😞. solid.openscad_params? I guess the "gold bricks" color scheme is fine for now.