fix bug 3524174, thanks to Jeff Higgins for the report, thanks to Michael J Gruber...
[PyX.git] / manual / colorname.py
blobe683f2be17d9c27eb04c5ebfbad396c1f148e10b
1 #!/usr/bin/env python
2 import sys, imp, re
3 sys.path[:0] = [".."]
4 import pyx
5 from pyx import *
7 text.set(mode="latex")
8 text.preamble(r"\renewcommand{\familydefault}{\ttdefault}")
9 c = canvas.canvas()
11 # positioning is quite ugly ... but it works at the moment
12 x = 0
13 y = 0
14 dx = 4.8
15 dy = -0.65
16 lastmodel = 0
18 # we could use (gray|rgb|cmyk).__dict__ to get the instances, but we
19 # would loose the ordering ... instead we just parse the file:
21 # TODO: code something along the lines of c.l.p post cbs38g$2kp$04$1@news.t-online.com
23 p = re.compile("(?P<id>(?P<model>[a-z]+)\\.(?P<name>[a-z]+)) += (?P=model)\\([0-9\\., ]+\\)\n", re.IGNORECASE)
24 lines = imp.find_module("color", pyx.__path__)[0].readlines()
25 for line in lines: # we yet don't use a file iterator
26 m = p.match(line)
27 if m:
28 if lastmodel and (m.group("model") != lastmodel):
29 y += dy
30 myc = pyx.color.__dict__[m.group("model")].__dict__[m.group("name")]
31 c.stroke(path.line(x + 0.1, y + 0.1, x + 0.4, y + 0.4), [myc])
32 c.stroke(path.line(x + 0.4, y + 0.1, x + 0.1, y + 0.4), [myc])
33 c.fill(path.rect(x + 0.5, y, 1, 0.5), [myc])
34 c.stroke(path.line(x + 0.6, y + 0.1, x + 0.9, y + 0.4), [color.gray.black])
35 c.stroke(path.line(x + 0.9, y + 0.1, x + 0.6, y + 0.4), [color.gray.black])
36 c.stroke(path.line(x + 1.1, y + 0.1, x + 1.4, y + 0.4), [color.gray.white])
37 c.stroke(path.line(x + 1.4, y + 0.1, x + 1.1, y + 0.4), [color.gray.white])
38 c.text(x + 1.7, y + 0.15, m.group("id"), [text.size.footnotesize])
39 y += dy
40 lastmodel = m.group("model")
41 if y < -16.5:
42 y = 0
43 x += dx
45 c.writePDFfile()