#!/usr/bin/python2.4 import os import sys import math import cgitb; cgitb.enable() import cgi sys.path.append("./../") from magazinelayout import MagazineLayout def flush(): sys.stdout.flush() form = cgi.FieldStorage() template = '' try: width = int(form.getfirst('width', '600'), 10) except ValueError: width = 600 width = max(width, 200) try: padding = int(form.getfirst('padding', '3'), 10) except ValueError: padding = 3 padding = max(padding, 0) print 'Content-Type: text/html\n' print ''' Magazine Layout Test

Magazine Layout Test

''' % dict(padding=padding) flush() images = [fn for fn in os.listdir('.') if fn.endswith('.jpg')] # Generate the layout layout = MagazineLayout(maxwidth=width, padding=padding, imagetemplate=template) added = 0 for image in images: if image in form: layout.addImage(image) added += 1 if added: print layout.getHTML() flush() else: print '

Select some images below.

' if added > 8: print "

You selected more than eight images—some won't be displayed.

" # Generate the form images.sort() size = 100 # Maximum thumbnail size print ('''
Settings

Images''' % (width, padding) ) for image in images: print '''

''' % { "fn": image, "size": size, "checked": (image in form) and " checked" or '' } flush() print '''

''' print '''

Image credit: NASA

Part of freecog.net | © 2006 Tom W.M.

'''