[Zope] Accessing .gif on disk with Python Product?

Kevin Howe support@performance-net.com
Mon, 7 Aug 2000 13:38:56 -0300


Right you are, here's how I solved it:

# __init.py__ for myProduct

misc_={
  'chooserIcon': ImageFile('images/chooserIcon.gif',globals()),
  }

# DTML file

<img src="<dtml-var absolute_url>/misc_/myProduct/chooserIcon" border=0>


Thanks!
Kevin

----- Original Message -----
From: "Martijn Pieters" <mj@digicool.com>
To: "Performance.net Strategic Internet Solutions"
<support@performance-net.com>
Cc: "ZOPE Mailing List" <zope@zope.org>
Sent: Monday, August 07, 2000 1:15 PM
Subject: Re: [Zope] Accessing .gif on disk with Python Product?


>
> On Mon, Aug 07, 2000 at 01:12:03PM -0300, Performance.net Strategic
Internet Solutions wrote:
> > > On Mon, Aug 07, 2000 at 11:21:53AM -0300, Performance.net Strategic
> > > Internet Solutions wrote:
> > > > I am writing a python product and want to display a GIF file in some
of
> > > > the manage_pages. It is not meant to be the "icon" property of the
> > > > class, just an image to be included in DTML. I included it in my
class
> > > > as follows:
> > > >
> > > >   chooser = ImageFile('images/chooser.gif',globals()),
> > > >
> > > > but when I call it in DTML (<dtml-var chooser>) I get the following:
> > > >
> > > >     <ImageFile instance at 014F1D90>
> > > >
> > > > I thought maybe I could use an instance of the Image class:
> > > >
> > > >   chooser = OFS.Image('images/chooser.gif',globals()),
> > > >
> > > > but this doesn't seem to work.
> > > >
> > > > How do you create an instance of an Image in a Python Product?
> > >
> > > ImageFile objects do not (like ZODB stored Image objects) generate an
IMG
> > > tag when called. Image object, when called, generate an IMG tag that
> > > points the browser to the correct address to retrieve tha actual
image.
> > >
> > > With an ImageFile object, you need to construct the tag yourself. If
this
> > > class has an instance foo, with this ImageFile attribute chooser, and
the
> > > instance foo is stored in the root of your Zope ZODB, you need to
point
> > > the browser to http://yoursever/foo/chooser. So your DTML needs to
> > > generate the following HTML:
> > >
> > >   <img src="http://yoursever/foo/chooser">
> > >
> > > I don't know enough about your DTML, but if it is another attribute of
the
> > > same class, you could use one of the URLx REQUEST variables or
something
> > > to construct the URL for the image. Also, absolute_url() called on the
foo
> > > instance may also work for a base URL.
> > >
> > > Hope this helps.
> >
> > Okay, I've done the following:
> >
> > # Create the method in the .py Class File
> > chooserIcon=ImageFile('images/chooserIcon.gif',globals()),
> >
> > # Call from the .dtml File <img src="<dtml-var
absolute_url>/chooserIcon"
> > border=0>
> >
> > absolute_url() works and the URL points correctly to
> > http://myserver/foo/chooserIcon, but  if I type in that URL directly, I
get
> > a "Not Found" error as though the method does not exist. I've
double-checked
> > that the image is there and named correctly, so it's not a syntax thing.
> >
> > Perhaps I need to convert it to an "Image" object something like below?
> >
> >     # this doesn't work but illustrates the idea chooserIcon = Image(
> >     ImageFile('images/chooserIcon.gif',globals() )
> >
> > Help! =:)
>
> Hmm.. This is how Product Icons are stored, that is, as ImageFile objects.
At
> product init time, a ImageFile objetcs is created for the Product icon and
> stroed in the special misc_ structure for later access.
>
> Have a look through the Product initialisation code, which is started up
in
> OFS/Application.py::install_products().
>
> --
> Martijn Pieters
> | Software Engineer            mailto:mj@digicool.com
> | Digital Creations          http://www.digicool.com/
> | Creators of Zope               http://www.zope.org/
> | ZopeStudio: http://www.zope.org/Products/ZopeStudio
> -----------------------------------------------------
>