code style/efficiency question: text file templates
karaatanasov at hotmail.com
Mon Aug 5 14:36:19 CEST 2002
I actually have a small Pytohn program along with couple of HTML forms
to do this. I were also trying to resolve this dilema until I found
out how it is realy easy to do.
You need to do one copy of the HTML document that has all deisgn
gadgets it needs (In my case these were three files since I did couple
of frames one for preview and one for regular size).
Then you need to replace the customizable places with document.write
statements, that fetch data from an array. This seems to be compatible
with all browsers.
Last step is to declare the array in an outer script file .js. This
can be loaded at the user machine.
then I created a Pytoh program that basicly goes through all jpeg
files in a directory, creates thumbnails in one subdirectory and
640x480 images in another subdirectory, then it writes the names of
the pictures in to the .js file. Thus the image viewer web app is
automaticly generated. You may add to the python code statements to
write blank strings associated with each image to add comments there
manually afterwards. Or if you have a way to connect filenames to a
string table do it automaticly :o))) The possiblities are limitless.
In my opinion nanoseconds in an esentially not optimized sequence do
not matter. These matter only when your app is well designed and is
sure to be capable to do the job.
In my opinion binding data to UI should take place as late as possible
e.g. on the client computer. This minimizes the effort one needs to do
when data or look&feel is updated e.g. if you generate static HTML's
this might be good for some cases, but once changes ocur all files
need be updated the more files that get up[dated the higher the risk
that something will go wrong.
Here are some relevant pieces of code. If you eed the whole thing drop
me a line.
The .py progie:
c = 
for i in os.listdir(path):
ar = i.split(".")
if len(ar) > 1 and (ar=="jpg" or ar=="JPG"):
c.append('ar[' + str(indx) + '] = "' + i + '";\n')
indx = indx + 1
f.write('var ar = new Array(' + str(len(c)) + ');')
for i in c:
The .js result file
var ar = new Array(20);ar = "PICT0031.JPG";
ar = "PICT0032.JPG";
ar = "PICT0033.JPG";
ar = "PICT0034.JPG";
ar = "PICT0035.JPG";
ar = "PICT0036.JPG";
ar = "PICT0037.JPG";
ar = "PICT0038.JPG";
ar = "PICT0039.JPG";
ar = "PICT0040.JPG";
Here is the script loading in the main frame
Here is part of the index frame that displays thumbnails
var ar = window.top.ar;
');"><IMG SRC="thumbs/' + ar[i] + '"></TD/TR>');
The package is easy to use and modify. All you need to do is
Copy the HTMLs and .py file into the image directory
Double click the python file.
Wait for a while.
Open the index.html to see what has happened
When desing changes you need to put fine touch on the HTML's. When new
pictures are to be added or old remove just copy the pictures and
click on the .py file
Simple and powerfull design is foremost important.
More information about the Python-list