2016-07-31 17:18:17 +02:00
|
|
|
import importlib
|
2022-12-31 15:52:55 +01:00
|
|
|
import inspect
|
|
|
|
import pkgutil
|
|
|
|
|
2016-07-31 17:18:17 +02:00
|
|
|
import boxes
|
2016-03-25 17:49:33 +01:00
|
|
|
|
2017-02-13 17:31:02 +01:00
|
|
|
ui_groups_by_name = {}
|
|
|
|
|
|
|
|
class UIGroup:
|
|
|
|
|
2021-06-05 18:22:05 +02:00
|
|
|
def __init__(self, name, title=None, description="", image=""):
|
2017-02-13 17:31:02 +01:00
|
|
|
self.name = name
|
|
|
|
self.title = title or name
|
|
|
|
self.description = description
|
2021-06-05 18:22:05 +02:00
|
|
|
self._image = image
|
2017-02-13 17:31:02 +01:00
|
|
|
self.generators = []
|
|
|
|
# register
|
|
|
|
ui_groups_by_name[name] = self
|
|
|
|
|
|
|
|
def add(self, box):
|
|
|
|
self.generators.append(box)
|
2017-03-19 07:34:06 +01:00
|
|
|
self.generators.sort(key=lambda b:getattr(b, '__name__', None) or b.__class__.__name__)
|
2017-02-13 17:31:02 +01:00
|
|
|
|
2021-06-05 18:22:05 +02:00
|
|
|
@property
|
|
|
|
def thumbnail(self):
|
|
|
|
return self._image and f"{self._image}-thumb.jpg"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def image(self):
|
|
|
|
return self._image and f"{self._image}.jpg"
|
|
|
|
|
2017-02-13 17:31:02 +01:00
|
|
|
ui_groups = [
|
2021-06-05 18:22:05 +02:00
|
|
|
UIGroup("Box", "Boxes", image="UniversalBox"),
|
|
|
|
UIGroup("FlexBox", "Boxes with flex", image="RoundedBox"),
|
|
|
|
UIGroup("Tray", "Trays and Drawer Inserts", image="TypeTray"),
|
|
|
|
UIGroup("Shelf", "Shelves", image="DisplayShelf"),
|
2022-02-20 21:18:28 +01:00
|
|
|
UIGroup("WallMounted", image="WallTypeTray"),
|
2021-06-05 18:22:05 +02:00
|
|
|
UIGroup("Holes", "Hole patterns", image=""),
|
|
|
|
UIGroup("Part", "Parts and Samples", image="BurnTest"),
|
|
|
|
UIGroup("Misc", image="TrafficLight"),
|
2017-02-15 15:55:01 +01:00
|
|
|
UIGroup("Unstable", description="Generators are still untested or need manual adjustment to be useful."),
|
2017-02-13 17:31:02 +01:00
|
|
|
]
|
|
|
|
|
2016-03-25 17:49:33 +01:00
|
|
|
def getAllBoxGenerators():
|
2016-07-31 17:18:17 +02:00
|
|
|
generators = {}
|
|
|
|
for importer, modname, ispkg in pkgutil.walk_packages(
|
|
|
|
path=__path__,
|
2017-12-19 19:36:37 +01:00
|
|
|
prefix=__name__+'.'):
|
2016-07-31 17:18:17 +02:00
|
|
|
module = importlib.import_module(modname)
|
2019-07-12 00:47:09 +02:00
|
|
|
if module.__name__.split('.')[-1].startswith("_"):
|
|
|
|
continue
|
2016-07-31 17:18:17 +02:00
|
|
|
for k, v in module.__dict__.items():
|
|
|
|
if v is boxes.Boxes:
|
|
|
|
continue
|
2017-02-12 22:20:32 +01:00
|
|
|
if (inspect.isclass(v) and issubclass(v, boxes.Boxes) and
|
|
|
|
v.__name__[0] != '_'):
|
2016-07-31 17:18:17 +02:00
|
|
|
generators[modname + '.' + v.__name__] = v
|
|
|
|
return generators
|
|
|
|
|
|
|
|
def getAllGeneratorModules():
|
|
|
|
generators = {}
|
|
|
|
for importer, modname, ispkg in pkgutil.walk_packages(
|
|
|
|
path=__path__,
|
|
|
|
prefix=__name__+'.',
|
|
|
|
onerror=lambda x: None):
|
|
|
|
module = importlib.import_module(modname)
|
|
|
|
generators[modname.split('.')[-1]] = module
|
|
|
|
return generators
|
|
|
|
|