__init__.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import pkgutil
  2. import inspect
  3. import sys
  4. # allowed command modules
  5. import tclCommands.TclCommandExteriors
  6. import tclCommands.TclCommandInteriors
  7. import tclCommands.TclCommandAddPolygon
  8. import tclCommands.TclCommandAddPolyline
  9. __all__=[]
  10. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  11. module = loader.find_module(name).load_module(name)
  12. __all__.append(name)
  13. def register_all_commands(app, commands):
  14. """
  15. Static method which register all known commands.
  16. Command should be for now in directory tclCommands and module should start with TCLCommand
  17. Class have to follow same name as module.
  18. we need import all modules in top section:
  19. import tclCommands.TclCommandExteriors
  20. at this stage we can include only wanted commands with this, autoloading may be implemented in future
  21. I have no enought knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  22. :param app: FlatCAMApp
  23. :param commands: array of commands which should be modified
  24. :return: None
  25. """
  26. tcl_modules = {k: v for k, v in sys.modules.items() if k.startswith('tclCommands.TclCommand')}
  27. for key, module in tcl_modules.items():
  28. if key != 'tclCommands.TclCommand':
  29. classname = key.split('.')[1]
  30. class_ = getattr(module, classname)
  31. commandInstance=class_(app)
  32. for alias in commandInstance.aliases:
  33. commands[alias]={
  34. 'fcn': commandInstance.execute_wrapper,
  35. 'help': commandInstance.get_decorated_help()
  36. }