diff --git a/android/tests_backend/widgets/label.py b/android/tests_backend/widgets/label.py index 21dda7535f..c8e7ed6e62 100644 --- a/android/tests_backend/widgets/label.py +++ b/android/tests_backend/widgets/label.py @@ -2,7 +2,7 @@ from java import jclass from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class LabelProbe(SimpleProbe): @@ -30,4 +30,4 @@ def text_align(self): justification_mode = ( None if Build.VERSION.SDK_INT < 26 else self.native.getJustificationMode() ) - return to_toga_text_align(self.native.getGravity(), justification_mode) + return toga_text_align(self.native.getGravity(), justification_mode) diff --git a/android/tests_backend/widgets/properties.py b/android/tests_backend/widgets/properties.py index fa74eda5d0..a21cb874e0 100644 --- a/android/tests_backend/widgets/properties.py +++ b/android/tests_backend/widgets/properties.py @@ -22,7 +22,7 @@ def toga_color(color_int): ) -def to_toga_text_align(gravity, justification_mode=None): +def toga_text_align(gravity, justification_mode=None): horizontal_gravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK if (Build.VERSION.SDK_INT < 26) or ( justification_mode in (None, Layout.JUSTIFICATION_MODE_NONE) diff --git a/cocoa/tests_backend/widgets/label.py b/cocoa/tests_backend/widgets/label.py index be6c448879..58d827fc28 100644 --- a/cocoa/tests_backend/widgets/label.py +++ b/cocoa/tests_backend/widgets/label.py @@ -1,7 +1,7 @@ from toga_cocoa.libs import NSTextField from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class LabelProbe(SimpleProbe): @@ -17,7 +17,7 @@ def color(self): @property def text_align(self): - return to_toga_text_align(self.native.alignment) + return toga_text_align(self.native.alignment) def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextField diff --git a/cocoa/tests_backend/widgets/multilinetextinput.py b/cocoa/tests_backend/widgets/multilinetextinput.py index ec2e8de5af..76894cb19d 100644 --- a/cocoa/tests_backend/widgets/multilinetextinput.py +++ b/cocoa/tests_backend/widgets/multilinetextinput.py @@ -2,7 +2,7 @@ from toga_cocoa.libs import NSRange, NSScrollView, NSTextView from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class MultilineTextInputProbe(SimpleProbe): @@ -59,7 +59,7 @@ def font(self): @property def text_align(self): - return to_toga_text_align(self.native_text.alignment) + return toga_text_align(self.native_text.alignment) def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextView diff --git a/cocoa/tests_backend/widgets/numberinput.py b/cocoa/tests_backend/widgets/numberinput.py index e06b09bee3..a576aeb3ac 100644 --- a/cocoa/tests_backend/widgets/numberinput.py +++ b/cocoa/tests_backend/widgets/numberinput.py @@ -11,7 +11,7 @@ ) from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class NumberInputProbe(SimpleProbe): @@ -87,7 +87,7 @@ def font(self): @property def text_align(self): - return to_toga_text_align(self.native_input.alignment) + return toga_text_align(self.native_input.alignment) def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextField diff --git a/cocoa/tests_backend/widgets/properties.py b/cocoa/tests_backend/widgets/properties.py index f9155556c7..de5b55621f 100644 --- a/cocoa/tests_backend/widgets/properties.py +++ b/cocoa/tests_backend/widgets/properties.py @@ -20,7 +20,7 @@ def toga_color(color): return None -def to_toga_text_align(alignment): +def toga_text_align(alignment): return { NSLeftTextAlignment: LEFT, NSRightTextAlignment: RIGHT, diff --git a/cocoa/tests_backend/widgets/textinput.py b/cocoa/tests_backend/widgets/textinput.py index dd676d5e0c..aa8f152a5e 100644 --- a/cocoa/tests_backend/widgets/textinput.py +++ b/cocoa/tests_backend/widgets/textinput.py @@ -9,7 +9,7 @@ ) from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class TextInputProbe(SimpleProbe): @@ -61,7 +61,7 @@ def font(self): @property def text_align(self): - result = to_toga_text_align(self.native.alignment) + result = toga_text_align(self.native.alignment) if result == RIGHT: assert self.impl.error_label.alignment == NSLeftTextAlignment else: diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index e3c85fdf7a..e9e4c0c093 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -68,7 +68,8 @@ VISIBILITY_CHOICES = Choices(VISIBLE, HIDDEN) DIRECTION_CHOICES = Choices(ROW, COLUMN) ALIGN_ITEMS_CHOICES = Choices(START, CENTER, END) -ALIGNMENT_CHOICES = Choices(TOP, RIGHT, BOTTOM, LEFT, CENTER) +# Deprecated, but maintained for backwards compatibility with Toga <= 0.4.8 +ALIGNMENT_CHOICES = Choices(LEFT, RIGHT, TOP, BOTTOM, CENTER) SIZE_CHOICES = Choices(NONE, integer=True) FLEX_CHOICES = Choices(number=True) @@ -1053,9 +1054,9 @@ def __css__(self) -> str: Pack.validated_property("display", choices=DISPLAY_CHOICES, initial=PACK) Pack.validated_property("visibility", choices=VISIBILITY_CHOICES, initial=VISIBLE) Pack.validated_property("direction", choices=DIRECTION_CHOICES, initial=ROW) -Pack.validated_property("alignment", choices=ALIGNMENT_CHOICES) -# Legacy "alias" (ish) of align_items Pack.validated_property("align_items", choices=ALIGN_ITEMS_CHOICES) +# Deprecated, but maintained for backwards compatibility with Toga <= 0.4.8 +Pack.validated_property("alignment", choices=ALIGNMENT_CHOICES) Pack.validated_property("width", choices=SIZE_CHOICES, initial=NONE) Pack.validated_property("height", choices=SIZE_CHOICES, initial=NONE) diff --git a/gtk/tests_backend/widgets/label.py b/gtk/tests_backend/widgets/label.py index 1f6069bc9c..55b47914c6 100644 --- a/gtk/tests_backend/widgets/label.py +++ b/gtk/tests_backend/widgets/label.py @@ -1,7 +1,7 @@ from toga_gtk.libs import Gtk from .base import SimpleProbe -from .properties import to_toga_x_text_align, to_toga_y_text_align +from .properties import toga_x_text_align, toga_y_text_align class LabelProbe(SimpleProbe): @@ -13,11 +13,11 @@ def text(self): @property def text_align(self): - return to_toga_x_text_align(self.native.get_xalign(), self.native.get_justify()) + return toga_x_text_align(self.native.get_xalign(), self.native.get_justify()) @property def vertical_text_align(self): return def assert_vertical_text_align(self, expected): - assert to_toga_y_text_align(self.native.get_yalign()) == expected + assert toga_y_text_align(self.native.get_yalign()) == expected diff --git a/gtk/tests_backend/widgets/multilinetextinput.py b/gtk/tests_backend/widgets/multilinetextinput.py index 9f3a96d6ea..0acf22fd42 100644 --- a/gtk/tests_backend/widgets/multilinetextinput.py +++ b/gtk/tests_backend/widgets/multilinetextinput.py @@ -3,7 +3,7 @@ from toga_gtk.libs import Gtk from .base import SimpleProbe -from .properties import to_toga_text_align_from_justification, toga_color +from .properties import toga_color, toga_text_align_from_justification class MultilineTextInputProbe(SimpleProbe): @@ -89,7 +89,7 @@ def font(self): @property def text_align(self): - return to_toga_text_align_from_justification( + return toga_text_align_from_justification( self.native_textview.get_justification(), ) diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index bb2516b8cd..5029d509d8 100644 --- a/gtk/tests_backend/widgets/numberinput.py +++ b/gtk/tests_backend/widgets/numberinput.py @@ -4,7 +4,7 @@ from toga_gtk.libs import Gtk from .base import SimpleProbe -from .properties import to_toga_x_text_align +from .properties import toga_x_text_align class NumberInputProbe(SimpleProbe): @@ -32,7 +32,7 @@ async def decrement(self): @property def text_align(self): - return to_toga_x_text_align(self.native.get_alignment()) + return toga_x_text_align(self.native.get_alignment()) def assert_text_align(self, expected): if expected == JUSTIFY: diff --git a/gtk/tests_backend/widgets/properties.py b/gtk/tests_backend/widgets/properties.py index d0b9debf6d..18470f02be 100644 --- a/gtk/tests_backend/widgets/properties.py +++ b/gtk/tests_backend/widgets/properties.py @@ -23,7 +23,7 @@ def toga_color(color): return None -def to_toga_x_text_align(xalign, justify=None): +def toga_x_text_align(xalign, justify=None): try: return { 0.0: JUSTIFY if justify == Gtk.Justification.FILL else LEFT, @@ -36,7 +36,7 @@ def to_toga_x_text_align(xalign, justify=None): ) -def to_toga_y_text_align(yalign): +def toga_y_text_align(yalign): try: return { 0.0: TOP, @@ -47,7 +47,7 @@ def to_toga_y_text_align(yalign): pytest.fail(f"Can't interpret GTK y text alignment {yalign}") -def to_toga_text_align_from_justification(justify): +def toga_text_align_from_justification(justify): return { Gtk.Justification.LEFT: LEFT, Gtk.Justification.RIGHT: RIGHT, diff --git a/gtk/tests_backend/widgets/textinput.py b/gtk/tests_backend/widgets/textinput.py index 3160981cc0..988e2baaae 100644 --- a/gtk/tests_backend/widgets/textinput.py +++ b/gtk/tests_backend/widgets/textinput.py @@ -4,7 +4,7 @@ from toga_gtk.libs import Gtk from .base import SimpleProbe -from .properties import to_toga_x_text_align +from .properties import toga_x_text_align class TextInputProbe(SimpleProbe): @@ -34,7 +34,7 @@ def placeholder_hides_on_focus(self): @property def text_align(self): - return to_toga_x_text_align(self.native.get_alignment()) + return toga_x_text_align(self.native.get_alignment()) def assert_text_align(self, expected): if expected == JUSTIFY: diff --git a/iOS/tests_backend/widgets/label.py b/iOS/tests_backend/widgets/label.py index 90293647c3..55155bdebb 100644 --- a/iOS/tests_backend/widgets/label.py +++ b/iOS/tests_backend/widgets/label.py @@ -1,7 +1,7 @@ from toga_iOS.libs import UILabel from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class LabelProbe(SimpleProbe): @@ -20,7 +20,7 @@ def color(self): @property def text_align(self): - return to_toga_text_align(self.native.textAlignment) + return toga_text_align(self.native.textAlignment) def assert_vertical_text_align(self, alignment): # iOS has a custom draw method that always draw the text at the top; diff --git a/iOS/tests_backend/widgets/numberinput.py b/iOS/tests_backend/widgets/numberinput.py index 0c2df37538..fcbe70401b 100644 --- a/iOS/tests_backend/widgets/numberinput.py +++ b/iOS/tests_backend/widgets/numberinput.py @@ -4,7 +4,7 @@ from toga_iOS.libs import UITextField from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class NumberInputProbe(SimpleProbe): @@ -30,7 +30,7 @@ def color(self): @property def text_align(self): - return to_toga_text_align(self.native.textAlignment) + return toga_text_align(self.native.textAlignment) def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on a UITextField diff --git a/iOS/tests_backend/widgets/properties.py b/iOS/tests_backend/widgets/properties.py index 9777984afd..c91a93ce0e 100644 --- a/iOS/tests_backend/widgets/properties.py +++ b/iOS/tests_backend/widgets/properties.py @@ -33,7 +33,7 @@ def toga_color(color): return None -def to_toga_text_align(alignment): +def toga_text_align(alignment): return { NSLeftTextAlignment: LEFT, NSRightTextAlignment: RIGHT, diff --git a/iOS/tests_backend/widgets/selection.py b/iOS/tests_backend/widgets/selection.py index 1976dcecef..a3a2863962 100644 --- a/iOS/tests_backend/widgets/selection.py +++ b/iOS/tests_backend/widgets/selection.py @@ -5,7 +5,7 @@ from toga_iOS.libs import UIPickerView, UITextField from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class SelectionProbe(SimpleProbe): @@ -21,7 +21,7 @@ def assert_resizes_on_content_change(self): @property def text_align(self): - return to_toga_text_align(self.native.textAlignment) + return toga_text_align(self.native.textAlignment) def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable on UITextField diff --git a/iOS/tests_backend/widgets/textinput.py b/iOS/tests_backend/widgets/textinput.py index cdce9c1fad..c42b2ea393 100644 --- a/iOS/tests_backend/widgets/textinput.py +++ b/iOS/tests_backend/widgets/textinput.py @@ -4,7 +4,7 @@ from toga_iOS.libs import UITextField from .base import SimpleProbe -from .properties import to_toga_text_align, toga_color +from .properties import toga_color, toga_text_align class TextInputProbe(SimpleProbe): @@ -44,7 +44,7 @@ def color(self): @property def text_align(self): - return to_toga_text_align(self.native.textAlignment) + return toga_text_align(self.native.textAlignment) def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable on UITextField diff --git a/winforms/tests_backend/widgets/label.py b/winforms/tests_backend/widgets/label.py index c5de57ad06..3c2e6507d2 100644 --- a/winforms/tests_backend/widgets/label.py +++ b/winforms/tests_backend/widgets/label.py @@ -1,7 +1,7 @@ import System.Windows.Forms from .base import SimpleProbe -from .properties import to_toga_x_text_align, to_toga_y_text_align +from .properties import toga_x_text_align, toga_y_text_align class LabelProbe(SimpleProbe): @@ -13,7 +13,7 @@ def text(self): @property def text_align(self): - return to_toga_x_text_align(self.native.TextAlign) + return toga_x_text_align(self.native.TextAlign) def assert_vertical_text_align(self, expected): - assert to_toga_y_text_align(self.native.TextAlign) == expected + assert toga_y_text_align(self.native.TextAlign) == expected diff --git a/winforms/tests_backend/widgets/multilinetextinput.py b/winforms/tests_backend/widgets/multilinetextinput.py index 172ff786d6..6e97ff33f9 100644 --- a/winforms/tests_backend/widgets/multilinetextinput.py +++ b/winforms/tests_backend/widgets/multilinetextinput.py @@ -1,7 +1,7 @@ import System.Windows.Forms from System.Drawing import SystemColors -from .properties import to_toga_x_text_align +from .properties import toga_x_text_align from .textinput import TextInputProbe @@ -58,4 +58,4 @@ async def wait_for_scroll_completion(self): @property def text_align(self): self.native.SelectAll() - return to_toga_x_text_align(self.native.SelectionAlignment) + return toga_x_text_align(self.native.SelectionAlignment) diff --git a/winforms/tests_backend/widgets/numberinput.py b/winforms/tests_backend/widgets/numberinput.py index 8b3d60f257..283d2a80c7 100644 --- a/winforms/tests_backend/widgets/numberinput.py +++ b/winforms/tests_backend/widgets/numberinput.py @@ -2,7 +2,7 @@ from System.Windows.Forms import NumericUpDown from .base import SimpleProbe -from .properties import to_toga_x_text_align +from .properties import toga_x_text_align class NumberInputProbe(SimpleProbe): @@ -34,7 +34,7 @@ async def decrement(self): @property def text_align(self): - return to_toga_x_text_align(self.native.TextAlign) + return toga_x_text_align(self.native.TextAlign) def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable in this native widget. diff --git a/winforms/tests_backend/widgets/properties.py b/winforms/tests_backend/widgets/properties.py index 8db6917534..276126c7fe 100644 --- a/winforms/tests_backend/widgets/properties.py +++ b/winforms/tests_backend/widgets/properties.py @@ -9,7 +9,7 @@ def toga_color(color): return rgba(color.R, color.G, color.B, color.A / 255) -def to_toga_x_text_align(alignment): +def toga_x_text_align(alignment): return { ContentAlignment.TopLeft: LEFT, ContentAlignment.MiddleLeft: LEFT, @@ -27,7 +27,7 @@ def to_toga_x_text_align(alignment): }[alignment] -def to_toga_y_text_align(alignment): +def toga_y_text_align(alignment): return { ContentAlignment.TopLeft: TOP, ContentAlignment.TopCenter: TOP, diff --git a/winforms/tests_backend/widgets/textinput.py b/winforms/tests_backend/widgets/textinput.py index af42ba4fa4..dee65b2f39 100644 --- a/winforms/tests_backend/widgets/textinput.py +++ b/winforms/tests_backend/widgets/textinput.py @@ -6,7 +6,7 @@ from System.Windows.Forms import TextBox from .base import SimpleProbe -from .properties import to_toga_x_text_align +from .properties import toga_x_text_align class TextInputProbe(SimpleProbe): @@ -49,7 +49,7 @@ def readonly(self): @property def text_align(self): - return to_toga_x_text_align(self.native.TextAlign) + return toga_x_text_align(self.native.TextAlign) def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable in this native widget.