Cleaned up the CQGI execution code and made it a little more robust.

This commit is contained in:
Jeremy Mack Wright 2017-08-19 23:12:14 -04:00
parent 68907ba9d7
commit 44e8533f26
2 changed files with 13 additions and 17 deletions

View File

@ -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)

View File

@ -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