__init__.py 3.4 KB

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