Re: [PythonReports-users] Images
Brought to you by:
a1s
|
From: Werner F. B. <wer...@fr...> - 2013-02-10 20:09:27
|
On 10/02/2013 18:16, alexander smishlajev wrote:
> On 10.02.2013 15:29, Werner F. Bruhin wrote:
>>
>> expr gets saved
>
> I guess you are talking about template designer. Sorry, I didn't
> think of checking that. I have modified only report building and
> checked PDF formatting.
>
>> I keep digging through the doc etc, a pointer would obviously be very
>> welcome.
>
> The data returnded from expr is image data - same as would be returned
> by reading an image file.
Hhm, unless I still do something wrong - quit likely, here is what I get:
Changed things to:
def getRecipeImagePNG(recid):
"""
Return a PIL.Image instance of the first image found
of type "Recipe finished" (fk_exttype_id=4), or an empty image
:param str `recid`: the recipe id
:return: Image full path or None
"""
if recid:
app = wx.GetApp()
ds = app.ds
imgF = app.getDirLocations()[5]
with no_autoflush(ds):
extfiler = ds.query(db.Extfiler).filter_by(fk_recipe_id =
recid,
fk_exttype_id = 4).first()
if extfiler:
img = Image.open(os.path.join(imgF, extfiler.filename))
else:
# return a blank one if none is found
bDir = os.path.join(wx.GetApp().baseDir, "images")
bImg = os.path.join(bDir, "blankImage.jpg")
img = Image.open(bImg)
buf= StringIO.StringIO()
img.save(buf, format= 'PNG')
temp = buf.getvalue()
return temp
The image element is:
<image type="png">
<box height="30" width="75" x="374" y="50" />
<data> expr="ru.getRecipeImagePNG(THIS.id)"</data>
</image>
But I get this traceback:
IOError: cannot identify image file
File "c:\dev\twcbv4\twcbsrc\controllers\dreports.py", line 555, in <module>
dlg.ShowModal()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_windows.py", line
805, in ShowModal
return _windows_.Dialog_ShowModal(*args, **kwargs)
File
"c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\aquabutton.py",
line 434, in OnLeftUp
self.Notify()
File
"c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\lib\agw\aquabutton.py",
line 864, in Notify
self.GetEventHandler().ProcessEvent(evt)
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_core.py", line
4154, in ProcessEvent
return _core_.EvtHandler_ProcessEvent(*args, **kwargs)
File "c:\dev\twcbv4\twcbsrc\controllers\dreports.py", line 345, in
doReportPreview
env.report_preview()
File
"c:\Python27\Lib\site-packages\PythonReports\editor\environment.py",
line 263, in report_preview
_printout = self.report_build()
File
"c:\Python27\Lib\site-packages\PythonReports\editor\environment.py",
line 245, in report_build
return Builder(_template).run(_data)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
1459, in run
self._build(_data_iter, _callback)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
1475, in _build
self.fill_title()
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
1634, in fill_title
self.start_group(_group)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
1852, in start_group
self.add_section(self.build_section(_title))
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
2067, in build_section
_section = Section(self, template, _context)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line 469,
in __init__
self.build(context)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line 741,
in build
_element.image = self.builder.image(_item)
File "c:\Python27\Lib\site-packages\PythonReports\builder.py", line
1321, in image
img_type=_type)
File "c:\Python27\Lib\site-packages\PythonReports\PILDrivers.py", line
92, in fromdata
_rv._image = Image.open(StringIO(data))
File "c:\Python27\Lib\site-packages\PIL\Image.py", line 1980, in open
raise IOError("cannot identify image file")
And "data" in fromdata at line 92 is my expression string instead of the
image data, as if the expression is never "run".
data
u'expr="ru.getRecipeImagePNG(THIS.id)"'
Hope I am clear and not doing something stupid. Anyhow it is late, I
will look at this again tomorrow.
Werner
|