Path: Relocate valueChanged signal translation to QSB class

Moved the translation method from PathFeatureExtensionsGui module to proper location within QuantitySpinBox class in PathGui module.
This change adds a missing translation method for passing the `editingFinished` signal to the parent task panel when the user is finished editing a QuantitySpinBox object with an active expression in the Gui.
If no expression is active, this new method is dormant.

Some cleanup of initial changes related to development of this fix are included.
This commit is contained in:
Russell Johnson
2022-04-05 17:56:23 -05:00
parent 477c912ad0
commit 03c5661690
2 changed files with 19 additions and 23 deletions

View File

@@ -285,7 +285,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
self._initializeExtensions(obj) # Efficiently initialize Extensions
self.defaultLength.updateSpinBox()
self._getUseOutlineState() # Find `useOutline` checkbox and get its boolean value
self.lastDefaultLength = self.form.defaultLength.text()
self.lastDefaultLength = self.form.defaultLength.text() # set last DL value
self.fieldsSet = True # flag to identify initial values set
def _initializeExtensions(self, obj):
@@ -301,33 +301,16 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
self.form.extensionEdit.setDisabled(True)
self.setExtensions(self.extensions)
def _isDefaultLengthExpression(self):
"""_isDefaultLengthExpression()... Return True if Default Length is determined by an expression."""
for prop, __ in self.obj.ExpressionEngine:
if prop == "ExtensionLengthDefault":
return True
return False
def _applyDefaultLengthChange(self, index=None):
"""_applyDefaultLengthChange(index=None)...
Helper method to update Default Length spinbox, and update extensions due to change in Default Length."""
Helper method to update Default Length spinbox,
and update extensions due to change in Default Length."""
self.defaultLength.updateSpinBox()
if self.form.defaultLength.text() != self.lastDefaultLength:
self.lastDefaultLength = self.form.defaultLength.text()
self._resetCachedExtensions() # Reset extension cache because extension dimensions likely changed
self._enableExtensions() # Recalculate extensions
def _defaultLengthChanged(self):
"""_defaultLengthChanged()... Slot method for determining if a change in Default Length
value is determined from an expression edit, or a simple spinbox change. If the former,
emit a `editingFinished` signal manually because the Formula Editor window returned
a value to the base SpinBox."""
if (
self._isDefaultLengthExpression()
and self.form.defaultLength.text() != self.lastDefaultLength
):
self.form.defaultLength.editingFinished.emit()
def createItemForBaseModel(self, base, sub, edges, extensions):
PathLog.track(
base.Label, sub, "+", len(edges), len(base.Shape.getElement(sub).Edges)
@@ -645,10 +628,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
self.form.buttonDisable.clicked.connect(self.extensionsDisable)
self.form.buttonEnable.clicked.connect(self.extensionsEnable)
self.form.enableExtensions.toggled.connect(self._enableExtensions)
# These two handlers are needed to provide immediate updates to extension length
self.form.defaultLength.editingFinished.connect(self._applyDefaultLengthChange)
self.form.defaultLength.textChanged.connect(self._defaultLengthChanged)
self.model.itemChanged.connect(self.updateItemEnabled)

View File

@@ -125,14 +125,29 @@ class QuantitySpinBox(QtCore.QObject):
self.onBeforeChange = onBeforeChange
self.prop = None
self.obj = obj
self.lastWidgetText = self.widget.text()
self.attachTo(obj, prop)
self.widget.installEventFilter(self)
# Connect local class method as slot
self.widget.textChanged.connect(self.onWidgetValueChanged)
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.Type.FocusIn:
self.updateSpinBox()
return False
def onWidgetValueChanged(self):
"""onWidgetValueChanged()... Slot method for determining if a change
in widget value is a result of an expression edit, or a simple spinbox change.
If the former, emit a manual `editingFinished` signal because the Formula Editor
window returned a value to the base widget, leaving it in read-only mode,
and finishing the editing of the value. Otherwise, due nothing if the value
has not changed, or there is no active expression for the property.
If the user closes the Formula Editor to cancel the edit, the value will not
be changed, and this manual signal will not be emitted."""
if self._hasExpression() and self.widget.text() != self.lastWidgetText:
self.widget.editingFinished.emit()
def attachTo(self, obj, prop=None):
"""attachTo(obj, prop=None) ... use an existing editor for the given object and property"""
PathLog.track(self.prop, prop)
@@ -180,6 +195,7 @@ class QuantitySpinBox(QtCore.QObject):
quantity = PathUtil.getProperty(self.obj, self.prop)
value = quantity.Value if hasattr(quantity, "Value") else quantity
self.widget.setProperty("rawValue", value)
self.lastWidgetText = self.widget.text() # update last widget value
if expr:
self.widget.setReadOnly(True)
self.widget.setStyleSheet("color: gray")