From 81d1f4e8508616739c5f67ceafb0cc2669eafe0d Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Sun, 13 Aug 2017 08:46:29 -0400 Subject: [PATCH] Got the variables editor to populate with controls for each of the variables in the script. --- Gui/Command.py | 6 +++++- Shared.py | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Gui/Command.py b/Gui/Command.py index 338ddb6..a81699a 100644 --- a/Gui/Command.py +++ b/Gui/Command.py @@ -346,6 +346,10 @@ 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) @@ -378,7 +382,7 @@ class CadQueryValidateScript: if "build_object(" not in scriptText or "# build_object(" in scriptText or "#build_boject(" in scriptText: FreeCAD.Console.PrintError("Script did not call build_object, no output available. Script must be CQGI compliant to get build output, variable editing and validation.\r\n") return - + # A repreentation of the CQ script with all the metadata attached cqModel = cqgi.parse(scriptText) diff --git a/Shared.py b/Shared.py index 7354c54..a6ff2e7 100644 --- a/Shared.py +++ b/Shared.py @@ -94,19 +94,39 @@ def populateParameterEditor(parameters): """Puts the proper controls in the script variable editor pane based on the parameters found""" FreeCAD.Console.PrintMessage("Script Variables:\r\n") - for key, value in parameters.iteritems(): - FreeCAD.Console.PrintMessage("variable name: " + key + ", variable value: " + str(value.default_value) + "\r\n") mw = FreeCADGui.getMainWindow() # Tracks whether or not we have already added the variables editor isPresent = False + # TODO: Clear and then populate the controls in the widget based on the variables + # https://stackoverflow.com/questions/3940409/how-to-clear-all-the-widgets-in-parent-widgets + # If the widget is open, we need to close it dockWidgets = mw.findChildren(QtGui.QDockWidget) for widget in dockWidgets: if widget.objectName() == "cqVarsEditor": - # TODO: Clear and then populate the controls in the widget based on the variables + gridLayout = QtGui.QGridLayout() + + line = 1 + for pKey, pVal in parameters.iteritems(): + FreeCAD.Console.PrintMessage("variable name: " + pKey + ", variable value: " + str(pVal.default_value) + "\r\n") + label = QtGui.QLabel(pKey) + value = QtGui.QLineEdit() + value.setText(str(pVal.default_value)) + btn = QtGui.QPushButton("OK") + 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 + newWidget = QtGui.QWidget() + newWidget.setLayout(gridLayout) + + widget.setWidget(newWidget) # Toggle the visibility of the widget # if widget.visibleRegion().isEmpty():