Make Traylayout work without main function

This commit is contained in:
Florian Festi 2017-03-22 22:01:47 +01:00
parent 5b9c8e4d71
commit b63dcfeee6
2 changed files with 46 additions and 53 deletions

View File

@ -17,30 +17,28 @@
import sys, re
from boxes import *
import boxes
import argparse
class Layout(Boxes):
class TrayLayout(Boxes):
"""Generate a typetray from a layout file"""
webinterface = False
webinterface = True
ui_group = "Tray"
def __init__(self, input=None, webargs=False):
Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.buildArgParser("h", "hi", "outside")
if not webargs:
self.argparser.add_argument(
"--input", action="store", type=argparse.FileType('r'),
help="layout file")
self.argparser.add_argument(
"--x", action="store", type=int, default=None,
help="number of compartments side by side")
self.argparser.add_argument(
"--y", action="store", type=int, default=None,
help="number of compartments back to front")
else:
self.argparser.add_argument(
"--layout", action="store", type=str)
self.argparser = argparse.ArgumentParser()
self.argparser.add_argument(
"--x", action="store", type=int, default=2,
help="number of compartments side by side")
self.argparser.add_argument(
"--y", action="store", type=int, default=2,
help="number of compartments back to front")
self.argparser.add_argument(
"--output", action="store", type=str, default="traylayout.txt",
help="name of the layout text file")
def fillDefault(self, x, y):
self.x = [0.0] * x
@ -64,6 +62,30 @@ class Layout(Boxes):
return "".join(r)
def render(self):
self.fillDefault(self.x, self.y)
with open(self.output, 'w') as f:
f.write(str(self))
class TrayLayout2(TrayLayout):
"""Generate a typetray from a layout file"""
webinterface = True
def __init__(self, input=None, webargs=False):
Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.buildArgParser("h", "hi", "outside")
if not webargs:
self.argparser.add_argument(
"--input", action="store", type=argparse.FileType('r'),
default='traylayout.txt',
help="layout file")
self.layout = None
else:
self.argparser.add_argument(
"--layout", action="store", type=str)
def vWalls(self, x, y):
"Number of vertical walls at a crossing"
result = 0
@ -101,6 +123,12 @@ class Layout(Boxes):
edge(length)
def render(self):
if self.layout:
self.parse(self.layout.split('\n'))
else:
self.parse(self.input)
if self.outside:
self.x = self.adjustSize(self.x)
self.y = self.adjustSize(self.y)
@ -377,39 +405,3 @@ class Layout(Boxes):
self.hwalls = hwalls
self.vwalls = vwalls
self.floors = floors
class TrayLayout(Layout):
"""Type tray with each wall and floor tile being optional"""
webinterface = True
ui_group = "Tray"
def __init__(self):
Boxes.__init__(self)
self.argparser = boxes.ArgumentParser()
self.argparser.add_argument(
"--x", action="store", type=int, default=2,
help="number of compartments side by side")
self.argparser.add_argument(
"--y", action="store", type=int, default=2,
help="number of compartments back to front")
def render(self):
return
class TrayLayout2(Layout):
"""Generate a typetray from a layout file"""
webinterface = True
def __init__(self, input=None):
Boxes.__init__(self)
self.addSettingsArgs(boxes.edges.FingerJointSettings)
self.buildArgParser("h", "hi", "outside")
self.argparser.add_argument(
"--layout", action="store", type=str)

View File

@ -89,6 +89,7 @@ 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.boxes['TrayLayout2'] = boxes.generators.traylayout.TrayLayout2(self, webargs=True)
self.groups = boxes.generators.ui_groups
self.groups_by_name = boxes.generators.ui_groups_by_name