__init__.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import pkgutil
  2. import sys
  3. # allowed command modules (please append them alphabetically ordered)
  4. import tclCommands.TclCommandAddCircle
  5. import tclCommands.TclCommandAddPolygon
  6. import tclCommands.TclCommandAddPolyline
  7. import tclCommands.TclCommandAddRectangle
  8. import tclCommands.TclCommandAlignDrill
  9. import tclCommands.TclCommandAlignDrillGrid
  10. import tclCommands.TclCommandBbox
  11. import tclCommands.TclCommandBounds
  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.TclCommandExportDXF
  19. import tclCommands.TclCommandExportExcellon
  20. import tclCommands.TclCommandExportGerber
  21. import tclCommands.TclCommandExportGcode
  22. import tclCommands.TclCommandExportSVG
  23. import tclCommands.TclCommandExteriors
  24. import tclCommands.TclCommandGeoCutout
  25. import tclCommands.TclCommandGeoUnion
  26. import tclCommands.TclCommandGetNames
  27. import tclCommands.TclCommandGetSys
  28. import tclCommands.TclCommandHelp
  29. import tclCommands.TclCommandImportSvg
  30. import tclCommands.TclCommandInteriors
  31. import tclCommands.TclCommandIsolate
  32. import tclCommands.TclCommandFollow
  33. import tclCommands.TclCommandJoinExcellon
  34. import tclCommands.TclCommandJoinGeometry
  35. import tclCommands.TclCommandListSys
  36. import tclCommands.TclCommandMillDrills
  37. import tclCommands.TclCommandMillSlots
  38. import tclCommands.TclCommandMirror
  39. import tclCommands.TclCommandNew
  40. import tclCommands.TclCommandNregions
  41. import tclCommands.TclCommandNewExcellon
  42. import tclCommands.TclCommandNewGeometry
  43. import tclCommands.TclCommandNewGerber
  44. import tclCommands.TclCommandOffset
  45. import tclCommands.TclCommandOpenExcellon
  46. import tclCommands.TclCommandOpenGCode
  47. import tclCommands.TclCommandOpenGerber
  48. import tclCommands.TclCommandOpenProject
  49. import tclCommands.TclCommandOptions
  50. import tclCommands.TclCommandPaint
  51. import tclCommands.TclCommandPanelize
  52. import tclCommands.TclCommandPlotAll
  53. import tclCommands.TclCommandPlotObjects
  54. import tclCommands.TclCommandQuit
  55. import tclCommands.TclCommandSaveProject
  56. import tclCommands.TclCommandSaveSys
  57. import tclCommands.TclCommandScale
  58. import tclCommands.TclCommandSetActive
  59. import tclCommands.TclCommandSetOrigin
  60. import tclCommands.TclCommandSetSys
  61. import tclCommands.TclCommandSkew
  62. import tclCommands.TclCommandSubtractPoly
  63. import tclCommands.TclCommandSubtractRectangle
  64. import tclCommands.TclCommandVersion
  65. import tclCommands.TclCommandWriteGCode
  66. __all__ = []
  67. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  68. module = loader.find_module(name).load_module(name)
  69. __all__.append(name)
  70. def register_all_commands(app, commands):
  71. """
  72. Static method which registers all known commands.
  73. Command should be for now in directory tclCommands and module should start with TCLCommand
  74. Class have to follow same name as module.
  75. we need import all modules in top section:
  76. import tclCommands.TclCommandExteriors
  77. at this stage we can include only wanted commands with this, auto loading may be implemented in future
  78. I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  79. :param app: FlatCAMApp
  80. :param commands: List of commands being updated
  81. :return: None
  82. """
  83. tcl_modules = {k: v for k, v in list(sys.modules.items()) if k.startswith('tclCommands.TclCommand')}
  84. for key, mod in list(tcl_modules.items()):
  85. if key != 'tclCommands.TclCommand':
  86. class_name = key.split('.')[1]
  87. class_type = getattr(mod, class_name)
  88. command_instance = class_type(app)
  89. for alias in command_instance.aliases:
  90. try:
  91. description = command_instance.description
  92. except AttributeError:
  93. description = ''
  94. commands[alias] = {
  95. 'fcn': command_instance.execute_wrapper,
  96. 'help': command_instance.get_decorated_help(),
  97. 'description': description
  98. }