Remove call to .close() from .render() method

There is really no need for all the generator to care
Still calling it is deprecated but won't result in an error
This commit is contained in:
Florian Festi 2019-02-08 17:32:04 +01:00
parent 2ba6fa1bf3
commit 861c8451e2
68 changed files with 12 additions and 71 deletions

View File

@ -569,7 +569,11 @@ class Boxes:
"""Finish rendering
Call at the end of your .render() method"""
if self.ctx == None:
return
self.ctx.stroke()
self.ctx = None
self.surface.flush()
self.surface.finish()

View File

@ -60,4 +60,3 @@ class BOX(Boxes): # Change class name!
# render your parts here
self.close()

View File

@ -50,4 +50,3 @@ class AllEdges(Boxes):
self.edges[c](x, h=4*t)
self.text("%s - %s" % (c, self.edges[c].description), y=5*t)
self.close()

View File

@ -136,6 +136,5 @@ class AngledBox(Boxes):
self.rectangularWall(lx, h, move="right",
edges="fGfG" if fingers else "fGeG")
self.close()

View File

@ -65,4 +65,3 @@ class AngledCutJig(Boxes): # Change class name!
self.rectangularTriangle(x, th, "fef", num=2, move="up")
self.rectangularTriangle(20, th2, "fef", num=2, move="up")
self.close()

View File

@ -97,5 +97,4 @@ class Arcade(Boxes):
self.side(move="up")
self.side(move="up")
self.close()

View File

@ -139,6 +139,5 @@ class BinTray(Boxes):
e = [edges.SlottedEdge(self, self.sx, "g"), "F", "e", "F"]
self.rectangularWall(x, self.sy[i]*self.front*2**0.5, e, callback=[self.frontHoles(i)], move="up")
self.close()

View File

@ -153,4 +153,3 @@ class CardBox(Boxes):
for i in range(self.num - 1):
self.rectangularWall(h-t, y, "fAff", move="right")
self.close()

View File

@ -43,6 +43,5 @@ class Castle(Boxes):
self.rectangularWall(w1_x, w1_h, "efpe", move="right")
self.rectangularWall(w2_x, w2_h, "efpe", move="right")
self.close()

View File

@ -52,6 +52,5 @@ class ClosedBox(Boxes):
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3], move="right")
self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3])
self.close()

View File

@ -64,5 +64,4 @@ class ConcaveKnob(Boxes):
self.parts.concaveKnob(self.diameter, self.serrations,
self.rounded, self.angle)
self.close()

View File

@ -54,4 +54,3 @@ class Display(Boxes):
x-2*r+2*math.sin(math.radians(a))*oh,
(90+a, r), oh, (90-a, r))
self.close()

View File

@ -60,4 +60,3 @@ class DisplayCase(Boxes):
self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4, move="right")
self.flangedWall(x, y, "FFFF", flanges=[self.overhang] * 4)
self.close()

View File

@ -80,5 +80,4 @@ class DisplayShelf(Boxes): # change class name here and below
for i in range(self.num):
self.rectangularWall(x, sl, "Efef", move="up")
self.close()

View File

