improve transparency support for bitmaps together with some code cleanup/reorganizati...
[PyX.git] / manual / gradientname.py
blob8a188d6f070820415f1ec27b3b1a220c410b74f0
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}")
10 c = canvas.canvas()
12 # data to be plotted
13 pf = graph.data.paramfunction("k", 0, 1, "color, xmin, xmax, ymin, ymax= k, k, 1, 0, 1")
15 # positioning is quite ugly ... but it works at the moment
16 y = 0
17 dy = -0.65
19 # we could use gradient.__dict__ to get the instances, but we
20 # would loose the ordering ... instead we just parse the file:
22 # see comment in colorname.py
24 p = re.compile("(?P<id>gradient\\.(?P<name>[a-z]+)) += [a-z]+gradient\\(.*\\)\n", re.IGNORECASE)
25 lines = imp.find_module("color", pyx.__path__)[0].readlines()
26 firstgraph = None
27 for line in lines: # we yet don't use a file iterator
28 m = p.match(line)
29 if m:
30 if firstgraph is None:
31 xaxis = graph.axis.lin(
32 parter=graph.axis.parter.lin(tickdists=["0.5","0.1"], labeldists=["1"]),
33 painter=graph.axis.painter.regular(
34 innerticklength=None,
35 outerticklength=graph.axis.painter.ticklength.normal),
36 linkpainter=graph.axis.painter.regular(innerticklength=None, labelattrs=None))
37 firstgraph = g = graph.graphxy(ypos=y, width=10, height=0.5, x2=xaxis, y=graph.axis.lin(parter=None))
38 else:
39 g = graph.graphxy(ypos=y, width=10, height=0.5, x2=graph.axis.linkedaxis(firstgraph.axes["x2"]), y=graph.axis.lin(parter=None))
40 g.plot(pf, [graph.style.rect(getattr(pyx.color.gradient, m.group("name")))])
41 g.dodata()
42 g.finish()
43 c.insert(g)
44 c.text(10.2, y + 0.15, m.group("id"), [text.size.footnotesize])
45 y += dy
48 c.writeEPSfile("gradientname")
49 c.writePDFfile("gradientname")