biggles icon indicating copy to clipboard operation
biggles copied to clipboard

Allow containers to be used as context managers

Open beckermr opened this issue 8 years ago • 7 comments
trafficstars

beckermr avatar Mar 08 '17 14:03 beckermr

I don't know what this means, I'm glad you do

esheldon avatar Mar 08 '17 14:03 esheldon

Ohhhh. Just this

with biggles.FramedPlot() as p:
    biggles.Point(1, 2)

This would add the point to the container p automatically.

beckermr avatar Mar 08 '17 14:03 beckermr

I see, interesting idea.

Here is how to get the formatting:

with biggles.FramedPlot() as p:
    biggles.Point(1, 2)

esheldon avatar Mar 08 '17 15:03 esheldon

We would need objects to be able to set all their properties on construction. for example Points and other components for some reason cannot set their label on construction, but we would want that so that the PlotKey can do its thing when an object is added (needs to have label before adding).

key=PlotKey(0.1,0.9,halign='left')
with FramedPlot(key=key) as plt:
    Points(x, y, label='data')
    Curve(x, yfit, label='model')

The add is implied here. What about writing images or showing when the context is exited?

esheldon avatar Mar 29 '17 12:03 esheldon

I think we don't automatically show or write files on exit of the manager.

Objects should prob be able to set all properties on construction anyways.

beckermr avatar Mar 29 '17 12:03 beckermr

When the context exits, you are left with the plot container p and can do what you want with it.

beckermr avatar Mar 29 '17 12:03 beckermr

I see, I was assuming this would be like a file that gets closed, but leaving the plot usable makes more sense in this case.

esheldon avatar Mar 29 '17 12:03 esheldon