diff --git a/src/Mod/Path/PathScripts/PathGui.py b/src/Mod/Path/PathScripts/PathGui.py index c9fee42062..fb37725bf3 100644 --- a/src/Mod/Path/PathScripts/PathGui.py +++ b/src/Mod/Path/PathScripts/PathGui.py @@ -48,6 +48,7 @@ def updateInputField(obj, prop, widget, onBeforeChange=None): If onBeforeChange is specified it is called before a new value is assigned to the property. Returns True if a new value was assigned, False otherwise (new value is the same as the current). ''' + PathLog.track() value = widget.property('rawValue') attr = PathUtil.getProperty(obj, prop) attrValue = attr.Value if hasattr(attr, 'Value') else attr @@ -98,10 +99,12 @@ class QuantitySpinBox: PathLog.track(widget) self.widget = widget self.onBeforeChange = onBeforeChange + self.prop = None self.attachTo(obj, prop) 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) self.obj = obj self.prop = prop if obj and prop: @@ -119,12 +122,14 @@ class QuantitySpinBox: def expression(self): '''expression() ... returns the expression if one is bound to the property''' + PathLog.track(self.prop, self.valid) if self.valid: return self.widget.property('expression') return '' def setMinimum(self, quantity): '''setMinimum(quantity) ... set the minimum''' + PathLog.track(self.prop, self.valid) if self.valid: value = quantity.Value if hasattr(quantity, 'Value') else quantity self.widget.setProperty('setMinimum', value) @@ -133,6 +138,7 @@ class QuantitySpinBox: '''updateSpinBox(quantity=None) ... update the display value of the spin box. If no value is provided the value of the bound property is used. quantity can be of type Quantity or Float.''' + PathLog.track(self.prop, self.valid) if self.valid: if quantity is None: quantity = PathUtil.getProperty(self.obj, self.prop) @@ -141,6 +147,7 @@ class QuantitySpinBox: def updateProperty(self): '''updateProperty() ... update the bound property with the value from the spin box''' + PathLog.track(self.prop, self.valid) if self.valid: return updateInputField(self.obj, self.prop, self.widget, self.onBeforeChange) return None diff --git a/src/Mod/Path/PathScripts/PathToolBitEdit.py b/src/Mod/Path/PathScripts/PathToolBitEdit.py index 724f5b65cc..3028bd7bb1 100644 --- a/src/Mod/Path/PathScripts/PathToolBitEdit.py +++ b/src/Mod/Path/PathScripts/PathToolBitEdit.py @@ -115,6 +115,7 @@ class ToolBitEditor(object): # for all properties either assign them to existing labels and editors # or create additional ones for them if not enough have already been # created. + usedRows = 0 for nr, name in enumerate(tool.Proxy.toolShapeProperties(tool)): if nr < len(self.widgets): PathLog.debug("re-use row: {} [{}]".format(nr, name)) @@ -134,9 +135,11 @@ class ToolBitEditor(object): if nr >= layout.rowCount(): layout.addRow(label, qsb) + usedRows = usedRows + 1 # hide all rows which aren't being used - for i in range(len(tool.BitPropertyNames), len(self.widgets)): + PathLog.track(usedRows, len(self.widgets)) + for i in range(usedRows, len(self.widgets)): label, qsb, editor = self.widgets[i] label.hide() qsb.hide() @@ -152,9 +155,14 @@ class ToolBitEditor(object): def setupAttributes(self, tool): PathLog.track() - self.delegate = _Delegate(self.form.attrTree) - self.model = QtGui.QStandardItemModel(self.form.attrTree) - self.model.setHorizontalHeaderLabels(['Property', 'Value']) + setup = True + if not hasattr(self, 'delegate'): + self.delegate = _Delegate(self.form.attrTree) + self.model = QtGui.QStandardItemModel(self.form.attrTree) + self.model.setHorizontalHeaderLabels(['Property', 'Value']) + else: + self.model.removeRows(0, self.model.rowCount()) + setup = False attributes = tool.Proxy.toolGroupsAndProperties(tool, False) for name in attributes: @@ -175,8 +183,9 @@ class ToolBitEditor(object): self.model.appendRow(group) - self.form.attrTree.setModel(self.model) - self.form.attrTree.setItemDelegateForColumn(1, self.delegate) + if setup: + self.form.attrTree.setModel(self.model) + self.form.attrTree.setItemDelegateForColumn(1, self.delegate) self.form.attrTree.expandAll() self.form.attrTree.resizeColumnToContents(0) self.form.attrTree.resizeColumnToContents(1) @@ -199,15 +208,29 @@ class ToolBitEditor(object): for lbl, qsb, editor in self.widgets: editor.updateSpinBox() + def _updateBitShape(self, shapePath): + # Only need to go through this exercise if the shape actually changed. + if self.tool.BitShape != shapePath: + # Before setting a new bitshape we need to make sure that none of + # editors fires an event and tries to access its old property, which + # might not exist anymore. + for lbl, qsb, editor in self.widgets: + editor.attachTo(self.tool, 'File') + self.tool.BitShape = shapePath + self.setupTool(self.tool) + self.form.toolName.setText(self.tool.Label) + if self.tool.BitBody and self.tool.BitBody.ViewObject: + if not self.tool.BitBody.ViewObject.Visibility: + self.tool.BitBody.ViewObject.Visibility = True + self.setupAttributes(self.tool) + return True + return False + def updateShape(self): PathLog.track() shapePath = str(self.form.shapePath.text()) # Only need to go through this exercise if the shape actually changed. - if self.tool.BitShape != shapePath: - self.tool.BitShape = shapePath - self.setupTool(self.tool) - self.form.toolName.setText(self.tool.Label) - + if self._updateBitShape(shapePath): for lbl, qsb, editor in self.widgets: editor.updateSpinBox() @@ -218,8 +241,7 @@ class ToolBitEditor(object): shape = str(self.form.shapePath.text()) if self.tool.Label != label: self.tool.Label = label - if self.tool.BitShape != shape: - self.tool.BitShape = shape + self._updateBitShape(shape) for lbl, qsb, editor in self.widgets: editor.updateProperty() @@ -238,10 +260,7 @@ class ToolBitEditor(object): path = self.tool.BitShape if not path: path = PathPreferences.lastPathToolShape() - foo = QtGui.QFileDialog.getOpenFileName(self.form, - "Path - Tool Shape", - path, - "*.fcstd") + foo = QtGui.QFileDialog.getOpenFileName(self.form, "Path - Tool Shape", path, "*.fcstd") if foo and foo[0]: PathPreferences.setLastPathToolShape(os.path.dirname(foo[0])) self.form.shapePath.setText(foo[0])