epsfile arglist TODO added
[PyX/mjg.git] / manual / colorname.py
blob6cfd807ec96caa2e49a4bb8106125dcba4257601
1 #!/usr/bin/env python
2 import sys, imp, re
3 sys.path[:0] = [".."]
4 import pyx
5 from pyx import *
7 c = canvas.canvas()
8 t = tex.latex()
9 t.define(r"\renewcommand{\familydefault}{\ttdefault}")
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:
20 p = re.compile("(?P<id>(?P<model>[a-z]+)\\.(?P<name>[a-z]+)) += (?P=model)\\([0-9\\., ]+\\)\n", re.IGNORECASE)
21 lines = imp.find_module("color", pyx.__path__)[0].readlines()
22 for line in lines: # we yet don't use a file iterator
23 m = p.match(line)
24 if m:
25 if lastmodel and (m.group("model") != lastmodel):
26 y += dy
27 myc = pyx.color.__dict__[m.group("model")].__dict__[m.group("name")]
28 c.stroke(path.line(x + 0.1, y + 0.1, x + 0.4, y + 0.4), myc)
29 c.stroke(path.line(x + 0.4, y + 0.1, x + 0.1, y + 0.4), myc)
30 c.fill(path.rect(x + 0.5, y, 1, 0.5), myc)
31 c.stroke(path.line(x + 0.6, y + 0.1, x + 0.9, y + 0.4), color.gray.black)
32 c.stroke(path.line(x + 0.9, y + 0.1, x + 0.6, y + 0.4), color.gray.black)
33 c.stroke(path.line(x + 1.1, y + 0.1, x + 1.4, y + 0.4), color.gray.white)
34 c.stroke(path.line(x + 1.4, y + 0.1, x + 1.1, y + 0.4), color.gray.white)
35 t.text(x + 1.7, y + 0.15, m.group("id"), tex.fontsize.footnotesize)
36 y += dy
37 lastmodel = m.group("model")
38 if y < -16:
39 y = 0
40 x += dx
42 c.insert(t)
43 c.writetofile("colorname", paperformat="a4")