Forráskód Böngészése

New TCL Command OpenFolder added

Robert Niemöller 6 éve
szülő
commit
89410b0740
2 módosított fájl, 49 hozzáadás és 0 törlés
  1. 48 0
      tclCommands/TclCommandOpenFolder.py
  2. 1 0
      tclCommands/__init__.py

+ 48 - 0
tclCommands/TclCommandOpenFolder.py

@@ -0,0 +1,48 @@
+from tclCommands.TclCommand import *
+from PyQt5.QtWidgets import QFileDialog
+
+
+class TclCommandOpenFolder(TclCommand):
+    """
+    Tcl shell command to get open a folder browser dialog and return the result
+
+    example:
+        open_folder
+    """
+
+    # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
+    aliases = ['open_folder']
+
+    # Dictionary of types from Tcl command, needs to be ordered
+    arg_names = collections.OrderedDict()
+
+    # Dictionary of types from Tcl command, needs to be ordered , this  is  for options  like -optionname value
+    option_types = collections.OrderedDict([
+        ('dir', str)
+    ])
+
+    # array of mandatory options for current Tcl command: required = {'name','outname'}
+    required = []
+
+    # structured help for current command, args needs to be ordered
+    help = {
+        'main': "Opens a dialog to browse for a folder",
+        'args': collections.OrderedDict([
+            ('dir', 'Initial directory to open')
+        ]),
+        'examples': ['open_folder']
+    }
+
+    def execute(self, args, unnamed_args):
+        """
+        execute current TCL shell command
+
+        :param args: array of known named arguments and options
+        :param unnamed_args: array of other values which were passed into command
+            without -somename and  we do not have them in known arg_names
+        :return: None or exception
+        """
+        if "dir" in args:
+            return QFileDialog.getExistingDirectory(dir=args['dir'])
+        else:
+            return QFileDialog.getExistingDirectory()

+ 1 - 0
tclCommands/__init__.py

@@ -37,6 +37,7 @@ import tclCommands.TclCommandOpenExcellon
 import tclCommands.TclCommandOpenGCode
 import tclCommands.TclCommandOpenGerber
 import tclCommands.TclCommandOpenProject
+import tclCommands.TclCommandOpenFolder
 import tclCommands.TclCommandOptions
 import tclCommands.TclCommandPaint
 import tclCommands.TclCommandPanelize