__init__.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.TclCommandOptions
  40. import tclCommands.TclCommandPaint
  41. import tclCommands.TclCommandPanelize
  42. import tclCommands.TclCommandPlot
  43. import tclCommands.TclCommandSaveProject
  44. import tclCommands.TclCommandSaveSys
  45. import tclCommands.TclCommandScale
  46. import tclCommands.TclCommandSetActive
  47. import tclCommands.TclCommandSetSys
  48. import tclCommands.TclCommandSkew
  49. import tclCommands.TclCommandSubtractPoly
  50. import tclCommands.TclCommandSubtractRectangle
  51. import tclCommands.TclCommandVersion
  52. import tclCommands.TclCommandWriteGCode
  53. __all__ = []
  54. for loader, name, is_pkg in pkgutil.walk_packages(__path__):
  55. module = loader.find_module(name).load_module(name)
  56. __all__.append(name)
  57. def register_all_commands(app, commands):
  58. """
  59. Static method which registers all known commands.
  60. Command should be for now in directory tclCommands and module should start with TCLCommand
  61. Class have to follow same name as module.
  62. we need import all modules in top section:
  63. import tclCommands.TclCommandExteriors
  64. at this stage we can include only wanted commands with this, auto loading may be implemented in future
  65. I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc.
  66. :param app: FlatCAMApp
  67. :param commands: List of commands being updated
  68. :return: None
  69. """
  70. tcl_modules = {k: v for k, v in list(sys.modules.items()) if k.startswith('tclCommands.TclCommand')}
  71. for key, mod in list(tcl_modules.items()):
  72. if key != 'tclCommands.TclCommand':
  73. class_name = key.split('.')[1]
  74. class_type = getattr(mod, class_name)
  75. command_instance = class_type(app)
  76. for alias in command_instance.aliases:
  77. commands[alias] = {
  78. 'fcn': command_instance.execute_wrapper,
  79. 'help': command_instance.get_decorated_help()
  80. }