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