Add boxes.text() and use it in drillbox.py
This commit is contained in:
parent
82ebbf09ed
commit
13d46195b7
22
boxes.py
22
boxes.py
|
@ -705,6 +705,28 @@ class Boxes:
|
||||||
self.corner(-90, r)
|
self.corner(-90, r)
|
||||||
self.edge(d)
|
self.edge(d)
|
||||||
|
|
||||||
|
@restore
|
||||||
|
def text(self, text, x=0, y=0, angle=0, align=""):
|
||||||
|
self.moveTo(x, y, angle)
|
||||||
|
(tx, ty, width, height, dx, dy) = self.ctx.text_extents(text)
|
||||||
|
align = align.split()
|
||||||
|
moves = {
|
||||||
|
"top" : (0, -height),
|
||||||
|
"middle" : (0, -0.5*height),
|
||||||
|
"bottom" : (0, 0),
|
||||||
|
"left" : (0, 0),
|
||||||
|
"center" : (-0.5*width, 0),
|
||||||
|
"right" : (-width, 0),
|
||||||
|
}
|
||||||
|
for a in align:
|
||||||
|
if a in moves:
|
||||||
|
self.moveTo(*moves[a])
|
||||||
|
else:
|
||||||
|
raise ValueError("Unknown alignment: %s" % align)
|
||||||
|
|
||||||
|
self.ctx.scale(1, -1)
|
||||||
|
self.ctx.show_text(text)
|
||||||
|
|
||||||
@restore
|
@restore
|
||||||
def NEMA(self, size, x=0, y=0, angle=0):
|
def NEMA(self, size, x=0, y=0, angle=0):
|
||||||
nema = {
|
nema = {
|
||||||
|
|
|
@ -29,12 +29,10 @@ class Box(Boxes):
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
for j in range(6):
|
for j in range(6):
|
||||||
self.rectangularHole(i*60+30, 20*j+10, 58, 14+1*j)
|
self.rectangularHole(i*60+30, 20*j+10, 58, 14+1*j)
|
||||||
self.ctx.save()
|
|
||||||
self.ctx.move_to(i*60+14, 19*j+6)
|
|
||||||
d = 2.5-0.5*i+2*j
|
d = 2.5-0.5*i+2*j
|
||||||
self.ctx.scale(1,-1)
|
self.text("%.1f" % d, i*60+20, 19*j+6,
|
||||||
self.ctx.show_text("%.1f" % d)
|
align="center")
|
||||||
self.ctx.restore()
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h = self.x, self.y, self.h
|
x, y, h = self.x, self.y, self.h
|
||||||
|
|
Loading…
Reference in New Issue