LetterType.cgi: Difference between revisions

From XPUB & Lens-Based wiki
(New page: Example of a simple "typing" interface using CGI. Two variables are used for state, one to represent the "current word", and a second to represent the "current letter" to be typed. <sourc...)
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 33: Line 33:
"""
"""
</source>
</source>
[[techdazecgi:lettertype.cgi | See this script]]


Note how the "clear" links works by clearing all state.
Note how the "clear" links works by clearing all state.

Latest revision as of 16:49, 9 February 2009

Example of a simple "typing" interface using CGI. Two variables are used for state, one to represent the "current word", and a second to represent the "current letter" to be typed.

#!/usr/bin/python
 
import cgi
import cgitb; cgitb.enable()
 
fs = cgi.FieldStorage()
curword = fs.getvalue("curword", "")
addletter = fs.getvalue("addletter", None)
 
if addletter:
  curword += addletter
 
print "Content-type: text/html; charset=utf8"
print
 
print "<html><head><title>lettertype</title></head><body>"

letters = "abcdefghijklmnopqrstuvwxyz"
print "<p>"
for l in letters:
  print """<a href="?curword=%s&addletter=%s">%s</a>""" % (curword, l, l)
print """<a href="?">clear</a>"""
print "</p>"

print "<h2>%s</h2>" % curword

print """
</body>
</html> 
"""

See this script

Note how the "clear" links works by clearing all state.

Exercise

Implement a "backspace" link.