__init__.py 1.8 KB

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