@ -66,6 +66,5 @@ in 0.5mm steps, 3 holes each size"""
self.rectangularWall(x, y, "ffff", callback=[self.drillholes], move="up")
self.rectangularWall(x, y, "ffff", callback=[self.drillholes, self.descriptionText], move="up")
self.close()

View File

@ -92,6 +92,5 @@ class ElectronicsBox(Boxes):
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
self.close()

View File

@ -122,6 +122,5 @@ class FlexBox(boxes.Boxes):
self.flexBoxSide(self.x, self.y, self.radius, move="right")
self.flexBoxSide(self.x, self.y, self.radius, move="mirror")
self.close()

View File

@ -118,6 +118,5 @@ class FlexBox2(Boxes):
self.flexBoxSide(self.y, self.h, self.radius, move="right")
self.flexBoxSide(self.y, self.h, self.radius, move= "mirror right")
self.rectangularWall(self.x, self.h - self.radius - self.latchsize, edges="fFeF")
self.close()

View File

@ -165,6 +165,5 @@ class FlexBox3(Boxes):
self.flexBoxSide(x, y, r, move="mirror right")
self.rectangularWall(z, y, edges="fFeF")
self.close()

View File

@ -117,6 +117,5 @@ class FlexBox4(Boxes):
self.flexBoxSide(self.x, self.y, self.radius, move="mirror right")
self.rectangularWall(self.x, self.h, edges="FeFF")
self.close()

View File

@ -43,6 +43,5 @@ class FlexTest(Boxes):
self.edge(y)
self.corner(90)
self.close()

View File

@ -34,6 +34,5 @@ class FlexTest2(Boxes):
self.open()
self.rectangularWall(x, y, callback=[lambda: self.flex2D(x, y, self.fw)])
self.close()

View File

@ -46,6 +46,5 @@ class Folder(Boxes):
self.edge(y - 2 * r)
self.corner(90, r)
self.close()

View File

@ -93,4 +93,3 @@ Outer diameter 2: %.1fmm
Axis distance: %.1fmm
""" % (r1, d1, r2, d2, r1+r2), align="bottom left")
self.close()

View File

@ -96,6 +96,5 @@ class GearBox(Boxes):
self.gears(teeth=self.teeth1, dimension=self.modulus, angle=pressure_angle,
mount_hole=mh, profile_shift=profile_shift, move="down")
self.close()

View File

@ -83,6 +83,5 @@ class HingeBox(Boxes):
if s:
self.edges['u'].parts(move="up")
self.close()

View File

@ -58,7 +58,6 @@ class Hook(Boxes):
lambda: self.hole((h - t)/2, w/2, d=17)])
self.rectangularWall(s-t, w, 'FeFf', move='right')
self.close()
def back_callback(self, n):

View File

@ -63,6 +63,5 @@ class IntegratedHingeBox(Boxes):
self.rectangularWall(y, x, "ffff", move="up")
self.rectangularWall(y, x, "ffff")
self.close()

View File

@ -85,6 +85,5 @@ class JigsawPuzzle(Boxes): # change class name here and below
self.burn = 0.0
self.moveTo(10, 10)
self.hilbert(self.depth)
self.close()

View File

@ -131,6 +131,5 @@ class Lamp(Boxes):
self.rectangularWall(x, h, edges='hFFF', holesMargin=5, move="right")
self.rectangularWall(x, h, edges='hFFF', holesMargin=5)
self.close()

View File

@ -95,4 +95,3 @@ parts sliding on each other to reduce friction.
self.roundedPlate(4*t, h_min+h_extra+4*t, edge="e", r=t, move="right",
callback=[lambda: self.fingerHolesAt(1*t, 2*t, h_min+h_extra)])
self.rectangularWall(1.1*t, h_min+h_extra, "efef")
self.close()

View File

@ -40,5 +40,4 @@ class LBeam(Boxes):
self.rectangularWall(x, h, "eFee", move="right")
self.rectangularWall(y, h, "eeef")
self.close()

View File

@ -81,6 +81,5 @@ class MagazinFile(Boxes):
self.moveTo(y + 15, h + hi + 15, 180)
self.side(y, h, hi)
self.close()

View File

@ -53,5 +53,4 @@ class NemaMount(Boxes):
self.fingerHolesAt(0.5*t, t, x, 90)
self.fingerHolesAt(1.5*t+x, t, x, 90)
self.fingerHolesAt(t, 0.5*t, x, 0)
self.close()

View File

@ -50,5 +50,4 @@ class OpenBox(Boxes):
self.rectangularWall(x, y, "efff", bedBolts=[d2, d3, d2, d3], move="left")
#self.rectangularWall(x, y, "ffff", bedBolts=[d2, d3, d2, d3])
self.close()

