__init__.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import pkgutil
  2. import sys
  3. # Todo: I think these imports are not needed.
  4. # allowed command modules (please append them alphabetically ordered)
  5. import tclCommands.TclCommandAddCircle
  6. import tclCommands.TclCommandAddPolygon
  7. import tclCommands.TclCommandAddPolyline
  8. import tclCommands.TclCommandAddRectangle
  9. import tclCommands.TclCommandAlignDrill
  10. import tclCommands.TclCommandAlignDrillGrid
  11. import tclCommands.TclCommandCncjob
  12. import tclCommands.TclCommandCutout
  13. import tclCommands.TclCommandDelete
  14. import tclCommands.TclCommandDrillcncjob
  15. import tclCommands.TclCommandExportGcode
  16. import tclCommands.TclCommandExportSVG
  17. import tclCommands.TclCommandExteriors
  18. import tclCommands.TclCommandGeoCutout
  19. import tclCommands.TclCommandGeoUnion
  20. import tclCommands.TclCommandGetNames
  21. import tclCommands.TclCommandImportSvg
  22. import tclCommands.TclCommandInteriors
  23. import tclCommands.TclCommandIsolate
  24. import tclCommands.TclCommandJoinExcellon
  25. import tclCommands.TclCommandJoinGeometry
  26. import tclCommands.TclCommandMillHoles
  27. import tclCommands.TclCommandMirror
  28. import tclCommands.TclCommandNew
  29. import tclCommands.TclCommandNewGeometry
  30. import tclCommands.TclCommandOffset
  31. import tclCommands.TclCommandOpenExcellon
  32. import tclCommands.TclCommandOpenGCode
  33. import tclCommands.TclCommandOpenGerber
  34. import tclCommands.TclCommandOpenProject
  35. import tclCommands.TclCommandOptions
  36. import tclCommands.TclCommandPaint
  37. import tclCommands.TclCommandPanelize
  38. import tclCommands.TclCommandPlot
  39. import tclCommands.TclCommandSaveProject
  40. import tclCommands.TclCommandScale
  41. import tclCommands.TclCommandSetActive
  42. import tclCommands.TclCommandSubtractPoly
  43. import tclCommands.TclCommandSubtractRectangle
  44. import tclCommands.TclCommandWriteGCode
  45. __all__ = []
  46. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  47. module = loader.find_module(name).load_module(name)
  48. __all__.append(name)
  49. def register_all_commands(app, commands):
  50. """
  51. Static method which registers all known commands.
  52. Command should be for now in directory tclCommands and module should start with TCLCommand
  53. Class have to follow same name as module.
  54. we need import all modules in top section:
  55. import tclCommands.TclCommandExteriors
  56. at this stage we can include only wanted commands with this, auto loading may be implemented in future
  57. I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  58. :param app: FlatCAMApp
  59. :param commands: array of commands which should be modified
  60. :return: None
  61. """
  62. tcl_modules = {k: v for k, v in sys.modules.items() if k.startswith('tclCommands.TclCommand')}
  63. for key, mod in tcl_modules.items():
  64. if key != 'tclCommands.TclCommand':
  65. class_name = key.split('.')[1]
  66. class_type = getattr(mod, class_name)
  67. command_instance = class_type(app)
  68. for alias in command_instance.aliases:
  69. commands[alias] = {
  70. 'fcn': command_instance.execute_wrapper,
  71. 'help': command_instance.get_decorated_help()
  72. }