From 44e8533f26b89487cb6aa10b0a14e9cbc10f8032 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Sat, 19 Aug 2017 23:12:14 -0400 Subject: [PATCH] Cleaned up the CQGI execution code and made it a little more robust. --- Gui/Command.py | 11 ++++------- Shared.py | 19 +++++++++---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Gui/Command.py b/Gui/Command.py index 868a298..6b12fba 100644 --- a/Gui/Command.py +++ b/Gui/Command.py @@ -152,18 +152,15 @@ class CadQueryExecuteScript: if widget.objectName() == "cqVarsEditor": # Toggle the visibility of the widget if not widget.visibleRegion().isEmpty(): - # build_parameters = {'param': 2} - # Find all of the controls that will have parameter values in them valueControls = mw.findChildren(QtGui.QLineEdit) for valueControl in valueControls: objectName = valueControl.objectName() - FreeCAD.Console.PrintMessage(objectName + "\r\n") - if objectName != None and objectName != '' and objectName[0] == 'p': - FreeCAD.Console.PrintMessage(objectName.split('_')[1] + "\r\n") - build_parameters[objectName.split('_')[1]] = valueControl.text() - FreeCAD.Console.PrintMessage(build_parameters[objectName.split('_')[1]] + "\r\n") + # We only want text fields that will have parameter values in them + if objectName != None and objectName != '' and objectName.find('pcontrol_') >= 0: + # Associate the value in the text field with the variable name in the script + build_parameters[objectName.replace('pcontrol_', '')] = valueControl.text() build_result = cqModel.build(build_parameters=build_parameters) diff --git a/Shared.py b/Shared.py index 9726cca..ed271ea 100644 --- a/Shared.py +++ b/Shared.py @@ -107,22 +107,27 @@ def populateParameterEditor(parameters): gridLayout = QtGui.QGridLayout() line = 1 + + # Add controls for all the parameters so that they can be edited from the GUI for pKey, pVal in parameters.iteritems(): - FreeCAD.Console.PrintMessage("variable name: " + pKey + ", variable value: " + str(pVal.default_value) + "\r\n") label = QtGui.QLabel(pKey) + + # We want to keep track of this parameter value field so that we can pull its value later when executing value = QtGui.QLineEdit() value.setText(str(pVal.default_value)) - value.setObjectName("p_" + pKey) - # btn = QtGui.QPushButton("OK") + value.setObjectName("pcontrol_" + pKey) + + # Add the parameter control sets, one set per line gridLayout.addWidget(label, line, 0) gridLayout.addWidget(value, line, 1) - # gridLayout.addWidget(btn, line, 2) line += 1 # Create a widget we can put the layout in and add a scrollbar newWidget = QtGui.QWidget() newWidget.setLayout(gridLayout) + + # Add a scroll bar in case there are a lot of variables in the script scrollArea = QtGui.QScrollArea() scrollArea.setBackgroundRole(QtGui.QPalette.Light) scrollArea.setStyleSheet("QLabel { color : black; }"); @@ -130,10 +135,4 @@ def populateParameterEditor(parameters): widget.setWidget(scrollArea) - # Toggle the visibility of the widget - # if widget.visibleRegion().isEmpty(): - # widget.setVisible(True) - # else: - # widget.setVisible(False) - isPresent = True \ No newline at end of file