def test_conversion_with_symbols(qtbot):
    widget = UnitEdit(text='1*b*mm')
    show(locals())
    syms = widget.getSymbols()
    assert set(syms.keys()) == {'b'}

    expr = widget.getExpr()
    conv = units.convert_to(expr, units.meter)
    assert conv == units.meter * Symbol('b') / 1000
    assert widget.convertTo('meter') == conv
    assert widget.convertTo(units.meter) == conv
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()
Пример #3
0
expr = ExprEdit(text='1*a + 2*b - 1*a + cos(pi)')
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',