__init__.py 1.9 KB

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