Cleaned up the CQGI execution code and made it a little more robust.
This commit is contained in:
parent
68907ba9d7
commit
44e8533f26
|
@ -152,18 +152,15 @@ class CadQueryExecuteScript:
|
||||||
if widget.objectName() == "cqVarsEditor":
|
if widget.objectName() == "cqVarsEditor":
|
||||||
# Toggle the visibility of the widget
|
# Toggle the visibility of the widget
|
||||||
if not widget.visibleRegion().isEmpty():
|
if not widget.visibleRegion().isEmpty():
|
||||||
# build_parameters = {'param': 2}
|
|
||||||
|
|
||||||
# Find all of the controls that will have parameter values in them
|
# Find all of the controls that will have parameter values in them
|
||||||
valueControls = mw.findChildren(QtGui.QLineEdit)
|
valueControls = mw.findChildren(QtGui.QLineEdit)
|
||||||
for valueControl in valueControls:
|
for valueControl in valueControls:
|
||||||
objectName = valueControl.objectName()
|
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)
|
build_result = cqModel.build(build_parameters=build_parameters)
|
||||||
|
|
||||||
|
|
19
Shared.py
19
Shared.py
|
@ -107,22 +107,27 @@ def populateParameterEditor(parameters):
|
||||||
gridLayout = QtGui.QGridLayout()
|
gridLayout = QtGui.QGridLayout()
|
||||||
|
|
||||||
line = 1
|
line = 1
|
||||||
|
|
||||||
|
# Add controls for all the parameters so that they can be edited from the GUI
|
||||||
for pKey, pVal in parameters.iteritems():
|
for pKey, pVal in parameters.iteritems():
|
||||||
FreeCAD.Console.PrintMessage("variable name: " + pKey + ", variable value: " + str(pVal.default_value) + "\r\n")
|
|
||||||
label = QtGui.QLabel(pKey)
|
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 = QtGui.QLineEdit()
|
||||||
value.setText(str(pVal.default_value))
|
value.setText(str(pVal.default_value))
|
||||||
value.setObjectName("p_" + pKey)
|
value.setObjectName("pcontrol_" + pKey)
|
||||||
# btn = QtGui.QPushButton("OK")
|
|
||||||
|
# Add the parameter control sets, one set per line
|
||||||
gridLayout.addWidget(label, line, 0)
|
gridLayout.addWidget(label, line, 0)
|
||||||
gridLayout.addWidget(value, line, 1)
|
gridLayout.addWidget(value, line, 1)
|
||||||
# gridLayout.addWidget(btn, line, 2)
|
|
||||||
|
|
||||||
line += 1
|
line += 1
|
||||||
|
|
||||||
# Create a widget we can put the layout in and add a scrollbar
|
# Create a widget we can put the layout in and add a scrollbar
|
||||||
newWidget = QtGui.QWidget()
|
newWidget = QtGui.QWidget()
|
||||||
newWidget.setLayout(gridLayout)
|
newWidget.setLayout(gridLayout)
|
||||||
|
|
||||||
|
# Add a scroll bar in case there are a lot of variables in the script
|
||||||
scrollArea = QtGui.QScrollArea()
|
scrollArea = QtGui.QScrollArea()
|
||||||
scrollArea.setBackgroundRole(QtGui.QPalette.Light)
|
scrollArea.setBackgroundRole(QtGui.QPalette.Light)
|
||||||
scrollArea.setStyleSheet("QLabel { color : black; }");
|
scrollArea.setStyleSheet("QLabel { color : black; }");
|
||||||
|
@ -130,10 +135,4 @@ def populateParameterEditor(parameters):
|
||||||
|
|
||||||
widget.setWidget(scrollArea)
|
widget.setWidget(scrollArea)
|
||||||
|
|
||||||
# Toggle the visibility of the widget
|
|
||||||
# if widget.visibleRegion().isEmpty():
|
|
||||||
# widget.setVisible(True)
|
|
||||||
# else:
|
|
||||||
# widget.setVisible(False)
|
|
||||||
|
|
||||||
isPresent = True
|
isPresent = True
|
Loading…
Reference in New Issue
Block a user