__init__.py 1.5 KB

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