home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / gl / glstdwin / tcolor.py < prev    next >
Text File  |  1992-12-14  |  939b  |  44 lines

  1. # Try colors -- display all 256 possible colors, with their color index
  2.  
  3. import stdwingl
  4.  
  5. import stdwin
  6. from stdwinevents import *
  7.  
  8. NROWS = 16
  9. NCOLS = 16
  10.  
  11. def main():
  12.     stdwin.setdefwinsize(NCOLS * stdwin.textwidth('12345'), \
  13.                 NROWS * stdwin.lineheight() * 3)
  14.     w = stdwin.open('TestColors')
  15.     #
  16.     while 1:
  17.         type, window, detail = stdwin.getevent()
  18.         if type == WE_CLOSE:
  19.             print 'Bye.'
  20.             break
  21.         elif type == WE_SIZE:
  22.             w.change((0,0), (10000, 10000))
  23.         elif type == WE_DRAW:
  24.             width, height = w.getwinsize()
  25.             d = w.begindrawing()
  26.             for row in range(NROWS):
  27.                 for col in range(NCOLS):
  28.                     color = row*NCOLS + col
  29.                     d.setfgcolor(color)
  30.                     p = col*width/NCOLS, row*height/NROWS
  31.                     q = (col+1)*width/NCOLS, \
  32.                         (row+1)*height/NROWS
  33.                     d.paint((p, q))
  34.                     d.setfgcolor(0)
  35.                     d.box((p, q))
  36.                     d.text(p, `color`)
  37.                     p = p[0] , p[1]+ d.lineheight()
  38.                     d.setfgcolor(7)
  39.                     d.text(p, `color`)
  40.             del d
  41.     #
  42.  
  43. main()
  44.