2008-11-05 02:19:44 |
Luiz Fernando Barbosa Vital |
description |
I was trying to get data generated from Plot classes to a StringIO object instead of a file, so I passed a Cairo surface instance to the Plot class for later access to the surface methods wanted.
{{{
data = [3,1,10,2]
width, height = 300, 300
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
CairoPlot.bar_plot(surface, data, width, height, border = 20, grid = True, rounded_corners = True)
resp = StringIO()
surface.write_to_png(resp)
}}}
That raised 2 errors:
* one complaining about endswith called with None (the value of self.filename in the class)
* and the other of calling write_to_png on a finished surface.
I'm attaching a quick and dirty fix for this.
Probably a better approach to solve this problem is to accept file-like objects as argument as well strings and surface instances. |
I was trying to get data generated from Plot classes to a StringIO object instead of a file, so I passed a Cairo surface instance to the Plot class for later access to the surface methods wanted.
{{{
data = [3,1,10,2]
width, height = 300, 300
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
CairoPlot.bar_plot(surface, data, width, height, border = 20, grid = True, rounded_corners = True)
resp = StringIO()
surface.write_to_png(resp)
}}}
That raised 2 errors:
* one complaining about endswith called with None (the value of self.filename in the class)
* and the other of calling write_to_png on a finished surface.
I'm attaching a quick and dirty fix for this.
Probably a better approach to solve this problem is to accept file-like objects as argument in addition to strings and surface instances. |
|