From 68907ba9d7c9477e9a10f4349000ad2efd2b349b Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Sat, 19 Aug 2017 17:22:20 -0400 Subject: [PATCH] Got the parameters editor working so that it can modify the model, but it still needs a lot of clean-up. --- Gui/Command.py | 36 +++++++++++++++++++++++++++++++----- Shared.py | 5 +++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Gui/Command.py b/Gui/Command.py index a81699a..868a298 100644 --- a/Gui/Command.py +++ b/Gui/Command.py @@ -138,8 +138,34 @@ class CadQueryExecuteScript: # Allows us to present parameters to users later that they can alter parameters = cqModel.metadata.parameters + build_parameters = {} - build_result = cqModel.build() + # Collect the build parameters from the Parameters Editor view, if they exist + mw = FreeCADGui.getMainWindow() + + # Tracks whether or not we have already added the variables editor + isPresent = False + + # If the widget is open, we need to close it + dockWidgets = mw.findChildren(QtGui.QDockWidget) + for widget in dockWidgets: + 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") + + build_result = cqModel.build(build_parameters=build_parameters) # Make sure that the build was successful if build_result.success: @@ -346,12 +372,12 @@ class ToggleParametersEditor: if not isPresent: cqVariablesEditor = QtGui.QDockWidget("CadQuery Variables Editor") cqVariablesEditor.setObjectName("cqVarsEditor") - # cqVariablesEditor.setAutoFillBackground(True) - # p = cqVariablesEditor.palette() - # p.setColor(cqVariablesEditor.backgroundRole(), '#FF0000') - # cqVariablesEditor.setPalette(p) + mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, cqVariablesEditor) + # Go ahead and populate the view if there are variables in the script + CadQueryValidateScript().Activated() + class CadQueryValidateScript: """Checks the script for the user without executing it and populates the variable editor, if needed""" diff --git a/Shared.py b/Shared.py index ae490bc..9726cca 100644 --- a/Shared.py +++ b/Shared.py @@ -112,10 +112,11 @@ def populateParameterEditor(parameters): label = QtGui.QLabel(pKey) value = QtGui.QLineEdit() value.setText(str(pVal.default_value)) - btn = QtGui.QPushButton("OK") + value.setObjectName("p_" + pKey) + # btn = QtGui.QPushButton("OK") gridLayout.addWidget(label, line, 0) gridLayout.addWidget(value, line, 1) - gridLayout.addWidget(btn, line, 2) + # gridLayout.addWidget(btn, line, 2) line += 1