Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
run pre-commit
  • Loading branch information
florianfesti committed Mar 22, 2024
1 parent d01f8bf commit eae0e7b
Show file tree
Hide file tree
Showing 177 changed files with 581 additions and 636 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cd ../build/ && ls && ls html/
cp -r ../../static .
rm -rf doctrees
touch .nojekyll
touch .nojekyll
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ include examples/*.svg
include documentation/presentation.odp
include inkex/*.txt
include po/*
include scripts/boxes2pot scripts/boxes2inkscape scripts/boxes_proxy.py
include scripts/boxes2pot scripts/boxes2inkscape scripts/boxes_proxy.py
15 changes: 5 additions & 10 deletions boxes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import argparse
import copy
import gettext
import math
import random
import re
Expand All @@ -28,20 +29,14 @@
from typing import Any
from xml.sax.saxutils import quoteattr

import qrcode
from shapely.geometry import *
from shapely.ops import split
import gettext

from boxes import edges
from boxes import formats
from boxes import gears
from boxes import parts
from boxes import pulley
from boxes import edges, formats, gears, parts, pulley
from boxes.Color import *
from boxes.vectors import kerf

import qrcode
from boxes.qrcode_factory import BoxesQrCodeFactory
from boxes.vectors import kerf

### Helpers

Expand Down Expand Up @@ -413,7 +408,7 @@ def open(self):
if self.qr_code:
self.renderQrCode()
self.ctx.stroke()

def renderQrCode(self):
content = self.metadata['url_short'] or self.metadata["cli_short"]
size = 1.5
Expand Down
20 changes: 10 additions & 10 deletions boxes/drawing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import codecs
import datetime
import math
import io
import codecs
import math
from typing import Any
from xml.etree import ElementTree as ET

Expand Down Expand Up @@ -519,7 +519,7 @@ def finish(self, inner_corners="loop"):
tree = ET.ElementTree(svg)

self._add_metadata(svg)

for i, part in enumerate(self.parts):
if not part.pathes:
continue
Expand Down Expand Up @@ -789,7 +789,7 @@ def finish(self, inner_corners="loop"):

tree = ET.ElementTree(svg)
if self.dbg: print ("8", num)

cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="3") # green layer (ETCHING)
name = ET.SubElement(cs, "name", Value="Etch")
Expand Down Expand Up @@ -829,7 +829,7 @@ def finish(self, inner_corners="loop"):
index = ET.SubElement(cs, "index", Value="30") # T1 layer (ANNOTATIONS)
name = ET.SubElement(cs, "name", Value="T1") # tool layer do not support names
priority = ET.SubElement(cs, "priority", Value="7") # is not cut at all

for i, part in enumerate(self.parts):
if self.dbg: print ("7", num)
if not part.pathes:
Expand All @@ -840,7 +840,7 @@ def finish(self, inner_corners="loop"):
children = ET.SubElement(gp, "Children")
children.text = "\n "
children.tail = "\n"

for j, path in enumerate(part.pathes):
myColor = self.lbrn2_colors[4*int(path.params["rgb"][0])+2*int(path.params["rgb"][1])+int(path.params["rgb"][2])]

Expand All @@ -858,7 +858,7 @@ def finish(self, inner_corners="loop"):
print ("6",num, c)
num += 1
num = 0

c = path.path[num]
C, x, y = c[0:3]
if self.dbg:
Expand Down Expand Up @@ -917,7 +917,7 @@ def finish(self, inner_corners="loop"):
print("unknown", c)
if done == False:
x0, y0 = x, y

if start and points_equal(start[1], start[2], x0, y0):
if bspline == False:
pl.text = "LineClosed"
Expand Down Expand Up @@ -947,7 +947,7 @@ def finish(self, inner_corners="loop"):
else:
hor = '0'
ver = 1 # vertical is always bottom, text is shifted in box class

pos = text.find('%')
offs = 0
if pos >- 1:
Expand Down Expand Up @@ -997,7 +997,7 @@ def finish(self, inner_corners="loop"):
num += 1

url = self.metadata["url"].replace("&render=1", "") # remove render argument to get web form again

pl = ET.SubElement(svg, "Notes", ShowOnLoad="1", Notes="File created by Boxes.py script, programmed by Florian Festi.\nLightburn output by Klaus Steinhammer.\n\nURL with settings:\n" + str(url))
pl.text = ""
pl.tail = "\n"
Expand Down
4 changes: 2 additions & 2 deletions boxes/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


import io
import os
import shutil
import subprocess
import io
import tempfile

from boxes.drawing import SVGSurface, PSSurface, LBRN2Surface, Context
from boxes.drawing import Context, LBRN2Surface, PSSurface, SVGSurface


class Formats:
Expand Down
38 changes: 19 additions & 19 deletions boxes/gears.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
# AttributeError: 'module' object inkex has no attribute 'uutounit
# Fixed https://github.com/jnweiger/inkscape-gears-dev

from math import pi, cos, sin, tan, radians, degrees, ceil, asin, acos, sqrt
from math import acos, asin, ceil, cos, degrees, pi, radians, sin, sqrt, tan
from os import devnull # for debugging

two_pi = 2 * pi
import argparse
from boxes.vectors import kerf, vdiff, vlength

from boxes.vectors import vdiff, vlength

__version__ = '0.9'

Expand Down Expand Up @@ -99,7 +100,7 @@ def have_undercut(teeth, pitch_angle=20.0, k=1.0):
## gather all basic gear calculations in one place
def gear_calculations(num_teeth, circular_pitch, pressure_angle, clearance=0, ring_gear=False, profile_shift=0.):
""" Put base calcs for spur/ring gears in one place.
- negative profile shifting helps against undercut.
- negative profile shifting helps against undercut.
"""
diametral_pitch = pi / circular_pitch
pitch_diameter = num_teeth / diametral_pitch
Expand Down Expand Up @@ -134,7 +135,7 @@ def generate_rack_points(tooth_count, pitch, addendum, pressure_angle,
- involute on a circle of infinite radius is a simple linear ramp
- the meshing circle touches at y = 0,
- the meshing circle touches at y = 0,
- the highest elevation of the teeth is at y = +addendum
- the lowest elevation of the teeth is at y = -addendum-clearance
- the base_height extends downwards from the lowest elevation.
Expand Down Expand Up @@ -171,7 +172,7 @@ def generate_rack_points(tooth_count, pitch, addendum, pressure_angle,
points.append((x-tasc, base_top))
points.append((x+tas, -addendum))
points.append((x+spacing-tas, -addendum))
points.append((x+spacing+tasc, base_top))
points.append((x+spacing+tasc, base_top))
x += pitch

# add base on RHS
Expand Down Expand Up @@ -215,7 +216,7 @@ def generate_spur_points(teeth, base_radius, pitch_radius, outer_radius, root_ra

pitch2 = c + half_thick_angle
base2 = pitch2 + pitch_to_base_angle
offsetangles2 = [ base2 - x for x in angles]
offsetangles2 = [ base2 - x for x in angles]
points2 = [ point_on_circle( radii[i], offsetangles2[i]) for i in range(0,len(radii)) ]

points_on_outer_radius = [ point_on_circle(outer_radius, x) for x in linspace(offsetangles1[-1], offsetangles2[-1], accuracy_circular) ]
Expand Down Expand Up @@ -274,7 +275,7 @@ def __init__(self, boxes, **kw) -> None:
help="Number of teeth")

self.OptionParser.add_option("-s", "--system",
action="store", type="string",
action="store", type="string",
dest="system", default='MM',
help="Select system: 'CP' (Cyclic Pitch (default)), 'DP' (Diametral Pitch), 'MM' (Metric Module)")

Expand Down Expand Up @@ -310,7 +311,7 @@ def __init__(self, boxes, **kw) -> None:
help="Clearance between bottom of gap of this gear and top of tooth of another")

self.OptionParser.add_option("", "--annotation",
action="store", type="inkbool",
action="store", type="inkbool",
dest="annotation", default=False,
help="Draw annotation text")

Expand Down Expand Up @@ -350,7 +351,7 @@ def __init__(self, boxes, **kw) -> None:
help="Active tab. Not used now.")

self.OptionParser.add_option("-x", "--centercross",
action="store", type="inkbool",
action="store", type="inkbool",
dest="centercross", default=False,
help="Draw cross in center")

Expand All @@ -360,7 +361,7 @@ def __init__(self, boxes, **kw) -> None:
help="Draw pitch circle (for mating)")

self.OptionParser.add_option("-r", "--draw-rack",
action="store", type="inkbool",
action="store", type="inkbool",
dest="drawrack", default=False,
help="Draw rack gear instead of spur gear")

Expand All @@ -380,7 +381,7 @@ def __init__(self, boxes, **kw) -> None:
help="Length of tabs on ends of rack")

self.OptionParser.add_option("", "--undercut-alert",
action="store", type="inkbool",
action="store", type="inkbool",
dest="undercut_alert", default=False,
help="Let the user confirm a warning dialog if undercut occurs. This dialog also shows helpful hints against undercut")

Expand All @@ -389,7 +390,7 @@ def calc_circular_pitch(self):
dimension = self.options.dimension
if self.options.system == 'CP': # circular pitch
circular_pitch = dimension * 25.4
elif self.options.system == 'DP': # diametral pitch
elif self.options.system == 'DP': # diametral pitch
circular_pitch = pi * 25.4 / dimension
elif self.options.system == 'MM': # module (metric)
circular_pitch = pi * dimension
Expand Down Expand Up @@ -539,26 +540,26 @@ def gearCarrier(self, r, spoke_width, positions, mount_radius, mount_hole, circl

self.boxes.moveTo(r+0.5*spoke_width+self.boxes.burn, 0, 90)
self.boxes.corner(360, r+0.5*spoke_width)

self.boxes.ctx.restore()
self.boxes.move(width, width, move)

def __call__(self, teeth_only=False, move="", callback=None, **kw):
""" Calculate Gear factors from inputs.
- Make list of radii, angles, and centers for each tooth and
- Make list of radii, angles, and centers for each tooth and
iterate through them
- Turn on other visual features e.g. cross, rack, annotations, etc
"""
self.options = self.OptionParser.parse_args([f"--{name}={value}" for name, value in kw.items()])

warnings = [] # list of extra messages to be shown in annotations
# calculate unit factor for units defined in dialog.
# calculate unit factor for units defined in dialog.
unit_factor = 1
# User defined options
teeth = self.options.teeth
# Angle of tangent to tooth at circular pitch wrt radial line.
angle = self.options.angle
# Clearance: Radial distance between top of tooth on one gear to
angle = self.options.angle
# Clearance: Radial distance between top of tooth on one gear to
# bottom of gap on another.
clearance = self.options.clearance * unit_factor
mount_hole = self.options.mount_hole * unit_factor
Expand All @@ -575,7 +576,7 @@ def __call__(self, teeth_only=False, move="", callback=None, **kw):
accuracy_involute = 20 # Number of points of the involute curve
accuracy_circular = 9 # Number of points on circular parts
if self.options.accuracy is not None:
if self.options.accuracy == 0:
if self.options.accuracy == 0:
# automatic
if teeth < 10: accuracy_involute = 20
elif teeth < 30: accuracy_involute = 12
Expand Down Expand Up @@ -706,4 +707,3 @@ def __call__(self, teeth_only=False, move="", callback=None, **kw):

if not teeth_only:
self.boxes.move(width, height, move)

2 changes: 1 addition & 1 deletion boxes/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import importlib
import inspect
import pkgutil
import os
import pkgutil
from types import ModuleType
from typing import Any

Expand Down
1 change: 1 addition & 0 deletions boxes/generators/_swtemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from boxes import *


class SlatwallXXX(Boxes): # Change class name!
"""DESCRIPTION"""

Expand Down
2 changes: 1 addition & 1 deletion boxes/generators/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from boxes import *


class BOX(Boxes): # Change class name!
"""DESCRIPTION"""

Expand Down Expand Up @@ -58,4 +59,3 @@ def render(self):
self.addPart(p)

# render your parts here

5 changes: 2 additions & 3 deletions boxes/generators/abox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from boxes import *
from boxes.lids import LidSettings


class ABox(Boxes):
"""A simple Box"""

description = "This box is kept simple on purpose. If you need more features have a look at the UniversalBox."

ui_group = "Box"

def __init__(self) -> None:
Expand Down Expand Up @@ -58,5 +59,3 @@ def render(self):
ignore_widths=[1, 6], move="up")
self.rectangularWall(y, h, [b, "f", t4, "f"],
ignore_widths=[1, 6], move="up")


6 changes: 2 additions & 4 deletions boxes/generators/agricolainsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
from functools import partial

from boxes import Boxes, edges
from .dividertray import (
SlotDescriptionsGenerator,
DividerSlotsEdge,
)

from .dividertray import DividerSlotsEdge, SlotDescriptionsGenerator


class AgricolaInsert(Boxes):
Expand Down
Loading

0 comments on commit eae0e7b

Please sign in to comment.