Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Combobox and Spinbox generic #142

Open
rdbende opened this issue Jun 2, 2023 · 5 comments
Open

Make Combobox and Spinbox generic #142

rdbende opened this issue Jun 2, 2023 · 5 comments

Comments

@rdbende
Copy link
Member

rdbende commented Jun 2, 2023

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"
@Moosems
Copy link
Collaborator

Moosems commented Jun 2, 2023

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

@rdbende
Copy link
Member Author

rdbende commented Jun 2, 2023

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

@rdbende rdbende changed the title Add useful type-safetyness stuff Make Combobox and Spinbox generic Jul 27, 2023
@rdbende
Copy link
Member Author

rdbende commented Jul 27, 2023

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")

@Moosems
Copy link
Collaborator

Moosems commented Jul 27, 2023

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

@rdbende
Copy link
Member Author

rdbende commented Jul 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants