TclCommandOpenFolder.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from tclCommands.TclCommand import *
  2. from PyQt5.QtWidgets import QFileDialog
  3. class TclCommandOpenFolder(TclCommand):
  4. """
  5. Tcl shell command to get open a folder browser dialog and return the result
  6. example:
  7. open_folder
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['open_folder']
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict()
  13. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  14. option_types = collections.OrderedDict([
  15. ('dir', str)
  16. ])
  17. # array of mandatory options for current Tcl command: required = {'name','outname'}
  18. required = []
  19. # structured help for current command, args needs to be ordered
  20. help = {
  21. 'main': "Opens a dialog to browse for a folder",
  22. 'args': collections.OrderedDict([
  23. ('dir', 'Initial directory to open')
  24. ]),
  25. 'examples': ['open_folder']
  26. }
  27. def execute(self, args, unnamed_args):
  28. """
  29. execute current TCL shell command
  30. :param args: array of known named arguments and options
  31. :param unnamed_args: array of other values which were passed into command
  32. without -somename and we do not have them in known arg_names
  33. :return: None or exception
  34. """
  35. if "dir" in args:
  36. return QFileDialog.getExistingDirectory(dir=args['dir'])
  37. else:
  38. return QFileDialog.getExistingDirectory()