How to return two images by one procedure
Hello, I worte an external procedure which returns an image. Now I want to add an additional image showing a legend to exactly this dynamically created image. Unfortunately I have no idea how I can make sure that this legend is connected to the image created in the external procedure. Any idea how to solve this? Andreas.
On Tuesday 01 July 2003 01:06 pm, Andreas Tille wrote:
I worte an external procedure which returns an image. Now I want to add an additional image showing a legend to exactly this dynamically created image. Unfortunately I have no idea how I can make sure that this legend is connected to the image created in the external procedure.
Any idea how to solve this?
Return a tuple: IN EXTERNAL METHOD: def image_processing_function(): return image1, image2 IN DTML TEMPLATE: <dtml-let images="image_processing_function()"> <dtml-var expr="images[0]"> <dtml-var expr="images[1]"> </dtml-let> (with lots of HTML formatting omitted, of course). Note that in general, Python allows many-to-many function mappings as a standard idiom: (e,f,g) = example_function(a,b,c,d) This is really "tuple unpacking" but note the symmetry between arguments and return values. Cool, huh? So there's no need to stick to the usual idea of having a single return value. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
I worte an external procedure which returns an image. Now I want to add an additional image showing a legend to exactly this dynamically created image. Unfortunately I have no idea how I can make sure that this legend is connected to the image created in the external procedure.
Any idea how to solve this?
Return a tuple:
IN EXTERNAL METHOD: def image_processing_function(): return image1, image2
IN DTML TEMPLATE: <dtml-let images="image_processing_function()"> <dtml-var expr="images[0]"> <dtml-var expr="images[1]"> </dtml-let>
That'll try to inline the images, which won't work. If you want to create them at the same time, you'll probably have to create a folder with two images in it, and store it somehow. Your external method would want to return the name of the created container. The better answer is to make two methods (one for image, one for key) and give both methods the same parameters so they can create images on the same information. That won't work if you have non-parameterized controls (random or external), in which case you'll have to figure out some sort of index/snapshot scheme. --jcc
On Wed, 2 Jul 2003, J Cameron Cooper wrote:
That'll try to inline the images, which won't work. Exactly.
If you want to create them at the same time, you'll probably have to create a folder with two images in it, and store it somehow. Your external method would want to return the name of the created container. This might be an option here.
The better answer is to make two methods (one for image, one for key) and give both methods the same parameters so they can create images on the same information. I considered this but it would be very bad because I would have to do the same database query twice which would cause quite bad performance.
My second thought was that I do not really need two images because the second image could be replaced by one constant image containing plain colors and returning legend text description combining it with the image in a table - but this causes fiddling around with save placement in different browsers. Moreover this reduces the problem only slightly: Replace return of two images by one image and a touple of text entries.
That won't work if you have non-parameterized controls (random or external), in which case you'll have to figure out some sort of index/snapshot scheme. I'm afraid I do not understand this sentence.
Kind regards Andreas.
The better answer is to make two methods (one for image, one for key) and give both methods the same parameters so they can create images on the same information.
I considered this but it would be very bad because I would have to do the same database query twice which would cause quite bad performance.
My second thought was that I do not really need two images because the second image could be replaced by one constant image containing plain colors and returning legend text description combining it with the image in a table - but this causes fiddling around with save placement in different browsers. Moreover this reduces the problem only slightly: Replace return of two images by one image and a touple of text entries.
Then you should create one method to get the dynamic data and pass that as parameters to the methods that make your images.
That won't work if you have non-parameterized controls (random or external), in which case you'll have to figure out some sort of index/snapshot scheme.
I'm afraid I do not understand this sentence.
I had a feeling that would be a little esoteric. What this might mean is that you something like the following: 1) Generate a random number with a high (or guaranteed, if you're feeling over-acheiving) probability of uniqueness. 2)Call your first method with a parameter being that number. It generates and returns your image, and caches the data the second method needs somehow under an index accessible by the number you gave it. (Like by filename.) 3) Call the second method with its parameter being the same index number. It retreives the cached data and creates its image. Perhaps it also flushes the cached value. This works with any type of data created by the first method, even if it's random, by making a snapshot and providing the index to it. It's also somewhat fragile as described, because it depends on order of call, but I think you can imagine how to fix that. Probably you don't need to be this complex, and can use the simplified case I suggested above (the one using three methods.) Or you can use one of the previous suggestions that makes sense. --jcc
On Wed, 2 Jul 2003, J Cameron Cooper wrote:
Then you should create one method to get the dynamic data and pass that as parameters to the methods that make your images. Perhaps this might be the most clever method.
1) Generate a random number with a high (or guaranteed, if you're feeling over-acheiving) probability of uniqueness. I guess tempfile.mktemp() is my friend here...
2)Call your first method with a parameter being that number. It generates and returns your image, and caches the data the second method needs somehow under an index accessible by the number you gave it. (Like by filename.)
3) Call the second method with its parameter being the same index number. It retreives the cached data and creates its image. Perhaps it also flushes the cached value. For one moment I've thought about that but I'm not sure in how far those methods might possibly run in parallel and the second method might try to acces a not existing tempfile.
This works with any type of data created by the first method, even if it's random, by making a snapshot and providing the index to it. It's also somewhat fragile as described, because it depends on order of call, but I think you can imagine how to fix that. Probably you don't need to be this complex, and can use the simplified case I suggested above (the one using three methods.) Or you can use one of the previous suggestions that makes sense. Thanks for the hints
Andreas.
Andreas Tille wrote at 2003-7-1 22:06 +0200:
I worte an external procedure which returns an image. Now I want to add an additional image showing a legend to exactly this dynamically created image. Unfortunately I have no idea how I can make sure that this legend is connected to the image created in the external procedure.
Any idea how to solve this?
There is no problem with Zope here... But HTML insists to access each image with its own URL. Therefore, a single request is unable to return two separate images to HTML. Dieter
On Fri, 4 Jul 2003, Dieter Maurer wrote:
There is no problem with Zope here... But HTML insists to access each image with its own URL. Therefore, a single request is unable to return two separate images to HTML. For sure - that's why I was asking whether I could do some tricks to work around this.
Kind regards Andreas.
Andreas Tille wrote at 2003-7-5 12:40 +0200:
On Fri, 4 Jul 2003, Dieter Maurer wrote:
There is no problem with Zope here... But HTML insists to access each image with its own URL. Therefore, a single request is unable to return two separate images to HTML. For sure - that's why I was asking whether I could do some tricks to work around this.
To trick out HTML, you need client side technology. Dieter
participants (4)
-
Andreas Tille -
Dieter Maurer -
J Cameron Cooper -
Terry Hancock