From dd2679bc46f9516143242814ef5e4c51bb99d1a9 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sat, 29 Sep 2018 18:12:35 -0700 Subject: [PATCH] Fixed PathSetupSheet task panel and added doc strings to the UI. --- src/Mod/Path/PathScripts/PathSetupSheetGui.py | 31 +++++++++++++++---- .../PathSetupSheetOpPrototypeGui.py | 31 ++++++++++++++++--- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathSetupSheetGui.py b/src/Mod/Path/PathScripts/PathSetupSheetGui.py index 3d6c634afc..eb6740d113 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheetGui.py +++ b/src/Mod/Path/PathScripts/PathSetupSheetGui.py @@ -50,6 +50,8 @@ else: PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) class ViewProvider: + '''ViewProvider for a SetupSheet. + It's sole job is to provide an icon and invoke the TaskPanel on edit.''' def __init__(self, vobj, name): PathLog.track(name) @@ -125,6 +127,15 @@ class Delegate(QtGui.QStyledItemDelegate): widget.setGeometry(option.rect) class OpTaskPanel: + '''Editor for an operation's property default values. + The implementation is a simplified generic property editor with basically 3 fields + - checkbox - if set a default value for the given property is set + - name - a non-editable string with the property name + - value - the actual editor for the property's default value + The specific editor classes for a given property type are implemented in + PathSetupSheetOpPrototypeGui which also provides a factory function. The properties + are displayed in a table, each field occypying a column and each row representing + a single property.''' def __init__(self, obj, name, op): self.name = name @@ -201,6 +212,10 @@ class OpTaskPanel: class OpsDefaultEditor: + '''Class to collect and display default property editors for all registered operations. + If a form is given at creation time it will integrate with that form and provide an interface to switch + between the editors of different operations. If no form is provided the class assumes that the UI is + taken care of somehow else and just serves as an interface to all operation editors.''' def __init__(self, obj, form): self.form = form @@ -233,11 +248,12 @@ class OpsDefaultEditor: if self.currentOp: self.currentOp.form.hide() self.currentOp = None - current = self.form.opDefaultOp.currentIndex() - if current < 0: - current = 0 - self.currentOp = self.form.opDefaultOp.itemData(current) - self.currentOp.form.show() + if self.form: + current = self.form.opDefaultOp.currentIndex() + if current < 0: + current = 0 + self.currentOp = self.form.opDefaultOp.itemData(current) + self.currentOp.form.show() def updateModel(self, recomp = True): PathLog.track() @@ -253,9 +269,11 @@ class OpsDefaultEditor: for op in self.ops: op.setupUi() self.updateUI() - self.form.opDefaultOp.currentIndexChanged.connect(self.updateUI) + if self.form: + self.form.opDefaultOp.currentIndexChanged.connect(self.updateUI) class GlobalEditor(object): + '''Editor for the global properties which affect almost every operation.''' def __init__(self, obj, form): self.form = form @@ -314,6 +332,7 @@ class GlobalEditor(object): self.setFields() class TaskPanel: + '''TaskPanel for the SetupSheet - if it is being edited directly.''' def __init__(self, vobj): self.vobj = vobj diff --git a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototypeGui.py b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototypeGui.py index f42b01400d..d67b2ca602 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototypeGui.py +++ b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototypeGui.py @@ -49,10 +49,26 @@ else: PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) class _PropertyEditor(object): + '''Base class of all property editors - just outlines the TableView delegate interface.''' def __init__(self, prop): self.prop = prop + def widget(self, parent): + '''widget(parent) ... called by the delegate to get a new editor widget. + Must be implemented by subclasses and return the widget.''' + pass + def setEditorData(self, widget): + '''setEditorData(widget) ... called by the delegate to initialize the editor. + The widget is the object returned by widget(). + Must be implemented by subclasses.''' + pass + def setModelData(self, widget): + '''setModelData(widget) ... called by the delegate to store new values. + Must be implemented by subclasses.''' + pass + class _PropertyEnumEditor(_PropertyEditor): + '''Editor for enumation values - uses a combo box.''' def widget(self, parent): PathLog.track(self.prop.name, self.prop.getEnumValues()) @@ -71,6 +87,8 @@ class _PropertyEnumEditor(_PropertyEditor): class _PropertyBoolEditor(_PropertyEditor): + '''Editor for boolean values - uses a combo box.''' + def widget(self, parent): return QtGui.QComboBox(parent) @@ -85,6 +103,7 @@ class _PropertyBoolEditor(_PropertyEditor): self.prop.setValue(widget.currentText() == 'true') class _PropertyStringEditor(_PropertyEditor): + '''Editor for string values - uses a line edit.''' def widget(self, parent): return QtGui.QLineEdit(parent) @@ -97,6 +116,8 @@ class _PropertyStringEditor(_PropertyEditor): self.prop.setValue(widget.text()) class _PropertyLengthEditor(_PropertyEditor): + '''Editor for length values - uses a line edit.''' + def widget(self, parent): return QtGui.QLineEdit(parent) @@ -110,6 +131,7 @@ class _PropertyLengthEditor(_PropertyEditor): self.prop.setValue(FreeCAD.Units.Quantity(widget.text())) class _PropertyPercentEditor(_PropertyEditor): + '''Editor for percent values - uses a spin box.''' def widget(self, parent): return QtGui.QSpinBox(parent) @@ -125,6 +147,7 @@ class _PropertyPercentEditor(_PropertyEditor): self.prop.setValue(widget.value()) class _PropertyIntegerEditor(_PropertyEditor): + '''Editor for integer values - uses a spin box.''' def widget(self, parent): return QtGui.QSpinBox(parent) @@ -139,6 +162,7 @@ class _PropertyIntegerEditor(_PropertyEditor): self.prop.setValue(widget.value()) class _PropertyFloatEditor(_PropertyEditor): + '''Editor for float values - uses a double spin box.''' def widget(self, parent): return QtGui.QDoubleSpinBox(parent) @@ -164,13 +188,10 @@ _EditorFactory = { PathSetupSheetOpPrototype.PropertyString: _PropertyStringEditor, } -X = [] - def Editor(prop): - '''Returns an editor class to be used for that property.''' - global X - X.append(prop) + '''Returns an editor class to be used for the given property.''' factory = _EditorFactory[prop.__class__] if factory: return factory(prop) return None +