__init__.py 3.1 KB

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