AaronWatters / jp_proxy_widget

Generic Jupyter/IPython widget implementation that will support many types of javascript libraries and interactions.
BSD 2-Clause "Simplified" License
61 stars 13 forks source link

Canvas download as png utility function #9

Open psychemedia opened 4 years ago

psychemedia commented 4 years ago

I notice that in your dual_canvas demo you have a utility function for generating a png from a canvas, with an example usage here invoked from a button click here.

Generating images from a canvas in the widget could be quite a common requirement, so would it make sense to for jp_proxy_widget, or a plugin to it, to offer a utility function supporting that natively?

I also have a use case where I am overlaying several canvases and want to grab a single image from those. The recipe here suggests one way of doing that; this suggests in turn an additional helper utility to make it easier grabbing a png from one or more canvases by way of a function that combines multiple canvases on one, and then saves the one as a png.

AaronWatters commented 4 years ago

Thanks. Yes I agree about the canvas capture. I intend to add this unless you implement it in a pull request first :). There are a number of other minor performance fixes that need to be pushed to pip too, so this would be another motivation for a new release.

I'm not sure about combining multiple canvases -- it might be hard to figure out which canvas is on top of which. It might make more sense to let the user implement the "combine" logic externally on a case by case basis.

psychemedia commented 4 years ago

Re: the multiple canvases, this could also be complicated by how to arrange the canvases; eg size by side, all on top of each other if they are the same size, or relative to a fixed registration point ((0, 0), dead centre etc). My initial case is canvases all the same size, so an ordered list works fine. But the more general cases maybe been an anchor point and a scale value.

Re: new release: I notice there have been some commits to the repo lately (exciting:-); are there release notes anywhere? Any breaking changes to be wary of?

Re: a PR - I am iterating my widget/simulator with teaching materials atm, trying to get sim functionality that works for what I need teaching to do, and v.v.. The png save is on my "should have for assessment purposes" list but that's still a bit down my to do list (first student use isn't till October with late November assessment, although I'm already late on my handovers!) If I get anything half working in next few weeks, I'll post a note... Or I'll try to look at it properly when the teaching material is done... which is taking forevvvvveeerrrrr:-(