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 """
|
||||
|
||||
webinterface = True
|
||||
ui_group = "Misc"
|
||||
|
||||
def __init__(self):
|
||||
self.formats = formats.Formats()
|
||||
|
|
|
@ -20,6 +20,8 @@ import math
|
|||
class AngledBox(Boxes):
|
||||
"""Box with both ends cornered"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -46,6 +46,8 @@ class BinFrontSideEdge(BinFrontEdge):
|
|||
class BinTray(Boxes):
|
||||
"""A Type tray variant to be used up right with sloped walls in front"""
|
||||
|
||||
ui_group = "Shelf"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("sx", "sy", "h", "outside")
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class Box(Boxes):
|
||||
"""Fully closed box"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -21,6 +21,8 @@ from boxes.lids import _TopEdge, _ChestLid
|
|||
class Box2(_TopEdge, _ChestLid):
|
||||
"""Box various options for different stypes and lids"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addTopEdgeSettings()
|
||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
|||
class Box3(Boxes):
|
||||
"""Box with just 3 walls"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y", "h", "outside")
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class Box4(Boxes):
|
||||
"""Box with lid and integraded hinge"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
|||
class Box5(Boxes):
|
||||
"""Box with lid attached by cabinet hinges"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -19,6 +19,8 @@ from boxes import *
|
|||
class DisplayShelf(Boxes): # change class name here and below
|
||||
"""Shelf with forward slanted floors"""
|
||||
|
||||
ui_group = "Shelf"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import math
|
|||
class FlexBox(boxes.Boxes):
|
||||
"""Box with living hinge and round corners"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
boxes.Boxes.__init__(self)
|
||||
self.addSettingsArgs(boxes.edges.FingerJointSettings)
|
||||
|
|
|
@ -21,6 +21,8 @@ import math
|
|||
class FlexBox2(Boxes):
|
||||
"""Box with living hinge and top corners rounded"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -21,6 +21,8 @@ import math
|
|||
class FlexBox3(Boxes):
|
||||
"""Box with living hinge"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -21,6 +21,8 @@ import math
|
|||
class FlexBox4(Boxes):
|
||||
"""Box with living hinge and left corners rounded"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class FlexTest(Boxes):
|
||||
"Piece for testing different flex settings"
|
||||
|
||||
ui_group = "Part"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FlexSettings)
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class FlexTest2(Boxes):
|
||||
"Piece for testing 2D flex settings"
|
||||
|
||||
ui_group = "Part"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("x", "y")
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class GearBox(Boxes):
|
||||
"""Gearbox with multiple identical stages"""
|
||||
|
||||
ui_group = "Part"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -22,6 +22,8 @@ class Planetary(Boxes):
|
|||
|
||||
"""Planetary Gear with possibly multiple identical stages"""
|
||||
|
||||
ui_group = "Part"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.argparser.add_argument(
|
||||
|
|
|
@ -22,6 +22,8 @@ import math
|
|||
class Pulley(Boxes):
|
||||
"""Timing belt pulleys for different profiles"""
|
||||
|
||||
ui_group = "Part"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
# remove cli params you do not need
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class RegularBox(Boxes):
|
||||
"""Regular box"""
|
||||
|
||||
ui_group = "Box"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class RoundedBox(Boxes):
|
||||
"""Box with rounded corners"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addSettingsArgs(edges.FingerJointSettings)
|
||||
|
|
|
@ -21,6 +21,8 @@ class Silverware(Boxes):
|
|||
"""Not yet parametrized cuttlery stand with carrying grip
|
||||
using flex for rounded corners"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
####################################################################
|
||||
### Parts
|
||||
####################################################################
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class TrayInsert(Boxes):
|
||||
"""Tray insert without floor and outer walls - allows only continuous walls"""
|
||||
|
||||
ui_group = "Tray"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("sx", "sy", "h", "outside")
|
||||
|
|
|
@ -384,6 +384,8 @@ class TrayLayout(Layout):
|
|||
|
||||
webinterface = True
|
||||
|
||||
ui_group = "Tray"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.argparser = boxes.ArgumentParser()
|
||||
|
|
|
@ -20,6 +20,8 @@ from boxes import *
|
|||
class TypeTray(Boxes):
|
||||
"""Type tray - allows only continuous walls"""
|
||||
|
||||
ui_group = "Tray"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.buildArgParser("sx", "sy", "h", "hi", "outside")
|
||||
|
|
|
@ -21,6 +21,8 @@ import math
|
|||
class UBox(_TopEdge, _ChestLid):
|
||||
"""Box various options for different stypes and lids"""
|
||||
|
||||
ui_group = "FlexBox"
|
||||
|
||||
def __init__(self):
|
||||
Boxes.__init__(self)
|
||||
self.addTopEdgeSettings()
|
||||
|
|
|
@ -74,6 +74,12 @@ boxes.ArgumentParser = ThrowingArgumentParser # Evil hack
|
|||
class BServer:
|
||||
def __init__(self):
|
||||
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):
|
||||
name = a.option_strings[0].replace("-", "")
|
||||
|
@ -103,20 +109,10 @@ class BServer:
|
|||
(name, a.default)
|
||||
|
||||
return row % input
|
||||
|
||||
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>
|
||||
|
||||
|
||||
|
||||
scripts = """
|
||||
<script type="text/javascript">
|
||||
function showHide(id) {
|
||||
function showHide(id) {
|
||||
var e = document.getElementById(id);
|
||||
if(e.style.display == null || e.style.display == "none") {
|
||||
e.style.display = "block";
|
||||
|
@ -125,10 +121,22 @@ class BServer:
|
|||
}
|
||||
}
|
||||
function hideargs() {
|
||||
for ( i=1; i<""" + str(len(box.argparser._action_groups)-2) + """; i++) {
|
||||
for ( i=0; i<%i; i++) {
|
||||
showHide(i);
|
||||
}
|
||||
}
|
||||
</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>
|
||||
<body onload="hideargs()">
|
||||
|
@ -156,16 +164,16 @@ class BServer:
|
|||
""" % (action)]
|
||||
groupid = 0
|
||||
for group in box.argparser._action_groups[3:] + box.argparser._action_groups[:3]:
|
||||
groupid += 1
|
||||
if not group._group_actions:
|
||||
continue
|
||||
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:
|
||||
if a.dest in ("input", "output"):
|
||||
continue
|
||||
result.append(self.arg2html(a, prefix))
|
||||
result.append("</table>")
|
||||
groupid += 1
|
||||
result.append("""
|
||||
<p><button name="render" value="1">Generate</button></p>
|
||||
</form>
|
||||
|
@ -224,9 +232,9 @@ class BServer:
|
|||
function changeback(img_link){
|
||||
document.getElementById("sample").src= "examples/" + img + ".svg";
|
||||
}
|
||||
</script>
|
||||
</script>""", self.scripts % len(self.groups), """
|
||||
</head>
|
||||
<body>
|
||||
<body onload="hideargs()">
|
||||
<div class="container" style="background-color: #FFF8EA;">
|
||||
<div style="width: 70%; float: left;">
|
||||
<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>
|
||||
<ul>
|
||||
""" ]
|
||||
for name in sorted(self.boxes):
|
||||
if name in ("TrayLayout2", ):
|
||||
continue
|
||||
box = self.boxes[name]
|
||||
docs = ""
|
||||
if box.__doc__:
|
||||
docs = " - " + box.__doc__
|
||||
result.append(""" <li><a href="%s">%s</a>%s</li>""" % (
|
||||
name, name, docs))
|
||||
result.append("""</ul>
|
||||
|
||||
|
||||
|
||||
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", ):
|
||||
continue
|
||||
docs = ""
|
||||
if box.__doc__:
|
||||
docs = " - " + box.__doc__
|
||||
result.append(""" <li><a href="%s">%s</a>%s</li>\n""" % (
|
||||
name, name, docs))
|
||||
result.append("</ul>\n</div>\n")
|
||||
result.append("""
|
||||
</div>
|
||||
|
||||
<!--
|
||||
|
|
Loading…
Reference in New Issue