View File

@ -149,4 +149,3 @@ class OrganPipe(Boxes): # Change class name!
lambda:self.hole(mouth_width/2, pipe_depth/2, d=air_hole_diameter)], move="right")
self.rectangularWall(mouth_width, pipe_depth - jet_thickness, "ffef", move="right")
self.close()

View File

@ -151,6 +151,5 @@ class OttoBody(Boxes):
self.rectangularWall(y-5.6, 14, callback=[
None, None, None, self.rightBottomCB], move="up")
self.close()

View File

@ -150,5 +150,4 @@ class OttoLegs(Boxes):
self.ankles(30, 25, callback=[None, self.ankle1], move="right")
self.ankles(30, 25, callback=[None, self.ankle2], move="right")
self.partsMatrix(2, 2, "right", self.servoring)
self.close()

View File

@ -70,4 +70,3 @@ class OttoSoles(Boxes):
self.edges["D"](w2)
self.polyline(0, 90, c2/2., 45, (x-2*c, 3), 45)
self.moveTo(0, w * 2**0.5 + 2*2**0.5*self.burn)
self.close()

View File

@ -96,4 +96,3 @@ class PaintStorage(Boxes):
lambda: self.rectangularHole(h/3, x/2., hh, hx, r=hr),
lambda: self.fingerHolesAt(0, self.canheight/3, x, 0)],
move="left")
self.close()

View File

@ -105,6 +105,5 @@ class Planetary(Boxes):
angle=pressure_angle,
mount_hole=self.shaft, profile_shift=profile_shift, move="up")
self.close()

View File

@ -208,4 +208,3 @@ class Planetary2(Boxes):
profile_shift=profile_shift, move="up only")
self.text("1:%.1f" % abs(ratio))
self.close()

View File

@ -128,5 +128,4 @@ class PoleHook(Boxes): # change class name here and below
for i in range(2):
self.parts.disc(ww, move="up")
self.close()

View File

@ -80,6 +80,5 @@ class Pulley(Boxes):
for i in range(int(math.ceil(self.h / self.thickness))):
self.pulley(self.teeth, self.profile, insideout=self.insideout, r_axle=self.axle / 2.0, move="right")
self.close()

View File

@ -93,7 +93,6 @@ class Rack19Box(Boxes):
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
self.close()
def render(self):
self._render(type=19)

View File

@ -94,6 +94,5 @@ class RackBox(Boxes):
self.rectangularTriangle(tr, tr, "ffe", num=4,
callback=[None, lambda: self.hole(trh, trh, d=d1)])
self.close()

View File

@ -71,4 +71,3 @@ class RectangularWall(Boxes):
self.moveTo(3*t, 3*t)
self.rectangularWall(self.x, self.h, self.edgetypes, callback=self.cb)
self.close()

View File

@ -94,6 +94,5 @@ class RegularBox(Boxes):
edges="fgfg" if fingers else "fgeg")
self.close()

View File

@ -58,5 +58,4 @@ class RobotArm(Boxes): # change class name here and below
servoClsA = getattr(servos, servoA)
servoClsB = getattr(servos, servoB)
armcls(self, servoClsA(self), servoClsB(self))(length, move="up")
self.close()

View File

@ -327,6 +327,5 @@ class Rotary(Boxes):
self.parts.disc(self.diameter - 2 * self.rubberthickness + 4,
hole=self.axle, move="right up")
self.close()

View File

@ -81,6 +81,5 @@ class RoundedBox(Boxes):
self.roundedPlate(x, y, r, wallpieces=self.wallpieces, move="up only")
self.surroundingWall(x, y, r, h, "F", "F", pieces=self.wallpieces)
self.close()

View File

@ -182,4 +182,3 @@ class RoyalGame(Boxes): # Change class name!
self.dice(size, 4, move="up")
self.dice(size, 4, move="up")
self.close()

