[Zope] Accessing .gif on disk with Python Product?
Performance.net Strategic Internet Solutions
support@performance-net.com
Mon, 7 Aug 2000 13:12:03 -0300
----- 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 12:19 PM
Subject: Re: [Zope] Accessing .gif on disk with Python Product?
>
> 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.
>
> --
> 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
> -----------------------------------------------------
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! =:)
Kevin