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

Number input supports alignment #1821

Merged
merged 14 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added changes/1821.feature.rst
kiljoy001 marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
14 changes: 11 additions & 3 deletions examples/textinput/textinput/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def do_extract_values(self, widget, **kwargs):
self.right_aligned_input.enabled = False
self.password_input.enabled = False
self.number_input.enabled = False
self.right_aligned_number_input.enabled = False

# Update the labels with the extracted values
self.text_label.text = "Text content: {}; {}".format(
Expand All @@ -29,11 +30,13 @@ def do_extract_values(self, widget, **kwargs):
self.password_input.value,
)

number = self.number_input.value
if number:
number = self.number_input.value + self.right_aligned_number_input.value
if number > 0:
self.number_label.text = f"Double the number is: {number * 2}"
else:
self.number_label.text = "You didn't enter a number"
self.number_label.text = (
"Pick some other numbers that won't add up to zero."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a misleading message, because that's not what you're testing with the if.

Copy link
Contributor Author

@kiljoy001 kiljoy001 Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Pick some numbers that add up to more than zero"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the label to show Pick some numbers that add up to more than zero

)

# Wait 5 seconds
for i in range(5, 0, -1):
Expand All @@ -47,6 +50,7 @@ def do_extract_values(self, widget, **kwargs):
self.right_aligned_input.enabled = True
self.password_input.enabled = True
self.number_input.enabled = True
self.right_aligned_number_input.enabled = True

def startup(self):
# Set up main window
Expand Down Expand Up @@ -75,6 +79,9 @@ def startup(self):
self.right_aligned_input = toga.TextInput(
placeholder="Right aligned text", style=Pack(padding=10, text_align=RIGHT)
)
self.right_aligned_number_input = toga.NumberInput(
style=Pack(padding=10, text_align=RIGHT)
)
self.password_input = toga.PasswordInput(
placeholder="Password...",
style=Pack(padding=10),
Expand Down Expand Up @@ -110,6 +117,7 @@ def startup(self):
self.password_content_label,
self.email_input,
self.number_input,
self.right_aligned_number_input,
self.text_label,
self.password_label,
self.number_label,
Expand Down
7 changes: 4 additions & 3 deletions gtk/src/toga_gtk/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from travertino.size import at_least

from ..libs import Gtk
from ..libs import Gtk, gtk_alignment
from .base import Widget


Expand Down Expand Up @@ -53,10 +53,11 @@ def set_value(self, value):
self.native.set_value(self.interface.value)

def set_alignment(self, value):
self.interface.factory.not_implemented("NumberInput.set_alignment()")
xalign, justify = gtk_alignment(value)
self.native.set_alignment(xalign)

def set_font(self, font):
self.interface.factory.not_implemented("NumberInput.set_font()")
super().set_font(font)
kiljoy001 marked this conversation as resolved.
Show resolved Hide resolved

def rehint(self):
width = self.native.get_preferred_width()
Expand Down