View File

@ -227,4 +227,3 @@ class ShutterBox(Boxes):
else:
self.rectangularWall(ls, y, "fefA", move="right")
self.close()

View File

@ -107,4 +107,3 @@ class Silverware(Boxes):
self.moveTo(-3.0 * (l + 2 * t + 8 * b), h - 10 + 2 * t + 8 * b)
self.basePlate(x, y, r)
self.close()

View File

@ -97,5 +97,4 @@ class Stachel(Boxes):
self.layer(ri, ro, rp, True, move="up")
self.layer(ri, ro, rp, move="up")
self.close()

View File

@ -168,5 +168,4 @@ When turned by 90°, it can be also used to create a bottle holder."""
for i in range(n):
self.parts.disc(h-2*t, move="right")
self.close()

View File

@ -48,6 +48,5 @@ class TrayInsert(Boxes):
e = ["e", "e", edges.SlottedEdge(self, self.sx[::-1], "e", slots=0.5 * h), "e"]
self.rectangularWall(x, h, e, move="up")
self.close()

View File

@ -327,7 +327,6 @@ class TrayLayout2(TrayLayout):
if x < lx:
posx += self.x[x] + self.thickness
self.close()
def parse(self, input):
x = []

View File

@ -62,4 +62,3 @@ class TwoPiece(Boxes):
self.rectangularWall(x, y, "hhhh", bedBolts=None, move="right")
self.rectangularWall(x+d, y+d, "FFFF", bedBolts=None, move="right")
self.close()

View File

@ -148,6 +148,5 @@ class TypeTray(_TopEdge):
self.rectangularWall(y, hi, e, move="up")
self.close()

View File

@ -105,5 +105,4 @@ class UBox(_TopEdge, _ChestLid):
self.drawLid(x, h, self.top_edge)
self.drawAddOnLid(x, h, self.lid)
self.close()

View File

@ -112,6 +112,5 @@ class UnevenHeightBox(Boxes):
self.wall(x, h1, h0, "FFF", move="right" +
(" only" if h1 == h0 == 0.0 else ""))
self.close()

View File

@ -92,5 +92,4 @@ class UniversalBox(_TopEdge, _ChestLid):
self.rectangularWall(y, h, [b, "f", t4, "f"],
bedBolts=[d3], move="up")
self.close()

View File

@ -58,5 +58,4 @@ class WaivyKnob(Boxes):
move="right")
self.parts.waivyKnob(self.diameter, self.serrations, angle)
self.close()

View File

@ -131,5 +131,4 @@ class WineRack(Boxes):
self.partsMatrix(tc, cx, "up", self.rectangularWall, r-2*self.delta, h, "fefe")
self.close()

View File

@ -69,6 +69,7 @@ def run_generator(name, args):
box = generators[lower_name]()
box.parseArgs(args)
box.render()
box.close()
else:
msg = ('Unknown generator \'{}\'. Use boxes --list to get a list of '
'available commands.\n').format(name)

View File

@ -21,13 +21,13 @@
"import tempfile, os\n",
"\n",
"import sys\n",
"#sys.path.append('/PATH/TO/boxes') # uncomments and adjust if your Boxes.py copy in not in the Python path\n",
"#sys.path.append('..') # uncomments and adjust if your Boxes.py copy in not in the Python path\n",
"from boxes import *"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {
"scrolled": true
},
@ -36,7 +36,7 @@
"data": {
"image/svg+xml": [
"<svg height=\"210mm\" version=\"1.1\" viewBox=\"0 9790 170 210\" width=\"170mm\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"surface11\">\n",
"<g id=\"surface4\">\n",
"<path d=\"M 150 50.103125 L 0 50.103125 M 0 50.103125 L -3 50.103125 C -3.054688 50.103125 -3.101562 50.060156 -3.101562 50.001562 M -3.101562 50.001562 L -3.101562 50.001562 M -3.101562 50.001562 L -3.101562 37.001562 M -3.101562 37.001562 C -3.101562 36.946875 -3.058594 36.9 -3 36.9 M -3 36.9 L 0 36.9 C -0.0546875 36.9 -0.101562 36.942969 -0.101562 37.001562 M -0.101562 37.001562 L -0.101562 28.001562 C -0.101562 28.05625 -0.0585938 28.103125 0 28.103125 M 0 28.103125 L -3 28.103125 C -3.054688 28.103125 -3.101562 28.060156 -3.101562 28.001562 M -3.101562 28.001562 L -3.101562 22.001562 M -3.101562 22.001562 C -3.101562 21.946875 -3.058594 21.9 -3 21.9 M -3 21.9 L 0 21.9 C -0.0546875 21.9 -0.101562 21.942969 -0.101562 22.001562 M -0.101562 22.001562 L -0.101562 13.001562 C -0.101562 13.05625 -0.0585938 13.103125 0 13.103125 M 0 13.103125 L -3 13.103125 C -3.054688 13.103125 -3.101562 13.060156 -3.101562 13.001562 M -3.101562 13.001562 L -3.101562 0.0015625 M -3.101562 0.0015625 L -3.101562 -5.998438 C -3.101562 -6.053125 -3.058594 -6.1 -3 -6.1 M -3 -6.1 L 0 -6.1 M 0 0.0015625 \" style=\"fill:none;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" transform=\"matrix(-1,-0.000000000000000122,-0.000000000000000122,1,153.851562,9949.045313)\"/>\n",
"<path d=\"M 0 -0.000000000000028422 C 1.867188 -0.000000000000028422 1.867188 -2.796875 0 -2.796875 C -1.863281 -2.796875 -1.863281 -0.000000000000028422 0 -0.000000000000028422 \" style=\"fill:none;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;\" transform=\"matrix(-0.000000000000000184,-1,-1,0.000000000000000184,142.453125,9959.046875)\"/>\n",
"<path d=\"M 0 0 C -0.0546875 0 -0.101562 0.046875 -0.101562 0.101562 M -0.101562 0.101562 L -0.101562 -2.898438 C -0.101562 -2.84375 -0.0585938 -2.796875 0 -2.796875 M 0 -2.796875 L -9 -2.796875 C -8.945312 -2.796875 -8.898438 -2.839844 -8.898438 -2.898438 M -8.898438 -2.898438 L -8.898438 0.101562 C -8.898438 0.046875 -8.941406 0 -9 0 M -9 0 L 0 0 \" style=\"fill:none;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;\" transform=\"matrix(1,-0,-0,-1,143.351562,9946.046875)\"/>\n",
@ -107,15 +107,14 @@
" self.rectangularWall(x, h, \"eFhF\", move=\"up\", callback=[None, None, hole, hole]) # back board\n",
"\n",
" self.rectangularWall(x, y, \"ehfh\", move=\"up\") # top board\n",
" self.rectangularTriangle(y, h, \"ff\", num=2) # braces\n",
" self.rectangularTriangle(y, h, \"ff\", num=2) # braces \n",
" \n",
" \n",
" self.close()\n",
"\n",
"b = Example()\n",
"fd, fn = tempfile.mkstemp()\n",
"b.parseArgs(['--reference=0', '--debug=0', '--output=' + fn])\n",
"b.render()\n",
"b.close()\n",
"\n",
"display(SVG(fn))\n",
"os.close(fd)\n",
@ -146,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.6.8"
}
},
"nbformat": 4,

View File

@ -396,6 +396,7 @@ Create boxes and more with a laser cutter!
[('Content-type', 'application/unknown; charset=utf-8')]))
fd, box.output = tempfile.mkstemp()
box.render()
box.close()
result = open(box.output).readlines()
os.close(fd)
os.remove(box.output)