__init__.py 3.6 KB

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