def test_constructor_units(qtbot): widget = UnitEdit(text='2.0*mm') show(locals()) assert widget.getError() is False assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['default'][0] assert widget.getSymbols() == dict() assert widget.getExpr().atoms(units.Unit) == {units.mm} assert widget.getDimension() == units.Dimension('length') assert widget.getMagnitude() == 2 assert widget.getUnits() == units.millimeter assert widget.getValue() == widget.getUnits() * widget.getMagnitude()
expr.hasError[str].connect(printer('ExprEdit.hasError[str]')) expr.exprChanged[str].connect( printer('ExprEdit.exprChanged[str] -> Expression is:')) expr.editingFinished.connect(lambda: show_symbols(expr)) expr.editingFinished.connect( lambda: print('ExprEdit.editingFinished -> getValue():', expr.getValue())) expr.setToolTip("Do some math") layout.addWidget(expr) unit = UnitEdit(text='2*mm + 1*inch') unit.hasError[str].connect(printer('UnitEdit.hasError[str]')) unit.exprChanged[object].connect(printer('UnitEdit.exprChanged[object]')) unit.exprChanged.connect( lambda: print('UnitEdit.exprChanged -> getExpr()', unit.getExpr())) unit.exprChanged.connect( lambda: print('UnitEdit.exprChanged -> getValue()', unit.getValue())) unit.valueChanged[object].connect(printer('UnitEdit.valueChanged[object]')) unit.setToolTip("Do math with units") layout.addWidget(unit) dim = DimensionEdit(text='2*mm + 1*inch', dimension='length') dim.hasError[str].connect(printer('DimensionEdit.hasError[str]')) dim.exprChanged[object].connect(printer('DimensionEdit.exprChanged[object]')) dim.valueChanged[object].connect(printer('DimensionEdit.valueChanged[object]')) dim.setToolTip("Dimension (length) is enforced") layout.addWidget(dim) entry = SympyEntryWidget(text='3*mm + 1*inch', objectName='EntryWidget', options='length', label='->')