2016-07-31 17:18:17 +02:00
|
|
|
import pkgutil
|
|
|
|
import inspect
|
|
|
|
import importlib
|
|
|
|
import boxes
|
2016-03-25 17:49:33 +01:00
|
|
|
|
2017-02-13 17:31:02 +01:00
|
|
|
ui_groups_by_name = {}
|
|
|
|
|
|
|
|
class UIGroup:
|
|
|
|
|
|
|
|
def __init__(self, name, title=None, description=""):
|
|
|
|
self.name = name
|
|
|
|
self.title = title or name
|
|
|
|
self.description = description
|
|
|
|
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
|
|
|
|
|
|
|
ui_groups = [
|
|
|
|
UIGroup("Box", "Boxes"),
|
|
|
|
UIGroup("FlexBox", "Boxes with flex"),
|
|
|
|
UIGroup("Tray", "Trays and Drawer Inserts"),
|
|
|
|
UIGroup("Shelf", "Shelves"),
|
|
|
|
UIGroup("Part", "Parts and Samples"),
|
|
|
|
UIGroup("Misc"),
|
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__,
|
|
|
|
prefix=__name__+'.',
|
|
|
|
onerror=lambda x: None):
|
|
|
|
module = importlib.import_module(modname)
|
|
|
|
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
|
|
|
|
|