__init__.py 4.3 KB

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