Put box generator into groups and adjust the menu web page accordingly
This commit is contained in:
parent
5a0f3d42ea
commit
d3c76f2b9e
|
@ -199,6 +199,7 @@ class Boxes:
|
||||||
"""Main class -- Generator should sub class this """
|
"""Main class -- Generator should sub class this """
|
||||||
|
|
||||||
webinterface = True
|
webinterface = True
|
||||||
|
ui_group = "Misc"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.formats = formats.Formats()
|
self.formats = formats.Formats()
|
||||||
|
|
|
@ -20,6 +20,8 @@ import math
|
||||||
class AngledBox(Boxes):
|
class AngledBox(Boxes):
|
||||||
"""Box with both ends cornered"""
|
"""Box with both ends cornered"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -46,6 +46,8 @@ class BinFrontSideEdge(BinFrontEdge):
|
||||||
class BinTray(Boxes):
|
class BinTray(Boxes):
|
||||||
"""A Type tray variant to be used up right with sloped walls in front"""
|
"""A Type tray variant to be used up right with sloped walls in front"""
|
||||||
|
|
||||||
|
ui_group = "Shelf"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.buildArgParser("sx", "sy", "h", "outside")
|
self.buildArgParser("sx", "sy", "h", "outside")
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
"""Fully closed box"""
|
"""Fully closed box"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -21,6 +21,8 @@ from boxes.lids import _TopEdge, _ChestLid
|
||||||
class Box2(_TopEdge, _ChestLid):
|
class Box2(_TopEdge, _ChestLid):
|
||||||
"""Box various options for different stypes and lids"""
|
"""Box various options for different stypes and lids"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addTopEdgeSettings()
|
self.addTopEdgeSettings()
|
||||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
||||||
class Box3(Boxes):
|
class Box3(Boxes):
|
||||||
"""Box with just 3 walls"""
|
"""Box with just 3 walls"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.buildArgParser("x", "y", "h", "outside")
|
self.buildArgParser("x", "y", "h", "outside")
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class Box4(Boxes):
|
class Box4(Boxes):
|
||||||
"""Box with lid and integraded hinge"""
|
"""Box with lid and integraded hinge"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
||||||
class Box5(Boxes):
|
class Box5(Boxes):
|
||||||
"""Box with lid attached by cabinet hinges"""
|
"""Box with lid attached by cabinet hinges"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
||||||
class DisplayShelf(Boxes): # change class name here and below
|
class DisplayShelf(Boxes): # change class name here and below
|
||||||
"""Shelf with forward slanted floors"""
|
"""Shelf with forward slanted floors"""
|
||||||
|
|
||||||
|
ui_group = "Shelf"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
class FlexBox(boxes.Boxes):
|
class FlexBox(boxes.Boxes):
|
||||||
"""Box with living hinge and round corners"""
|
"""Box with living hinge and round corners"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
boxes.Boxes.__init__(self)
|
boxes.Boxes.__init__(self)
|
||||||
self.addSettingsArgs(boxes.edges.FingerJointSettings)
|
self.addSettingsArgs(boxes.edges.FingerJointSettings)
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
class FlexBox2(Boxes):
|
class FlexBox2(Boxes):
|
||||||
"""Box with living hinge and top corners rounded"""
|
"""Box with living hinge and top corners rounded"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
class FlexBox3(Boxes):
|
class FlexBox3(Boxes):
|
||||||
"""Box with living hinge"""
|
"""Box with living hinge"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
class FlexBox4(Boxes):
|
class FlexBox4(Boxes):
|
||||||
"""Box with living hinge and left corners rounded"""
|
"""Box with living hinge and left corners rounded"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class FlexTest(Boxes):
|
class FlexTest(Boxes):
|
||||||
"Piece for testing different flex settings"
|
"Piece for testing different flex settings"
|
||||||
|
|
||||||
|
ui_group = "Part"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FlexSettings)
|
self.addSettingsArgs(edges.FlexSettings)
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class FlexTest2(Boxes):
|
class FlexTest2(Boxes):
|
||||||
"Piece for testing 2D flex settings"
|
"Piece for testing 2D flex settings"
|
||||||
|
|
||||||
|
ui_group = "Part"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.buildArgParser("x", "y")
|
self.buildArgParser("x", "y")
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class GearBox(Boxes):
|
class GearBox(Boxes):
|
||||||
"""Gearbox with multiple identical stages"""
|
"""Gearbox with multiple identical stages"""
|
||||||
|
|
||||||
|
ui_group = "Part"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -22,6 +22,8 @@ class Planetary(Boxes):
|
||||||
|
|
||||||
"""Planetary Gear with possibly multiple identical stages"""
|
"""Planetary Gear with possibly multiple identical stages"""
|
||||||
|
|
||||||
|
ui_group = "Part"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.argparser.add_argument(
|
self.argparser.add_argument(
|
||||||
|
|
|
@ -22,6 +22,8 @@ import math
|
||||||
class Pulley(Boxes):
|
class Pulley(Boxes):
|
||||||
"""Timing belt pulleys for different profiles"""
|
"""Timing belt pulleys for different profiles"""
|
||||||
|
|
||||||
|
ui_group = "Part"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
# remove cli params you do not need
|
# remove cli params you do not need
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class RegularBox(Boxes):
|
class RegularBox(Boxes):
|
||||||
"""Regular box"""
|
"""Regular box"""
|
||||||
|
|
||||||
|
ui_group = "Box"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class RoundedBox(Boxes):
|
class RoundedBox(Boxes):
|
||||||
"""Box with rounded corners"""
|
"""Box with rounded corners"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings)
|
||||||
|
|
|
@ -21,6 +21,8 @@ class Silverware(Boxes):
|
||||||
"""Not yet parametrized cuttlery stand with carrying grip
|
"""Not yet parametrized cuttlery stand with carrying grip
|
||||||
using flex for rounded corners"""
|
using flex for rounded corners"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
### Parts
|
### Parts
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class TrayInsert(Boxes):
|
class TrayInsert(Boxes):
|
||||||
"""Tray insert without floor and outer walls - allows only continuous walls"""
|
"""Tray insert without floor and outer walls - allows only continuous walls"""
|
||||||
|
|
||||||
|
ui_group = "Tray"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.buildArgParser("sx", "sy", "h", "outside")
|
self.buildArgParser("sx", "sy", "h", "outside")
|
||||||
|
|
|
@ -384,6 +384,8 @@ class TrayLayout(Layout):
|
||||||
|
|
||||||
webinterface = True
|
webinterface = True
|
||||||
|
|
||||||
|
ui_group = "Tray"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.argparser = boxes.ArgumentParser()
|
self.argparser = boxes.ArgumentParser()
|
||||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
||||||
class TypeTray(Boxes):
|
class TypeTray(Boxes):
|
||||||
"""Type tray - allows only continuous walls"""
|
"""Type tray - allows only continuous walls"""
|
||||||
|
|
||||||
|
ui_group = "Tray"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.buildArgParser("sx", "sy", "h", "hi", "outside")
|
self.buildArgParser("sx", "sy", "h", "hi", "outside")
|
||||||
|
|
|
@ -21,6 +21,8 @@ import math
|
||||||
class UBox(_TopEdge, _ChestLid):
|
class UBox(_TopEdge, _ChestLid):
|
||||||
"""Box various options for different stypes and lids"""
|
"""Box various options for different stypes and lids"""
|
||||||
|
|
||||||
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
self.addTopEdgeSettings()
|
self.addTopEdgeSettings()
|
||||||
|
|
|
@ -74,6 +74,12 @@ boxes.ArgumentParser = ThrowingArgumentParser # Evil hack
|
||||||
class BServer:
|
class BServer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface}
|
self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface}
|
||||||
|
self.groups = boxes.generators.ui_groups
|
||||||
|
self.groups_by_name = boxes.generators.ui_groups_by_name
|
||||||
|
|
||||||
|
for name, box in self.boxes.items():
|
||||||
|
self.groups_by_name.get(box.ui_group,
|
||||||
|
self.groups_by_name["Misc"]).add(box)
|
||||||
|
|
||||||
def arg2html(self, a, prefix):
|
def arg2html(self, a, prefix):
|
||||||
name = a.option_strings[0].replace("-", "")
|
name = a.option_strings[0].replace("-", "")
|
||||||
|
@ -104,17 +110,7 @@ class BServer:
|
||||||
|
|
||||||
return row % input
|
return row % input
|
||||||
|
|
||||||
def args2html(self, name, box, action=""):
|
scripts = """
|
||||||
result = ["""<html><head><title>Boxes - """, name, """</title>
|
|
||||||
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/4.1.1/normalize.css" type="text/css" />
|
|
||||||
<style>
|
|
||||||
|
|
||||||
""", css, """
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function showHide(id) {
|
function showHide(id) {
|
||||||
var e = document.getElementById(id);
|
var e = document.getElementById(id);
|
||||||
|
@ -125,11 +121,23 @@ class BServer:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function hideargs() {
|
function hideargs() {
|
||||||
for ( i=1; i<""" + str(len(box.argparser._action_groups)-2) + """; i++) {
|
for ( i=0; i<%i; i++) {
|
||||||
showHide(i);
|
showHide(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
|
def args2html(self, name, box, action=""):
|
||||||
|
result = ["""<html><head><title>Boxes - """, name, """</title>
|
||||||
|
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/4.1.1/normalize.css" type="text/css" />
|
||||||
|
<style>
|
||||||
|
|
||||||
|
""", css, """
|
||||||
|
|
||||||
|
</style>""", self.scripts % (len(box.argparser._action_groups)-3), """
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="hideargs()">
|
<body onload="hideargs()">
|
||||||
|
|
||||||
|
@ -156,16 +164,16 @@ class BServer:
|
||||||
""" % (action)]
|
""" % (action)]
|
||||||
groupid = 0
|
groupid = 0
|
||||||
for group in box.argparser._action_groups[3:] + box.argparser._action_groups[:3]:
|
for group in box.argparser._action_groups[3:] + box.argparser._action_groups[:3]:
|
||||||
groupid += 1
|
|
||||||
if not group._group_actions:
|
if not group._group_actions:
|
||||||
continue
|
continue
|
||||||
prefix = getattr(group, "prefix", None)
|
prefix = getattr(group, "prefix", None)
|
||||||
result.append('<h3 onclick="showHide(%s)">%s</h3>\n<table id="%s">\n' % (groupid, group.title, groupid))
|
result.append('''<h3 onclick="showHide(%s)">%s</h3>\n<table id="%s">\n''' % (groupid, group.title, groupid))
|
||||||
for a in group._group_actions:
|
for a in group._group_actions:
|
||||||
if a.dest in ("input", "output"):
|
if a.dest in ("input", "output"):
|
||||||
continue
|
continue
|
||||||
result.append(self.arg2html(a, prefix))
|
result.append(self.arg2html(a, prefix))
|
||||||
result.append("</table>")
|
result.append("</table>")
|
||||||
|
groupid += 1
|
||||||
result.append("""
|
result.append("""
|
||||||
<p><button name="render" value="1">Generate</button></p>
|
<p><button name="render" value="1">Generate</button></p>
|
||||||
</form>
|
</form>
|
||||||
|
@ -224,9 +232,9 @@ class BServer:
|
||||||
function changeback(img_link){
|
function changeback(img_link){
|
||||||
document.getElementById("sample").src= "examples/" + img + ".svg";
|
document.getElementById("sample").src= "examples/" + img + ".svg";
|
||||||
}
|
}
|
||||||
</script>
|
</script>""", self.scripts % len(self.groups), """
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body onload="hideargs()">
|
||||||
<div class="container" style="background-color: #FFF8EA;">
|
<div class="container" style="background-color: #FFF8EA;">
|
||||||
<div style="width: 70%; float: left;">
|
<div style="width: 70%; float: left;">
|
||||||
<h1>Boxes.py</h1>
|
<h1>Boxes.py</h1>
|
||||||
|
@ -250,21 +258,20 @@ flex cuts, holes and slots for screws and more high level functions.
|
||||||
|
|
||||||
|
|
||||||
<p>These are the available generators:</p>
|
<p>These are the available generators:</p>
|
||||||
<ul>
|
|
||||||
""" ]
|
""" ]
|
||||||
for name in sorted(self.boxes):
|
for nr, group in enumerate(self.groups):
|
||||||
|
result.append('''<h3 onclick="showHide('%s')">%s</h3>\n<div id="%s">\n<ul>\n''' % (nr, group.title, nr))
|
||||||
|
for box in group.generators:
|
||||||
|
name = box.__class__.__name__
|
||||||
if name in ("TrayLayout2", ):
|
if name in ("TrayLayout2", ):
|
||||||
continue
|
continue
|
||||||
box = self.boxes[name]
|
|
||||||
docs = ""
|
docs = ""
|
||||||
if box.__doc__:
|
if box.__doc__:
|
||||||
docs = " - " + box.__doc__
|
docs = " - " + box.__doc__
|
||||||
result.append(""" <li><a href="%s">%s</a>%s</li>""" % (
|
result.append(""" <li><a href="%s">%s</a>%s</li>\n""" % (
|
||||||
name, name, docs))
|
name, name, docs))
|
||||||
result.append("""</ul>
|
result.append("</ul>\n</div>\n")
|
||||||
|
result.append("""
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
Loading…
Reference in New Issue