__init__.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.TclCommandGetPath
  28. import tclCommands.TclCommandGetSys
  29. import tclCommands.TclCommandHelp
  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.TclCommandOpenDXF
  46. import tclCommands.TclCommandOpenExcellon
  47. import tclCommands.TclCommandOpenFolder
  48. import tclCommands.TclCommandOpenGCode
  49. import tclCommands.TclCommandOpenGerber
  50. import tclCommands.TclCommandOpenProject
  51. import tclCommands.TclCommandOpenSVG
  52. import tclCommands.TclCommandOptions
  53. import tclCommands.TclCommandPaint
  54. import tclCommands.TclCommandPanelize
  55. import tclCommands.TclCommandPlotAll
  56. import tclCommands.TclCommandPlotObjects
  57. import tclCommands.TclCommandQuit
  58. import tclCommands.TclCommandSaveProject
  59. import tclCommands.TclCommandSaveSys
  60. import tclCommands.TclCommandScale
  61. import tclCommands.TclCommandSetActive
  62. import tclCommands.TclCommandSetOrigin
  63. import tclCommands.TclCommandSetPath
  64. import tclCommands.TclCommandSetSys
  65. import tclCommands.TclCommandSkew
  66. import tclCommands.TclCommandSplitGeometry
  67. import tclCommands.TclCommandSubtractPoly
  68. import tclCommands.TclCommandSubtractRectangle
  69. import tclCommands.TclCommandVersion
  70. import tclCommands.TclCommandWriteGCode
  71. __all__ = []
  72. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  73. module = loader.find_module(name).load_module(name)
  74. __all__.append(name)
  75. def register_all_commands(app, commands):
  76. """
  77. Static method which registers all known commands.
  78. Command should be for now in directory tclCommands and module should start with TCLCommand
  79. Class have to follow same name as module.
  80. we need import all modules in top section:
  81. import tclCommands.TclCommandExteriors
  82. at this stage we can include only wanted commands with this, auto loading may be implemented in future
  83. I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  84. :param app: FlatCAMApp
  85. :param commands: List of commands being updated
  86. :return: None
  87. """
  88. tcl_modules = {k: v for k, v in list(
  89. sys.modules.items()) if k.startswith('tclCommands.TclCommand')}
  90. for key, mod in list(tcl_modules.items()):
  91. if key != 'tclCommands.TclCommand':
  92. class_name = key.split('.')[1]
  93. class_type = getattr(mod, class_name)
  94. command_instance = class_type(app)
  95. for alias in command_instance.aliases:
  96. try:
  97. description = command_instance.description
  98. except AttributeError:
  99. description = ''
  100. commands[alias] = {
  101. 'fcn': command_instance.execute_wrapper,
  102. 'help': command_instance.get_decorated_help(),
  103. 'description': description
  104. }