__init__.py 3.4 KB

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