Hi,
I've contacted Bill Casselman about PyScript last night because I've made a patch to make the TeX labels to work on Windows.
Bill is currently travelling, so we have to wait untill he comes back. I don't leave the patch here because it's very experimental, and I'm waiting for Bill's permission.
From what I've seen so far, it's just a matter of paths being hard coded like "/temp/myfolder". In fact, to be portable, your paths needs to use Python's excellent libs, like os.path. ie, don't write this:
mypath = "/temp/myfolder"
but rather use :
import os
mypath = os.path.join("temp","folder")
Also, for Python's docs, you can now use those new beautiful ones made with Georg Brandl's Sphinx tool.
But let's comme back a little to PyScript, here's a little picture I translated from Adobe's Bluebook and the Python's source :
from PiModule import *
from math import sin, radians
# Transcription of Adobe's Bluebook sample
# see http://melusine.eu.org/syracuse/postscript/bluebook/?opt=eps&f=01
# define what's an inch
inch = lambda x: x*72
# petal of the flower
def wedge():
newpath()
moveto(0,0)
translate(1,0)
rotate(15)
translate(0,sin(radians(15)))
arc(0, 0, sin(radians(15)), -90, 90)
closepath()
init("Flower", 800, 800 )
beginpage()
setdeg()
gsave()
translate(inch(3.75), inch(7.25))
scale(inch(1), inch(1))
wedge()
setlinewidth(0.02)
stroke()
grestore()
def make_flower():
gsave()
translate(inch(4.25), inch(4.25))
scale(inch(1.75), inch(1.75))
setlinewidth(0.02)
for c in range(1,13,1):
setgray(c/12.)
gsave()
wedge()
gsave()
fill(c/12.)
grestore()
setgray(0)
stroke()
grestore()
rotate(30)
grestore()
make_flower()
endpage()
flush()
But I've got a problem with the eps output : the bounding box does not seems to work fine. To make it work, I have to modify the first line of the EPS header like this : %!PS-Adobe-2.0 EPSF-3.0
Here's a PieChart diagram with TeX labels and the code following it.
from PiModule import *
from math import sin,cos,hypot, radians
datas = [("Blueberry" , 0.12),
("Cherry" , 0.3),
("Apple" , 0.26),
("Boston~Cream" , 0.16),
("Other" , 0.04),
("Vanilla~Cream" , 0.12),
]
def camembert(deg_num, r=10):
newpath()
moveto(0,0)
lineto(r,0)
arc(0, 0, r, 0, deg_num)
closepath()
cadre = 280
init("PieChart", cadre,cadre )
beginpage()
setdeg()
center()
moveto(0,0)
setlinewidth(0.2)
angle = 0
scale(5)
def draw_diagram():
sum=0
angle = 0
for text,an in datas :
i = an*360
# draw and fill a camembert
gsave()
rotate(angle)
camembert(i,15)
setgray(sum/6.)
fill()
stroke(0)
grestore()
# draw the label
sc = 0.15
isc = 1/sc
r2 = 16
gsave()
setcolor(1,0,0)
scale(sc)
myangle = (angle+i/2)
translate(r2*isc*cos(radians(myangle))+1, r2*isc*sin(radians(myangle))+1 )
rotate(myangle)
t = texinsert("$%s$"%text)
place(t)
grestore()
angle += i
sum += 1
draw_diagram()
endpage()
finish()