File: tcolor.py

package info (click to toggle)
python 1.5.1-4
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 11,592 kB
  • ctags: 32,695
  • sloc: ansic: 90,267; python: 73,993; makefile: 2,423; lisp: 2,097; sh: 702
file content (43 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Try colors -- display all 256 possible colors, with their color index

import stdwingl

import stdwin
from stdwinevents import *

NROWS = 16
NCOLS = 16

def main():
	stdwin.setdefwinsize(NCOLS * stdwin.textwidth('12345'), \
				NROWS * stdwin.lineheight() * 3)
	w = stdwin.open('TestColors')
	#
	while 1:
		type, window, detail = stdwin.getevent()
		if type == WE_CLOSE:
			print 'Bye.'
			break
		elif type == WE_SIZE:
			w.change((0,0), (10000, 10000))
		elif type == WE_DRAW:
			width, height = w.getwinsize()
			d = w.begindrawing()
			for row in range(NROWS):
				for col in range(NCOLS):
					color = row*NCOLS + col
					d.setfgcolor(color)
					p = col*width/NCOLS, row*height/NROWS
					q = (col+1)*width/NCOLS, \
						(row+1)*height/NROWS
					d.paint((p, q))
					d.setfgcolor(0)
					d.box((p, q))
					d.text(p, `color`)
					p = p[0] , p[1]+ d.lineheight()
					d.setfgcolor(7)
					d.text(p, `color`)
			del d
	#

main()