def updateSpinBox(self, quantity=None): '''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.''' if self.valid: if quantity is None: quantity = PathUtil.getProperty(self.obj, self.prop) value = quantity.Value if hasattr(quantity, 'Value') else quantity self.widget.setProperty('rawValue', value)
def __init__(self, widget, obj, prop, onBeforeChange=None): self.obj = obj self.widget = widget self.prop = prop self.onBeforeChange = onBeforeChange attr = PathUtil.getProperty(self.obj, self.prop) if attr is not None: if hasattr(attr, 'Value'): widget.setProperty('unit', attr.getUserPreferred()[2]) widget.setProperty('binding', "%s.%s" % (obj.Name, prop)) self.valid = True else: PathLog.warning(translate('PathGui', "Cannot find property %s of %s") % (prop, obj.Label)) self.valid = False
def updateInputField(obj, prop, widget, onBeforeChange=None): """updateInputField(obj, prop, widget) ... update obj's property prop with the value of widget. The property's value is only assigned if the new value differs from the current value. This prevents onChanged notifications where the value didn't actually change. Gui::InputField and Gui::QuantitySpinBox widgets are supported - and the property can be of type Quantity or Float. 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") PathLog.track("value: {}".format(value)) attr = PathUtil.getProperty(obj, prop) attrValue = attr.Value if hasattr(attr, "Value") else attr isDiff = False if not PathGeom.isRoughly(attrValue, value): isDiff = True else: if hasattr(obj, "ExpressionEngine"): noExpr = True for (prp, expr) in obj.ExpressionEngine: if prp == prop: noExpr = False PathLog.debug('prop = "expression": {} = "{}"'.format( prp, expr)) value = FreeCAD.Units.Quantity( obj.evalExpression(expr)).Value if not PathGeom.isRoughly(attrValue, value): isDiff = True break if noExpr: widget.setReadOnly(False) widget.setStyleSheet("color: black") else: widget.setReadOnly(True) widget.setStyleSheet("color: gray") widget.update() if isDiff: PathLog.debug("updateInputField(%s, %s): %.2f -> %.2f" % (obj.Label, prop, attr, value)) if onBeforeChange: onBeforeChange(obj) PathUtil.setProperty(obj, prop, value) return True return False
def updateSpinBox(self, quantity=None): '''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: expr = self._hasExpression() if quantity is None: if expr: quantity = FreeCAD.Units.Quantity( self.obj.evalExpression(expr)) else: quantity = PathUtil.getProperty(self.obj, self.prop) value = quantity.Value if hasattr(quantity, 'Value') else quantity self.widget.setProperty('rawValue', value)
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: attr = PathUtil.getProperty(obj, prop) if attr is not None: if hasattr(attr, 'Value'): self.widget.setProperty('unit', attr.getUserPreferred()[2]) self.widget.setProperty('binding', "%s.%s" % (obj.Name, prop)) self.valid = True else: PathLog.warning(translate('PathGui', "Cannot find property %s of %s") % (prop, obj.Label)) self.valid = False else: self.valid = False
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: attr = PathUtil.getProperty(obj, prop) if attr is not None: if hasattr(attr, "Value"): self.widget.setProperty("unit", attr.getUserPreferred()[2]) self.widget.setProperty("binding", "%s.%s" % (obj.Name, prop)) self.valid = True else: PathLog.warning("Cannot find property {} of {}".format(prop, obj.Label)) self.valid = False else: self.valid = False
def updateInputField(obj, prop, widget, onBeforeChange=None): '''updateInputField(obj, prop, widget) ... update obj's property prop with the value of widget. The property's value is only assigned if the new value differs from the current value. This prevents onChanged notifications where the value didn't actually change. Gui::InputField and Gui::QuantitySpinBox widgets are supported - and the property can be of type Quantity or Float. 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). ''' value = FreeCAD.Units.Quantity(widget.text()).Value attr = PathUtil.getProperty(obj, prop) attrValue = attr.Value if hasattr(attr, 'Value') else attr if not PathGeom.isRoughly(attrValue, value): PathLog.debug("updateInputField(%s, %s): %.2f -> %.2f" % (obj.Label, prop, attr, value)) if onBeforeChange: onBeforeChange(obj) PathUtil.setProperty(obj, prop, value) return True return False
def updateSpinBox(self, quantity=None): """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, quantity) if self.valid: expr = self._hasExpression() if quantity is None: if expr: quantity = FreeCAD.Units.Quantity(self.obj.evalExpression(expr)) else: quantity = PathUtil.getProperty(self.obj, self.prop) value = quantity.Value if hasattr(quantity, "Value") else quantity self.widget.setProperty("rawValue", value) if expr: self.widget.setReadOnly(True) self.widget.setStyleSheet("color: gray") else: self.widget.setReadOnly(False) self.widget.setStyleSheet("color: black")
def updateExpression(name, widget): value = str(widget.text()) val = PathUtil.getProperty(self.obj, name) if val != value: PathUtil.setProperty(self.obj, name, value)
for i, fname in enumerate(args.path): #print(fname) doc = FreeCAD.openDocument(fname, False) print("{}:".format(doc.Name)) for o in doc.Objects: if PathPropertyBag.IsPropertyBag(o): if args.print_groups: print(" {}: {}".format(o.Label, sorted(o.CustomPropertyGroups))) else: print(" {}:".format(o.Label)) for p in o.Proxy.getCustomProperties(): grp = o.getGroupOfProperty(p) typ = o.getTypeIdOfProperty(p) ttp = PathPropertyBag.getPropertyTypeName(typ) val = PathUtil.getProperty(o, p) dsc = o.getDocumentationOfProperty(p) enm = '' enum = [] if ttp == 'Enumeration': enum = o.getEnumerationsOfProperty(p) enm = "{}".format(','.join(enum)) if GroupMap.get(grp): group = GroupMap.get(grp) print("move: {}.{} -> {}".format(grp, p, group)) o.removeProperty(p) o.Proxy.addCustomProperty(typ, p, group, dsc) if enum: print("enum {}.{}: {}".format(group, p, enum)) setattr(o, p, enum) PathUtil.setProperty(o, p, val)