-
-
Notifications
You must be signed in to change notification settings - Fork 827
Added numberinput to web and textual backends. #3299
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
36f7072
05d1ad6
576b0f8
5be0757
517efff
599d84f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added numberinput to web and textual backends. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The widget screenshots should match the content of the other platforms; if you need an example to screenshot, the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also - I'm interested how you've generated this screenshot - text inputs should have a blue border around them Textual's default style.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was generated in a normal terminal on Ubuntu. I don't remember exactly what I did but I do remember that the blue border came and went semi consistently.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see how that might be happening because of focus - but you're seeing no border at all when not-focussed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly yes. I did more testing with the textarea with making a multiline textinput but it seemed to behave similarly to the little testing I did with this input.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did confirm, when the input is not focused I have no border on any inputs. Only when it is in focus do I have a blue border
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirming I'm seeing the same thing. Looking at the other screenshots, I don't think they have focus; so we should be consistent. However, I do see a very slightly different color in the background between the "input" and the background:
so we should try to capture that context in the screenshot if possible.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I have the screenshot correct now? I had to pull out a different monitor cause mine were not showing the background color differences for some reason. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| from travertino.size import at_least | ||
|
|
||
| from textual.validation import Number | ||
| from textual.widgets import Input as TextualInput | ||
|
|
||
| from .base import Widget | ||
|
|
||
|
|
||
| class TogaInput(TextualInput): | ||
| def __init__(self, impl): | ||
| super().__init__() | ||
| self.interface = impl.interface | ||
| self.impl = impl | ||
|
|
||
| def on_input_changed(self, event: TextualInput.Changed) -> None: | ||
| self.interface.on_change() | ||
|
|
||
| def on_input_submitted(self, event: TextualInput.Submitted) -> None: | ||
| self.interface.on_confirm() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I press Enter when the input has focus, I get an exception because Numberinput doesn't support |
||
|
|
||
|
|
||
| class NumberInput(Widget): | ||
| def create(self): | ||
| self.native = TogaInput(self) | ||
| self.native.type = "number" | ||
| self.min = None | ||
| self.max = None | ||
|
|
||
| def get_readonly(self): | ||
| return self.native.disabled | ||
|
|
||
| def set_readonly(self, value): | ||
| self.native.disabled = value | ||
|
|
||
| def get_placeholder(self): | ||
| return self.native.placeholder | ||
|
|
||
| def set_placeholder(self, value): | ||
| self.native.placeholder = value | ||
|
|
||
| def get_value(self): | ||
| if self.native.value == "" or self.native.value is None: | ||
| return None | ||
| else: | ||
| if self.native.value != "-": | ||
| return float(self.native.value) | ||
| else: | ||
| return self.native.value | ||
|
|
||
| def set_value(self, value): | ||
| try: | ||
| if value is None: | ||
| self.native.value = "" | ||
| else: | ||
| self.native.value = str(value) | ||
| except AttributeError: | ||
| self.native.value = "" | ||
|
|
||
| def set_step(self, step): | ||
| pass | ||
|
|
||
| def set_min_value(self, value): | ||
| self.min = value | ||
| self.native.validators = [ | ||
| Number(minimum=self.min), | ||
| ] | ||
|
|
||
| def set_max_value(self, value): | ||
| self.max = value | ||
| self.native.validators = [ | ||
| Number(maximum=self.max), | ||
| ] | ||
|
|
||
| @property | ||
| def width_adjustment(self): | ||
| return 2 | ||
|
|
||
| @property | ||
| def height_adjustment(self): | ||
| return 2 | ||
|
|
||
| def rehint(self): | ||
| self.interface.intrinsic.width = at_least(len(self.native.value) + 4) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This geometry isn't working out right in my testing - it's consistently using a width of 4 characters, which won't display a value. This is looks like it's an oversight on the TextInput class as well - the size of the widget should be clamped to a "useful minimum" ( |
||
| self.interface.intrinsic.height = 3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from .base import Widget | ||
|
|
||
|
|
||
| class NumberInput(Widget): | ||
| def create(self): | ||
| self._return_listener = None | ||
| self.native = self._create_native_widget("sl-input") | ||
| self.native.type = "number" | ||
| self.native.value = None | ||
| self.native.onkeyup = self.dom_keyup | ||
|
|
||
| def dom_keyup(self, event): | ||
| if event.key == "Enter": | ||
| self.interface.on_confirm() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NumberInput doesn't have an |
||
|
|
||
| def get_readonly(self, value): | ||
| return self.native.readOnly | ||
|
|
||
| def set_readonly(self, value): | ||
| self.native.readOnly = value | ||
|
|
||
| def set_step(self, step): | ||
| self.native.step = step | ||
|
|
||
| def set_min_value(self, value): | ||
| self.native.min = value | ||
|
|
||
| def set_max_value(self, value): | ||
| self.native.max = value | ||
|
|
||
| def get_value(self): | ||
| if self.native.value == "" or self.native.value is None: | ||
| return None | ||
| else: | ||
| return float(self.native.value) | ||
|
|
||
| def set_value(self, value): | ||
| self.native.value = value | ||
|
|
||
| def set_text_align(self, value): | ||
| pass | ||

Uh oh!
There was an error while loading. Please reload this page.