__init__.py 1.8 KB

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