tukaan icon indicating copy to clipboard operation
tukaan copied to clipboard

Make Combobox and Spinbox generic

Open rdbende opened this issue 2 years ago • 5 comments

Specifying the type, a combobox or a spinbox should accept and return

combo = ComboBox[int](parent, values=[2, 4, 8])
assert isinstance(combo.value, int)

combo = ComboBox[str](parent, values=[2, 4, 8])
# TypeError: expected "str", got "int"

rdbende avatar Jun 02 '23 15:06 rdbende

What exactly are the args and kwargs for Tcl.call?

Moosems avatar Jun 02 '23 15:06 Moosems

There are no kwargs (though I plan to add them), the args are arbitrary. https://tukaan.github.io/docs/advanced/behind-the-scenes

rdbende avatar Jun 02 '23 15:06 rdbende

I'm no longer sure about this idea:

For callback handlers we should be able to add type hints, and Tukaan should convert the Tcl strings to Python type (at least for easier ones)

def spam(foo: int, bar: list[float]) -> None:
    assert isinstance(foo, int)
    assert isinstance(bar, list)
    assert all(isinstance(x, float) for x in bar)

Tcl.call(None, spam, "1234", "3.14 4.15")

rdbende avatar Jul 27 '23 13:07 rdbende

Wasn't type to string conversion a main point of Tukaan?

Moosems avatar Jul 27 '23 18:07 Moosems

It still is, but adding such feature would introduce significant runtime overhead, and if an internal function needs converted values, it can do it itself.

rdbende avatar Jul 27 '23 20:07 rdbende