__init__.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.TclCommandFollow
  19. import tclCommands.TclCommandGeoCutout
  20. import tclCommands.TclCommandGeoUnion
  21. import tclCommands.TclCommandGetNames
  22. import tclCommands.TclCommandGetSys
  23. import tclCommands.TclCommandImportSvg
  24. import tclCommands.TclCommandInteriors
  25. import tclCommands.TclCommandIsolate
  26. import tclCommands.TclCommandJoinExcellon
  27. import tclCommands.TclCommandJoinGeometry
  28. import tclCommands.TclCommandListSys
  29. import tclCommands.TclCommandMillHoles
  30. import tclCommands.TclCommandMirror
  31. import tclCommands.TclCommandNew
  32. import tclCommands.TclCommandNewGeometry
  33. import tclCommands.TclCommandOffset
  34. import tclCommands.TclCommandOpenExcellon
  35. import tclCommands.TclCommandOpenGCode
  36. import tclCommands.TclCommandOpenGerber
  37. import tclCommands.TclCommandOpenProject
  38. import tclCommands.TclCommandOptions
  39. import tclCommands.TclCommandPaint
  40. import tclCommands.TclCommandPanelize
  41. import tclCommands.TclCommandPlot
  42. import tclCommands.TclCommandSaveProject
  43. import tclCommands.TclCommandScale
  44. import tclCommands.TclCommandSetActive
  45. import tclCommands.TclCommandSetSys
  46. import tclCommands.TclCommandSubtractPoly
  47. import tclCommands.TclCommandSubtractRectangle
  48. import tclCommands.TclCommandVersion
  49. import tclCommands.TclCommandWriteGCode
  50. __all__ = []
  51. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  52. module = loader.find_module(name).load_module(name)
  53. __all__.append(name)
  54. def register_all_commands(app, commands):
  55. """
  56. Static method which registers all known commands.
  57. Command should be for now in directory tclCommands and module should start with TCLCommand
  58. Class have to follow same name as module.
  59. we need import all modules in top section:
  60. import tclCommands.TclCommandExteriors
  61. at this stage we can include only wanted commands with this, auto loading may be implemented in future
  62. I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  63. :param app: FlatCAMApp
  64. :param commands: List of commands being updated
  65. :return: None
  66. """
  67. tcl_modules = {k: v for k, v in list(sys.modules.items()) if k.startswith('tclCommands.TclCommand')}
  68. for key, mod in list(tcl_modules.items()):
  69. if key != 'tclCommands.TclCommand':
  70. class_name = key.split('.')[1]
  71. class_type = getattr(mod, class_name)
  72. command_instance = class_type(app)
  73. for alias in command_instance.aliases:
  74. commands[alias] = {
  75. 'fcn': command_instance.execute_wrapper,
  76. 'help': command_instance.get_decorated_help()
  77. }