__init__.py 1.9 KB

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