From ee27fc876f6b9fda37d0c49d41ac72c5c47b2cfe Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sat, 2 Jan 2021 00:05:36 -0800 Subject: [PATCH] Added support for enumerations to property-bag, relies on base api to get the enum values. --- .../Gui/Resources/panels/PropertyCreate.ui | 31 ++++++++++++++++--- src/Mod/Path/PathScripts/PathPropertyBag.py | 2 +- .../Path/PathScripts/PathPropertyBagGui.py | 23 +++++++++++++- .../Path/PathScripts/PathPropertyEditor.py | 19 ++++++++++-- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui index 28f62a039db8..e50a671ccafc 100644 --- a/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui +++ b/src/Mod/Path/Gui/Resources/panels/PropertyCreate.ui @@ -6,8 +6,8 @@ 0 0 - 474 - 300 + 484 + 362 @@ -77,14 +77,14 @@ - + ToolTip - + <html><head/><body><p>ToolTip to be displayed when user hovers mouse over property.</p></body></html> @@ -94,7 +94,7 @@ - + @@ -132,12 +132,33 @@ + + + + false + + + Values + + + + + + + false + + + <html><head/><body><p>Comma separated list of enumeration values.</p></body></html> + + + propertyName propertyGroup propertyType + enumValues propertyInfo createAnother diff --git a/src/Mod/Path/PathScripts/PathPropertyBag.py b/src/Mod/Path/PathScripts/PathPropertyBag.py index 01455fa5beb7..a9cc8d4c00ea 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBag.py +++ b/src/Mod/Path/PathScripts/PathPropertyBag.py @@ -36,7 +36,7 @@ def translate(context, text, disambig=None): 'Angle' : 'App::PropertyAngle', 'Bool' : 'App::PropertyBool', 'Distance' : 'App::PropertyDistance', - # 'Enumeration' : 'App::PropertyEnumeration', + 'Enumeration' : 'App::PropertyEnumeration', 'File' : 'App::PropertyFile', 'Float' : 'App::PropertyFloat', 'Integer' : 'App::PropertyInteger', diff --git a/src/Mod/Path/PathScripts/PathPropertyBagGui.py b/src/Mod/Path/PathScripts/PathPropertyBagGui.py index bebdfcfca68f..948f41d14fb2 100644 --- a/src/Mod/Path/PathScripts/PathPropertyBagGui.py +++ b/src/Mod/Path/PathScripts/PathPropertyBagGui.py @@ -148,12 +148,26 @@ def __init__(self, obj, grp, typ, another): self.form.propertyGroup.currentTextChanged.connect(self.updateUI) self.form.propertyGroup.currentIndexChanged.connect(self.updateUI) self.form.propertyName.textChanged.connect(self.updateUI) + self.form.propertyType.currentIndexChanged.connect(self.updateUI) + self.form.enumValues.textChanged.connect(self.updateUI) self.updateUI() def updateUI(self): + typeSet = True + if self.propertyIsEnumeration(): + self.form.enumLabel.setEnabled(True) + self.form.enumValues.setEnabled(True) + typeSet = self.form.enumValues.text().strip() != '' + else: + self.form.enumLabel.setEnabled(False) + self.form.enumValues.setEnabled(False) + if self.form.enumValues.text().strip(): + self.form.enumValues.setText('') + ok = self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok) - if self.form.propertyName.text() and self.form.propertyGroup.currentText(): + + if typeSet and self.propertyName() and self.propertyGroup(): ok.setEnabled(True) else: ok.setEnabled(False) @@ -168,10 +182,15 @@ def propertyInfo(self): return self.form.propertyInfo.toPlainText().strip() def createAnother(self): return self.form.createAnother.isChecked() + def propertyEnumerations(self): + return [s.strip() for s in self.form.enumValues.text().strip().split(',')] + def propertyIsEnumeration(self): + return self.propertyType() == 'App::PropertyEnumeration' def exec_(self): self.form.propertyName.setText('') self.form.propertyInfo.setText('') + self.form.enumValues.setText('') #self.form.propertyName.setFocus() return self.form.exec_() @@ -261,6 +280,8 @@ def propertyAdd(self): grp = dialog.propertyGroup() info = dialog.propertyInfo() self.obj.Proxy.addCustomProperty(typ, name, grp, info) + if dialog.propertyIsEnumeration(): + setattr(self.obj, name, dialog.propertyEnumerations()) index = 0 for i in range(self.model.rowCount()): index = i diff --git a/src/Mod/Path/PathScripts/PathPropertyEditor.py b/src/Mod/Path/PathScripts/PathPropertyEditor.py index d45add0658ce..f376e351fd34 100644 --- a/src/Mod/Path/PathScripts/PathPropertyEditor.py +++ b/src/Mod/Path/PathScripts/PathPropertyEditor.py @@ -78,12 +78,12 @@ def widget(self, parent): def setEditorData(self, widget): widget.clear() - widget.addItems(['false', 'true']) + widget.addItems([str(False), str(True)]) index = 1 if self.propertyValue() else 0 widget.setCurrentIndex(index) def setModelData(self, widget): - self.setProperty(widget.currentText() == 'true') + self.setProperty(widget.currentText() == str(True)) class _PropertyEditorString(_PropertyEditor): '''Editor for string values - uses a line edit.''' @@ -190,11 +190,24 @@ def setEditorData(self, widget): def setModelData(self, widget): self.setProperty(widget.text()) +class _PropertyEditorEnumeration(_PropertyEditor): + + def widget(self, parent): + return QtGui.QComboBox(parent) + + def setEditorData(self, widget): + widget.clear() + widget.addItems(self.obj.getEnumerationsOfProperty(self.prop)) + widget.setCurrentText(self.propertyValue()) + + def setModelData(self, widget): + self.setProperty(widget.currentText()) + _EditorFactory = { 'App::PropertyAngle' : _PropertyEditorAngle, 'App::PropertyBool' : _PropertyEditorBool, 'App::PropertyDistance' : _PropertyEditorLength, - #'App::PropertyEnumeration' : _PropertyEditorEnum, + 'App::PropertyEnumeration' : _PropertyEditorEnumeration, #'App::PropertyFile' : _PropertyEditorFile, 'App::PropertyFloat' : _PropertyEditorFloat, 'App::PropertyInteger' : _PropertyEditorInteger,