Skip to content

adding _repr_png_ for ipython #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2015
Merged

Conversation

bollwyvl
Copy link
Contributor

Motiviation

When using SolidPython in the IPython Notebook, it would be nice if just typing:

cube([1,1,1])

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.

etjones added a commit that referenced this pull request Aug 12, 2015
adding _repr_png_ for ipython
@etjones etjones merged commit f8dac5f into SolidCode:master Aug 12, 2015
@bollwyvl
Copy link
Contributor Author

Hey great!

We've been doing a lot of thinking about notebook CAD recently. An
interesting first step here would be to create versions of the scad
classes (widgets) with eventful attributes (traitlets) that feed into a
automatically updated display of the current state of the model... This
would let solid tie into all kinds of interesting things, sliders, solvers,
etc. I think it could be done as a second layer of api, so

from solid.widgets import *

I'll take a hack at it when I'm not so slammed, but would be interested in
your thoughts about other directions for integration!

On 20:45, Tue, Aug 11, 2015 Evan Jones [email protected] wrote:

Merged #37 #37.


Reply to this email directly or view it on GitHub
#37 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants