__init__.py 3.2 KB

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