translation cleanup

This commit is contained in:
sliptonic
2022-01-21 09:20:57 -06:00
parent f99639f2fe
commit 73b3afe05d

View File

@@ -24,7 +24,6 @@ import FreeCAD
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PySide
__title__ = "Path UI helper and utility functions"
@@ -32,32 +31,33 @@ __author__ = "sliptonic (Brad Collette)"
__url__ = "https://www.freecadweb.org"
__doc__ = "A collection of helper and utility functions for the Path GUI."
def translate(context, text, disambig=None):
return PySide.QtCore.QCoreApplication.translate(context, text, disambig)
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
def updateInputField(obj, prop, widget, onBeforeChange=None):
'''updateInputField(obj, prop, widget) ... update obj's property prop with the value of widget.
"""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')
value = widget.property("rawValue")
attr = PathUtil.getProperty(obj, prop)
attrValue = attr.Value if hasattr(attr, 'Value') else attr
attrValue = attr.Value if hasattr(attr, "Value") else attr
isDiff = False
if not PathGeom.isRoughly(attrValue, value):
isDiff = True
else:
if hasattr(obj, 'ExpressionEngine'):
if hasattr(obj, "ExpressionEngine"):
noExpr = True
for (prp, expr) in obj.ExpressionEngine:
if prp == prop:
@@ -76,7 +76,9 @@ def updateInputField(obj, prop, widget, onBeforeChange=None):
widget.update()
if isDiff:
PathLog.debug("updateInputField(%s, %s): %.2f -> %.2f" % (obj.Label, prop, attr, value))
PathLog.debug(
"updateInputField(%s, %s): %.2f -> %.2f" % (obj.Label, prop, attr, value)
)
if onBeforeChange:
onBeforeChange(obj)
PathUtil.setProperty(obj, prop, value)
@@ -86,14 +88,14 @@ def updateInputField(obj, prop, widget, onBeforeChange=None):
class QuantitySpinBox:
'''Controller class to interface a Gui::QuantitySpinBox.
"""Controller class to interface a Gui::QuantitySpinBox.
The spin box gets bound to a given property and supports update in both directions.
QuatitySpinBox(widget, obj, prop, onBeforeChange=None)
widget ... expected to be reference to a Gui::QuantitySpinBox
obj ... document object
prop ... canonical name of the (sub-) property
onBeforeChange ... an optional callback being executed before the value of the property is changed
'''
"""
def __init__(self, widget, obj, prop, onBeforeChange=None):
PathLog.track(widget)
@@ -103,59 +105,61 @@ class QuantitySpinBox:
self.obj = obj
self.attachTo(obj, prop)
def attachTo(self, obj, prop = None):
'''attachTo(obj, prop=None) ... use an existing editor for the given object and property'''
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))
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))
PathLog.warning("Cannot find property {} of {}".format(prop, obj.Label))
self.valid = False
else:
self.valid = False
def expression(self):
'''expression() ... returns the expression if one is bound to the property'''
"""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 ''
return self.widget.property("expression")
return ""
def setMinimum(self, quantity):
'''setMinimum(quantity) ... set the minimum'''
"""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)
value = quantity.Value if hasattr(quantity, "Value") else quantity
self.widget.setProperty("setMinimum", value)
def updateSpinBox(self, quantity=None):
'''updateSpinBox(quantity=None) ... update the display value of the spin box.
"""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.'''
quantity can be of type Quantity or Float."""
PathLog.track(self.prop, self.valid)
if self.valid:
expr = self._hasExpression()
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)
value = quantity.Value if hasattr(quantity, "Value") else quantity
self.widget.setProperty("rawValue", value)
def updateProperty(self):
'''updateProperty() ... update the bound property with the value from the spin box'''
"""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 updateInputField(
self.obj, self.prop, self.widget, self.onBeforeChange
)
return None
def _hasExpression(self):