From b8d0efb9b85c8f343afb34aa600cd145e5f64aa1 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 8 Dec 2024 22:40:25 -0500 Subject: [PATCH 01/12] Changed padding to margin and alignment to align_items --- android/src/toga_android/widgets/base.py | 4 +- android/src/toga_android/widgets/label.py | 6 +- .../widgets/multilinetextinput.py | 2 +- android/src/toga_android/widgets/textinput.py | 2 +- android/tests_backend/widgets/base.py | 4 +- android/tests_backend/widgets/label.py | 6 +- android/tests_backend/widgets/properties.py | 2 +- android/tests_backend/widgets/selection.py | 4 +- cocoa/src/toga_cocoa/hardware/camera.py | 2 +- cocoa/src/toga_cocoa/widgets/base.py | 2 +- cocoa/src/toga_cocoa/widgets/label.py | 2 +- .../toga_cocoa/widgets/multilinetextinput.py | 2 +- cocoa/src/toga_cocoa/widgets/numberinput.py | 2 +- cocoa/src/toga_cocoa/widgets/textinput.py | 2 +- cocoa/tests_backend/widgets/base.py | 4 +- cocoa/tests_backend/widgets/label.py | 6 +- .../widgets/multilinetextinput.py | 6 +- cocoa/tests_backend/widgets/numberinput.py | 6 +- cocoa/tests_backend/widgets/properties.py | 2 +- cocoa/tests_backend/widgets/selection.py | 4 +- cocoa/tests_backend/widgets/textinput.py | 8 +- core/src/toga/style/applicator.py | 2 +- core/src/toga/style/pack.py | 216 +++++++++++------- core/tests/style/pack/layout/test_beeliza.py | 4 +- .../pack/layout/test_column_alignment.py | 36 +-- .../style/pack/layout/test_row_alignment.py | 36 +-- core/tests/style/pack/layout/test_rtl.py | 24 +- .../tests/style/pack/layout/test_tutorial0.py | 4 +- .../tests/style/pack/layout/test_tutorial1.py | 16 +- .../tests/style/pack/layout/test_tutorial3.py | 4 +- core/tests/style/pack/test_apply.py | 8 +- core/tests/style/pack/test_css.py | 116 +++++----- .../style/pack/test_deprecated_properties.py | 58 +++++ core/tests/style/test_applicator.py | 2 +- core/tests/widgets/test_base.py | 6 +- demo/toga_demo/app.py | 2 +- docs/reference/api/containers/box.rst | 2 +- docs/reference/api/widgets/divider.rst | 2 +- docs/reference/api/widgets/label.rst | 2 +- docs/reference/api/widgets/selection.rst | 2 +- docs/reference/style/pack.rst | 32 +-- docs/tutorial/tutorial-0.rst | 12 +- docs/tutorial/tutorial-1.rst | 2 +- dummy/src/toga_dummy/widgets/base.py | 4 +- .../{{ cookiecutter.name }}/app.py | 2 +- .../activityindicator/app.py | 6 +- examples/beeliza/beeliza/app.py | 4 +- examples/button/button/app.py | 2 +- examples/canvas/canvas/app.py | 10 +- examples/colors/colors/app.py | 36 +-- examples/command/command/app.py | 2 +- examples/detailedlist/detailedlist/app.py | 6 +- examples/dialogs/dialogs/app.py | 8 +- examples/divider/divider/app.py | 8 +- .../examples_overview/app.py | 14 +- examples/font/font/app.py | 6 +- examples/handlers/handlers/app.py | 14 +- examples/hardware/hardware/app.py | 8 +- examples/imageview/imageview/app.py | 4 +- examples/layout/layout/app.py | 21 +- examples/mapview/mapview/app.py | 8 +- .../multilinetextinput/app.py | 8 +- examples/numberinput/numberinput/app.py | 6 +- .../optioncontainer/optioncontainer/app.py | 18 +- examples/passwordinput/passwordinput/app.py | 6 +- examples/progressbar/progressbar/app.py | 8 +- examples/resize/resize/app.py | 2 +- examples/screenshot/screenshot/app.py | 52 ++--- .../scrollcontainer/scrollcontainer/app.py | 8 +- examples/selection/selection/app.py | 8 +- examples/simpleapp/simpleapp/app.py | 2 +- examples/slider/slider/app.py | 6 +- examples/splitcontainer/splitcontainer/app.py | 6 +- examples/switch_demo/switch_demo/app.py | 8 +- examples/table/table/app.py | 16 +- examples/table_source/table_source/app.py | 2 +- examples/textinput/textinput/app.py | 26 +-- examples/tree/tree/app.py | 4 +- examples/tree_source/tree_source/app.py | 2 +- examples/tutorial0/tutorial/app.py | 2 +- examples/tutorial1/tutorial/app.py | 16 +- examples/tutorial2/tutorial/app.py | 4 +- examples/tutorial3/tutorial/app.py | 6 +- examples/webview/webview/app.py | 4 +- examples/window/window/app.py | 10 +- gtk/src/toga_gtk/libs/utils.py | 4 +- gtk/src/toga_gtk/widgets/base.py | 2 +- gtk/src/toga_gtk/widgets/label.py | 6 +- .../toga_gtk/widgets/multilinetextinput.py | 6 +- gtk/src/toga_gtk/widgets/numberinput.py | 8 +- gtk/src/toga_gtk/widgets/textinput.py | 8 +- gtk/src/toga_gtk/window.py | 4 +- gtk/tests_backend/widgets/base.py | 4 +- gtk/tests_backend/widgets/label.py | 6 +- .../widgets/multilinetextinput.py | 8 +- gtk/tests_backend/widgets/numberinput.py | 4 +- gtk/tests_backend/widgets/properties.py | 12 +- gtk/tests_backend/widgets/selection.py | 4 +- gtk/tests_backend/widgets/textinput.py | 6 +- iOS/src/toga_iOS/widgets/base.py | 2 +- iOS/src/toga_iOS/widgets/label.py | 2 +- .../toga_iOS/widgets/multilinetextinput.py | 2 +- iOS/src/toga_iOS/widgets/numberinput.py | 2 +- iOS/src/toga_iOS/widgets/selection.py | 2 +- iOS/src/toga_iOS/widgets/textinput.py | 2 +- iOS/tests_backend/widgets/base.py | 4 +- iOS/tests_backend/widgets/label.py | 8 +- iOS/tests_backend/widgets/numberinput.py | 8 +- iOS/tests_backend/widgets/properties.py | 2 +- iOS/tests_backend/widgets/selection.py | 10 +- iOS/tests_backend/widgets/textinput.py | 10 +- testbed/tests/app/test_desktop.py | 6 +- testbed/tests/widgets/properties.py | 42 ++-- testbed/tests/widgets/test_label.py | 2 +- .../tests/widgets/test_multilinetextinput.py | 2 +- testbed/tests/widgets/test_numberinput.py | 4 +- testbed/tests/widgets/test_passwordinput.py | 4 +- testbed/tests/widgets/test_scrollcontainer.py | 24 +- testbed/tests/widgets/test_selection.py | 4 +- testbed/tests/widgets/test_textinput.py | 4 +- textual/src/toga_textual/widgets/base.py | 2 +- web/src/toga_web/widgets/base.py | 2 +- web/src/toga_web/widgets/label.py | 2 +- web/src/toga_web/widgets/textinput.py | 2 +- winforms/src/toga_winforms/widgets/base.py | 4 +- winforms/src/toga_winforms/widgets/label.py | 2 +- .../widgets/multilinetextinput.py | 2 +- .../src/toga_winforms/widgets/numberinput.py | 2 +- .../src/toga_winforms/widgets/textinput.py | 2 +- winforms/tests_backend/widgets/base.py | 4 +- winforms/tests_backend/widgets/label.py | 10 +- .../widgets/multilinetextinput.py | 6 +- winforms/tests_backend/widgets/numberinput.py | 10 +- winforms/tests_backend/widgets/properties.py | 4 +- winforms/tests_backend/widgets/selection.py | 4 +- winforms/tests_backend/widgets/textinput.py | 10 +- 136 files changed, 733 insertions(+), 622 deletions(-) create mode 100644 core/tests/style/pack/test_deprecated_properties.py diff --git a/android/src/toga_android/widgets/base.py b/android/src/toga_android/widgets/base.py index 90a05849d4..63533b5193 100644 --- a/android/src/toga_android/widgets/base.py +++ b/android/src/toga_android/widgets/base.py @@ -161,7 +161,7 @@ def set_background_filter(self, value): else PorterDuffColorFilter(native_color(value), PorterDuff.Mode.SRC_IN) ) - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): pass # If appropriate, a widget subclass will implement this. def set_color(self, color): @@ -190,7 +190,7 @@ def rehint(self): pass -def align(value): +def android_text_align(value): """Convert toga alignment values into Android alignment values.""" return { LEFT: Gravity.LEFT, diff --git a/android/src/toga_android/widgets/label.py b/android/src/toga_android/widgets/label.py index e2bcff7a6a..2d6ee24136 100644 --- a/android/src/toga_android/widgets/label.py +++ b/android/src/toga_android/widgets/label.py @@ -10,7 +10,7 @@ from toga.constants import JUSTIFY from toga_android.colors import native_color -from .base import Widget, align +from .base import Widget, android_text_align def set_textview_font(tv, font, default_typeface, default_size): @@ -51,7 +51,7 @@ def set_textview_alignment(self, value, vertical_gravity): else Layout.JUSTIFICATION_MODE_NONE ) - self.native.setGravity(vertical_gravity | align(value)) + self.native.setGravity(vertical_gravity | android_text_align(value)) class Label(TextViewWidget): @@ -80,5 +80,5 @@ def rehint(self): at_least(self.native.getMeasuredWidth()), ROUND_UP ) - def set_alignment(self, value): + def set_text_alignment(self, value): self.set_textview_alignment(value, Gravity.TOP) diff --git a/android/src/toga_android/widgets/multilinetextinput.py b/android/src/toga_android/widgets/multilinetextinput.py index 0f876c6136..8ca156ebf2 100644 --- a/android/src/toga_android/widgets/multilinetextinput.py +++ b/android/src/toga_android/widgets/multilinetextinput.py @@ -23,7 +23,7 @@ def _on_gain_focus(self): def _on_lose_focus(self): pass # The interface doesn't support this event. - def set_alignment(self, value): + def set_text_alignment(self, value): self.set_textview_alignment(value, Gravity.TOP) # This method is necessary to override the TextInput base class. diff --git a/android/src/toga_android/widgets/textinput.py b/android/src/toga_android/widgets/textinput.py index 83ecec4241..b90032426d 100644 --- a/android/src/toga_android/widgets/textinput.py +++ b/android/src/toga_android/widgets/textinput.py @@ -98,7 +98,7 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.setHint(value) - def set_alignment(self, value): + def set_text_alignment(self, value): self.set_textview_alignment(value, Gravity.CENTER_VERTICAL) def set_error(self, error_message): diff --git a/android/tests_backend/widgets/base.py b/android/tests_backend/widgets/base.py index 123c7b8d1c..56f36f0973 100644 --- a/android/tests_backend/widgets/base.py +++ b/android/tests_backend/widgets/base.py @@ -37,8 +37,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.getParent() is None - def assert_alignment(self, expected): - actual = self.alignment + def assert_text_alignment(self, expected): + actual = self.text_alignment if expected == JUSTIFY and ( Build.VERSION.SDK_INT < 26 or not self.supports_justify ): diff --git a/android/tests_backend/widgets/label.py b/android/tests_backend/widgets/label.py index f74ccb6562..9f568313a5 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class LabelProbe(SimpleProbe): @@ -26,8 +26,8 @@ def text_size(self): return self.native.getTextSize() @property - def alignment(self): + def text_alignment(self): justification_mode = ( None if Build.VERSION.SDK_INT < 26 else self.native.getJustificationMode() ) - return toga_alignment(self.native.getGravity(), justification_mode) + return toga_text_alignment(self.native.getGravity(), justification_mode) diff --git a/android/tests_backend/widgets/properties.py b/android/tests_backend/widgets/properties.py index 356fb78552..b56eb8f36a 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 toga_alignment(gravity, justification_mode=None): +def toga_text_alignment(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/android/tests_backend/widgets/selection.py b/android/tests_backend/widgets/selection.py index 390cd90004..6c46f71094 100644 --- a/android/tests_backend/widgets/selection.py +++ b/android/tests_backend/widgets/selection.py @@ -12,8 +12,8 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes on this backend") @property - def alignment(self): - xfail("Can't change the alignment of Selection on this backend") + def text_alignment(self): + xfail("Can't change the text alignment of Selection on this backend") @property def color(self): diff --git a/cocoa/src/toga_cocoa/hardware/camera.py b/cocoa/src/toga_cocoa/hardware/camera.py index 9be10da170..3de9e64c20 100644 --- a/cocoa/src/toga_cocoa/hardware/camera.py +++ b/cocoa/src/toga_cocoa/hardware/camera.py @@ -131,7 +131,7 @@ def create_preview_window(self): style=Pack(flex=1), ), ], - style=Pack(padding=10), + style=Pack(margin=10), ), ], style=Pack(direction=COLUMN), diff --git a/cocoa/src/toga_cocoa/widgets/base.py b/cocoa/src/toga_cocoa/widgets/base.py index 06e6264135..d4e65eb05d 100644 --- a/cocoa/src/toga_cocoa/widgets/base.py +++ b/cocoa/src/toga_cocoa/widgets/base.py @@ -59,7 +59,7 @@ def set_bounds(self, x, y, width, height): # print(f"SET BOUNDS ON {self.interface} {width}x{height} @ ({x},{y})") self.constraints.update(x, y, width, height) - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): pass def set_hidden(self, hidden): diff --git a/cocoa/src/toga_cocoa/widgets/label.py b/cocoa/src/toga_cocoa/widgets/label.py index a0e0461e67..5b0bd2ce83 100644 --- a/cocoa/src/toga_cocoa/widgets/label.py +++ b/cocoa/src/toga_cocoa/widgets/label.py @@ -17,7 +17,7 @@ def create(self): # Add the layout constraints self.add_constraints() - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.alignment = NSTextAlignment(value) def set_color(self, value): diff --git a/cocoa/src/toga_cocoa/widgets/multilinetextinput.py b/cocoa/src/toga_cocoa/widgets/multilinetextinput.py index c651fa8e47..d6036f2349 100644 --- a/cocoa/src/toga_cocoa/widgets/multilinetextinput.py +++ b/cocoa/src/toga_cocoa/widgets/multilinetextinput.py @@ -95,7 +95,7 @@ def set_background_color(self, color): self.native_text.drawsBackground = True self.native_text.backgroundColor = native_color(color) - def set_alignment(self, value): + def set_text_alignment(self, value): self.native_text.alignment = NSTextAlignment(value) def set_font(self, font): diff --git a/cocoa/src/toga_cocoa/widgets/numberinput.py b/cocoa/src/toga_cocoa/widgets/numberinput.py index 9bbb6e73f7..096e5a6829 100644 --- a/cocoa/src/toga_cocoa/widgets/numberinput.py +++ b/cocoa/src/toga_cocoa/widgets/numberinput.py @@ -214,7 +214,7 @@ def set_max_value(self, value): else: self.native_stepper.maxValue = float(value) - def set_alignment(self, value): + def set_text_alignment(self, value): self.native_input.alignment = NSTextAlignment(value) def set_font(self, font): diff --git a/cocoa/src/toga_cocoa/widgets/textinput.py b/cocoa/src/toga_cocoa/widgets/textinput.py index 0ea3bf22ab..68eba3535b 100644 --- a/cocoa/src/toga_cocoa/widgets/textinput.py +++ b/cocoa/src/toga_cocoa/widgets/textinput.py @@ -184,7 +184,7 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.cell.placeholderString = value - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.alignment = NSTextAlignment(value) # The alert label should be on the trailing edge if value == RIGHT: diff --git a/cocoa/tests_backend/widgets/base.py b/cocoa/tests_backend/widgets/base.py index ab5d957d69..42689102a8 100644 --- a/cocoa/tests_backend/widgets/base.py +++ b/cocoa/tests_backend/widgets/base.py @@ -33,8 +33,8 @@ def assert_not_contained(self): assert self.native.superview is None assert self.native.window is None - def assert_alignment(self, expected): - assert self.alignment == expected + def assert_text_alignment(self, expected): + assert self.text_alignment == expected async def redraw(self, message=None, delay=0): """Request a redraw of the app, waiting until that redraw has completed.""" diff --git a/cocoa/tests_backend/widgets/label.py b/cocoa/tests_backend/widgets/label.py index ee4d681c61..fc1f33920c 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class LabelProbe(SimpleProbe): @@ -16,8 +16,8 @@ def color(self): return toga_color(self.native.textColor) @property - def alignment(self): - return toga_alignment(self.native.alignment) + def text_alignment(self): + return toga_text_alignment(self.native.alignment) def assert_vertical_alignment(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 9584f426c6..f315a1b46f 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class MultilineTextInputProbe(SimpleProbe): @@ -58,8 +58,8 @@ def font(self): return self.native_text.font @property - def alignment(self): - return toga_alignment(self.native_text.alignment) + def text_alignment(self): + return toga_text_alignment(self.native_text.alignment) def assert_vertical_alignment(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 54b5e4be92..d7f0cfcea4 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class NumberInputProbe(SimpleProbe): @@ -86,8 +86,8 @@ def font(self): return self.native_input.font @property - def alignment(self): - return toga_alignment(self.native_input.alignment) + def text_alignment(self): + return toga_text_alignment(self.native_input.alignment) def assert_vertical_alignment(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 85375bcb0d..e000228f80 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 toga_alignment(alignment): +def toga_text_alignment(alignment): return { NSLeftTextAlignment: LEFT, NSRightTextAlignment: RIGHT, diff --git a/cocoa/tests_backend/widgets/selection.py b/cocoa/tests_backend/widgets/selection.py index 33229e0fbe..58faafaa33 100644 --- a/cocoa/tests_backend/widgets/selection.py +++ b/cocoa/tests_backend/widgets/selection.py @@ -13,8 +13,8 @@ def assert_resizes_on_content_change(self): pass @property - def alignment(self): - xfail("Can't change the alignment of Selection on macOS") + def text_alignment(self): + xfail("Can't change the text alignment of Selection on macOS") @property def color(self): diff --git a/cocoa/tests_backend/widgets/textinput.py b/cocoa/tests_backend/widgets/textinput.py index 4cd89acab7..fddcdda850 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class TextInputProbe(SimpleProbe): @@ -60,15 +60,15 @@ def font(self): return self.native.font @property - def alignment(self): - result = toga_alignment(self.native.alignment) + def text_alignment(self): + result = toga_text_alignment(self.native.alignment) if result == RIGHT: assert self.impl.error_label.alignment == NSLeftTextAlignment else: assert self.impl.error_label.alignment == NSRightTextAlignment return result - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/core/src/toga/style/applicator.py b/core/src/toga/style/applicator.py index 43674a0d24..0a5d617e89 100644 --- a/core/src/toga/style/applicator.py +++ b/core/src/toga/style/applicator.py @@ -46,7 +46,7 @@ def set_bounds(self) -> None: child.applicator.set_bounds() def set_text_alignment(self, alignment: str) -> None: - self.widget._impl.set_alignment(alignment) + self.widget._impl.set_text_alignment(alignment) def set_hidden(self, hidden: bool) -> None: self.widget._impl.set_hidden(hidden) diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index 57db86b12a..ead9c69649 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -1,5 +1,6 @@ from __future__ import annotations +import warnings from typing import Any from travertino.constants import ( # noqa: F401 @@ -43,6 +44,9 @@ Font, ) +# Make sure deprecation warnings are shown by default +warnings.filterwarnings("default", category=DeprecationWarning) + ###################################################################### # Display ###################################################################### @@ -56,12 +60,12 @@ DISPLAY_CHOICES = Choices(PACK, NONE) VISIBILITY_CHOICES = Choices(VISIBLE, HIDDEN) DIRECTION_CHOICES = Choices(ROW, COLUMN) -ALIGNMENT_CHOICES = Choices(LEFT, RIGHT, TOP, BOTTOM, CENTER) +ALIGN_ITEMS_CHOICES = Choices(LEFT, RIGHT, TOP, BOTTOM, CENTER) SIZE_CHOICES = Choices(NONE, integer=True) FLEX_CHOICES = Choices(number=True) -PADDING_CHOICES = Choices(integer=True) +MARGIN_CHOICES = Choices(integer=True) TEXT_ALIGN_CHOICES = Choices(LEFT, RIGHT, CENTER, JUSTIFY) TEXT_DIRECTION_CHOICES = Choices(RTL, LTR) @@ -93,6 +97,54 @@ def _hidden(self) -> bool: """Does this style declaration define an object that should be hidden.""" return self.visibility == HIDDEN + ####################################################### + # Backwards compatibility for Toga <= 0.4.8 + ####################################################### + + DEPRECATED_PROPERTIES = { + # Map each deprecated property name to its replacement. + "padding": "margin", + "padding_top": "margin_top", + "padding_right": "margin_right", + "padding_bottom": "margin_bottom", + "padding_left": "margin_left", + "alignment": "align_items", + } + + def _dealias_property_name(self, name): + if aliased_name := self.DEPRECATED_PROPERTIES.get(name): + msg = f"Pack.{name} is deprecated; use {aliased_name} instead" + warnings.warn(msg, DeprecationWarning, stacklevel=3) + name = aliased_name + + return name + + # Dot lookup + + def __getattr__(self, name): + return super().__getattribute__(self._dealias_property_name(name)) + + def __setattr__(self, name, value): + super().__setattr__(self._dealias_property_name(name), value) + + def __delattr__(self, name): + super().__delattr__(self._dealias_property_name(name)) + + # Index notation + + def __getitem__(self, name): + return super().__getitem__(self._dealias_property_name(name.replace("-", "_"))) + + def __setitem__(self, name, value): + super().__setitem__(self._dealias_property_name(name.replace("-", "_")), value) + + def __delitem__(self, name): + super().__delattr__(self._dealias_property_name(name.replace("-", "_"))) + + ####################################################### + # End backwards compatibility + ####################################################### + def apply(self, prop: str, value: object) -> None: if self._applicator: if prop == "text_align": @@ -155,11 +207,11 @@ def layout(self, node: Node, viewport: Any) -> None: use_all_height=True, # root node uses all height use_all_width=True, # root node uses all width ) - node.layout.content_top = node.style.padding_top - node.layout.content_bottom = node.style.padding_bottom + node.layout.content_top = node.style.margin_top + node.layout.content_bottom = node.style.margin_bottom - node.layout.content_left = node.style.padding_left - node.layout.content_right = node.style.padding_right + node.layout.content_left = node.style.margin_left + node.layout.content_right = node.style.margin_right def _layout_node( self, @@ -188,7 +240,7 @@ def _layout_node( # the available width. If there is an intrinsic width, # use it to make sure the width is at least the amount specified. available_width = max( - 0, (alloc_width - self.padding_left - self.padding_right) + 0, (alloc_width - self.margin_left - self.margin_right) ) # self._debug(f"INITIAL {available_width=}") if node.intrinsic.width is not None: @@ -214,7 +266,7 @@ def _layout_node( else: available_height = max( 0, - alloc_height - self.padding_top - self.padding_bottom, + alloc_height - self.margin_top - self.margin_bottom, ) # self._debug(f"INITIAL {available_height=}") if node.intrinsic.height is not None: @@ -317,9 +369,9 @@ def _layout_row_children( child_content_width = child.intrinsic.width.value min_child_content_width = child.intrinsic.width.value min_flex += ( - child.style.padding_left + child.style.margin_left + child.intrinsic.width.value - + child.style.padding_right + + child.style.margin_right ) else: # self._debug(f"- intrinsic non-flex {child.intrinsic.width=}") @@ -369,17 +421,15 @@ def _layout_row_children( min_child_content_width = child.layout.min_content_width child_width = ( - child.style.padding_left - + child_content_width - + child.style.padding_right + child.style.margin_left + child_content_width + child.style.margin_right ) width += child_width remaining_width -= child_width min_child_width = ( - child.style.padding_left + child.style.margin_left + min_child_content_width - + child.style.padding_right + + child.style.margin_right ) min_width += min_child_width @@ -401,9 +451,9 @@ def _layout_row_children( # self._debug(f"- {child} overflows ideal width") flex_total -= child.style.flex min_flex -= ( - child.style.padding_left + child.style.margin_left + child.intrinsic.width.value - + child.style.padding_right + + child.style.margin_right ) except AttributeError: # Intrinsic width isn't flexible @@ -428,9 +478,9 @@ def _layout_row_children( if child.intrinsic.width is not None: try: child_alloc_width = ( - child.style.padding_left + child.style.margin_left + child.intrinsic.width.value - + child.style.padding_right + + child.style.margin_right ) ideal_width = quantum * child.style.flex # self._debug(f"- flexible intrinsic {child_alloc_width=}") @@ -473,7 +523,7 @@ def _layout_row_children( else: # self._debug("- unspecified flex width") child_alloc_width = ( - child.style.padding_left + child.style.padding_right + child.style.margin_left + child.style.margin_right ) child.style._layout_node( @@ -508,26 +558,26 @@ def _layout_row_children( # self._debug(f"PASS 3: {child} AT HORIZONTAL {offset=}") if node.style.text_direction is RTL: # self._debug("- RTL") - offset += child.layout.content_width + child.style.padding_right + offset += child.layout.content_width + child.style.margin_right child.layout.content_left = width - offset - offset += child.style.padding_left + offset += child.style.margin_left else: # self._debug("- LTR") - offset += child.style.padding_left + offset += child.style.margin_left child.layout.content_left = offset - offset += child.layout.content_width + child.style.padding_right + offset += child.layout.content_width + child.style.margin_right child_height = ( - child.style.padding_top + child.style.margin_top + child.layout.content_height - + child.style.padding_bottom + + child.style.margin_bottom ) height = max(height, child_height) min_child_height = ( - child.style.padding_top + child.style.margin_top + child.layout.min_content_height - + child.style.padding_bottom + + child.style.margin_bottom ) min_height = max(min_height, min_child_height) @@ -541,18 +591,18 @@ def _layout_row_children( # self._debug(f"PASS 4: {child}") extra = height - ( child.layout.content_height - + child.style.padding_top - + child.style.padding_bottom + + child.style.margin_top + + child.style.margin_bottom ) # self._debug(f"- row extra width {extra}") - if self.alignment is BOTTOM: - child.layout.content_top = extra + child.style.padding_top + if self.align_items is BOTTOM: + child.layout.content_top = extra + child.style.margin_top # self._debug(f" align {child} to bottom {child.layout.content_top=}") - elif self.alignment is CENTER: - child.layout.content_top = int(extra / 2) + child.style.padding_top + elif self.align_items is CENTER: + child.layout.content_top = int(extra / 2) + child.style.margin_top # self._debug(f" align {child} to center {child.layout.content_top=}") else: - child.layout.content_top = child.style.padding_top + child.layout.content_top = child.style.margin_top # self._debug(f" align {child} to top {child.layout.content_top=}") return min_width, width, min_height, height @@ -603,9 +653,9 @@ def _layout_column_children( child_content_height = child.intrinsic.height.value min_child_content_height = child.intrinsic.height.value min_flex += ( - child.style.padding_top + child.style.margin_top + child_content_height - + child.style.padding_bottom + + child.style.margin_bottom ) else: # self._debug(f"- intrinsic non-flex {child.intrinsic.height=}") @@ -655,17 +705,17 @@ def _layout_column_children( min_child_content_height = child.layout.min_content_height child_height = ( - child.style.padding_top + child.style.margin_top + child_content_height - + child.style.padding_bottom + + child.style.margin_bottom ) height += child_height remaining_height -= child_height min_child_height = ( - child.style.padding_top + child.style.margin_top + min_child_content_height - + child.style.padding_bottom + + child.style.margin_bottom ) min_height += min_child_height @@ -687,9 +737,9 @@ def _layout_column_children( # self._debug(f"- {child} overflows ideal height") flex_total -= child.style.flex min_flex -= ( - child.style.padding_top + child.style.margin_top + child.intrinsic.height.value - + child.style.padding_bottom + + child.style.margin_bottom ) except AttributeError: # Intrinsic height isn't flexible @@ -715,9 +765,9 @@ def _layout_column_children( if child.intrinsic.height is not None: try: child_alloc_height = ( - child.style.padding_top + child.style.margin_top + child.intrinsic.height.value - + child.style.padding_bottom + + child.style.margin_bottom ) ideal_height = quantum * child.style.flex # self._debug(f"- flexible intrinsic {child_alloc_height=}") @@ -760,7 +810,7 @@ def _layout_column_children( else: # self._debug("- unspecified flex height") child_alloc_height = ( - child.style.padding_top + child.style.padding_bottom + child.style.margin_top + child.style.margin_bottom ) child.style._layout_node( @@ -794,20 +844,20 @@ def _layout_column_children( min_width = 0 for child in node.children: # self._debug(f"PASS 3: {child} AT VERTICAL OFFSET {offset}") - offset += child.style.padding_top + offset += child.style.margin_top child.layout.content_top = offset - offset += child.layout.content_height + child.style.padding_bottom + offset += child.layout.content_height + child.style.margin_bottom child_width = ( child.layout.content_width - + child.style.padding_left - + child.style.padding_right + + child.style.margin_left + + child.style.margin_right ) width = max(width, child_width) min_child_width = ( - child.style.padding_left + child.style.margin_left + child.layout.min_content_width - + child.style.padding_right + + child.style.margin_right ) min_width = max(min_width, min_child_width) @@ -821,18 +871,18 @@ def _layout_column_children( # self._debug(f"PASS 4: {child}") extra = width - ( child.layout.content_width - + child.style.padding_left - + child.style.padding_right + + child.style.margin_left + + child.style.margin_right ) # self._debug(f"- row extra width {extra}") - if self.alignment is RIGHT: - child.layout.content_left = extra + child.style.padding_left + if self.align_items is RIGHT: + child.layout.content_left = extra + child.style.margin_left # self._debug(f" align {child} to right {child.layout.content_left=}") - elif self.alignment is CENTER: - child.layout.content_left = int(extra / 2) + child.style.padding_left + elif self.align_items is CENTER: + child.layout.content_left = int(extra / 2) + child.style.margin_left # self._debug(f" align {child} to center {child.layout.content_left=}") else: - child.layout.content_left = child.style.padding_left + child.layout.content_left = child.style.margin_left # self._debug(f" align {child} to left {child.layout.content_left=}") return min_width, width, min_height, height @@ -867,33 +917,33 @@ def __css__(self) -> str: if self.height != NONE: css.append(f"height: {self.height}px;") - # alignment + # align_items if self.direction == ROW: - if self.alignment: - if self.alignment == LEFT: + if self.align_items: + if self.align_items == LEFT: css.append("align-items: start;") - elif self.alignment == RIGHT: + elif self.align_items == RIGHT: css.append("align-items: end;") - elif self.alignment == CENTER: + elif self.align_items == CENTER: css.append("align-items: center;") else: - if self.alignment: - if self.alignment == TOP: + if self.align_items: + if self.align_items == TOP: css.append("align-items: start;") - elif self.alignment == BOTTOM: + elif self.align_items == BOTTOM: css.append("align-items: end;") - elif self.alignment == CENTER: + elif self.align_items == CENTER: css.append("align-items: center;") - # padding_* - if self.padding_top: - css.append(f"margin-top: {self.padding_top}px;") - if self.padding_bottom: - css.append(f"margin-bottom: {self.padding_bottom}px;") - if self.padding_left: - css.append(f"margin-left: {self.padding_left}px;") - if self.padding_right: - css.append(f"margin-right: {self.padding_right}px;") + # margin_* + if self.margin_top: + css.append(f"margin-top: {self.margin_top}px;") + if self.margin_bottom: + css.append(f"margin-bottom: {self.margin_bottom}px;") + if self.margin_left: + css.append(f"margin-left: {self.margin_left}px;") + if self.margin_right: + css.append(f"margin-right: {self.margin_right}px;") # color if self.color: @@ -932,17 +982,17 @@ 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) +Pack.validated_property("align_items", choices=ALIGN_ITEMS_CHOICES) Pack.validated_property("width", choices=SIZE_CHOICES, initial=NONE) Pack.validated_property("height", choices=SIZE_CHOICES, initial=NONE) Pack.validated_property("flex", choices=FLEX_CHOICES, initial=0) -Pack.validated_property("padding_top", choices=PADDING_CHOICES, initial=0) -Pack.validated_property("padding_right", choices=PADDING_CHOICES, initial=0) -Pack.validated_property("padding_bottom", choices=PADDING_CHOICES, initial=0) -Pack.validated_property("padding_left", choices=PADDING_CHOICES, initial=0) -Pack.directional_property("padding%s") +Pack.validated_property("margin_top", choices=MARGIN_CHOICES, initial=0) +Pack.validated_property("margin_right", choices=MARGIN_CHOICES, initial=0) +Pack.validated_property("margin_bottom", choices=MARGIN_CHOICES, initial=0) +Pack.validated_property("margin_left", choices=MARGIN_CHOICES, initial=0) +Pack.directional_property("margin%s") Pack.validated_property("color", choices=COLOR_CHOICES) Pack.validated_property("background_color", choices=BACKGROUND_COLOR_CHOICES) diff --git a/core/tests/style/pack/layout/test_beeliza.py b/core/tests/style/pack/layout/test_beeliza.py index c9dbec657e..985afbcf73 100644 --- a/core/tests/style/pack/layout/test_beeliza.py +++ b/core/tests/style/pack/layout/test_beeliza.py @@ -21,11 +21,11 @@ def test_beeliza(): children=[ ExampleNode( "input", - style=Pack(flex=1, padding=5), + style=Pack(flex=1, margin=5), size=(at_least(100), 15), ), ExampleNode( - "button", style=Pack(padding=5), size=(at_least(40), 10) + "button", style=Pack(margin=5), size=(at_least(40), 10) ), ], ), diff --git a/core/tests/style/pack/layout/test_column_alignment.py b/core/tests/style/pack/layout/test_column_alignment.py index 20b2dbd2f9..b583d22759 100644 --- a/core/tests/style/pack/layout/test_column_alignment.py +++ b/core/tests/style/pack/layout/test_column_alignment.py @@ -6,20 +6,20 @@ def test_left(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, alignment=LEFT, height=300), + style=Pack(direction=COLUMN, align_items=LEFT, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode( "container", - style=Pack(direction=ROW, padding_left=110, padding_right=120), + style=Pack(direction=ROW, margin_left=110, margin_right=120), children=[ ExampleNode( "widget_a", - style=Pack(width=30, padding_left=32, padding_right=34), + style=Pack(width=30, margin_left=32, margin_right=34), ), ExampleNode( "widget_b", - style=Pack(width=36, padding_left=38, padding_right=40), + style=Pack(width=36, margin_left=38, margin_right=40), ), ], ), @@ -52,20 +52,20 @@ def test_left(): def test_center(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, alignment=CENTER, height=300), + style=Pack(direction=COLUMN, align_items=CENTER, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode( "container", - style=Pack(direction=ROW, padding_left=110, padding_right=120), + style=Pack(direction=ROW, margin_left=110, margin_right=120), children=[ ExampleNode( "widget_a", - style=Pack(width=30, padding_left=32, padding_right=34), + style=Pack(width=30, margin_left=32, margin_right=34), ), ExampleNode( "widget_b", - style=Pack(width=36, padding_left=38, padding_right=40), + style=Pack(width=36, margin_left=38, margin_right=40), ), ], ), @@ -98,20 +98,20 @@ def test_center(): def test_right(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, alignment=RIGHT, height=300), + style=Pack(direction=COLUMN, align_items=RIGHT, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode( "container", - style=Pack(direction=ROW, padding_left=110, padding_right=120), + style=Pack(direction=ROW, margin_left=110, margin_right=120), children=[ ExampleNode( "widget_a", - style=Pack(width=30, padding_left=32, padding_right=34), + style=Pack(width=30, margin_left=32, margin_right=34), ), ExampleNode( "widget_b", - style=Pack(width=36, padding_left=38, padding_right=40), + style=Pack(width=36, margin_left=38, margin_right=40), ), ], ), @@ -141,10 +141,10 @@ def test_right(): ) -def test_no_padding(): +def test_no_margin(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, alignment=CENTER, height=300), + style=Pack(direction=COLUMN, align_items=CENTER, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode("widget", style=Pack(width=440)), @@ -170,23 +170,23 @@ def test_no_padding(): def test_column_box(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, alignment=CENTER), + style=Pack(direction=COLUMN, align_items=CENTER), children=[ ExampleNode("space_filler", style=Pack(width=430, height=100)), ExampleNode( "container", - style=Pack(direction=COLUMN, padding_left=110, padding_right=120), + style=Pack(direction=COLUMN, margin_left=110, margin_right=120), children=[ ExampleNode( "widget_a", style=Pack( - width=100, height=30, padding_top=32, padding_bottom=34 + width=100, height=30, margin_top=32, margin_bottom=34 ), ), ExampleNode( "widget_b", style=Pack( - width=100, height=36, padding_top=38, padding_bottom=40 + width=100, height=36, margin_top=38, margin_bottom=40 ), ), ], diff --git a/core/tests/style/pack/layout/test_row_alignment.py b/core/tests/style/pack/layout/test_row_alignment.py index 941dad8663..14b526226f 100644 --- a/core/tests/style/pack/layout/test_row_alignment.py +++ b/core/tests/style/pack/layout/test_row_alignment.py @@ -6,20 +6,20 @@ def test_top(): root = ExampleNode( "root", - style=Pack(direction=ROW, alignment=TOP, width=300), + style=Pack(direction=ROW, align_items=TOP, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode( "container", - style=Pack(direction=COLUMN, padding_top=110, padding_bottom=120), + style=Pack(direction=COLUMN, margin_top=110, margin_bottom=120), children=[ ExampleNode( "widget_a", - style=Pack(height=30, padding_top=32, padding_bottom=34), + style=Pack(height=30, margin_top=32, margin_bottom=34), ), ExampleNode( "widget_b", - style=Pack(height=36, padding_top=38, padding_bottom=40), + style=Pack(height=36, margin_top=38, margin_bottom=40), ), ], ), @@ -52,20 +52,20 @@ def test_top(): def test_center(): root = ExampleNode( "root", - style=Pack(direction=ROW, alignment=CENTER, width=300), + style=Pack(direction=ROW, align_items=CENTER, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode( "container", - style=Pack(direction=COLUMN, padding_top=110, padding_bottom=120), + style=Pack(direction=COLUMN, margin_top=110, margin_bottom=120), children=[ ExampleNode( "widget_a", - style=Pack(height=30, padding_top=32, padding_bottom=34), + style=Pack(height=30, margin_top=32, margin_bottom=34), ), ExampleNode( "widget_b", - style=Pack(height=36, padding_top=38, padding_bottom=40), + style=Pack(height=36, margin_top=38, margin_bottom=40), ), ], ), @@ -98,20 +98,20 @@ def test_center(): def test_bottom(): root = ExampleNode( "root", - style=Pack(direction=ROW, alignment=BOTTOM, width=300), + style=Pack(direction=ROW, align_items=BOTTOM, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode( "container", - style=Pack(direction=COLUMN, padding_top=110, padding_bottom=120), + style=Pack(direction=COLUMN, margin_top=110, margin_bottom=120), children=[ ExampleNode( "widget_a", - style=Pack(height=30, padding_top=32, padding_bottom=34), + style=Pack(height=30, margin_top=32, margin_bottom=34), ), ExampleNode( "widget_b", - style=Pack(height=36, padding_top=38, padding_bottom=40), + style=Pack(height=36, margin_top=38, margin_bottom=40), ), ], ), @@ -141,10 +141,10 @@ def test_bottom(): ) -def test_no_padding(): +def test_no_margin(): root = ExampleNode( "root", - style=Pack(direction=ROW, alignment=CENTER, width=300), + style=Pack(direction=ROW, align_items=CENTER, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode("widget", style=Pack(height=440)), @@ -170,23 +170,23 @@ def test_no_padding(): def test_row_box(): root = ExampleNode( "root", - style=Pack(direction=ROW, alignment=CENTER), + style=Pack(direction=ROW, align_items=CENTER), children=[ ExampleNode("space_filler", style=Pack(width=100, height=430)), ExampleNode( "container", - style=Pack(direction=ROW, padding_top=110, padding_bottom=120), + style=Pack(direction=ROW, margin_top=110, margin_bottom=120), children=[ ExampleNode( "widget_a", style=Pack( - width=30, height=100, padding_left=32, padding_right=34 + width=30, height=100, margin_left=32, margin_right=34 ), ), ExampleNode( "widget_b", style=Pack( - width=36, height=100, padding_left=38, padding_right=40 + width=36, height=100, margin_left=38, margin_right=40 ), ), ], diff --git a/core/tests/style/pack/layout/test_rtl.py b/core/tests/style/pack/layout/test_rtl.py index 5ba231816b..9ea9b8100d 100644 --- a/core/tests/style/pack/layout/test_rtl.py +++ b/core/tests/style/pack/layout/test_rtl.py @@ -10,11 +10,11 @@ def test_row_box_child_layout(): children=[ ExampleNode( "widget_a", - style=Pack(width=30, height=100, padding_left=32, padding_right=34), + style=Pack(width=30, height=100, margin_left=32, margin_right=34), ), ExampleNode( "widget_b", - style=Pack(width=36, height=100, padding_left=38, padding_right=40), + style=Pack(width=36, height=100, margin_left=38, margin_right=40), ), ], ) @@ -42,11 +42,11 @@ def test_column_box_child_layout(): children=[ ExampleNode( "widget_a", - style=Pack(width=100, height=30, padding_top=32, padding_bottom=34), + style=Pack(width=100, height=30, margin_top=32, margin_bottom=34), ), ExampleNode( "widget_b", - style=Pack(width=100, height=36, padding_top=38, padding_bottom=40), + style=Pack(width=100, height=36, margin_top=38, margin_bottom=40), ), ], ) @@ -68,10 +68,10 @@ def test_column_box_child_layout(): ) -def test_alignment_top(): +def test_align_items_top(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=ROW, alignment=TOP), + style=Pack(text_direction=RTL, direction=ROW, align_items=TOP), children=[ ExampleNode("space_filler", style=Pack(width=30, height=100)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -94,10 +94,10 @@ def test_alignment_top(): ) -def test_alignment_bottom(): +def test_align_items_bottom(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=ROW, alignment=BOTTOM), + style=Pack(text_direction=RTL, direction=ROW, align_items=BOTTOM), children=[ ExampleNode("space_filler", style=Pack(width=30, height=100)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -120,10 +120,10 @@ def test_alignment_bottom(): ) -def test_alignment_left(): +def test_align_items_left(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=COLUMN, alignment=LEFT), + style=Pack(text_direction=RTL, direction=COLUMN, align_items=LEFT), children=[ ExampleNode("space_filler", style=Pack(width=100, height=30)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -146,10 +146,10 @@ def test_alignment_left(): ) -def test_alignment_right(): +def test_align_items_right(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=COLUMN, alignment=RIGHT), + style=Pack(text_direction=RTL, direction=COLUMN, align_items=RIGHT), children=[ ExampleNode("space_filler", style=Pack(width=100, height=30)), ExampleNode("widget", style=Pack(width=30, height=30)), diff --git a/core/tests/style/pack/layout/test_tutorial0.py b/core/tests/style/pack/layout/test_tutorial0.py index 6c72c0dbeb..00d04eac06 100644 --- a/core/tests/style/pack/layout/test_tutorial0.py +++ b/core/tests/style/pack/layout/test_tutorial0.py @@ -11,7 +11,7 @@ def test_tutorial_0(): style=Pack(), children=[ ExampleNode( - "button", style=Pack(flex=1, padding=50), size=(at_least(120), 30) + "button", style=Pack(flex=1, margin=50), size=(at_least(120), 30) ), ], ) @@ -36,7 +36,7 @@ def test_vertical(): children=[ # ExampleNode('button', style=Pack(flex=1), size=(30, at_least(120))), ExampleNode( - "button", style=Pack(flex=1, padding=50), size=(30, at_least(120)) + "button", style=Pack(flex=1, margin=50), size=(30, at_least(120)) ), ], ) diff --git a/core/tests/style/pack/layout/test_tutorial1.py b/core/tests/style/pack/layout/test_tutorial1.py index a84e2b13bd..7992cba5f2 100644 --- a/core/tests/style/pack/layout/test_tutorial1.py +++ b/core/tests/style/pack/layout/test_tutorial1.py @@ -8,31 +8,31 @@ def test_tutorial_1(): root = ExampleNode( "app", - style=Pack(direction=COLUMN, padding_top=10), + style=Pack(direction=COLUMN, margin_top=10), children=[ ExampleNode( "f_box", - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ ExampleNode( "f_input", - style=Pack(flex=1, padding_left=160), + style=Pack(flex=1, margin_left=160), size=(at_least(100), 15), ), ExampleNode( "f_label", - style=Pack(width=100, padding_left=10), + style=Pack(width=100, margin_left=10), size=(at_least(40), 10), ), ], ), ExampleNode( "c_box", - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ ExampleNode( "join_label", - style=Pack(width=150, padding_right=10), + style=Pack(width=150, margin_right=10), size=(at_least(80), 10), ), ExampleNode( @@ -40,13 +40,13 @@ def test_tutorial_1(): ), ExampleNode( "c_label", - style=Pack(width=100, padding_left=10), + style=Pack(width=100, margin_left=10), size=(at_least(40), 10), ), ], ), ExampleNode( - "button", style=Pack(flex=1, padding=15), size=(at_least(120), 30) + "button", style=Pack(flex=1, margin=15), size=(at_least(120), 30) ), ], ) diff --git a/core/tests/style/pack/layout/test_tutorial3.py b/core/tests/style/pack/layout/test_tutorial3.py index 1dc4c81d5b..2d7b0d1563 100644 --- a/core/tests/style/pack/layout/test_tutorial3.py +++ b/core/tests/style/pack/layout/test_tutorial3.py @@ -16,12 +16,12 @@ def test_tutorial_3(): children=[ ExampleNode( "input", - style=Pack(flex=1, padding=5), + style=Pack(flex=1, margin=5), size=(at_least(100), 15), ), ExampleNode( "button", - style=Pack(width=50, padding=5), + style=Pack(width=50, margin=5), size=(at_least(40), 10), ), ], diff --git a/core/tests/style/pack/test_apply.py b/core/tests/style/pack/test_apply.py index 2a0dea3ad5..04a7b0826e 100644 --- a/core/tests/style/pack/test_apply.py +++ b/core/tests/style/pack/test_apply.py @@ -20,7 +20,7 @@ def test_set_default_right_textalign_when_rtl(): root.style.reapply() # Two calls; one caused by text_align, one because text_direction # implies a change to text alignment. - assert root._impl.set_alignment.mock_calls == [call(RIGHT), call(RIGHT)] + assert root._impl.set_text_alignment.mock_calls == [call(RIGHT), call(RIGHT)] def test_set_default_left_textalign_when_no_rtl(): @@ -28,13 +28,13 @@ def test_set_default_left_textalign_when_no_rtl(): root.style.reapply() # Two calls; one caused by text_align, one because text_direction # implies a change to text alignment. - assert root._impl.set_alignment.mock_calls == [call(LEFT), call(LEFT)] + assert root._impl.set_text_alignment.mock_calls == [call(LEFT), call(LEFT)] -def test_set_center_alignment(): +def test_set_center_text_alignment(): root = ExampleNode("app", style=Pack(text_align="center")) root.style.reapply() - root._impl.set_alignment.assert_called_once_with(CENTER) + root._impl.set_text_alignment.assert_called_once_with(CENTER) def test_set_color(): diff --git a/core/tests/style/pack/test_css.py b/core/tests/style/pack/test_css.py index 5630ab1b50..53b446816a 100644 --- a/core/tests/style/pack/test_css.py +++ b/core/tests/style/pack/test_css.py @@ -222,137 +222,137 @@ ), # Alignment - default layout pytest.param( - Pack(alignment=LEFT), + Pack(align_items=LEFT), "flex-direction: row; flex: 0.0 0 auto; align-items: start;", - id="alignment-left", + id="align-items-left", ), pytest.param( - Pack(alignment=RIGHT), + Pack(align_items=RIGHT), "flex-direction: row; flex: 0.0 0 auto; align-items: end;", - id="alignment-right", + id="align-items-right", ), - pytest.param( # alignment is ignored - Pack(alignment=TOP), + pytest.param( # align_items is ignored + Pack(align_items=TOP), "flex-direction: row; flex: 0.0 0 auto;", - id="alignment-top", + id="align-items-top", ), - pytest.param( # alignment is ignored - Pack(alignment=BOTTOM), + pytest.param( # align_items is ignored + Pack(align_items=BOTTOM), "flex-direction: row; flex: 0.0 0 auto;", - id="alignment-bottom", + id="align-items-bottom", ), pytest.param( - Pack(alignment=CENTER), + Pack(align_items=CENTER), "flex-direction: row; flex: 0.0 0 auto; align-items: center;", - id="alignment-center", + id="align-items-center", ), # Alignment - row layout pytest.param( - Pack(direction=ROW, alignment=LEFT), + Pack(direction=ROW, align_items=LEFT), "flex-direction: row; flex: 0.0 0 auto; align-items: start;", - id="row-alignment-left", + id="row-align_items-left", ), pytest.param( - Pack(direction=ROW, alignment=RIGHT), + Pack(direction=ROW, align_items=RIGHT), "flex-direction: row; flex: 0.0 0 auto; align-items: end;", - id="row-alignment-right", + id="row-align_items-right", ), - pytest.param( # alignment is ignored - Pack(direction=ROW, alignment=TOP), + pytest.param( # align_items is ignored + Pack(direction=ROW, align_items=TOP), "flex-direction: row; flex: 0.0 0 auto;", - id="row-alignment-top", + id="row-align_items-top", ), - pytest.param( # alignment is ignored - Pack(direction=ROW, alignment=BOTTOM), + pytest.param( # align_items is ignored + Pack(direction=ROW, align_items=BOTTOM), "flex-direction: row; flex: 0.0 0 auto;", - id="row-alignment-bottom", + id="row-align_items-bottom", ), pytest.param( - Pack(direction=ROW, alignment=CENTER), + Pack(direction=ROW, align_items=CENTER), "flex-direction: row; flex: 0.0 0 auto; align-items: center;", - id="row-alignment-center", + id="row-align_items-center", ), # Alignment - column layout - pytest.param( # alignment is ignored - Pack(direction=COLUMN, alignment=LEFT), + pytest.param( # align_items is ignored + Pack(direction=COLUMN, align_items=LEFT), "flex-direction: column; flex: 0.0 0 auto;", - id="column-alignment-left", + id="column-align_items-left", ), - pytest.param( # alignment is ignored - Pack(direction=COLUMN, alignment=RIGHT), + pytest.param( # align_items is ignored + Pack(direction=COLUMN, align_items=RIGHT), "flex-direction: column; flex: 0.0 0 auto;", - id="column-alignment-right", + id="column-align_items-right", ), pytest.param( - Pack(direction=COLUMN, alignment=TOP), + Pack(direction=COLUMN, align_items=TOP), "flex-direction: column; flex: 0.0 0 auto; align-items: start;", - id="column-alignment-top", + id="column-align_items-top", ), pytest.param( - Pack(direction=COLUMN, alignment=BOTTOM), + Pack(direction=COLUMN, align_items=BOTTOM), "flex-direction: column; flex: 0.0 0 auto; align-items: end;", - id="column-alignment-bottom", + id="column-align_items-bottom", ), pytest.param( - Pack(direction=COLUMN, alignment=CENTER), + Pack(direction=COLUMN, align_items=CENTER), "flex-direction: column; flex: 0.0 0 auto; align-items: center;", - id="column-alignment-center", + id="column-align_items-center", ), - # Padding + # Margin pytest.param( - Pack(padding_top=42), + Pack(margin_top=42), "flex-direction: row; flex: 0.0 0 auto; margin-top: 42px;", - id="padding-top", + id="margin-top", ), pytest.param( - Pack(padding_bottom=42), + Pack(margin_bottom=42), "flex-direction: row; flex: 0.0 0 auto; margin-bottom: 42px;", - id="padding-bottom", + id="margin-bottom", ), pytest.param( - Pack(padding_left=42), + Pack(margin_left=42), "flex-direction: row; flex: 0.0 0 auto; margin-left: 42px;", - id="padding-left", + id="margin-left", ), pytest.param( - Pack(padding_right=42), + Pack(margin_right=42), "flex-direction: row; flex: 0.0 0 auto; margin-right: 42px;", - id="padding-right", + id="margin-right", ), pytest.param( - Pack(padding=42), + Pack(margin=42), ( "flex-direction: row; flex: 0.0 0 auto; " "margin-top: 42px; margin-bottom: 42px; " "margin-left: 42px; margin-right: 42px;" ), - id="padding", + id="margin", ), - # Explicitly 0 padding + # Explicitly 0 margin pytest.param( - Pack(padding_top=0), + Pack(margin_top=0), "flex-direction: row; flex: 0.0 0 auto;", - id="padding-top-0", + id="margin-top-0", ), pytest.param( - Pack(padding_bottom=0), + Pack(margin_bottom=0), "flex-direction: row; flex: 0.0 0 auto;", - id="padding-bottom-0", + id="margin-bottom-0", ), pytest.param( - Pack(padding_left=0), + Pack(margin_left=0), "flex-direction: row; flex: 0.0 0 auto;", - id="padding-left-0", + id="margin-left-0", ), pytest.param( - Pack(padding_right=0), + Pack(margin_right=0), "flex-direction: row; flex: 0.0 0 auto;", - id="padding-right-0", + id="margin-right-0", ), pytest.param( - Pack(padding=0), + Pack(margin=0), "flex-direction: row; flex: 0.0 0 auto;", - id="padding-0", + id="margin-0", ), # Color pytest.param( diff --git a/core/tests/style/pack/test_deprecated_properties.py b/core/tests/style/pack/test_deprecated_properties.py new file mode 100644 index 0000000000..b65f455369 --- /dev/null +++ b/core/tests/style/pack/test_deprecated_properties.py @@ -0,0 +1,58 @@ +import pytest + +from toga.style.pack import Pack + + +def setitem(obj, name, value): + obj[name] = value + + +def getitem(obj, name): + return obj[name] + + +@pytest.mark.parametrize( + "old_name, new_name, value", + [ + # Travertino 0.3.0 doesn't support accessing a directional property via bracket + # notation. + # ("padding", "margin", (5, 5, 5, 5)), + ("padding_top", "margin_top", 5), + ("padding_right", "margin_right", 5), + ("padding_bottom", "margin_bottom", 5), + ("padding_left", "margin_left", 5), + ("alignment", "align_items", "center"), + ], +) +@pytest.mark.parametrize("set_fn", (setattr, setitem)) +@pytest.mark.parametrize("get_fn", (getattr, getitem)) +def test_deprecated_properties(old_name, new_name, value, set_fn, get_fn): + """Deprecated names alias to new names, and issue deprecation warnings.""" + + # Set the old name, then check the new name. + style = Pack() + with pytest.warns(DeprecationWarning): + set_fn(style, old_name, value) + assert get_fn(style, new_name) == value + + # Set the new name, then check the old name. + style = Pack() + set_fn(style, new_name, value) + with pytest.warns(DeprecationWarning): + assert get_fn(style, old_name) == value + + +def test_padding_margin(): + """Padding aliases margin, but can't be checked with bracket notation.""" + + # Set the old name, then check the new name. + style = Pack() + with pytest.warns(DeprecationWarning): + style.padding = (5, 5, 5, 5) + assert style.margin == (5, 5, 5, 5) + + # Set the new name, then check the old name. + style = Pack() + style.margin = (5, 5, 5, 5) + with pytest.warns(DeprecationWarning): + assert style.padding == (5, 5, 5, 5) diff --git a/core/tests/style/test_applicator.py b/core/tests/style/test_applicator.py index 01a0594bf3..4091549118 100644 --- a/core/tests/style/test_applicator.py +++ b/core/tests/style/test_applicator.py @@ -71,7 +71,7 @@ def test_text_alignment(widget): """Text alignment can be set on a widget.""" widget.applicator.set_text_alignment(RIGHT) - assert_action_performed_with(widget, "set alignment", alignment=RIGHT) + assert_action_performed_with(widget, "set text alignment", alignment=RIGHT) @pytest.mark.parametrize( diff --git a/core/tests/widgets/test_base.py b/core/tests/widgets/test_base.py index 9052bdf095..761bb79146 100644 --- a/core/tests/widgets/test_base.py +++ b/core/tests/widgets/test_base.py @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs): @pytest.fixture def widget(app): # App fixture is needed to ensure a fresh widget registry is created - return ExampleWidget(id="widget_id", style=Pack(padding=666)) + return ExampleWidget(id="widget_id", style=Pack(margin=666)) def test_simple_widget(): @@ -50,7 +50,7 @@ def test_simple_widget(): # Base properties of the widget have been set assert widget.id == str(id(widget)) assert isinstance(widget.style, Pack) - assert widget.style.padding == (0, 0, 0, 0) + assert widget.style.margin == (0, 0, 0, 0) def test_widget_created(widget): @@ -63,7 +63,7 @@ def test_widget_created(widget): assert widget.enabled assert widget.id == "widget_id" assert isinstance(widget.style, Pack) - assert widget.style.padding == (666, 666, 666, 666) + assert widget.style.margin == (666, 666, 666, 666) def test_add_child_to_leaf(): diff --git a/demo/toga_demo/app.py b/demo/toga_demo/app.py index e272f8c869..8d015d6f07 100755 --- a/demo/toga_demo/app.py +++ b/demo/toga_demo/app.py @@ -50,7 +50,7 @@ def startup(self): toga.Button( "Hello world %s" % b, on_press=self.button_handler, - style=Pack(padding=20), + style=Pack(margin=20), ) ) diff --git a/docs/reference/api/containers/box.rst b/docs/reference/api/containers/box.rst index 0869688821..7e973c7e7e 100644 --- a/docs/reference/api/containers/box.rst +++ b/docs/reference/api/containers/box.rst @@ -41,7 +41,7 @@ Alternatively, children can be specified at the time the box is constructed: In most apps, a layout is constructed by building a tree of boxes inside boxes, with concrete widgets (such as :class:`~toga.Label` or :class:`~toga.Button`) forming the -leaf nodes of the tree. Style directives can be applied to enforce padding around the +leaf nodes of the tree. Style directives can be applied to enforce margin around the outside of the box, direction of child stacking inside the box, and background color of the box. diff --git a/docs/reference/api/widgets/divider.rst b/docs/reference/api/widgets/divider.rst index 663f6cf809..67db585a34 100644 --- a/docs/reference/api/widgets/divider.rst +++ b/docs/reference/api/widgets/divider.rst @@ -63,7 +63,7 @@ To separate two labels stacked vertically with a horizontal line: toga.Divider(), toga.Label("Second section"), ], - style=Pack(direction=COLUMN, flex=1, padding=10) + style=Pack(direction=COLUMN, flex=1, margin=10) ) The direction (horizontal or vertical) can be given as an argument. If not diff --git a/docs/reference/api/widgets/label.rst b/docs/reference/api/widgets/label.rst index cfc5119e0c..aca16c1a23 100644 --- a/docs/reference/api/widgets/label.rst +++ b/docs/reference/api/widgets/label.rst @@ -63,7 +63,7 @@ Usage Notes ----- -* Winforms does not support an alignment value of ``JUSTIFIED``. If this +* Winforms does not support a text alignment value of ``JUSTIFIED``. If this alignment value is used, the label will default to left alignment. Reference diff --git a/docs/reference/api/widgets/selection.rst b/docs/reference/api/widgets/selection.rst index c398956425..7adf1ce177 100644 --- a/docs/reference/api/widgets/selection.rst +++ b/docs/reference/api/widgets/selection.rst @@ -105,7 +105,7 @@ Notes * On macOS and Android, you cannot change the font of a Selection. * On macOS, GTK and Android, you cannot change the text color, background color, or - alignment of labels in a Selection. + text alignment of labels in a Selection. * On GTK, a Selection widget with flexible sizing will expand its width (to the extent possible possible) to accommodate any changes in content (for example, diff --git a/docs/reference/style/pack.rst b/docs/reference/style/pack.rst index caafe24257..9c76dda8c3 100644 --- a/docs/reference/style/pack.rst +++ b/docs/reference/style/pack.rst @@ -64,7 +64,7 @@ children will be stacked vertically, from top to bottom. A value of ``row`` indicates children will be packed horizontally; left-to-right if ``text_direction`` is ``ltr``, or right-to-left if ``text_direction`` is ``rtl``. -``alignment`` +``align_items`` ------------- **Values:** ``top`` | ``bottom`` | ``left`` | ``right`` | ``center`` @@ -121,16 +121,16 @@ Once fixed space allocations have been performed, this box will assume ``flex / (sum of all flex for all siblings)`` of all remaining available space in the direction of the parent's layout. -``padding_top`` +``margin_top`` --------------- -``padding_right`` +``margin_right`` ----------------- -``padding_bottom`` +``margin_bottom`` ------------------ -``padding_left`` +``margin_left`` ---------------- **Values:** ```` @@ -140,20 +140,20 @@ direction of the parent's layout. The amount of space to allocate between the edge of the box, and the edge of the content in the box, in :ref:`CSS pixels `. -``padding`` +``margin`` ----------- **Values:** ```` or ```` of length 1-4 -A shorthand for setting the top, right, bottom and left padding with a single declaration. +A shorthand for setting the top, right, bottom and left margin with a single declaration. -If 1 integer is provided, that value will be used as the padding for all sides. +If 1 integer is provided, that value will be used as the margin for all sides. -If 2 integers are provided, the first value will be used as the padding for the top and bottom; the second will be used as the value for the left and right. +If 2 integers are provided, the first value will be used as the margin for the top and bottom; the second will be used as the value for the left and right. -If 3 integers are provided, the first value will be used as the top padding, the second for the left and right padding, and the third for the bottom padding. +If 3 integers are provided, the first value will be used as the top margin, the second for the left and right margin, and the third for the bottom margin. -If 4 integers are provided, they will be used as the top, right, bottom and left padding, respectively. +If 4 integers are provided, they will be used as the top, right, bottom and left margin, respectively. ``color`` --------- @@ -323,7 +323,7 @@ The mapping that can be used to establish the reference implementation is: ============================= =================================================== Pack property CSS property ============================= =================================================== - ``alignment: top`` ``align-items: start`` if ``direction == row``; + ``align_items: top`` ``align-items: start`` if ``direction == row``; otherwise ignored. ``alignment: bottom`` ``align-items: end`` if ``direction == row``; otherwise ignored. @@ -340,10 +340,10 @@ The mapping that can be used to establish the reference implementation is: ``font_size: `` ``font-size: pt`` ``height: `` ``height: px`` if value is an integer; ``height: auto`` if value is ``none``. - ``padding_top: `` ``margin-top: px`` - ``padding_bottom: `` ``margin-bottom: px`` - ``padding_left: `` ``margin-left: px`` - ``padding_right: `` ``margin-right: px`` + ``margin_top: `` ``margin-top: px`` + ``margin_bottom: `` ``margin-bottom: px`` + ``margin_left: `` ``margin-left: px`` + ``margin_right: `` ``margin-right: px`` ``text_direction: `` ``direction: `` ``width: `` ``width: px`` if value is an integer; ``width: auto`` if value is ``none``. diff --git a/docs/tutorial/tutorial-0.rst b/docs/tutorial/tutorial-0.rst index 2965419118..e7864bf454 100644 --- a/docs/tutorial/tutorial-0.rst +++ b/docs/tutorial/tutorial-0.rst @@ -119,7 +119,7 @@ fill the entire app window, we can't just put the button into the app window. Instead, we need create a box, and put the button in the box. A box is an object that can be used to hold multiple widgets, and to -define padding around widgets. So, we define a box:: +define margin around widgets. So, we define a box:: box = toga.Box() @@ -133,12 +133,12 @@ Now we have to define how the button will appear in the window. By default, Toga uses a style algorithm called ``Pack``, which is a bit like "CSS-lite". We can set style properties of the button:: - button.style.padding = 50 + button.style.margin = 50 -What we've done here is say that the button will have a padding of 50 pixels -on all sides. If we wanted to define padding of 20 pixels on top of the -button, we could have defined ``padding_top = 20``, or we could have specified -the ``padding = (20, 50, 50, 50)``. +What we've done here is say that the button will have a margin of 50 pixels +on all sides. If we wanted to define margin of 20 pixels on top of the +button, we could have defined ``margin_top = 20``, or we could have specified +the ``margin = (20, 50, 50, 50)``. Now we will make the button take up all the available width:: diff --git a/docs/tutorial/tutorial-1.rst b/docs/tutorial/tutorial-1.rst index f04cba53bd..e9bd7416d6 100644 --- a/docs/tutorial/tutorial-1.rst +++ b/docs/tutorial/tutorial-1.rst @@ -20,5 +20,5 @@ Since there's no width styling on the horizontal boxes, they'll try to fit the widgets they contain into the available space. The ``TextInput`` widgets have a style of ``flex=1``, but the ``Label`` widgets have a fixed width; as a result, the ``TextInput`` widgets will be stretched to fit the -available horizontal space. The margin and padding terms then ensure that the +available horizontal space. The margin terms then ensure that the widgets will be aligned vertically and horizontally. diff --git a/dummy/src/toga_dummy/widgets/base.py b/dummy/src/toga_dummy/widgets/base.py index 186f3fb9a3..a3e76afd5d 100644 --- a/dummy/src/toga_dummy/widgets/base.py +++ b/dummy/src/toga_dummy/widgets/base.py @@ -44,8 +44,8 @@ def set_tab_index(self, tab_index): def set_bounds(self, x, y, width, height): self._action("set bounds", x=x, y=y, width=width, height=height) - def set_alignment(self, alignment): - self._action("set alignment", alignment=alignment) + def set_text_alignment(self, alignment): + self._action("set text alignment", alignment=alignment) def set_hidden(self, hidden): self._action("set hidden", hidden=hidden) diff --git a/examples/.template/{{ cookiecutter.name }}/{{ cookiecutter.name }}/app.py b/examples/.template/{{ cookiecutter.name }}/{{ cookiecutter.name }}/app.py index 2e179f619a..81e088a5eb 100644 --- a/examples/.template/{{ cookiecutter.name }}/{{ cookiecutter.name }}/app.py +++ b/examples/.template/{{ cookiecutter.name }}/{{ cookiecutter.name }}/app.py @@ -38,7 +38,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=10, + margin=10, width=500, height=300 ) diff --git a/examples/activityindicator/activityindicator/app.py b/examples/activityindicator/activityindicator/app.py index 75430b7552..3ced0d547f 100644 --- a/examples/activityindicator/activityindicator/app.py +++ b/examples/activityindicator/activityindicator/app.py @@ -17,14 +17,14 @@ def startup(self): # Set up main window self.main_window = toga.MainWindow() - self.spinner = toga.ActivityIndicator(style=Pack(padding_left=10)) + self.spinner = toga.ActivityIndicator(style=Pack(margin_left=10)) self.button = toga.Button( - "Start", on_press=self.do_stuff, style=Pack(padding_right=10) + "Start", on_press=self.do_stuff, style=Pack(margin_right=10) ) box = toga.Box( children=[self.button, self.spinner], - style=Pack(direction=ROW, height=20, padding=20, alignment=CENTER, flex=1), + style=Pack(direction=ROW, height=20, margin=20, align_items=CENTER, flex=1), ) # Add the content on the main window diff --git a/examples/beeliza/beeliza/app.py b/examples/beeliza/beeliza/app.py index 37503b947a..cb7ae483db 100644 --- a/examples/beeliza/beeliza/app.py +++ b/examples/beeliza/beeliza/app.py @@ -63,13 +63,13 @@ def startup(self): # Buttons self.text_input = toga.TextInput( - style=Pack(flex=1, padding=5), + style=Pack(flex=1, margin=5), on_confirm=self.handle_input, ) send_button = toga.Button( "Send", on_press=self.handle_input, - style=Pack(padding=5), + style=Pack(margin=5), ) input_box = toga.Box( children=[self.text_input, send_button], diff --git a/examples/button/button/app.py b/examples/button/button/app.py index 8d4cbceebd..d5a1081b80 100644 --- a/examples/button/button/app.py +++ b/examples/button/button/app.py @@ -55,7 +55,7 @@ def startup(self): ) # Button with text and margin style - button5 = toga.Button("Far from home", style=Pack(padding=50, color=BLUE)) + button5 = toga.Button("Far from home", style=Pack(margin=50, color=BLUE)) # Button with text and RGB color button6 = toga.Button("RGB : Fashion", style=Pack(background_color=RED)) diff --git a/examples/canvas/canvas/app.py b/examples/canvas/canvas/app.py index ca37af3dac..89984ed921 100644 --- a/examples/canvas/canvas/app.py +++ b/examples/canvas/canvas/app.py @@ -103,14 +103,14 @@ def startup(self): ) self.italic_switch = toga.Switch(text="italic", on_change=self.refresh_canvas) self.bold_switch = toga.Switch(text="bold", on_change=self.refresh_canvas) - label_style = Pack(padding=5) + label_style = Pack(margin=5) # Add the content on the main window box = toga.Box( style=Pack(direction=COLUMN), children=[ toga.Box( - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ self.context_selection, self.shape_selection, @@ -119,7 +119,7 @@ def startup(self): ], ), toga.Box( - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ toga.Label("Line Width:", style=label_style), self.line_width_slider, @@ -127,7 +127,7 @@ def startup(self): ], ), toga.Box( - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ toga.Label("X Scale:", style=label_style), self.scale_x_slider, @@ -139,7 +139,7 @@ def startup(self): ], ), toga.Box( - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), children=[ toga.Label("Font Family:", style=label_style), self.font_selection, diff --git a/examples/colors/colors/app.py b/examples/colors/colors/app.py index b7aeaf688d..4b9b6f9cb7 100644 --- a/examples/colors/colors/app.py +++ b/examples/colors/colors/app.py @@ -31,24 +31,24 @@ def startup(self): self.main_window = toga.MainWindow(size=(700, 800)) # create widgets to test colors on - button = toga.Button("This is a button", style=Pack(padding=5)) - label = toga.Label("This is a Label", style=Pack(padding=5)) + button = toga.Button("This is a button", style=Pack(margin=5)) + label = toga.Label("This is a Label", style=Pack(margin=5)) multiline_text_input = toga.MultilineTextInput( value="This is a Multiline Text Input field!", placeholder="placeholder", - style=Pack(padding=5, flex=1), + style=Pack(margin=5, flex=1), ) - number_input = toga.NumberInput(value=1337, style=Pack(padding=5)) - password_input = toga.PasswordInput(value="adminadmin", style=Pack(padding=5)) + number_input = toga.NumberInput(value=1337, style=Pack(margin=5)) + password_input = toga.PasswordInput(value="adminadmin", style=Pack(margin=5)) progress_bar = toga.ProgressBar( - max=100, value=50, running=True, style=Pack(padding=5) + max=100, value=50, running=True, style=Pack(margin=5) ) selection = toga.Selection( items=["item 1", "item 2", "item 3", "item 4", "item 5", "item 6"], - style=Pack(padding=5), + style=Pack(margin=5), ) - slider = toga.Slider(style=Pack(padding=5)) - switch = toga.Switch("Switch", style=Pack(padding=5)) + slider = toga.Slider(style=Pack(margin=5)) + switch = toga.Switch("Switch", style=Pack(margin=5)) table = toga.Table( headings=["Heading 1", "Heading 2"], data=[ @@ -60,12 +60,12 @@ def startup(self): ("value 1", "value 2"), ], missing_value="none", - style=Pack(padding=5, flex=1), + style=Pack(margin=5, flex=1), ) text_input = toga.TextInput( value="This is a Text input field!", placeholder="placeholder", - style=Pack(padding=5), + style=Pack(margin=5), ) scroll_container = toga.ScrollContainer( @@ -81,8 +81,8 @@ def startup(self): temp_box.add(toga.Label(f"Label {x}")) scroll_container.content = temp_box - box_label = toga.Label("This is a Box:", style=Pack(padding=5)) - box = toga.Box(style=Pack(flex=1, padding=5)) + box_label = toga.Label("This is a Box:", style=Pack(margin=5)) + box = toga.Box(style=Pack(flex=1, margin=5)) self.widget_box = toga.Box( children=[ @@ -103,10 +103,10 @@ def startup(self): box_label, box, ], - # Stack widgets vertically, and add padding so the + # Stack widgets vertically, and add margin so the # background cyan of the parent is a border around the # widgets - style=Pack(direction=COLUMN, flex=1, padding=10), + style=Pack(direction=COLUMN, flex=1, margin=10), ) ], # Use a cyan background so that color changes are obvious @@ -130,7 +130,7 @@ def startup(self): ] # setup control box - button_style = Pack(padding=2, width=100) + button_style = Pack(margin=2, width=100) change_fcolor_r = toga.Button( "Red", on_press=self.change_color_foreground(colors.RED), @@ -184,14 +184,14 @@ def startup(self): change_fcolor_g, change_fcolor_b, change_fcolor_reset, - toga.Label("Background", style=Pack(padding_top=10)), + toga.Label("Background", style=Pack(margin_top=10)), change_bcolor_r, change_bcolor_g, change_bcolor_b, change_bcolor_t, change_bcolor_reset, ], - style=Pack(direction=COLUMN, padding=5), + style=Pack(direction=COLUMN, margin=5), ) # Outermost box diff --git a/examples/command/command/app.py b/examples/command/command/app.py index 283688ade3..d842b08151 100644 --- a/examples/command/command/app.py +++ b/examples/command/command/app.py @@ -157,7 +157,7 @@ def action4(widget): # Outermost box outer_box = toga.Box( children=[btn_box, self.textpanel], - style=Pack(flex=1, direction=COLUMN, padding=10), + style=Pack(flex=1, direction=COLUMN, margin=10), ) # Add the content on the main window diff --git a/examples/detailedlist/detailedlist/app.py b/examples/detailedlist/detailedlist/app.py index b151504662..e80fc63ad0 100644 --- a/examples/detailedlist/detailedlist/app.py +++ b/examples/detailedlist/detailedlist/app.py @@ -60,7 +60,7 @@ def startup(self): self.main_window = toga.MainWindow() # Buttons - btn_style = Pack(flex=1, padding=10) + btn_style = Pack(flex=1, margin=10) self.btn_insert = toga.Button( "Insert Row", on_press=self.insert_handler, style=btn_style ) @@ -72,7 +72,7 @@ def startup(self): ) # Switches to enable/disable actions - switch_style = Pack(padding=10) + switch_style = Pack(margin=10) self.switch_box = toga.Box( style=Pack(direction=ROW), children=[ @@ -130,7 +130,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=10, + margin=10, ), ) diff --git a/examples/dialogs/dialogs/app.py b/examples/dialogs/dialogs/app.py index bd86493129..7866617000 100644 --- a/examples/dialogs/dialogs/app.py +++ b/examples/dialogs/dialogs/app.py @@ -222,7 +222,7 @@ def action_open_secondary_window(self, widget): self.set_window_label_text(len(self.windows) - 1) secondary_label = toga.Label(text="You are in a secondary window!") window.content = toga.Box( - children=[secondary_label], style=Pack(flex=1, direction=COLUMN, padding=10) + children=[secondary_label], style=Pack(flex=1, direction=COLUMN, margin=10) ) window.on_close = self.window_close_handler window.show() @@ -253,8 +253,8 @@ def startup(self): self.on_exit = self.exit_handler # Label to show responses. - self.label = toga.Label("Ready.", style=Pack(padding_top=20)) - self.window_label = toga.Label("", style=Pack(padding_top=20)) + self.label = toga.Label("Ready.", style=Pack(margin_top=20)) + self.window_label = toga.Label("", style=Pack(margin_top=20)) self.window_counter = 0 self.close_attempts = set() self.set_window_label_text(0) @@ -362,7 +362,7 @@ def startup(self): self.label, self.window_label, ], - style=Pack(flex=1, direction=COLUMN, padding=10), + style=Pack(flex=1, direction=COLUMN, margin=10), ) # Add the content on the main window diff --git a/examples/divider/divider/app.py b/examples/divider/divider/app.py index c541e8c0fc..2d8b7cbd23 100644 --- a/examples/divider/divider/app.py +++ b/examples/divider/divider/app.py @@ -7,8 +7,8 @@ class DividerApp(toga.App): def startup(self): self.main_window = toga.MainWindow(size=(300, 150)) - style = Pack(padding_top=24) - substyle = Pack(padding_right=12, padding_left=12, flex=1) + style = Pack(margin_top=24) + substyle = Pack(margin_right=12, margin_left=12, flex=1) # Add the content on the main window self.main_window.content = toga.Box( @@ -24,10 +24,10 @@ def startup(self): toga.Divider(direction=toga.Divider.VERTICAL, style=substyle), toga.TextInput(placeholder="Second textbox"), ], - style=Pack(direction=ROW, padding=24, flex=1), + style=Pack(direction=ROW, margin=24, flex=1), ), ], - style=Pack(direction=COLUMN, padding=24), + style=Pack(direction=COLUMN, margin=24), ) # Show the main window diff --git a/examples/examples_overview/examples_overview/app.py b/examples/examples_overview/examples_overview/app.py index 637187ff2f..92c8b27972 100644 --- a/examples/examples_overview/examples_overview/app.py +++ b/examples/examples_overview/examples_overview/app.py @@ -50,7 +50,7 @@ def startup(self): # Label for user instructions label = toga.Label( "Please select an example to run", - style=Pack(padding_bottom=10), + style=Pack(margin_bottom=10), ) # ==== Table with examples ===================================================== @@ -72,15 +72,15 @@ def startup(self): data=self.examples, on_activate=self.run, on_select=self.on_example_selected, - style=Pack(padding_bottom=10, flex=1), + style=Pack(margin_bottom=10, flex=1), ) # Buttons self.btn_run = toga.Button( - "Run Example", on_press=self.run, style=Pack(flex=1, padding_right=5) + "Run Example", on_press=self.run, style=Pack(flex=1, margin_right=5) ) self.btn_open = toga.Button( - "Open folder", on_press=self.open, style=Pack(flex=1, padding_left=5) + "Open folder", on_press=self.open, style=Pack(flex=1, margin_left=5) ) button_box = toga.Box(children=[self.btn_run, self.btn_open]) @@ -88,7 +88,7 @@ def startup(self): # ==== View of example README ================================================== self.info_view = toga.MultilineTextInput( - placeholder="Please select example", readonly=True, style=Pack(padding=1) + placeholder="Please select example", readonly=True, style=Pack(margin=1) ) # ==== Assemble layout ========================================================= @@ -97,7 +97,7 @@ def startup(self): children=[self.table, button_box], style=Pack( direction=COLUMN, - padding=1, + margin=1, flex=1, ), ) @@ -109,7 +109,7 @@ def startup(self): outer_box = toga.Box( children=[label, split_container], - style=Pack(padding=10, direction=COLUMN, flex=1), + style=Pack(margin=10, direction=COLUMN, flex=1), ) # Add the content on the main window diff --git a/examples/font/font/app.py b/examples/font/font/app.py index def38bb02e..2535f71f33 100644 --- a/examples/font/font/app.py +++ b/examples/font/font/app.py @@ -56,7 +56,7 @@ def startup(self): # Buttons btn_box1 = toga.Box( - style=Pack(direction=ROW, padding_bottom=10), + style=Pack(direction=ROW, margin_bottom=10), children=[ toga.Button("Clear", on_press=self.do_clear), toga.Button("Weight", on_press=self.do_weight), @@ -89,7 +89,7 @@ def startup(self): style=Pack(font_family="awesome-free-solid", font_size=14, width=50), ) btn_box2 = toga.Box( - style=Pack(direction=ROW, padding_bottom=10), + style=Pack(direction=ROW, margin_bottom=10), children=[btn1, btn2, btn3, btn4], ) @@ -176,7 +176,7 @@ def startup(self): self.labels, self.textpanel, ], - style=Pack(flex=1, direction=COLUMN, padding=10), + style=Pack(flex=1, direction=COLUMN, margin=10), ) # Add the content on the main window diff --git a/examples/handlers/handlers/app.py b/examples/handlers/handlers/app.py index a081c81b06..cb6f620bdf 100644 --- a/examples/handlers/handlers/app.py +++ b/examples/handlers/handlers/app.py @@ -78,12 +78,12 @@ def startup(self): self.main_window = toga.MainWindow() # Labels to show responses. - self.on_running_label = toga.Label("Ready.", style=Pack(padding=10)) - self.background_label = toga.Label("Ready.", style=Pack(padding=10)) - self.function_label = toga.Label("Ready.", style=Pack(padding=10)) - self.generator_label = toga.Label("Ready.", style=Pack(padding=10)) - self.async_label = toga.Label("Ready.", style=Pack(padding=10)) - self.web_label = toga.Label("Ready.", style=Pack(padding=10)) + self.on_running_label = toga.Label("Ready.", style=Pack(margin=10)) + self.background_label = toga.Label("Ready.", style=Pack(margin=10)) + self.function_label = toga.Label("Ready.", style=Pack(margin=10)) + self.generator_label = toga.Label("Ready.", style=Pack(margin=10)) + self.async_label = toga.Label("Ready.", style=Pack(margin=10)) + self.web_label = toga.Label("Ready.", style=Pack(margin=10)) # Add a background task. self.counter = 0 @@ -120,7 +120,7 @@ def startup(self): self.web_label, btn_clear, ], - style=Pack(flex=1, direction=COLUMN, padding=10), + style=Pack(flex=1, direction=COLUMN, margin=10), ) # Add the content on the main window diff --git a/examples/hardware/hardware/app.py b/examples/hardware/hardware/app.py index 6dee053220..3223a8ff13 100644 --- a/examples/hardware/hardware/app.py +++ b/examples/hardware/hardware/app.py @@ -27,18 +27,18 @@ def startup(self): toga.Button( "Take Photo", on_press=self.take_photo, - style=Pack(flex=1, padding=5), + style=Pack(flex=1, margin=5), ), # Select a photo from the photo library # toga.Button( # "Select Photo", # on_press=self.select_photo, - # style=Pack(flex=1, padding=5), + # style=Pack(flex=1, margin=5), # ), ], ), ], - style=Pack(direction=COLUMN, padding_bottom=20), + style=Pack(direction=COLUMN, margin_bottom=20), ) ############################################################# @@ -73,7 +73,7 @@ def startup(self): style=Pack(flex=1), ), ], - style=Pack(padding=5), + style=Pack(margin=5), ), ], style=Pack(direction=COLUMN), diff --git a/examples/imageview/imageview/app.py b/examples/imageview/imageview/app.py index 6d4a8ffd75..5d79852faf 100644 --- a/examples/imageview/imageview/app.py +++ b/examples/imageview/imageview/app.py @@ -12,8 +12,8 @@ def startup(self): box = toga.Box( style=Pack( - padding=10, - alignment=CENTER, + margin=10, + align_items=CENTER, direction=COLUMN, ) ) diff --git a/examples/layout/layout/app.py b/examples/layout/layout/app.py index c9af3d86d9..48f29f5d25 100644 --- a/examples/layout/layout/app.py +++ b/examples/layout/layout/app.py @@ -7,49 +7,49 @@ class ExampleLayoutApp(toga.App): def startup(self): self.button_hide = toga.Button( text="Hide label", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.hide_label, ) self.button_add = toga.Button( text="Add image", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.add_image, ) self.button_remove = toga.Button( text="Remove image", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.remove_image, enabled=False, ) self.button_insert = toga.Button( text="Insert image", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.insert_image, ) self.button_reparent = toga.Button( text="Reparent image", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.reparent_image, enabled=False, ) self.button_add_to_scroll = toga.Button( text="Add new label", - style=Pack(padding=10, width=120), + style=Pack(margin=10, width=120), on_press=self.add_label, ) self.content_box = toga.Box( - children=[], style=Pack(direction=COLUMN, padding=10, flex=1) + children=[], style=Pack(direction=COLUMN, margin=10, flex=1) ) image = toga.Image("resources/tiberius.png") self.image_view = toga.ImageView( - image, style=Pack(padding=10, width=60, height=60) + image, style=Pack(margin=10, width=60, height=60) ) # this tests adding children during init, before we have an implementation @@ -66,7 +66,8 @@ def startup(self): ) self.box = toga.Box( - children=[], style=Pack(direction=ROW, padding=10, alignment=CENTER, flex=1) + children=[], + style=Pack(direction=ROW, margin=10, align_items=CENTER, flex=1), ) # this tests adding children when we already have an impl but no window or app @@ -123,7 +124,7 @@ def reparent_image(self, sender): def add_label(self, sender=None): # this tests adding children when we already have an impl, window and app new_label = toga.Label( - f"Label {len(self.content_box.children)}", style=Pack(padding=2, width=70) + f"Label {len(self.content_box.children)}", style=Pack(margin=2, width=70) ) self.content_box.add(new_label) self.labels.append(new_label) diff --git a/examples/mapview/mapview/app.py b/examples/mapview/mapview/app.py index 1255d0cb1f..8f48371605 100644 --- a/examples/mapview/mapview/app.py +++ b/examples/mapview/mapview/app.py @@ -79,7 +79,7 @@ def startup(self): btn_where = toga.Button("???", on_press=self.where_am_i, style=btn_style) location_box = toga.Box( children=[btn_perth, btn_london, btn_austin, btn_rio, btn_where], - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), ) # Zoom buttons @@ -88,7 +88,7 @@ def startup(self): toga.Button(i, on_press=self.zoom(i), style=btn_style) for i in range(0, 20, 3) ], - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), ) # Point Of Interest buttons @@ -98,11 +98,11 @@ def startup(self): btn_move = toga.Button("Move", on_press=self.move_carmen, style=btn_style) pin_box = toga.Box( children=[btn_pin_1, btn_pin_2, btn_pin_3, btn_move], - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), ) # Label to show responses. - self.label = toga.Label("Ready.", style=Pack(padding=5)) + self.label = toga.Label("Ready.", style=Pack(margin=5)) # Add the content on the main window self.main_window.content = toga.Box( diff --git a/examples/multilinetextinput/multilinetextinput/app.py b/examples/multilinetextinput/multilinetextinput/app.py index ca0f80dca8..43417d4773 100644 --- a/examples/multilinetextinput/multilinetextinput/app.py +++ b/examples/multilinetextinput/multilinetextinput/app.py @@ -68,14 +68,14 @@ def startup(self): button_toggle_enabled, button_toggle_readonly, ], - style=Pack(direction=ROW, padding_bottom=10), + style=Pack(direction=ROW, margin_bottom=10), ) btn_box2 = toga.Box( children=[ button_add_content, button_clear, ], - style=Pack(direction=ROW, padding_bottom=10), + style=Pack(direction=ROW, margin_bottom=10), ) btn_box3 = toga.Box( children=[ @@ -83,13 +83,13 @@ def startup(self): button_scroll_bottom, toga.TextInput(style=Pack(flex=1)), ], - style=Pack(direction=ROW, padding_bottom=10), + style=Pack(direction=ROW, margin_bottom=10), ) self.label = toga.Label("Nothing has been written yet") outer_box = toga.Box( children=[btn_box1, btn_box2, btn_box3, self.multiline_input, self.label], - style=Pack(direction=COLUMN, padding=10), + style=Pack(direction=COLUMN, margin=10), ) self.main_window.content = outer_box diff --git a/examples/numberinput/numberinput/app.py b/examples/numberinput/numberinput/app.py index d6c6e7b104..3228b42541 100644 --- a/examples/numberinput/numberinput/app.py +++ b/examples/numberinput/numberinput/app.py @@ -42,11 +42,11 @@ def startup(self): ) box1 = toga.Box( children=[label1, self.input1], - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), ) box2 = toga.Box( children=[label2, self.input2], - style=Pack(direction=ROW, padding=5), + style=Pack(direction=ROW, margin=5), ) # Buttons btn_style = Pack(flex=1) @@ -59,7 +59,7 @@ def startup(self): # Outermost box outer_box = toga.Box( children=[btn_box, box1, box2, self.label], - style=Pack(flex=1, direction=COLUMN, padding=10), + style=Pack(flex=1, direction=COLUMN, margin=10), ) # Add the content on the main window diff --git a/examples/optioncontainer/optioncontainer/app.py b/examples/optioncontainer/optioncontainer/app.py index 4530d94c81..bec1efbf24 100644 --- a/examples/optioncontainer/optioncontainer/app.py +++ b/examples/optioncontainer/optioncontainer/app.py @@ -14,7 +14,7 @@ def _create_option(self): result = ( f"Option {self._box_count}", toga.Box( - style=Pack(background_color="cyan", padding=10), + style=Pack(background_color="cyan", margin=10), children=[toga.Label(f"This is Box {self._box_count}")], ), ) @@ -89,11 +89,11 @@ def startup(self): self.main_window = toga.MainWindow() # styles - style_flex = Pack(flex=1, padding=5) + style_flex = Pack(flex=1, margin=5) # select label_select = toga.Label("Select an Option position:", style=style_flex) - self.select_option = toga.Selection(style=Pack(padding=5, width=50)) + self.select_option = toga.Selection(style=Pack(margin=5, width=50)) # buttons btn_activate = toga.Button( "Activate", on_press=self.on_activate_option, style=style_flex @@ -111,7 +111,7 @@ def startup(self): ) box_select = toga.Box( - style=Pack(direction=ROW, padding_right=10, width=200), + style=Pack(direction=ROW, margin_right=10, width=200), children=[label_select, self.select_option], ) box_actions_1 = toga.Box( @@ -125,20 +125,20 @@ def startup(self): self.selected_label = toga.Label("") self.optioncontainer = toga.OptionContainer( - on_select=self.on_select_tab, style=Pack(padding_bottom=20, flex=1) + on_select=self.on_select_tab, style=Pack(margin_bottom=20, flex=1) ) self._create_options() btn_add = toga.Button( - "Append new option", style=Pack(padding=5), on_press=self.on_add_option + "Append new option", style=Pack(margin=5), on_press=self.on_add_option ) btn_insert = toga.Button( "Insert new option before active option", - style=Pack(padding=5), + style=Pack(margin=5), on_press=self.on_insert_option, ) box_general_actions = toga.Box( - style=Pack(padding_bottom=10), children=[btn_add, btn_insert] + style=Pack(margin_bottom=10), children=[btn_add, btn_insert] ) # Outermost box @@ -154,7 +154,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=10, + margin=10, ), ) diff --git a/examples/passwordinput/passwordinput/app.py b/examples/passwordinput/passwordinput/app.py index 284c2f4583..af0872930d 100644 --- a/examples/passwordinput/passwordinput/app.py +++ b/examples/passwordinput/passwordinput/app.py @@ -35,13 +35,13 @@ def startup(self): # Label to show responses. self.label = toga.Label("Testing Password") self.password_content_label = toga.Label( - EMPTY_PASSWORD, style=Pack(padding_bottom=PADDING) + EMPTY_PASSWORD, style=Pack(margin_bottom=PADDING) ) # Padding box only self.password_input = toga.PasswordInput( placeholder="Password...", - style=Pack(padding=PADDING), + style=Pack(margin=PADDING), on_change=self.on_password_change, validators=[ validators.MinLength(10), @@ -60,7 +60,7 @@ def startup(self): ] outer_box = toga.Box( children=children, - style=Pack(flex=1, direction=COLUMN, padding=10, width=500, height=300), + style=Pack(flex=1, direction=COLUMN, margin=10, width=500, height=300), ) # Add the content on the main window diff --git a/examples/progressbar/progressbar/app.py b/examples/progressbar/progressbar/app.py index 0e795e8842..0ebae54829 100644 --- a/examples/progressbar/progressbar/app.py +++ b/examples/progressbar/progressbar/app.py @@ -15,10 +15,10 @@ def startup(self): self.progress_adder = toga.ProgressBar(max=MAX_PROGRESSBAR_VALUE) # set up common styles - label_style = Pack(flex=1, padding_right=5) - row_box_style = Pack(direction=ROW, padding=10) - col_box_style = Pack(direction=COLUMN, padding=10) - pbar_style = Pack(width=150, padding_right=5) + label_style = Pack(flex=1, margin_right=5) + row_box_style = Pack(direction=ROW, margin=10) + col_box_style = Pack(direction=COLUMN, margin=10) + pbar_style = Pack(width=150, margin_right=5) # Add the content on the main window self.main_window.content = toga.Box( diff --git a/examples/resize/resize/app.py b/examples/resize/resize/app.py index 1ce0f98e19..0f594e277f 100644 --- a/examples/resize/resize/app.py +++ b/examples/resize/resize/app.py @@ -24,7 +24,7 @@ def __init__(self, title, *, on_change): ) self.flex = SizeButton("F", value=0, max=3, on_press=self.on_press) super().__init__( - style=Pack(direction=COLUMN, alignment="center"), + style=Pack(direction=COLUMN, align_items="center"), children=[ toga.Label(title.upper(), style=Pack(font_weight="bold")), toga.Box( diff --git a/examples/screenshot/screenshot/app.py b/examples/screenshot/screenshot/app.py index 41700fe61e..60e9c35542 100644 --- a/examples/screenshot/screenshot/app.py +++ b/examples/screenshot/screenshot/app.py @@ -16,7 +16,7 @@ def create_activityindicator(self): return toga.Box( children=[ toga.Box(style=Pack(flex=1)), - toga.ActivityIndicator(running=True, style=Pack(padding=10)), + toga.ActivityIndicator(running=True, style=Pack(margin=10)), toga.Box(style=Pack(flex=1)), ], style=Pack(width=100), @@ -27,14 +27,14 @@ def create_button(self): children=[ toga.Button( "Launch rocket", - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), ) def create_canvas(self): - canvas = toga.Canvas(style=Pack(padding=10, width=280, height=290)) + canvas = toga.Canvas(style=Pack(margin=10, width=280, height=290)) draw_tiberius(canvas) return toga.Box(children=[canvas], style=Pack(width=280, height=290)) @@ -43,7 +43,7 @@ def create_dateinput(self): return toga.Box( children=[ toga.Box(style=Pack(flex=1)), - toga.DateInput(value=date(2014, 4, 21), style=Pack(padding=10)), + toga.DateInput(value=date(2014, 4, 21), style=Pack(margin=10)), toga.Box(style=Pack(flex=1)), ], style=Pack(width=300), @@ -75,18 +75,18 @@ def create_detailedlist(self): "subtitle": "I can quote the fights historical!", }, ], - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) def create_divider(self): return toga.Box( children=[ toga.Label( - "I'm on top", style=Pack(flex=1, padding=5, text_align=CENTER) + "I'm on top", style=Pack(flex=1, margin=5, text_align=CENTER) ), - toga.Divider(direction=toga.Divider.HORIZONTAL, style=Pack(padding=5)), + toga.Divider(direction=toga.Divider.HORIZONTAL, style=Pack(margin=5)), toga.Label( - "I'm below", style=Pack(flex=1, padding=5, text_align=CENTER) + "I'm below", style=Pack(flex=1, margin=5, text_align=CENTER) ), ], style=Pack(width=300, direction=COLUMN), @@ -97,7 +97,7 @@ def create_label(self): children=[ toga.Label( "Brutus was here!", - style=Pack(padding=10, text_align=CENTER, flex=1), + style=Pack(margin=10, text_align=CENTER, flex=1), ) ], style=Pack(width=300), @@ -107,7 +107,7 @@ def create_mapview(self): return toga.MapView( zoom=3, pins=[toga.MapPin((-31.95064, 115.85889), title="Yagan Square")], - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) def create_multilinetextinput(self): @@ -129,7 +129,7 @@ def create_multilinetextinput(self): "I am the very model of a modern Major-General.", ] ), - style=Pack(padding=10, width=self.MAX_WIDTH, height=200), + style=Pack(margin=10, width=self.MAX_WIDTH, height=200), ) def create_numberinput(self): @@ -138,7 +138,7 @@ def create_numberinput(self): toga.NumberInput( value=2.71818, step=0.00001, - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -149,7 +149,7 @@ def create_passwordinput(self): children=[ toga.PasswordInput( value="secret", - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -161,7 +161,7 @@ def create_progressbar(self): toga.ProgressBar( value=42, max=100, - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -172,7 +172,7 @@ def create_selection(self): children=[ toga.Selection( items=["Titanium", "Yttrium", "Yterbium"], - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -184,7 +184,7 @@ def create_slider(self): toga.Slider( value=42, max=100, - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -197,7 +197,7 @@ def create_switch(self): toga.Switch( "Turbo", value=True, - style=Pack(padding=10), + style=Pack(margin=10), ), toga.Box(style=Pack(flex=1)), ], @@ -213,7 +213,7 @@ def create_table(self): ("Tricia McMillan", 38, "Earth"), ("Slartibartfast", 1005, "Magrathea"), ], - style=Pack(padding=10, width=self.MAX_WIDTH, height=200), + style=Pack(margin=10, width=self.MAX_WIDTH, height=200), ) def create_textinput(self): @@ -221,7 +221,7 @@ def create_textinput(self): children=[ toga.TextInput( value="Brutus was here!", - style=Pack(padding=10, flex=1), + style=Pack(margin=10, flex=1), ) ], style=Pack(width=300), @@ -231,7 +231,7 @@ def create_timeinput(self): return toga.Box( children=[ toga.Box(style=Pack(flex=1)), - toga.TimeInput(value=time(9, 7, 37), style=Pack(padding=10)), + toga.TimeInput(value=time(9, 7, 37), style=Pack(margin=10)), toga.Box(style=Pack(flex=1)), ], style=Pack(width=300), @@ -252,7 +252,7 @@ def create_tree(self): ("Slartibartfast", 1005, "Annoyed"): None, }, }, - style=Pack(padding=10, width=self.MAX_WIDTH, height=200), + style=Pack(margin=10, width=self.MAX_WIDTH, height=200), ) tree.expand() return tree @@ -260,7 +260,7 @@ def create_tree(self): def create_webview(self): return toga.WebView( url="https://beeware.org", - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) def create_optioncontainer(self): @@ -274,7 +274,7 @@ def create_optioncontainer(self): ("Green", toga.Box(), "resources/landmark"), ("Red", toga.Box()), ], - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) return container @@ -291,7 +291,7 @@ def create_scrollcontainer(self): ], style=Pack(direction=COLUMN), ), - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) return container @@ -302,7 +302,7 @@ def create_splitcontainer(self): toga.Box(style=Pack(background_color="goldenrod")), toga.Box(style=Pack(background_color="cornflowerblue")), ], - style=Pack(padding=10, width=self.MAX_WIDTH, height=300), + style=Pack(margin=10, width=self.MAX_WIDTH, height=300), ) return container @@ -327,7 +327,7 @@ def proceed(button, **kwargs): proceed_button = toga.Button( "Done", on_press=proceed, - style=Pack(padding=10), + style=Pack(margin=10), ) if content: diff --git a/examples/scrollcontainer/scrollcontainer/app.py b/examples/scrollcontainer/scrollcontainer/app.py index c0dd1f5c48..ed723e98cc 100644 --- a/examples/scrollcontainer/scrollcontainer/app.py +++ b/examples/scrollcontainer/scrollcontainer/app.py @@ -5,12 +5,12 @@ class Item(toga.Box): def __init__(self, width, text): - super().__init__(style=Pack(direction=ROW, padding=10, background_color="lime")) + super().__init__(style=Pack(direction=ROW, margin=10, background_color="lime")) for x in range(width): label = toga.Label( text + "," + str(x), - style=Pack(padding_right=10, background_color="cyan"), + style=Pack(margin_right=10, background_color="cyan"), ) self.add(label) @@ -47,13 +47,13 @@ def startup(self): ) self.inner_box = toga.Box( - style=Pack(direction=COLUMN, padding=10, background_color="yellow") + style=Pack(direction=COLUMN, margin=10, background_color="yellow") ) self.scroller = toga.ScrollContainer( horizontal=self.hswitch.value, vertical=self.vswitch.value, on_scroll=self.on_scroll, - style=Pack(flex=1, padding=10, background_color="pink"), + style=Pack(flex=1, margin=10, background_color="pink"), ) self.update_content() diff --git a/examples/selection/selection/app.py b/examples/selection/selection/app.py index e3dede0464..666d555a59 100644 --- a/examples/selection/selection/app.py +++ b/examples/selection/selection/app.py @@ -18,8 +18,8 @@ def startup(self): self.main_window = toga.MainWindow(size=(640, 400)) # set up common styles - label_style = Pack(flex=1, padding_right=24) - box_style = Pack(direction=ROW, padding=10) + label_style = Pack(flex=1, margin_right=24) + box_style = Pack(direction=ROW, margin=10) # Add the content on the main window self.selection = toga.Selection(items=self.OPTIONS) @@ -93,7 +93,7 @@ def startup(self): children=[ toga.Label("Use some style!", style=label_style), toga.Selection( - style=Pack(width=200, padding=24), + style=Pack(width=200, margin=24), items=["Curium", "Titanium", "Copernicium"], ), ], @@ -117,7 +117,7 @@ def startup(self): ], ), ], - style=Pack(direction=COLUMN, padding=24), + style=Pack(direction=COLUMN, margin=24), ) self.main_window.show() diff --git a/examples/simpleapp/simpleapp/app.py b/examples/simpleapp/simpleapp/app.py index 310d364a14..e836a3e35b 100644 --- a/examples/simpleapp/simpleapp/app.py +++ b/examples/simpleapp/simpleapp/app.py @@ -13,7 +13,7 @@ def startup(self): # Outermost box outer_box = toga.Box( children=[self.label], - style=Pack(padding=10), + style=Pack(margin=10), ) # Add the content on the main window diff --git a/examples/slider/slider/app.py b/examples/slider/slider/app.py index fd08cb7d19..8de7f35de3 100644 --- a/examples/slider/slider/app.py +++ b/examples/slider/slider/app.py @@ -11,8 +11,8 @@ def startup(self): self.main_window = toga.MainWindow(size=(1000, 500)) # set up common styles - label_style = Pack(flex=1, padding_right=24) - box_style = Pack(direction=ROW, padding=10) + label_style = Pack(flex=1, margin_right=24) + box_style = Pack(direction=ROW, margin=10) slider_style = Pack(flex=1) self.continuous_label = toga.Label("Continuous", style=label_style) @@ -61,7 +61,7 @@ def startup(self): children=[self.scared_label, self.scared_slider], ), ], - style=Pack(direction=COLUMN, padding=24), + style=Pack(direction=COLUMN, margin=24), ) self.commands.add( diff --git a/examples/splitcontainer/splitcontainer/app.py b/examples/splitcontainer/splitcontainer/app.py index 7297fa6a62..b08754fb74 100644 --- a/examples/splitcontainer/splitcontainer/app.py +++ b/examples/splitcontainer/splitcontainer/app.py @@ -25,7 +25,7 @@ def on_change(self, switch): self.sw_flexible.enabled = self.sw_content.value if self.sw_content.value: - box = toga.Box(style=Pack(padding=10, background_color="cyan")) + box = toga.Box(style=Pack(margin=10, background_color="cyan")) if not self.sw_flexible.value: box.style.update(width=100, height=100) else: @@ -38,7 +38,7 @@ def on_change(self, switch): class SplitControls(toga.Box): def __init__(self, split): - super().__init__(style=Pack(direction=COLUMN, alignment=CENTER, flex=1)) + super().__init__(style=Pack(direction=COLUMN, align_items=CENTER, flex=1)) self.split = split self.add( @@ -73,7 +73,7 @@ def on_direction(self, button): class SplitContainerApp(toga.App): def startup(self): - self.split = toga.SplitContainer(style=Pack(padding=10, flex=1)) + self.split = toga.SplitContainer(style=Pack(margin=10, flex=1)) main_box = toga.Box( style=Pack(direction=COLUMN), diff --git a/examples/switch_demo/switch_demo/app.py b/examples/switch_demo/switch_demo/app.py index 8bf97785a4..6934ba5f55 100644 --- a/examples/switch_demo/switch_demo/app.py +++ b/examples/switch_demo/switch_demo/app.py @@ -14,14 +14,14 @@ def startup(self): # Simple switch with label and callback function called toggled toga.Switch("Change Label", on_change=self.callbackLabel), # Switch with initial state - toga.Switch("Initial state", value=True, style=Pack(padding_top=24)), + toga.Switch("Initial state", value=True, style=Pack(margin_top=24)), # Switch with label and enable option - toga.Switch("Disabled", enabled=False, style=Pack(padding_top=24)), + toga.Switch("Disabled", enabled=False, style=Pack(margin_top=24)), # Switch with a big font toga.Switch( "Big and colorful", style=Pack( - padding_top=24, + margin_top=24, font_family="serif", font_size=20, font_weight="bold", @@ -29,7 +29,7 @@ def startup(self): ), ), ], - style=Pack(direction=COLUMN, padding=24), + style=Pack(direction=COLUMN, margin=24), ) # Show the main window diff --git a/examples/table/table/app.py b/examples/table/table/app.py index 07adb78d91..dcbb60213d 100644 --- a/examples/table/table/app.py +++ b/examples/table/table/app.py @@ -101,13 +101,13 @@ def startup(self): self.main_window = toga.MainWindow() # Label to show which row is currently selected. - self.label_table1 = toga.Label("Ready.", style=Pack(flex=1, padding_right=5)) + self.label_table1 = toga.Label("Ready.", style=Pack(flex=1, margin_right=5)) self.label_table2 = toga.Label( - "Try multiple row selection.", style=Pack(flex=1, padding_left=5) + "Try multiple row selection.", style=Pack(flex=1, margin_left=5) ) labelbox = toga.Box( children=[self.label_table1, self.label_table2], - style=Pack(flex=0, padding_top=5), + style=Pack(flex=0, margin_top=5), ) # Change font size @@ -146,7 +146,7 @@ def startup(self): data=table_data, style=Pack( flex=1, - padding_right=5, + margin_right=5, font_family="monospace", font_size=int(self.lbl_fontsize.text), font_style="italic", @@ -162,7 +162,7 @@ def startup(self): accessors=[h.lower() for h in headings], data=self.table1.data, multiple_select=True, - style=Pack(flex=1, padding_left=5), + style=Pack(flex=1, margin_left=5), on_select=self.on_select_handler2, on_activate=self.on_activate2, missing_value="?", @@ -190,11 +190,11 @@ def startup(self): controls_1 = toga.Box( children=[font_box, btn_insert, btn_delete, btn_clear], - style=Pack(direction=ROW, padding_bottom=5), + style=Pack(direction=ROW, margin_bottom=5), ) controls_2 = toga.Box( children=[btn_reset, btn_toggle, btn_top, btn_bottom], - style=Pack(direction=ROW, padding_bottom=5), + style=Pack(direction=ROW, margin_bottom=5), ) # Most outer box @@ -203,7 +203,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=10, + margin=10, ), ) diff --git a/examples/table_source/table_source/app.py b/examples/table_source/table_source/app.py index f03473b6b8..b37a847ca1 100644 --- a/examples/table_source/table_source/app.py +++ b/examples/table_source/table_source/app.py @@ -187,7 +187,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=10, + margin=10, ), ) diff --git a/examples/textinput/textinput/app.py b/examples/textinput/textinput/app.py index 5d708fd1bd..76021f6c16 100644 --- a/examples/textinput/textinput/app.py +++ b/examples/textinput/textinput/app.py @@ -52,32 +52,32 @@ def startup(self): # Labels to show responses. self.label = toga.Label( - "Enter some values and press extract.", style=Pack(padding=PADDING) + "Enter some values and press extract.", style=Pack(margin=PADDING) ) - self.text_label = toga.Label("Ready.", style=Pack(padding=PADDING)) - self.password_label = toga.Label("Ready.", style=Pack(padding=PADDING)) + self.text_label = toga.Label("Ready.", style=Pack(margin=PADDING)) + self.password_label = toga.Label("Ready.", style=Pack(margin=PADDING)) self.password_content_label = toga.Label( - EMPTY_PASSWORD, style=Pack(padding_bottom=PADDING, font_size=9) + EMPTY_PASSWORD, style=Pack(margin_bottom=PADDING, font_size=9) ) - self.number_label = toga.Label("Ready.", style=Pack(padding=PADDING)) + self.number_label = toga.Label("Ready.", style=Pack(margin=PADDING)) # Text inputs and a button self.text_input = toga.TextInput( value="Initial value, and on_confirm handler", placeholder="Type something...", - style=Pack(padding=PADDING), + style=Pack(margin=PADDING), on_confirm=self.do_extract_values, ) self.right_aligned_input = toga.TextInput( placeholder="Right aligned text", - style=Pack(padding=PADDING, text_align=RIGHT), + style=Pack(margin=PADDING, text_align=RIGHT), ) self.text_input_placeholder = toga.TextInput( - placeholder="Type something...", style=Pack(padding=PADDING) + placeholder="Type something...", style=Pack(margin=PADDING) ) self.password_input = toga.PasswordInput( placeholder="Password...", - style=Pack(padding=PADDING), + style=Pack(margin=PADDING), on_change=self.on_password_change, validators=[ validators.MinLength(10), @@ -89,17 +89,17 @@ def startup(self): ) self.email_input = toga.TextInput( placeholder="Email...", - style=Pack(padding=PADDING), + style=Pack(margin=PADDING), validators=[validators.Email()], ) - self.number_input = toga.NumberInput(style=Pack(padding=PADDING)) + self.number_input = toga.NumberInput(style=Pack(margin=PADDING)) btn_extract = toga.Button( "Extract values", on_press=self.do_extract_values, style=Pack(flex=1), ) self.right_aligned_number_input = toga.NumberInput( - style=Pack(padding=PADDING, text_align=RIGHT) + style=Pack(margin=PADDING, text_align=RIGHT) ) children = [ @@ -129,7 +129,7 @@ def startup(self): style=Pack( flex=1, direction=COLUMN, - padding=PADDING, + margin=PADDING, ), ) diff --git a/examples/tree/tree/app.py b/examples/tree/tree/app.py index f5bf9ea613..98909a5e3f 100644 --- a/examples/tree/tree/app.py +++ b/examples/tree/tree/app.py @@ -92,7 +92,7 @@ def startup(self): self.main_window = toga.MainWindow() # Label to show responses. - self.label = toga.Label("Ready.", style=Pack(padding=10)) + self.label = toga.Label("Ready.", style=Pack(margin=10)) self.tree = toga.Tree( headings=["Year", "Title", "Rating", "Genre"], @@ -124,7 +124,7 @@ def startup(self): ) # Buttons - btn_style = Pack(flex=1, padding=10) + btn_style = Pack(flex=1, margin=10) self.btn_insert = toga.Button( "Insert Row", on_press=self.insert_handler, style=btn_style ) diff --git a/examples/tree_source/tree_source/app.py b/examples/tree_source/tree_source/app.py index ba867a711d..2c84f1f598 100644 --- a/examples/tree_source/tree_source/app.py +++ b/examples/tree_source/tree_source/app.py @@ -152,7 +152,7 @@ def startup(self): on_activate=self.activate_handler, ) self.label = toga.Label( - "A view of the current directory!", style=Pack(padding=10) + "A view of the current directory!", style=Pack(margin=10) ) # Outermost box diff --git a/examples/tutorial0/tutorial/app.py b/examples/tutorial0/tutorial/app.py index 23e5e063c6..77e6923093 100644 --- a/examples/tutorial0/tutorial/app.py +++ b/examples/tutorial0/tutorial/app.py @@ -9,7 +9,7 @@ def build(app): box = toga.Box() button = toga.Button("Hello world", on_press=button_handler) - button.style.padding = 50 + button.style.margin = 50 button.style.flex = 1 box.add(button) diff --git a/examples/tutorial1/tutorial/app.py b/examples/tutorial1/tutorial/app.py index aeef2b1afe..1e30745f02 100644 --- a/examples/tutorial1/tutorial/app.py +++ b/examples/tutorial1/tutorial/app.py @@ -33,17 +33,17 @@ def calculate(widget): box.add(c_box) box.add(button) - box.style.update(direction=COLUMN, padding=10) - f_box.style.update(direction=ROW, padding=5) - c_box.style.update(direction=ROW, padding=5) + box.style.update(direction=COLUMN, margin=10) + f_box.style.update(direction=ROW, margin=5) + c_box.style.update(direction=ROW, margin=5) c_input.style.update(flex=1) - f_input.style.update(flex=1, padding_left=210) - c_label.style.update(width=100, padding_left=10) - f_label.style.update(width=100, padding_left=10) - join_label.style.update(width=200, padding_right=10) + f_input.style.update(flex=1, margin_left=210) + c_label.style.update(width=100, margin_left=10) + f_label.style.update(width=100, margin_left=10) + join_label.style.update(width=200, margin_right=10) - button.style.update(padding=15) + button.style.update(margin=15) return box diff --git a/examples/tutorial2/tutorial/app.py b/examples/tutorial2/tutorial/app.py index 77a7a464de..45f489d94b 100644 --- a/examples/tutorial2/tutorial/app.py +++ b/examples/tutorial2/tutorial/app.py @@ -43,14 +43,14 @@ def startup(self): left_container = toga.Table(headings=["Hello", "World"], data=data) - right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50)) + right_content = toga.Box(style=Pack(direction=COLUMN, margin_top=50)) for b in range(0, 10): right_content.add( toga.Button( "Hello world %s" % b, on_press=button_handler, - style=Pack(width=200, padding=20), + style=Pack(width=200, margin=20), ) ) diff --git a/examples/tutorial3/tutorial/app.py b/examples/tutorial3/tutorial/app.py index 6e71bdadf7..7512b577de 100644 --- a/examples/tutorial3/tutorial/app.py +++ b/examples/tutorial3/tutorial/app.py @@ -21,13 +21,13 @@ def startup(self): toga.Button( "Go", on_press=self.load_page, - style=Pack(width=50, padding_left=5), + style=Pack(width=50, margin_left=5), ), ], style=Pack( direction=ROW, - alignment=CENTER, - padding=5, + align_items=CENTER, + margin=5, ), ), self.webview, diff --git a/examples/webview/webview/app.py b/examples/webview/webview/app.py index 454371c523..46fc8066db 100644 --- a/examples/webview/webview/app.py +++ b/examples/webview/webview/app.py @@ -54,7 +54,7 @@ def on_set_agent(self, widget, **kwargs): def startup(self): self.main_window = toga.MainWindow() - self.label = toga.Label("www is loading |", style=Pack(flex=1, padding=5)) + self.label = toga.Label("www is loading |", style=Pack(flex=1, margin=5)) button_box = toga.Box( children=[ @@ -84,7 +84,7 @@ def startup(self): ], ), ], - style=Pack(flex=0, direction=COLUMN, padding=5), + style=Pack(flex=0, direction=COLUMN, margin=5), ) self.webview = toga.WebView( diff --git a/examples/window/window/app.py b/examples/window/window/app.py index ba4d8849ab..d3f87773f3 100644 --- a/examples/window/window/app.py +++ b/examples/window/window/app.py @@ -235,7 +235,7 @@ def startup(self): self.label = toga.Label("Ready.") # Buttons - btn_style = Pack(flex=1, padding=5) + btn_style = Pack(flex=1, margin=5) row_move = toga.Box( style=Pack(direction=ROW), @@ -331,14 +331,14 @@ def startup(self): style=Pack(width=200, text_align=RIGHT), ) ], - style=Pack(padding=5), + style=Pack(margin=5), ) for index, screen in sorted(enumerate(self.screens), key=lambda s: s[1].origin): screen_change_btns_box.add( toga.Button( text=f"{index}: {screen.name}", on_press=partial(self.do_screen_change, screen), - style=Pack(padding_left=5), + style=Pack(margin_left=5), ) ) screen_as_image_btns_box = toga.Box( @@ -348,14 +348,14 @@ def startup(self): style=Pack(width=200, text_align=RIGHT), ) ], - style=Pack(padding=5), + style=Pack(margin=5), ) for index, screen in sorted(enumerate(self.screens), key=lambda s: s[1].origin): screen_as_image_btns_box.add( toga.Button( text=f"{index}: {screen.name}", on_press=partial(self.do_save_screenshot, screen), - style=Pack(padding_left=5), + style=Pack(margin_left=5), ) ) diff --git a/gtk/src/toga_gtk/libs/utils.py b/gtk/src/toga_gtk/libs/utils.py index c2f6ba5599..2533d01347 100644 --- a/gtk/src/toga_gtk/libs/utils.py +++ b/gtk/src/toga_gtk/libs/utils.py @@ -3,8 +3,8 @@ from . import Gtk -def gtk_alignment(alignment): - """Convert Toga alignments into arguments compatible with Gtk.""" +def gtk_text_alignment(alignment): + """Convert Toga text alignments into arguments compatible with Gtk.""" return { LEFT: (0.0, Gtk.Justification.LEFT), RIGHT: (1.0, Gtk.Justification.RIGHT), diff --git a/gtk/src/toga_gtk/widgets/base.py b/gtk/src/toga_gtk/widgets/base.py index 7363341459..bbf2cb30f6 100644 --- a/gtk/src/toga_gtk/widgets/base.py +++ b/gtk/src/toga_gtk/widgets/base.py @@ -141,7 +141,7 @@ def set_bounds(self, x, y, width, height): # Any position changes are applied by the container during do_size_allocate. self.container.make_dirty() - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): # By default, alignment can't be changed pass diff --git a/gtk/src/toga_gtk/widgets/label.py b/gtk/src/toga_gtk/widgets/label.py index c79a28856f..30874d2c3e 100644 --- a/gtk/src/toga_gtk/widgets/label.py +++ b/gtk/src/toga_gtk/widgets/label.py @@ -1,6 +1,6 @@ from travertino.size import at_least -from ..libs import Gtk, gtk_alignment +from ..libs import Gtk, gtk_text_alignment from .base import Widget @@ -9,8 +9,8 @@ def create(self): self.native = Gtk.Label() self.native.set_line_wrap(False) - def set_alignment(self, value): - xalign, justify = gtk_alignment(value) + def set_text_alignment(self, value): + xalign, justify = gtk_text_alignment(value) self.native.set_xalign(xalign) # Aligns the whole text block within the widget. self.native.set_yalign(0.0) # Aligns the text block to the top self.native.set_justify( diff --git a/gtk/src/toga_gtk/widgets/multilinetextinput.py b/gtk/src/toga_gtk/widgets/multilinetextinput.py index 5965938a37..d0c77692ea 100644 --- a/gtk/src/toga_gtk/widgets/multilinetextinput.py +++ b/gtk/src/toga_gtk/widgets/multilinetextinput.py @@ -5,7 +5,7 @@ get_background_color_css, get_color_css, get_font_css, - gtk_alignment, + gtk_text_alignment, ) from .base import Widget @@ -113,8 +113,8 @@ def set_placeholder(self, value): self.placeholder.get_end_iter(), ) # make the placeholder text gray. - def set_alignment(self, value): - _, justification = gtk_alignment(value) + def set_text_alignment(self, value): + _, justification = gtk_text_alignment(value) self.native_textview.set_justification(justification) def focus(self): diff --git a/gtk/src/toga_gtk/widgets/numberinput.py b/gtk/src/toga_gtk/widgets/numberinput.py index 176825bf3a..fb7eac4b4d 100644 --- a/gtk/src/toga_gtk/widgets/numberinput.py +++ b/gtk/src/toga_gtk/widgets/numberinput.py @@ -5,7 +5,7 @@ from toga.widgets.numberinput import _clean_decimal -from ..libs import Gtk, gtk_alignment +from ..libs import Gtk, gtk_text_alignment from .base import Widget @@ -59,9 +59,9 @@ def set_value(self, value): else: self.native.set_value(value) - def set_alignment(self, value): - xalign, justify = gtk_alignment(value) - self.native.set_alignment(xalign) + def set_text_alignment(self, value): + xalign, justify = gtk_text_alignment(value) + self.native.set_text_alignment(xalign) def rehint(self): width = self.native.get_preferred_width() diff --git a/gtk/src/toga_gtk/widgets/textinput.py b/gtk/src/toga_gtk/widgets/textinput.py index 75d9067b1d..267825eca8 100644 --- a/gtk/src/toga_gtk/widgets/textinput.py +++ b/gtk/src/toga_gtk/widgets/textinput.py @@ -3,7 +3,7 @@ from toga.keys import Key from toga_gtk.keys import toga_key -from ..libs import Gtk, gtk_alignment +from ..libs import Gtk, gtk_text_alignment from .base import Widget @@ -41,9 +41,9 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.set_placeholder_text(value) - def set_alignment(self, value): - xalign, justify = gtk_alignment(value) - self.native.set_alignment( + def set_text_alignment(self, value): + xalign, justify = gtk_text_alignment(value) + self.native.set_text_alignment( xalign ) # Aligns the whole text block within the widget. diff --git a/gtk/src/toga_gtk/window.py b/gtk/src/toga_gtk/window.py index 7cc71de6a3..d50e1d05e4 100644 --- a/gtk/src/toga_gtk/window.py +++ b/gtk/src/toga_gtk/window.py @@ -57,7 +57,7 @@ def __init__(self, interface, title, position, size): # Because expand and fill are True, the container will fill the available # space, and will get a size_allocate callback if the window is resized. self.container = TogaContainer() - self.layout.pack_end(self.container, expand=True, fill=True, padding=0) + self.layout.pack_end(self.container, expand=True, fill=True, margin=0) self.native.add(self.layout) @@ -387,6 +387,6 @@ def create_toolbar(self): self.native_toolbar, expand=False, fill=False, - padding=0, + margin=0, ) self.native_toolbar.show_all() diff --git a/gtk/tests_backend/widgets/base.py b/gtk/tests_backend/widgets/base.py index cc84a82136..c5bd0af7b4 100644 --- a/gtk/tests_backend/widgets/base.py +++ b/gtk/tests_backend/widgets/base.py @@ -38,8 +38,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.get_parent() is None - def assert_alignment(self, expected): - assert self.alignment == expected + def assert_align_items(self, expected): + assert self.align_items == expected def repaint_needed(self): return self.impl.container.needs_redraw or super().repaint_needed() diff --git a/gtk/tests_backend/widgets/label.py b/gtk/tests_backend/widgets/label.py index dc9556ad63..5c8c592f7a 100644 --- a/gtk/tests_backend/widgets/label.py +++ b/gtk/tests_backend/widgets/label.py @@ -12,12 +12,12 @@ def text(self): return self.native.get_label() @property - def alignment(self): + def text_alignment(self): return toga_xalignment(self.native.get_xalign(), self.native.get_justify()) @property - def vertical_alignment(self): + def vertical_text_alignment(self): return - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): assert toga_yalignment(self.native.get_yalign()) == expected diff --git a/gtk/tests_backend/widgets/multilinetextinput.py b/gtk/tests_backend/widgets/multilinetextinput.py index 95d85ffb67..61fe063b8c 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 toga_alignment_from_justification, toga_color +from .properties import toga_color, toga_text_alignment_from_justification class MultilineTextInputProbe(SimpleProbe): @@ -88,12 +88,12 @@ def font(self): return sc.get_property("font", sc.get_state()) @property - def alignment(self): - return toga_alignment_from_justification( + def text_alignment(self): + return toga_text_alignment_from_justification( self.native_textview.get_justification(), ) - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # GTK.TextView vertical alignment is non-configurable pass diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index e8bac75474..ee91d3866e 100644 --- a/gtk/tests_backend/widgets/numberinput.py +++ b/gtk/tests_backend/widgets/numberinput.py @@ -31,10 +31,10 @@ async def decrement(self): ) @property - def alignment(self): + def text_alignment(self): return toga_xalignment(self.native.get_alignment()) - def assert_alignment(self, expected): + def assert_text_alignment(self, expected): if expected == JUSTIFY: assert self.alignment == LEFT else: diff --git a/gtk/tests_backend/widgets/properties.py b/gtk/tests_backend/widgets/properties.py index d341975361..78bf687182 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 toga_xalignment(xalign, justify=None): +def toga_x_text_alignment(xalign, justify=None): try: return { 0.0: JUSTIFY if justify == Gtk.Justification.FILL else LEFT, @@ -31,10 +31,12 @@ def toga_xalignment(xalign, justify=None): 0.5: CENTER, }[xalign] except KeyError: - pytest.fail(f"Can't interpret GTK x alignment {xalign} with justify {justify}") + pytest.fail( + f"Can't interpret GTK x text alignment {xalign} with justify {justify}" + ) -def toga_yalignment(yalign): +def toga_y_text_alignment(yalign): try: return { 0.0: TOP, @@ -42,10 +44,10 @@ def toga_yalignment(yalign): 1.0: BOTTOM, }[yalign] except KeyError: - pytest.fail(f"Can't interpret GTK y alignment {yalign}") + pytest.fail(f"Can't interpret GTK y text alignment {yalign}") -def toga_alignment_from_justification(justify): +def toga_text_alignment_from_justification(justify): return { Gtk.Justification.LEFT: LEFT, Gtk.Justification.RIGHT: RIGHT, diff --git a/gtk/tests_backend/widgets/selection.py b/gtk/tests_backend/widgets/selection.py index 9a2a303eb4..ba14f14eaa 100644 --- a/gtk/tests_backend/widgets/selection.py +++ b/gtk/tests_backend/widgets/selection.py @@ -16,8 +16,8 @@ def shrink_on_resize(self): return False @property - def alignment(self): - xfail("Can't change the alignment of Selection on GTK") + def text_alignment(self): + xfail("Can't change the text alignment of Selection on GTK") @property def color(self): diff --git a/gtk/tests_backend/widgets/textinput.py b/gtk/tests_backend/widgets/textinput.py index c96a1af922..17891fe71a 100644 --- a/gtk/tests_backend/widgets/textinput.py +++ b/gtk/tests_backend/widgets/textinput.py @@ -33,16 +33,16 @@ def placeholder_hides_on_focus(self): return False @property - def alignment(self): + def text_alignment(self): return toga_xalignment(self.native.get_alignment()) - def assert_alignment(self, expected): + def assert_text_alignment(self, expected): if expected == JUSTIFY: assert self.alignment == LEFT else: assert self.alignment == expected - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # GTK.Entry vertical alignment is non-configurable pass diff --git a/iOS/src/toga_iOS/widgets/base.py b/iOS/src/toga_iOS/widgets/base.py index 4692a08286..2cc021f44d 100644 --- a/iOS/src/toga_iOS/widgets/base.py +++ b/iOS/src/toga_iOS/widgets/base.py @@ -73,7 +73,7 @@ def set_bounds(self, x, y, width, height): # print("SET BOUNDS", self, x, y, width, height, self.container.top_offset) self.constraints.update(x, y + self.container.top_offset, width, height) - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): pass def set_hidden(self, hidden): diff --git a/iOS/src/toga_iOS/widgets/label.py b/iOS/src/toga_iOS/widgets/label.py index 0426fc3cc8..38789810d2 100644 --- a/iOS/src/toga_iOS/widgets/label.py +++ b/iOS/src/toga_iOS/widgets/label.py @@ -41,7 +41,7 @@ def create(self): # Add the layout constraints self.add_constraints() - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.textAlignment = NSTextAlignment(value) def set_color(self, value): diff --git a/iOS/src/toga_iOS/widgets/multilinetextinput.py b/iOS/src/toga_iOS/widgets/multilinetextinput.py index 9959712e6f..08081141fa 100644 --- a/iOS/src/toga_iOS/widgets/multilinetextinput.py +++ b/iOS/src/toga_iOS/widgets/multilinetextinput.py @@ -144,7 +144,7 @@ def set_color(self, value): def set_background_color(self, color): self.set_background_color_simple(color) - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.textAlignment = NSTextAlignment(value) def set_font(self, font): diff --git a/iOS/src/toga_iOS/widgets/numberinput.py b/iOS/src/toga_iOS/widgets/numberinput.py index cbb7ca0b45..bb967b9929 100644 --- a/iOS/src/toga_iOS/widgets/numberinput.py +++ b/iOS/src/toga_iOS/widgets/numberinput.py @@ -108,7 +108,7 @@ def set_value(self, value): self.native.text = str(value) self.interface.on_change() - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.textAlignment = NSTextAlignment(value) def set_font(self, font): diff --git a/iOS/src/toga_iOS/widgets/selection.py b/iOS/src/toga_iOS/widgets/selection.py index 52af947f42..96a4f841e0 100644 --- a/iOS/src/toga_iOS/widgets/selection.py +++ b/iOS/src/toga_iOS/widgets/selection.py @@ -77,7 +77,7 @@ def create(self): self.add_constraints() - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.textAlignment = NSTextAlignment(value) def set_color(self, color): diff --git a/iOS/src/toga_iOS/widgets/textinput.py b/iOS/src/toga_iOS/widgets/textinput.py index 2397249bf7..58b4c5554d 100644 --- a/iOS/src/toga_iOS/widgets/textinput.py +++ b/iOS/src/toga_iOS/widgets/textinput.py @@ -128,7 +128,7 @@ def set_value(self, value): self.native.text = value self.interface._value_changed() - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.textAlignment = NSTextAlignment(value) if value == RIGHT: self.error_label.textAlignment = NSTextAlignment(LEFT) diff --git a/iOS/tests_backend/widgets/base.py b/iOS/tests_backend/widgets/base.py index 8a4200b806..22fd9d05d5 100644 --- a/iOS/tests_backend/widgets/base.py +++ b/iOS/tests_backend/widgets/base.py @@ -63,8 +63,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.superview() is None - def assert_alignment(self, expected): - assert self.alignment == expected + def assert_align_items(self, expected): + assert self.align_items == expected async def redraw(self, message=None, delay=0): """Request a redraw of the app, waiting until that redraw has completed.""" diff --git a/iOS/tests_backend/widgets/label.py b/iOS/tests_backend/widgets/label.py index 15feca8b24..93873b05af 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class LabelProbe(SimpleProbe): @@ -19,10 +19,10 @@ def color(self): return toga_color(self.native.textColor) @property - def alignment(self): - return toga_alignment(self.native.textAlignment) + def text_alignment(self): + return toga_text_alignment(self.native.textAlignment) - def assert_vertical_alignment(self, alignment): + def assert_vertical_text_alignment(self, alignment): # iOS has a custom draw method that always draw the text at the top; # this location isn't configurable pass diff --git a/iOS/tests_backend/widgets/numberinput.py b/iOS/tests_backend/widgets/numberinput.py index b9e9d402cf..094f7a98db 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class NumberInputProbe(SimpleProbe): @@ -29,10 +29,10 @@ def color(self): return toga_color(self.native.textColor) @property - def alignment(self): - return toga_alignment(self.native.textAlignment) + def text_alignment(self): + return toga_text_alignment(self.native.textAlignment) - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # Vertical alignment isn't configurable on a UITextField pass diff --git a/iOS/tests_backend/widgets/properties.py b/iOS/tests_backend/widgets/properties.py index 1259b9131b..0a9a1aadc1 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 toga_alignment(alignment): +def toga_text_alignment(alignment): return { NSLeftTextAlignment: LEFT, NSRightTextAlignment: RIGHT, diff --git a/iOS/tests_backend/widgets/selection.py b/iOS/tests_backend/widgets/selection.py index 41c9dbf4f4..fd5c6ced2b 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class SelectionProbe(SimpleProbe): @@ -20,11 +20,11 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes") @property - def alignment(self): - return toga_alignment(self.native.textAlignment) + def text_alignment(self): + return toga_text_alignment(self.native.textAlignment) - def assert_vertical_alignment(self, expected): - # Vertical alignment isn't configurable on UITextField + def assert_vertical_text_alignment(self, expected): + # Vertical text alignment isn't configurable on UITextField pass @property diff --git a/iOS/tests_backend/widgets/textinput.py b/iOS/tests_backend/widgets/textinput.py index 784570df30..5d0cac6842 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 toga_alignment, toga_color +from .properties import toga_color, toga_text_alignment class TextInputProbe(SimpleProbe): @@ -43,11 +43,11 @@ def color(self): return toga_color(self.native.textColor) @property - def alignment(self): - return toga_alignment(self.native.textAlignment) + def text_alignment(self): + return toga_text_alignment(self.native.textAlignment) - def assert_vertical_alignment(self, expected): - # Vertical alignment isn't configurable on UITextField + def assert_vertical_text_alignment(self, expected): + # Vertical text alignment isn't configurable on UITextField pass @property diff --git a/testbed/tests/app/test_desktop.py b/testbed/tests/app/test_desktop.py index 4ec5a7a027..c3ab9cdfb0 100644 --- a/testbed/tests/app/test_desktop.py +++ b/testbed/tests/app/test_desktop.py @@ -546,7 +546,7 @@ async def test_system_dpi_change( try: main_window.toolbar.add(toga.Command(None, "Test command")) - # Include widgets which are sized in different ways, with padding and fixed + # Include widgets which are sized in different ways, with margin and fixed # sizes in both dimensions. main_window.content = toga.Box( style=Pack(direction="row"), @@ -554,7 +554,7 @@ async def test_system_dpi_change( toga.Label( "fixed", id="fixed", - style=Pack(background_color="yellow", padding_left=20, width=100), + style=Pack(background_color="yellow", margin_left=20, width=100), ), toga.Label( "minimal", # Shrink to fit content @@ -565,7 +565,7 @@ async def test_system_dpi_change( "flex", id="flex", style=Pack( - background_color="pink", flex=1, padding_top=15, height=50 + background_color="pink", flex=1, margin_top=15, height=50 ), ), ], diff --git a/testbed/tests/widgets/properties.py b/testbed/tests/widgets/properties.py index 0870c09567..fb17380309 100644 --- a/testbed/tests/widgets/properties.py +++ b/testbed/tests/widgets/properties.py @@ -414,41 +414,41 @@ async def test_background_color_transparent(widget, probe): assert_color(probe.background_color, TRANSPARENT if supports_alpha else original) -async def test_alignment(widget, probe, verify_vertical_alignment): +async def test_text_alignment(widget, probe, verify_vertical_text_alignment): """Widget honors alignment settings.""" - # Use column alignment to ensure widget uses all available width + # Use column direction to ensure widget uses all available width widget.parent.style.direction = COLUMN - # Initial alignment is LEFT, initial direction is LTR + # Initial text alignment is LEFT, initial direction is LTR await probe.redraw("Text direction should be LTR") - probe.assert_alignment(LEFT) + probe.assert_text_alignment(LEFT) - for alignment in [RIGHT, CENTER, JUSTIFY]: - widget.style.text_align = alignment - await probe.redraw("Text direction should be %s" % alignment) - probe.assert_alignment(alignment) - probe.assert_vertical_alignment(verify_vertical_alignment) + for text_alignment in [RIGHT, CENTER, JUSTIFY]: + widget.style.text_align = text_alignment + await probe.redraw("Text alignment should be %s" % text_alignment) + probe.assert_text_alignment(text_alignment) + probe.assert_vertical_text_alignment(verify_vertical_text_alignment) - # Clearing the alignment reverts to default alignment of LEFT + # Clearing the text alignment reverts to default text alignment of LEFT del widget.style.text_align - await probe.redraw("Text direction should be reverted to LEFT") - probe.assert_alignment(LEFT) + await probe.redraw("Text alignment should be reverted to LEFT") + probe.assert_text_alignment(LEFT) - # If text direction is RTL, default alignment is RIGHT + # If text direction is RTL, default text alignment is RIGHT widget.style.text_direction = RTL - await probe.redraw("Text direction should be RTL") - probe.assert_alignment(RIGHT) + await probe.redraw("Text direction is RTL, so text alignment should be RIGHT") + probe.assert_text_alignment(RIGHT) - # If text direction is expliclty LTR, default alignment is LEFT + # If text direction is expliclty LTR, default text alignment is LEFT widget.style.text_direction = LTR - await probe.redraw("Text direction should be LTR") - probe.assert_alignment(LEFT) + await probe.redraw("Text direction is LTR, so text alignment should be LEFT") + probe.assert_text_alignment(LEFT) - # If the widget has an explicit height, the vertical alignment of the widget + # If the widget has an explicit height, the vertical text alignment of the widget # is unchanged. widget.style.height = 200 - await probe.redraw(f"Text should be at the {verify_vertical_alignment}") - probe.assert_vertical_alignment(verify_vertical_alignment) + await probe.redraw(f"Text should be at the {verify_vertical_text_alignment}") + probe.assert_vertical_text_alignment(verify_vertical_text_alignment) async def test_readonly(widget, probe): diff --git a/testbed/tests/widgets/test_label.py b/testbed/tests/widgets/test_label.py index aac296e18c..1eddea1dfc 100644 --- a/testbed/tests/widgets/test_label.py +++ b/testbed/tests/widgets/test_label.py @@ -4,7 +4,6 @@ from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -16,6 +15,7 @@ test_font, test_font_attrs, test_text, + test_text_alignment, test_text_width_change, ) diff --git a/testbed/tests/widgets/test_multilinetextinput.py b/testbed/tests/widgets/test_multilinetextinput.py index d979c2709b..49c23b5677 100644 --- a/testbed/tests/widgets/test_multilinetextinput.py +++ b/testbed/tests/widgets/test_multilinetextinput.py @@ -5,7 +5,6 @@ from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -20,6 +19,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, + test_text_alignment, test_text_value, ) from .test_textinput import ( # noqa: F401 diff --git a/testbed/tests/widgets/test_numberinput.py b/testbed/tests/widgets/test_numberinput.py index 10551a0425..96e8b6ab86 100644 --- a/testbed/tests/widgets/test_numberinput.py +++ b/testbed/tests/widgets/test_numberinput.py @@ -8,7 +8,6 @@ from ..conftest import skip_on_platforms from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -20,9 +19,10 @@ test_font, test_font_attrs, test_readonly, + test_text_alignment, ) from .test_textinput import ( # noqa: F401 - verify_vertical_alignment, + verify_vertical_text_alignment, ) diff --git a/testbed/tests/widgets/test_passwordinput.py b/testbed/tests/widgets/test_passwordinput.py index e12509fc91..e38da84452 100644 --- a/testbed/tests/widgets/test_passwordinput.py +++ b/testbed/tests/widgets/test_passwordinput.py @@ -4,7 +4,6 @@ from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -19,6 +18,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, + test_text_alignment, ) from .test_textinput import ( # noqa: F401 placeholder, @@ -30,7 +30,7 @@ test_undo_redo, test_validation, verify_focus_handlers, - verify_vertical_alignment, + verify_vertical_text_alignment, ) diff --git a/testbed/tests/widgets/test_scrollcontainer.py b/testbed/tests/widgets/test_scrollcontainer.py index 68b13434c4..4833513ae1 100644 --- a/testbed/tests/widgets/test_scrollcontainer.py +++ b/testbed/tests/widgets/test_scrollcontainer.py @@ -25,7 +25,7 @@ async def content(): toga.Label( f"I am line {i}", style=Pack( - padding=20, + margin=20, height=20, width=160, background_color=CORNFLOWERBLUE if i % 2 else REBECCAPURPLE, @@ -49,7 +49,7 @@ async def small_content(): toga.Label( "I am content", style=Pack( - padding=20, + margin=20, height=20, width=160, background_color=CORNFLOWERBLUE, @@ -96,7 +96,7 @@ async def test_clear_content(widget, probe, small_content): # Apply a style to guarantee a set_bounds() call has been made # when there is no content. - widget.style.padding = 10 + widget.style.margin = 10 await probe.redraw("Widget has definitely been refreshed") assert not probe.has_content @@ -107,22 +107,22 @@ async def test_clear_content(widget, probe, small_content): assert probe.document_height == probe.height -async def test_padding(widget, probe, content): - "Padding works correctly on the root widget" +async def test_margin(widget, probe, content): + "Margin works correctly on the root widget" original_width = probe.width original_height = probe.height original_document_width = probe.document_width original_document_height = probe.document_height - content.style.padding = 21 - await probe.redraw("Add padding") + content.style.margin = 21 + await probe.redraw("Add margin") assert probe.width == original_width assert probe.height == original_height assert probe.document_width == original_document_width assert probe.document_height == original_document_height + 42 - content.style.padding = 0 - await probe.redraw("Remove padding") + content.style.margin = 0 + await probe.redraw("Remove margin") assert probe.width == original_width assert probe.height == original_height assert probe.document_width == original_document_width @@ -139,7 +139,7 @@ async def test_enable_horizontal_scrolling(widget, probe, content, on_scroll): style=Pack( width=2000, background_color=CORNFLOWERBLUE, - padding=20, + margin=20, height=20, ), ), @@ -207,7 +207,7 @@ async def test_enable_vertical_scrolling(widget, probe, content, on_scroll): style=Pack( width=2000, background_color=CORNFLOWERBLUE, - padding=20, + margin=20, height=20, ), ), @@ -412,7 +412,7 @@ async def test_scroll_both(widget, probe, content, on_scroll): style=Pack( width=2000, background_color=CORNFLOWERBLUE, - padding=20, + margin=20, height=20, ), ) diff --git a/testbed/tests/widgets/test_selection.py b/testbed/tests/widgets/test_selection.py index 41e511078c..4631064f7b 100644 --- a/testbed/tests/widgets/test_selection.py +++ b/testbed/tests/widgets/test_selection.py @@ -8,7 +8,6 @@ from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -18,6 +17,7 @@ test_flex_horizontal_widget_size, test_font, test_font_attrs, + test_text_alignment, ) # FIXME: 2023-05-31 GTK's focus APIs are completely broken for GTK.ComboBox. The @@ -48,7 +48,7 @@ def verify_font_sizes(): @pytest.fixture -def verify_vertical_alignment(): +def verify_vertical_text_alignment(): return CENTER diff --git a/testbed/tests/widgets/test_textinput.py b/testbed/tests/widgets/test_textinput.py index f1ea09de5a..6855be9874 100644 --- a/testbed/tests/widgets/test_textinput.py +++ b/testbed/tests/widgets/test_textinput.py @@ -8,7 +8,6 @@ from ..data import TEXTS from .conftest import build_cleanup_test from .properties import ( # noqa: F401 - test_alignment, test_background_color, test_background_color_reset, test_background_color_transparent, @@ -23,6 +22,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, + test_text_alignment, ) @@ -32,7 +32,7 @@ async def widget(): @pytest.fixture -def verify_vertical_alignment(): +def verify_vertical_text_alignment(): return CENTER diff --git a/textual/src/toga_textual/widgets/base.py b/textual/src/toga_textual/widgets/base.py index dd2f0a6693..605065e926 100644 --- a/textual/src/toga_textual/widgets/base.py +++ b/textual/src/toga_textual/widgets/base.py @@ -143,7 +143,7 @@ def set_bounds(self, x, y, width, height): self.scale_in_horizontal(margin_left), ) - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): pass def set_hidden(self, hidden): diff --git a/web/src/toga_web/widgets/base.py b/web/src/toga_web/widgets/base.py index e7c9c565d1..8ccedc0bab 100644 --- a/web/src/toga_web/widgets/base.py +++ b/web/src/toga_web/widgets/base.py @@ -99,7 +99,7 @@ def _reapply_style(self): def set_bounds(self, x, y, width, height): self._reapply_style() - def set_alignment(self, alignment): + def set_text_alignment(self, alignment): self._reapply_style() def set_hidden(self, hidden): diff --git a/web/src/toga_web/widgets/label.py b/web/src/toga_web/widgets/label.py index 1f81d0b333..854eb2cf6b 100644 --- a/web/src/toga_web/widgets/label.py +++ b/web/src/toga_web/widgets/label.py @@ -11,7 +11,7 @@ def get_text(self): def set_text(self, value): self.native.innerHTML = value - def set_alignment(self, value): + def set_text_alignment(self, value): pass def rehint(self): diff --git a/web/src/toga_web/widgets/textinput.py b/web/src/toga_web/widgets/textinput.py index cd63750cf6..93220ae29f 100644 --- a/web/src/toga_web/widgets/textinput.py +++ b/web/src/toga_web/widgets/textinput.py @@ -27,7 +27,7 @@ def set_value(self, value): def set_font(self, font): pass - def set_alignment(self, value): + def set_text_alignment(self, value): pass def rehint(self): diff --git a/winforms/src/toga_winforms/widgets/base.py b/winforms/src/toga_winforms/widgets/base.py index cc683bd00e..e9eda6b229 100644 --- a/winforms/src/toga_winforms/widgets/base.py +++ b/winforms/src/toga_winforms/widgets/base.py @@ -120,8 +120,8 @@ def set_bounds(self, x, y, width, height): self.native.Size = Size(*map(self.scale_in, (width, height))) self.native.Location = Point(*map(self.scale_in, (x, y))) - def set_alignment(self, alignment): - # By default, alignment can't be changed + def set_text_alignment(self, alignment): + # By default, text alignment can't be changed pass def set_hidden(self, hidden): diff --git a/winforms/src/toga_winforms/widgets/label.py b/winforms/src/toga_winforms/widgets/label.py index c50f59b5ae..85b598b114 100644 --- a/winforms/src/toga_winforms/widgets/label.py +++ b/winforms/src/toga_winforms/widgets/label.py @@ -13,7 +13,7 @@ def create(self): self.native = WinForms.Label() self.native.AutoSizeMode = WinForms.AutoSizeMode.GrowAndShrink - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.TextAlign = TextAlignment(value) def get_text(self): diff --git a/winforms/src/toga_winforms/widgets/multilinetextinput.py b/winforms/src/toga_winforms/widgets/multilinetextinput.py index 7111d47c1e..719c59469a 100644 --- a/winforms/src/toga_winforms/widgets/multilinetextinput.py +++ b/winforms/src/toga_winforms/widgets/multilinetextinput.py @@ -89,7 +89,7 @@ def set_color(self, color): if not self._placeholder_visible: self.native.ForeColor = self._color - def set_alignment(self, value): + def set_text_alignment(self, value): original_selection = (self.native.SelectionStart, self.native.SelectionLength) self.native.SelectAll() self.native.SelectionAlignment = HorizontalTextAlignment(value) diff --git a/winforms/src/toga_winforms/widgets/numberinput.py b/winforms/src/toga_winforms/widgets/numberinput.py index a2246af087..8f6aaf142a 100644 --- a/winforms/src/toga_winforms/widgets/numberinput.py +++ b/winforms/src/toga_winforms/widgets/numberinput.py @@ -63,7 +63,7 @@ def set_value(self, value): else: self.native.Value = native_decimal(value) - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.TextAlign = HorizontalTextAlignment(value) def rehint(self): diff --git a/winforms/src/toga_winforms/widgets/textinput.py b/winforms/src/toga_winforms/widgets/textinput.py index 6086ac29ec..d958d17516 100644 --- a/winforms/src/toga_winforms/widgets/textinput.py +++ b/winforms/src/toga_winforms/widgets/textinput.py @@ -61,7 +61,7 @@ def get_value(self): def set_value(self, value): self.native.Text = value - def set_alignment(self, value): + def set_text_alignment(self, value): self.native.TextAlign = HorizontalTextAlignment(value) def set_color(self, color): diff --git a/winforms/tests_backend/widgets/base.py b/winforms/tests_backend/widgets/base.py index 8b55536f70..7cf4a0e02e 100644 --- a/winforms/tests_backend/widgets/base.py +++ b/winforms/tests_backend/widgets/base.py @@ -31,8 +31,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.Parent is None - def assert_alignment(self, expected): - # Winforms doesn't have a "Justified" alignment; it falls back to LEFT + def assert_text_alignment(self, expected): + # Winforms doesn't have a "Justified" text alignment; it falls back to LEFT actual = self.alignment if expected == JUSTIFY: assert actual == LEFT diff --git a/winforms/tests_backend/widgets/label.py b/winforms/tests_backend/widgets/label.py index 5a574f10db..768f39297c 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 toga_xalignment, toga_yalignment +from .properties import toga_x_text_alignment, toga_y_text_alignment class LabelProbe(SimpleProbe): @@ -12,8 +12,8 @@ def text(self): return self.native.Text @property - def alignment(self): - return toga_xalignment(self.native.TextAlign) + def text_alignment(self): + return toga_x_text_alignment(self.native.TextAlign) - def assert_vertical_alignment(self, expected): - assert toga_yalignment(self.native.TextAlign) == expected + def assert_vertical_text_alignment(self, expected): + assert toga_y_text_alignment(self.native.TextAlign) == expected diff --git a/winforms/tests_backend/widgets/multilinetextinput.py b/winforms/tests_backend/widgets/multilinetextinput.py index bd49a1506b..d21a09de6d 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 toga_xalignment +from .properties import toga_x_text_alignment from .textinput import TextInputProbe @@ -56,6 +56,6 @@ async def wait_for_scroll_completion(self): # SelectionAlignment.Left when the text selection contains multiple paragraphs with # mixed alignment." @property - def alignment(self): + def text_alignment(self): self.native.SelectAll() - return toga_xalignment(self.native.SelectionAlignment) + return toga_x_text_alignment(self.native.SelectionAlignment) diff --git a/winforms/tests_backend/widgets/numberinput.py b/winforms/tests_backend/widgets/numberinput.py index af8d8fd7d1..45944fcf4b 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 toga_xalignment +from .properties import toga_x_text_alignment class NumberInputProbe(SimpleProbe): @@ -33,11 +33,11 @@ async def decrement(self): await self.type_character("") @property - def alignment(self): - return toga_xalignment(self.native.TextAlign) + def text_alignment(self): + return toga_x_text_alignment(self.native.TextAlign) - def assert_vertical_alignment(self, expected): - # Vertical alignment isn't configurable in this native widget. + def assert_vertical_text_alignment(self, expected): + # Vertical text alignment isn't configurable in this native widget. pass def set_cursor_at_end(self): diff --git a/winforms/tests_backend/widgets/properties.py b/winforms/tests_backend/widgets/properties.py index d3ed86c23e..5d459dab5c 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 toga_xalignment(alignment): +def toga_x_text_alignment(alignment): return { ContentAlignment.TopLeft: LEFT, ContentAlignment.MiddleLeft: LEFT, @@ -27,7 +27,7 @@ def toga_xalignment(alignment): }[alignment] -def toga_yalignment(alignment): +def toga_y_text_alignment(alignment): return { ContentAlignment.TopLeft: TOP, ContentAlignment.TopCenter: TOP, diff --git a/winforms/tests_backend/widgets/selection.py b/winforms/tests_backend/widgets/selection.py index 73b4207d0b..823e580f19 100644 --- a/winforms/tests_backend/widgets/selection.py +++ b/winforms/tests_backend/widgets/selection.py @@ -13,8 +13,8 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes on this backend") @property - def alignment(self): - xfail("Can't change the alignment of Selection on this backend") + def text_alignment(self): + xfail("Can't change the text alignment of Selection on this backend") @property def titles(self): diff --git a/winforms/tests_backend/widgets/textinput.py b/winforms/tests_backend/widgets/textinput.py index 2e6b07776e..ac165df5b1 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 toga_xalignment +from .properties import toga_x_text_alignment class TextInputProbe(SimpleProbe): @@ -48,11 +48,11 @@ def readonly(self): return self.native.ReadOnly @property - def alignment(self): - return toga_xalignment(self.native.TextAlign) + def text_alignment(self): + return toga_x_text_alignment(self.native.TextAlign) - def assert_vertical_alignment(self, expected): - # Vertical alignment isn't configurable in this native widget. + def assert_vertical_text_alignment(self, expected): + # Vertical text alignment isn't configurable in this native widget. pass def set_cursor_at_end(self): From 52ecf6afc8946102eb016d325f1d6ce3d7bd1c15 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 8 Dec 2024 22:47:42 -0500 Subject: [PATCH 02/12] Added changenote --- changes/3033.removal.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/3033.removal.rst diff --git a/changes/3033.removal.rst b/changes/3033.removal.rst new file mode 100644 index 0000000000..e0419db3cd --- /dev/null +++ b/changes/3033.removal.rst @@ -0,0 +1 @@ +Pack's padding and alignment properties have been renamed to margin and align_items, to match their CSS analogues. The old names are still present, but are deprecated. From e71b659d5ac1a5add585b27ebdf8fe345db08f74 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 8 Dec 2024 23:20:45 -0500 Subject: [PATCH 03/12] Fixes to coverage and testbed --- android/src/toga_android/widgets/base.py | 2 +- android/src/toga_android/widgets/label.py | 4 +-- android/tests_backend/widgets/base.py | 2 +- cocoa/tests_backend/widgets/label.py | 2 +- .../widgets/multilinetextinput.py | 2 +- cocoa/tests_backend/widgets/numberinput.py | 2 +- .../style/pack/test_deprecated_properties.py | 33 ++++++++++++++----- gtk/tests_backend/widgets/numberinput.py | 2 +- iOS/tests_backend/widgets/base.py | 4 +-- 9 files changed, 35 insertions(+), 18 deletions(-) diff --git a/android/src/toga_android/widgets/base.py b/android/src/toga_android/widgets/base.py index 63533b5193..eb1126ceaf 100644 --- a/android/src/toga_android/widgets/base.py +++ b/android/src/toga_android/widgets/base.py @@ -190,7 +190,7 @@ def rehint(self): pass -def android_text_align(value): +def android_text_alignment(value): """Convert toga alignment values into Android alignment values.""" return { LEFT: Gravity.LEFT, diff --git a/android/src/toga_android/widgets/label.py b/android/src/toga_android/widgets/label.py index 2d6ee24136..2241d0cf3e 100644 --- a/android/src/toga_android/widgets/label.py +++ b/android/src/toga_android/widgets/label.py @@ -10,7 +10,7 @@ from toga.constants import JUSTIFY from toga_android.colors import native_color -from .base import Widget, android_text_align +from .base import Widget, android_text_alignment def set_textview_font(tv, font, default_typeface, default_size): @@ -51,7 +51,7 @@ def set_textview_alignment(self, value, vertical_gravity): else Layout.JUSTIFICATION_MODE_NONE ) - self.native.setGravity(vertical_gravity | android_text_align(value)) + self.native.setGravity(vertical_gravity | android_text_alignment(value)) class Label(TextViewWidget): diff --git a/android/tests_backend/widgets/base.py b/android/tests_backend/widgets/base.py index 56f36f0973..ecc8b5f1bb 100644 --- a/android/tests_backend/widgets/base.py +++ b/android/tests_backend/widgets/base.py @@ -46,7 +46,7 @@ def assert_text_alignment(self, expected): else: assert actual == expected - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): assert toga_vertical_alignment(self.native.getGravity()) == expected @property diff --git a/cocoa/tests_backend/widgets/label.py b/cocoa/tests_backend/widgets/label.py index fc1f33920c..47316a900b 100644 --- a/cocoa/tests_backend/widgets/label.py +++ b/cocoa/tests_backend/widgets/label.py @@ -19,6 +19,6 @@ def color(self): def text_alignment(self): return toga_text_alignment(self.native.alignment) - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/cocoa/tests_backend/widgets/multilinetextinput.py b/cocoa/tests_backend/widgets/multilinetextinput.py index f315a1b46f..232d5b6da2 100644 --- a/cocoa/tests_backend/widgets/multilinetextinput.py +++ b/cocoa/tests_backend/widgets/multilinetextinput.py @@ -61,7 +61,7 @@ def font(self): def text_alignment(self): return toga_text_alignment(self.native_text.alignment) - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # Vertical alignment isn't configurable on NSTextView pass diff --git a/cocoa/tests_backend/widgets/numberinput.py b/cocoa/tests_backend/widgets/numberinput.py index d7f0cfcea4..df6310c64a 100644 --- a/cocoa/tests_backend/widgets/numberinput.py +++ b/cocoa/tests_backend/widgets/numberinput.py @@ -89,7 +89,7 @@ def font(self): def text_alignment(self): return toga_text_alignment(self.native_input.alignment) - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/core/tests/style/pack/test_deprecated_properties.py b/core/tests/style/pack/test_deprecated_properties.py index b65f455369..679c84bf99 100644 --- a/core/tests/style/pack/test_deprecated_properties.py +++ b/core/tests/style/pack/test_deprecated_properties.py @@ -11,22 +11,29 @@ def getitem(obj, name): return obj[name] +def delitem(obj, name): + del obj[name] + + @pytest.mark.parametrize( - "old_name, new_name, value", + "old_name, new_name, value, default", [ # Travertino 0.3.0 doesn't support accessing a directional property via bracket # notation. - # ("padding", "margin", (5, 5, 5, 5)), - ("padding_top", "margin_top", 5), - ("padding_right", "margin_right", 5), - ("padding_bottom", "margin_bottom", 5), - ("padding_left", "margin_left", 5), - ("alignment", "align_items", "center"), + # ("padding", "margin", (5, 5, 5, 5), (0, 0, 0, 0)), + ("padding_top", "margin_top", 5, 0), + ("padding_right", "margin_right", 5, 0), + ("padding_bottom", "margin_bottom", 5, 0), + ("padding_left", "margin_left", 5, 0), + ("alignment", "align_items", "center", None), ], ) @pytest.mark.parametrize("set_fn", (setattr, setitem)) @pytest.mark.parametrize("get_fn", (getattr, getitem)) -def test_deprecated_properties(old_name, new_name, value, set_fn, get_fn): +@pytest.mark.parametrize("del_fn", (delattr, delitem)) +def test_deprecated_properties( + old_name, new_name, value, default, set_fn, get_fn, del_fn +): """Deprecated names alias to new names, and issue deprecation warnings.""" # Set the old name, then check the new name. @@ -35,12 +42,22 @@ def test_deprecated_properties(old_name, new_name, value, set_fn, get_fn): set_fn(style, old_name, value) assert get_fn(style, new_name) == value + # Delete the old name, check new name + with pytest.warns(DeprecationWarning): + del_fn(style, old_name) + assert get_fn(style, new_name) == default + # Set the new name, then check the old name. style = Pack() set_fn(style, new_name, value) with pytest.warns(DeprecationWarning): assert get_fn(style, old_name) == value + # Delete the new name, check old name + del_fn(style, new_name) + with pytest.warns(DeprecationWarning): + assert get_fn(style, old_name) == default + def test_padding_margin(): """Padding aliases margin, but can't be checked with bracket notation.""" diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index ee91d3866e..cc918ca73e 100644 --- a/gtk/tests_backend/widgets/numberinput.py +++ b/gtk/tests_backend/widgets/numberinput.py @@ -40,7 +40,7 @@ def assert_text_alignment(self, expected): else: assert self.alignment == expected - def assert_vertical_alignment(self, expected): + def assert_vertical_text_alignment(self, expected): # GTK.SpinButton vertical alignment is non-configurable pass diff --git a/iOS/tests_backend/widgets/base.py b/iOS/tests_backend/widgets/base.py index 22fd9d05d5..7aac1222c3 100644 --- a/iOS/tests_backend/widgets/base.py +++ b/iOS/tests_backend/widgets/base.py @@ -63,8 +63,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.superview() is None - def assert_align_items(self, expected): - assert self.align_items == expected + def assert_text_alignment(self, expected): + assert self.text_alignment == expected async def redraw(self, message=None, delay=0): """Request a redraw of the app, waiting until that redraw has completed.""" From a919c453ee1596ed41bfa61558eb9cfc42fbf79f Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 8 Dec 2024 23:41:10 -0500 Subject: [PATCH 04/12] More testbed fixes --- docs/reference/style/pack.rst | 2 +- gtk/src/toga_gtk/window.py | 2 +- gtk/tests_backend/widgets/numberinput.py | 4 ++-- gtk/tests_backend/widgets/textinput.py | 4 ++-- testbed/tests/widgets/conftest.py | 4 ++-- winforms/tests_backend/widgets/base.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/reference/style/pack.rst b/docs/reference/style/pack.rst index 9c76dda8c3..e49c2867a5 100644 --- a/docs/reference/style/pack.rst +++ b/docs/reference/style/pack.rst @@ -65,7 +65,7 @@ indicates children will be packed horizontally; left-to-right if ``text_direction`` is ``ltr``, or right-to-left if ``text_direction`` is ``rtl``. ``align_items`` -------------- +--------------- **Values:** ``top`` | ``bottom`` | ``left`` | ``right`` | ``center`` diff --git a/gtk/src/toga_gtk/window.py b/gtk/src/toga_gtk/window.py index d50e1d05e4..214ad78f90 100644 --- a/gtk/src/toga_gtk/window.py +++ b/gtk/src/toga_gtk/window.py @@ -57,7 +57,7 @@ def __init__(self, interface, title, position, size): # Because expand and fill are True, the container will fill the available # space, and will get a size_allocate callback if the window is resized. self.container = TogaContainer() - self.layout.pack_end(self.container, expand=True, fill=True, margin=0) + self.layout.pack_end(self.container, expand=True, fill=True, padding=0) self.native.add(self.layout) diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index cc918ca73e..e23cb05006 100644 --- a/gtk/tests_backend/widgets/numberinput.py +++ b/gtk/tests_backend/widgets/numberinput.py @@ -36,9 +36,9 @@ def text_alignment(self): def assert_text_alignment(self, expected): if expected == JUSTIFY: - assert self.alignment == LEFT + assert self.text_alignment == LEFT else: - assert self.alignment == expected + assert self.text_alignment == expected def assert_vertical_text_alignment(self, expected): # GTK.SpinButton vertical alignment is non-configurable diff --git a/gtk/tests_backend/widgets/textinput.py b/gtk/tests_backend/widgets/textinput.py index 17891fe71a..a50411d95d 100644 --- a/gtk/tests_backend/widgets/textinput.py +++ b/gtk/tests_backend/widgets/textinput.py @@ -38,9 +38,9 @@ def text_alignment(self): def assert_text_alignment(self, expected): if expected == JUSTIFY: - assert self.alignment == LEFT + assert self.text_alignment == LEFT else: - assert self.alignment == expected + assert self.text_alignment == expected def assert_vertical_text_alignment(self, expected): # GTK.Entry vertical alignment is non-configurable diff --git a/testbed/tests/widgets/conftest.py b/testbed/tests/widgets/conftest.py index 0035a1bfe2..873fc07b30 100644 --- a/testbed/tests/widgets/conftest.py +++ b/testbed/tests/widgets/conftest.py @@ -78,8 +78,8 @@ def verify_focus_handlers(): @fixture -def verify_vertical_alignment(): - """The widget's default vertical alignment""" +def verify_vertical_text_alignment(): + """The widget's default vertical text alignment""" return TOP diff --git a/winforms/tests_backend/widgets/base.py b/winforms/tests_backend/widgets/base.py index 7cf4a0e02e..ec30adbc57 100644 --- a/winforms/tests_backend/widgets/base.py +++ b/winforms/tests_backend/widgets/base.py @@ -33,7 +33,7 @@ def assert_not_contained(self): def assert_text_alignment(self, expected): # Winforms doesn't have a "Justified" text alignment; it falls back to LEFT - actual = self.alignment + actual = self.text_alignment if expected == JUSTIFY: assert actual == LEFT else: From 7edbccdf68f64fd4fa9431b44ca69e97c34c0a30 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Sun, 8 Dec 2024 23:55:41 -0500 Subject: [PATCH 05/12] More GTK testbed fixes --- gtk/src/toga_gtk/window.py | 2 +- gtk/tests_backend/widgets/base.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gtk/src/toga_gtk/window.py b/gtk/src/toga_gtk/window.py index 214ad78f90..7cc71de6a3 100644 --- a/gtk/src/toga_gtk/window.py +++ b/gtk/src/toga_gtk/window.py @@ -387,6 +387,6 @@ def create_toolbar(self): self.native_toolbar, expand=False, fill=False, - margin=0, + padding=0, ) self.native_toolbar.show_all() diff --git a/gtk/tests_backend/widgets/base.py b/gtk/tests_backend/widgets/base.py index c5bd0af7b4..cbea442708 100644 --- a/gtk/tests_backend/widgets/base.py +++ b/gtk/tests_backend/widgets/base.py @@ -38,8 +38,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.get_parent() is None - def assert_align_items(self, expected): - assert self.align_items == expected + def assert_text_alignment(self, expected): + assert self.text_alignment == expected def repaint_needed(self): return self.impl.container.needs_redraw or super().repaint_needed() From 97f8d6cc7265123f3363fd9236d96e0d6de3c749 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Mon, 9 Dec 2024 00:44:25 -0500 Subject: [PATCH 06/12] Yet more GTK testbed fixes --- gtk/src/toga_gtk/widgets/numberinput.py | 2 +- gtk/src/toga_gtk/widgets/textinput.py | 2 +- gtk/tests_backend/widgets/label.py | 6 ++++-- gtk/tests_backend/widgets/numberinput.py | 4 ++-- gtk/tests_backend/widgets/textinput.py | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gtk/src/toga_gtk/widgets/numberinput.py b/gtk/src/toga_gtk/widgets/numberinput.py index fb7eac4b4d..14f891cfdb 100644 --- a/gtk/src/toga_gtk/widgets/numberinput.py +++ b/gtk/src/toga_gtk/widgets/numberinput.py @@ -61,7 +61,7 @@ def set_value(self, value): def set_text_alignment(self, value): xalign, justify = gtk_text_alignment(value) - self.native.set_text_alignment(xalign) + self.native.set_alignment(xalign) def rehint(self): width = self.native.get_preferred_width() diff --git a/gtk/src/toga_gtk/widgets/textinput.py b/gtk/src/toga_gtk/widgets/textinput.py index 267825eca8..b7bc75c6ac 100644 --- a/gtk/src/toga_gtk/widgets/textinput.py +++ b/gtk/src/toga_gtk/widgets/textinput.py @@ -43,7 +43,7 @@ def set_placeholder(self, value): def set_text_alignment(self, value): xalign, justify = gtk_text_alignment(value) - self.native.set_text_alignment( + self.native.set_alignment( xalign ) # Aligns the whole text block within the widget. diff --git a/gtk/tests_backend/widgets/label.py b/gtk/tests_backend/widgets/label.py index 5c8c592f7a..3621f842fa 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 toga_xalignment, toga_yalignment +from .properties import toga_x_text_alignment, toga_yalignment class LabelProbe(SimpleProbe): @@ -13,7 +13,9 @@ def text(self): @property def text_alignment(self): - return toga_xalignment(self.native.get_xalign(), self.native.get_justify()) + return toga_x_text_alignment( + self.native.get_xalign(), self.native.get_justify() + ) @property def vertical_text_alignment(self): diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index e23cb05006..cbe9050e9e 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 toga_xalignment +from .properties import toga_x_text_alignment class NumberInputProbe(SimpleProbe): @@ -32,7 +32,7 @@ async def decrement(self): @property def text_alignment(self): - return toga_xalignment(self.native.get_alignment()) + return toga_x_text_alignment(self.native.get_alignment()) def assert_text_alignment(self, expected): if expected == JUSTIFY: diff --git a/gtk/tests_backend/widgets/textinput.py b/gtk/tests_backend/widgets/textinput.py index a50411d95d..27f02c78ac 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 toga_xalignment +from .properties import toga_x_text_alignment class TextInputProbe(SimpleProbe): @@ -34,7 +34,7 @@ def placeholder_hides_on_focus(self): @property def text_alignment(self): - return toga_xalignment(self.native.get_alignment()) + return toga_x_text_alignment(self.native.get_alignment()) def assert_text_alignment(self, expected): if expected == JUSTIFY: From e2f36281cc0394856ccda2ae314625aae4527d64 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Mon, 9 Dec 2024 00:58:06 -0500 Subject: [PATCH 07/12] Hopefully last GTK fix --- gtk/tests_backend/widgets/label.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtk/tests_backend/widgets/label.py b/gtk/tests_backend/widgets/label.py index 3621f842fa..cc335ac41c 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 toga_x_text_alignment, toga_yalignment +from .properties import toga_x_text_alignment, toga_y_text_alignment class LabelProbe(SimpleProbe): @@ -22,4 +22,4 @@ def vertical_text_alignment(self): return def assert_vertical_text_alignment(self, expected): - assert toga_yalignment(self.native.get_yalign()) == expected + assert toga_y_text_alignment(self.native.get_yalign()) == expected From e84de8901bc4d6b17980c62b8aa297ed2e65e8ff Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 11 Dec 2024 18:28:35 -0500 Subject: [PATCH 08/12] Documentation fixes --- docs/reference/api/containers/box.rst | 2 +- docs/reference/style/pack.rst | 4 ++-- docs/tutorial/tutorial-0.rst | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/reference/api/containers/box.rst b/docs/reference/api/containers/box.rst index 7e973c7e7e..ba42d0d03b 100644 --- a/docs/reference/api/containers/box.rst +++ b/docs/reference/api/containers/box.rst @@ -41,7 +41,7 @@ Alternatively, children can be specified at the time the box is constructed: In most apps, a layout is constructed by building a tree of boxes inside boxes, with concrete widgets (such as :class:`~toga.Label` or :class:`~toga.Button`) forming the -leaf nodes of the tree. Style directives can be applied to enforce margin around the +leaf nodes of the tree. Style directives can be applied to enforce a margin around the outside of the box, direction of child stacking inside the box, and background color of the box. diff --git a/docs/reference/style/pack.rst b/docs/reference/style/pack.rst index e49c2867a5..fb1b434811 100644 --- a/docs/reference/style/pack.rst +++ b/docs/reference/style/pack.rst @@ -137,8 +137,8 @@ direction of the parent's layout. **Initial value:** ``0`` -The amount of space to allocate between the edge of the box, and the edge of the content -in the box, in :ref:`CSS pixels `. +The amount of space to allocate outside the edge of the widget, in :ref:`CSS pixels +`. ``margin`` ----------- diff --git a/docs/tutorial/tutorial-0.rst b/docs/tutorial/tutorial-0.rst index e7864bf454..6dbecaf74a 100644 --- a/docs/tutorial/tutorial-0.rst +++ b/docs/tutorial/tutorial-0.rst @@ -119,7 +119,7 @@ fill the entire app window, we can't just put the button into the app window. Instead, we need create a box, and put the button in the box. A box is an object that can be used to hold multiple widgets, and to -define margin around widgets. So, we define a box:: +define a margin around widgets. So, we define a box:: box = toga.Box() @@ -136,7 +136,7 @@ We can set style properties of the button:: button.style.margin = 50 What we've done here is say that the button will have a margin of 50 pixels -on all sides. If we wanted to define margin of 20 pixels on top of the +on all sides. If we wanted to define a margin of 20 pixels on top of the button, we could have defined ``margin_top = 20``, or we could have specified the ``margin = (20, 50, 50, 50)``. From 5e1af526a964aeaef770b86e5ec32156a6a64b61 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 11 Dec 2024 21:47:39 -0500 Subject: [PATCH 09/12] Fixed align_items values, added backwards compatibilty for alignment values --- core/src/toga/style/pack.py | 137 +++++++++++++----- .../pack/layout/test_column_alignment.py | 6 +- .../style/pack/layout/test_row_alignment.py | 6 +- core/tests/style/pack/layout/test_rtl.py | 10 +- core/tests/style/pack/test_css.py | 58 ++------ .../style/pack/test_deprecated_properties.py | 80 +++++++++- docs/reference/style/pack.rst | 20 +-- 7 files changed, 209 insertions(+), 108 deletions(-) diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index ead9c69649..49f68a6464 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -57,10 +57,18 @@ # Declaration choices ###################################################################### +# Define here, since they're not available in Travertino 0.3.0 +START = "start" +END = "end" +# Used in backwards compatibility section below +ALIGNMENT = "alignment" +ALIGN_ITEMS = "align_items" + DISPLAY_CHOICES = Choices(PACK, NONE) VISIBILITY_CHOICES = Choices(VISIBLE, HIDDEN) DIRECTION_CHOICES = Choices(ROW, COLUMN) -ALIGN_ITEMS_CHOICES = Choices(LEFT, RIGHT, TOP, BOTTOM, CENTER) +ALIGN_ITEMS_CHOICES = Choices(START, CENTER, END) +ALIGNMENT_CHOICES = Choices(TOP, RIGHT, BOTTOM, LEFT, CENTER) SIZE_CHOICES = Choices(NONE, integer=True) FLEX_CHOICES = Choices(number=True) @@ -101,45 +109,116 @@ def _hidden(self) -> bool: # Backwards compatibility for Toga <= 0.4.8 ####################################################### + # Pack.alignment is still an actual property, despite being deprecated, so we need + # to suppress deprecation warnings when reapply is called. + def reapply(self, *args, **kw): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + super().reapply(*args, **kw) + DEPRECATED_PROPERTIES = { # Map each deprecated property name to its replacement. + # alignment / align_items is handled separately. "padding": "margin", "padding_top": "margin_top", "padding_right": "margin_right", "padding_bottom": "margin_bottom", "padding_left": "margin_left", - "alignment": "align_items", } - def _dealias_property_name(self, name): - if aliased_name := self.DEPRECATED_PROPERTIES.get(name): - msg = f"Pack.{name} is deprecated; use {aliased_name} instead" - warnings.warn(msg, DeprecationWarning, stacklevel=3) - name = aliased_name + @classmethod + def _update_property_name(cls, name): + if new_name := cls.DEPRECATED_PROPERTIES.get(name): + cls._warn_deprecated(name, new_name, stacklevel=4) + name = new_name return name + @staticmethod + def _warn_deprecated(old_name, new_name, stacklevel=3): + msg = f"Pack.{old_name} is deprecated; use {new_name} instead" + warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel) + # Dot lookup - def __getattr__(self, name): - return super().__getattribute__(self._dealias_property_name(name)) + def __getattribute__(self, name): + get = super().__getattribute__ + + # Align_items and alignment are paired. Both can never be set at the same time; + # if one is requested, and the other one is set, compute the requested value + # from the one that is set. + if name == ALIGN_ITEMS and (alignment := get(ALIGNMENT)): + if alignment == CENTER: + return CENTER + + if get("direction") == ROW: + if alignment == TOP: + return START + if alignment == BOTTOM: + return END + + # No remaining valid combinations + return None + + # direction must be COLUMN + if alignment == LEFT: + return START if get("text_direction") == LTR else END + if alignment == RIGHT: + return START if get("text_direction") == RTL else END + + # No remaining valid combinations + return None + + if name == ALIGNMENT: + # Warn, whether it's set or not. + get("_warn_deprecated")(ALIGNMENT, ALIGN_ITEMS) + + if align_items := get(ALIGN_ITEMS): + if align_items == START: + if get("direction") == COLUMN: + return LEFT if get("text_direction") == LTR else RIGHT + return TOP # for ROW + + if align_items == END: + if get("direction") == COLUMN: + return RIGHT if get("text_direction") == LTR else LEFT + return BOTTOM # for ROW + + # Only CENTER remains + return CENTER + + return get(get("_update_property_name")(name)) def __setattr__(self, name, value): - super().__setattr__(self._dealias_property_name(name), value) + # Only one of these can be set at a time. + if name == ALIGN_ITEMS: + super().__delattr__(ALIGNMENT) + elif name == ALIGNMENT: + self._warn_deprecated(ALIGNMENT, ALIGN_ITEMS) + super().__delattr__(ALIGN_ITEMS) + + super().__setattr__(self._update_property_name(name), value) def __delattr__(self, name): - super().__delattr__(self._dealias_property_name(name)) + # If one of the two is being deleted, delete the other also. + if name == ALIGN_ITEMS: + super().__delattr__(ALIGNMENT) + elif name == ALIGNMENT: + self._warn_deprecated(ALIGNMENT, ALIGN_ITEMS) + super().__delattr__(ALIGN_ITEMS) + + super().__delattr__(self._update_property_name(name)) # Index notation def __getitem__(self, name): - return super().__getitem__(self._dealias_property_name(name.replace("-", "_"))) + return getattr(self, name.replace("-", "_")) def __setitem__(self, name, value): - super().__setitem__(self._dealias_property_name(name.replace("-", "_")), value) + setattr(self, name.replace("-", "_"), value) def __delitem__(self, name): - super().__delattr__(self._dealias_property_name(name.replace("-", "_"))) + delattr(self, name.replace("-", "_")) ####################################################### # End backwards compatibility @@ -556,7 +635,7 @@ def _layout_row_children( min_height = 0 for child in node.children: # self._debug(f"PASS 3: {child} AT HORIZONTAL {offset=}") - if node.style.text_direction is RTL: + if node.style.text_direction == RTL: # self._debug("- RTL") offset += child.layout.content_width + child.style.margin_right child.layout.content_left = width - offset @@ -595,10 +674,10 @@ def _layout_row_children( + child.style.margin_bottom ) # self._debug(f"- row extra width {extra}") - if self.align_items is BOTTOM: + if self.align_items == END: child.layout.content_top = extra + child.style.margin_top # self._debug(f" align {child} to bottom {child.layout.content_top=}") - elif self.align_items is CENTER: + elif self.align_items == CENTER: child.layout.content_top = int(extra / 2) + child.style.margin_top # self._debug(f" align {child} to center {child.layout.content_top=}") else: @@ -875,10 +954,10 @@ def _layout_column_children( + child.style.margin_right ) # self._debug(f"- row extra width {extra}") - if self.align_items is RIGHT: + if (self.text_direction, self.align_items) in [(LTR, END), (RTL, START)]: child.layout.content_left = extra + child.style.margin_left # self._debug(f" align {child} to right {child.layout.content_left=}") - elif self.align_items is CENTER: + elif self.align_items == CENTER: child.layout.content_left = int(extra / 2) + child.style.margin_left # self._debug(f" align {child} to center {child.layout.content_left=}") else: @@ -918,22 +997,8 @@ def __css__(self) -> str: css.append(f"height: {self.height}px;") # align_items - if self.direction == ROW: - if self.align_items: - if self.align_items == LEFT: - css.append("align-items: start;") - elif self.align_items == RIGHT: - css.append("align-items: end;") - elif self.align_items == CENTER: - css.append("align-items: center;") - else: - if self.align_items: - if self.align_items == TOP: - css.append("align-items: start;") - elif self.align_items == BOTTOM: - css.append("align-items: end;") - elif self.align_items == CENTER: - css.append("align-items: center;") + if self.align_items: + css.append(f"align-items: {self.align_items};") # margin_* if self.margin_top: @@ -982,6 +1047,8 @@ 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) Pack.validated_property("width", choices=SIZE_CHOICES, initial=NONE) diff --git a/core/tests/style/pack/layout/test_column_alignment.py b/core/tests/style/pack/layout/test_column_alignment.py index b583d22759..d3d2fd23e8 100644 --- a/core/tests/style/pack/layout/test_column_alignment.py +++ b/core/tests/style/pack/layout/test_column_alignment.py @@ -1,4 +1,4 @@ -from toga.style.pack import CENTER, COLUMN, LEFT, RIGHT, ROW, Pack +from toga.style.pack import CENTER, COLUMN, END, ROW, START, Pack from ..utils import ExampleNode, ExampleViewport, assert_layout @@ -6,7 +6,7 @@ def test_left(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, align_items=LEFT, height=300), + style=Pack(direction=COLUMN, align_items=START, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode( @@ -98,7 +98,7 @@ def test_center(): def test_right(): root = ExampleNode( "root", - style=Pack(direction=COLUMN, align_items=RIGHT, height=300), + style=Pack(direction=COLUMN, align_items=END, height=300), children=[ ExampleNode("space_filler", style=Pack(width=540, height=100)), ExampleNode( diff --git a/core/tests/style/pack/layout/test_row_alignment.py b/core/tests/style/pack/layout/test_row_alignment.py index 14b526226f..c157085d1a 100644 --- a/core/tests/style/pack/layout/test_row_alignment.py +++ b/core/tests/style/pack/layout/test_row_alignment.py @@ -1,4 +1,4 @@ -from toga.style.pack import BOTTOM, CENTER, COLUMN, ROW, TOP, Pack +from toga.style.pack import CENTER, COLUMN, END, ROW, START, Pack from ..utils import ExampleNode, ExampleViewport, assert_layout @@ -6,7 +6,7 @@ def test_top(): root = ExampleNode( "root", - style=Pack(direction=ROW, align_items=TOP, width=300), + style=Pack(direction=ROW, align_items=START, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode( @@ -98,7 +98,7 @@ def test_center(): def test_bottom(): root = ExampleNode( "root", - style=Pack(direction=ROW, align_items=BOTTOM, width=300), + style=Pack(direction=ROW, align_items=END, width=300), children=[ ExampleNode("space_filler", style=Pack(width=100, height=540)), ExampleNode( diff --git a/core/tests/style/pack/layout/test_rtl.py b/core/tests/style/pack/layout/test_rtl.py index 9ea9b8100d..8f740c5826 100644 --- a/core/tests/style/pack/layout/test_rtl.py +++ b/core/tests/style/pack/layout/test_rtl.py @@ -1,4 +1,4 @@ -from toga.style.pack import BOTTOM, COLUMN, LEFT, RIGHT, ROW, RTL, TOP, Pack +from toga.style.pack import COLUMN, END, ROW, RTL, START, Pack from ..utils import ExampleNode, ExampleViewport, assert_layout @@ -71,7 +71,7 @@ def test_column_box_child_layout(): def test_align_items_top(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=ROW, align_items=TOP), + style=Pack(text_direction=RTL, direction=ROW, align_items=START), children=[ ExampleNode("space_filler", style=Pack(width=30, height=100)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -97,7 +97,7 @@ def test_align_items_top(): def test_align_items_bottom(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=ROW, align_items=BOTTOM), + style=Pack(text_direction=RTL, direction=ROW, align_items=END), children=[ ExampleNode("space_filler", style=Pack(width=30, height=100)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -123,7 +123,7 @@ def test_align_items_bottom(): def test_align_items_left(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=COLUMN, align_items=LEFT), + style=Pack(text_direction=RTL, direction=COLUMN, align_items=END), children=[ ExampleNode("space_filler", style=Pack(width=100, height=30)), ExampleNode("widget", style=Pack(width=30, height=30)), @@ -149,7 +149,7 @@ def test_align_items_left(): def test_align_items_right(): root = ExampleNode( "root", - style=Pack(text_direction=RTL, direction=COLUMN, align_items=RIGHT), + style=Pack(text_direction=RTL, direction=COLUMN, align_items=START), children=[ ExampleNode("space_filler", style=Pack(width=100, height=30)), ExampleNode("widget", style=Pack(width=30, height=30)), diff --git a/core/tests/style/pack/test_css.py b/core/tests/style/pack/test_css.py index 53b446816a..7321ac68c8 100644 --- a/core/tests/style/pack/test_css.py +++ b/core/tests/style/pack/test_css.py @@ -3,9 +3,9 @@ from toga.colors import REBECCAPURPLE from toga.style.pack import ( BOLD, - BOTTOM, CENTER, COLUMN, + END, HIDDEN, ITALIC, JUSTIFY, @@ -18,9 +18,9 @@ ROW, RTL, SMALL_CAPS, + START, SYSTEM, SYSTEM_DEFAULT_FONT_SIZE, - TOP, VISIBLE, Pack, ) @@ -222,24 +222,14 @@ ), # Alignment - default layout pytest.param( - Pack(align_items=LEFT), + Pack(align_items=START), "flex-direction: row; flex: 0.0 0 auto; align-items: start;", - id="align-items-left", + id="align-items-start", ), pytest.param( - Pack(align_items=RIGHT), + Pack(align_items=END), "flex-direction: row; flex: 0.0 0 auto; align-items: end;", - id="align-items-right", - ), - pytest.param( # align_items is ignored - Pack(align_items=TOP), - "flex-direction: row; flex: 0.0 0 auto;", - id="align-items-top", - ), - pytest.param( # align_items is ignored - Pack(align_items=BOTTOM), - "flex-direction: row; flex: 0.0 0 auto;", - id="align-items-bottom", + id="align-items-end", ), pytest.param( Pack(align_items=CENTER), @@ -248,24 +238,14 @@ ), # Alignment - row layout pytest.param( - Pack(direction=ROW, align_items=LEFT), + Pack(direction=ROW, align_items=START), "flex-direction: row; flex: 0.0 0 auto; align-items: start;", - id="row-align_items-left", + id="row-align_items-start", ), pytest.param( - Pack(direction=ROW, align_items=RIGHT), + Pack(direction=ROW, align_items=END), "flex-direction: row; flex: 0.0 0 auto; align-items: end;", - id="row-align_items-right", - ), - pytest.param( # align_items is ignored - Pack(direction=ROW, align_items=TOP), - "flex-direction: row; flex: 0.0 0 auto;", - id="row-align_items-top", - ), - pytest.param( # align_items is ignored - Pack(direction=ROW, align_items=BOTTOM), - "flex-direction: row; flex: 0.0 0 auto;", - id="row-align_items-bottom", + id="row-align_items-end", ), pytest.param( Pack(direction=ROW, align_items=CENTER), @@ -273,25 +253,15 @@ id="row-align_items-center", ), # Alignment - column layout - pytest.param( # align_items is ignored - Pack(direction=COLUMN, align_items=LEFT), - "flex-direction: column; flex: 0.0 0 auto;", - id="column-align_items-left", - ), - pytest.param( # align_items is ignored - Pack(direction=COLUMN, align_items=RIGHT), - "flex-direction: column; flex: 0.0 0 auto;", - id="column-align_items-right", - ), pytest.param( - Pack(direction=COLUMN, align_items=TOP), + Pack(direction=COLUMN, align_items=START), "flex-direction: column; flex: 0.0 0 auto; align-items: start;", - id="column-align_items-top", + id="column-align_items-start", ), pytest.param( - Pack(direction=COLUMN, align_items=BOTTOM), + Pack(direction=COLUMN, align_items=END), "flex-direction: column; flex: 0.0 0 auto; align-items: end;", - id="column-align_items-bottom", + id="column-align_items-end", ), pytest.param( Pack(direction=COLUMN, align_items=CENTER), diff --git a/core/tests/style/pack/test_deprecated_properties.py b/core/tests/style/pack/test_deprecated_properties.py index 679c84bf99..cd550e40cb 100644 --- a/core/tests/style/pack/test_deprecated_properties.py +++ b/core/tests/style/pack/test_deprecated_properties.py @@ -1,6 +1,19 @@ import pytest -from toga.style.pack import Pack +from toga.style.pack import ( + BOTTOM, + CENTER, + COLUMN, + END, + LEFT, + LTR, + RIGHT, + ROW, + RTL, + START, + TOP, + Pack, +) def setitem(obj, name, value): @@ -25,7 +38,6 @@ def delitem(obj, name): ("padding_right", "margin_right", 5, 0), ("padding_bottom", "margin_bottom", 5, 0), ("padding_left", "margin_left", 5, 0), - ("alignment", "align_items", "center", None), ], ) @pytest.mark.parametrize("set_fn", (setattr, setitem)) @@ -35,7 +47,6 @@ def test_deprecated_properties( old_name, new_name, value, default, set_fn, get_fn, del_fn ): """Deprecated names alias to new names, and issue deprecation warnings.""" - # Set the old name, then check the new name. style = Pack() with pytest.warns(DeprecationWarning): @@ -60,8 +71,7 @@ def test_deprecated_properties( def test_padding_margin(): - """Padding aliases margin, but can't be checked with bracket notation.""" - + """Padding aliases margin (but can't be checked with bracket notation).""" # Set the old name, then check the new name. style = Pack() with pytest.warns(DeprecationWarning): @@ -73,3 +83,63 @@ def test_padding_margin(): style.margin = (5, 5, 5, 5) with pytest.warns(DeprecationWarning): assert style.padding == (5, 5, 5, 5) + + +@pytest.mark.parametrize( + "direction, text_direction, alignment, align_items", + [ + (ROW, LTR, TOP, START), + (ROW, RTL, TOP, START), + (ROW, LTR, BOTTOM, END), + (ROW, RTL, BOTTOM, END), + (ROW, LTR, CENTER, CENTER), + (ROW, RTL, CENTER, CENTER), + (COLUMN, LTR, LEFT, START), + (COLUMN, RTL, LEFT, END), + (COLUMN, LTR, RIGHT, END), + (COLUMN, RTL, RIGHT, START), + (COLUMN, RTL, CENTER, CENTER), + (COLUMN, LTR, CENTER, CENTER), + ], +) +def test_alignment_align_items(direction, text_direction, alignment, align_items): + """Alignment (with deprecation warning) and align_items map to each other.""" + with pytest.warns(DeprecationWarning): + style = Pack( + direction=direction, + text_direction=text_direction, + alignment=alignment, + ) + assert style.align_items == align_items + + with pytest.warns(DeprecationWarning): + del style.alignment + assert style.align_items is None + + style = Pack( + direction=direction, + text_direction=text_direction, + align_items=align_items, + ) + with pytest.warns(DeprecationWarning): + assert style.alignment == alignment + + del style.align_items + with pytest.warns(DeprecationWarning): + assert style.alignment is None + + +@pytest.mark.parametrize( + "direction, alignment", + [ + (ROW, LEFT), + (ROW, RIGHT), + (COLUMN, TOP), + (COLUMN, BOTTOM), + ], +) +def test_alignment_align_items_invalid(direction, alignment): + """Invalid settings for alignment should return None for align_items.""" + with pytest.warns(DeprecationWarning): + style = Pack(direction=direction, alignment=alignment) + assert style.align_items is None diff --git a/docs/reference/style/pack.rst b/docs/reference/style/pack.rst index fb1b434811..acbb5581b7 100644 --- a/docs/reference/style/pack.rst +++ b/docs/reference/style/pack.rst @@ -67,20 +67,14 @@ indicates children will be packed horizontally; left-to-right if ``align_items`` --------------- -**Values:** ``top`` | ``bottom`` | ``left`` | ``right`` | ``center`` +**Values:** ``start`` | ``center`` | ``end`` -**Initial value:** ``top`` if direction is ``row``; ``left`` if direction is ``column`` +**Initial value:** ``start`` -The alignment of children relative to the outside of the packed box. - -If the box is a ``column`` box, only the values ``left``, ``right`` and -``center`` are honored. - -If the box is a ``row`` box, only the values ``top``, ``bottom`` and ``center`` -are honored. - -If a value is provided, but the value isn't honored, the alignment -reverts to the default for the direction. +The alignment of children relative to the outside of the packed box, along the cross +axis. A row's main axis is horizontal, so its cross axis is vertical; ``start`` aligns +children to the top, while ``end`` aligns them to the bottom. For columns, ``start`` is +on the left if ``text_direction`` is ``LTR``, and the right if ``RTL``. ``width`` @@ -137,7 +131,7 @@ direction of the parent's layout. **Initial value:** ``0`` -The amount of space to allocate outside the edge of the widget, in :ref:`CSS pixels +The amount of space to allocate outside the edge of the box, in :ref:`CSS pixels `. ``margin`` From a185b13b830f32656e6726b0856dd2cce56b92b5 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 11 Dec 2024 21:56:11 -0500 Subject: [PATCH 10/12] Consistently name text_align everywhere --- android/src/toga_android/widgets/base.py | 4 ++-- android/src/toga_android/widgets/label.py | 6 ++--- .../widgets/multilinetextinput.py | 2 +- android/src/toga_android/widgets/textinput.py | 2 +- android/tests_backend/widgets/base.py | 6 ++--- android/tests_backend/widgets/label.py | 6 ++--- android/tests_backend/widgets/properties.py | 2 +- android/tests_backend/widgets/selection.py | 2 +- cocoa/src/toga_cocoa/widgets/base.py | 2 +- cocoa/src/toga_cocoa/widgets/label.py | 2 +- .../toga_cocoa/widgets/multilinetextinput.py | 2 +- cocoa/src/toga_cocoa/widgets/numberinput.py | 2 +- cocoa/src/toga_cocoa/widgets/textinput.py | 2 +- cocoa/tests_backend/widgets/base.py | 4 ++-- cocoa/tests_backend/widgets/label.py | 8 +++---- .../widgets/multilinetextinput.py | 8 +++---- cocoa/tests_backend/widgets/numberinput.py | 8 +++---- cocoa/tests_backend/widgets/properties.py | 2 +- cocoa/tests_backend/widgets/selection.py | 2 +- cocoa/tests_backend/widgets/textinput.py | 8 +++---- core/src/toga/style/applicator.py | 4 ++-- core/src/toga/style/pack.py | 4 ++-- core/tests/style/pack/test_apply.py | 8 +++---- core/tests/style/test_applicator.py | 4 ++-- dummy/src/toga_dummy/widgets/base.py | 2 +- gtk/src/toga_gtk/libs/utils.py | 2 +- gtk/src/toga_gtk/widgets/base.py | 2 +- gtk/src/toga_gtk/widgets/label.py | 6 ++--- .../toga_gtk/widgets/multilinetextinput.py | 6 ++--- gtk/src/toga_gtk/widgets/numberinput.py | 6 ++--- gtk/src/toga_gtk/widgets/textinput.py | 6 ++--- gtk/tests_backend/widgets/base.py | 4 ++-- gtk/tests_backend/widgets/label.py | 14 +++++------ .../widgets/multilinetextinput.py | 8 +++---- gtk/tests_backend/widgets/numberinput.py | 14 +++++------ gtk/tests_backend/widgets/properties.py | 6 ++--- gtk/tests_backend/widgets/selection.py | 2 +- gtk/tests_backend/widgets/textinput.py | 14 +++++------ iOS/src/toga_iOS/widgets/base.py | 2 +- iOS/src/toga_iOS/widgets/label.py | 2 +- .../toga_iOS/widgets/multilinetextinput.py | 2 +- iOS/src/toga_iOS/widgets/numberinput.py | 2 +- iOS/src/toga_iOS/widgets/selection.py | 2 +- iOS/src/toga_iOS/widgets/textinput.py | 2 +- iOS/tests_backend/widgets/base.py | 4 ++-- iOS/tests_backend/widgets/label.py | 8 +++---- iOS/tests_backend/widgets/numberinput.py | 8 +++---- iOS/tests_backend/widgets/properties.py | 2 +- iOS/tests_backend/widgets/selection.py | 8 +++---- iOS/tests_backend/widgets/textinput.py | 8 +++---- testbed/tests/widgets/conftest.py | 2 +- testbed/tests/widgets/properties.py | 24 +++++++++---------- testbed/tests/widgets/test_label.py | 2 +- .../tests/widgets/test_multilinetextinput.py | 2 +- testbed/tests/widgets/test_numberinput.py | 4 ++-- testbed/tests/widgets/test_passwordinput.py | 4 ++-- testbed/tests/widgets/test_selection.py | 4 ++-- testbed/tests/widgets/test_textinput.py | 4 ++-- textual/src/toga_textual/widgets/base.py | 2 +- web/src/toga_web/widgets/base.py | 2 +- web/src/toga_web/widgets/label.py | 2 +- web/src/toga_web/widgets/textinput.py | 2 +- winforms/src/toga_winforms/widgets/base.py | 2 +- winforms/src/toga_winforms/widgets/label.py | 2 +- .../widgets/multilinetextinput.py | 2 +- .../src/toga_winforms/widgets/numberinput.py | 2 +- .../src/toga_winforms/widgets/textinput.py | 2 +- winforms/tests_backend/widgets/base.py | 4 ++-- winforms/tests_backend/widgets/label.py | 10 ++++---- .../widgets/multilinetextinput.py | 6 ++--- winforms/tests_backend/widgets/numberinput.py | 8 +++---- winforms/tests_backend/widgets/properties.py | 4 ++-- winforms/tests_backend/widgets/selection.py | 2 +- winforms/tests_backend/widgets/textinput.py | 8 +++---- 74 files changed, 173 insertions(+), 175 deletions(-) diff --git a/android/src/toga_android/widgets/base.py b/android/src/toga_android/widgets/base.py index eb1126ceaf..6c73276695 100644 --- a/android/src/toga_android/widgets/base.py +++ b/android/src/toga_android/widgets/base.py @@ -161,7 +161,7 @@ def set_background_filter(self, value): else PorterDuffColorFilter(native_color(value), PorterDuff.Mode.SRC_IN) ) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): pass # If appropriate, a widget subclass will implement this. def set_color(self, color): @@ -190,7 +190,7 @@ def rehint(self): pass -def android_text_alignment(value): +def to_android_text_align(value): """Convert toga alignment values into Android alignment values.""" return { LEFT: Gravity.LEFT, diff --git a/android/src/toga_android/widgets/label.py b/android/src/toga_android/widgets/label.py index 2241d0cf3e..458fcb2a04 100644 --- a/android/src/toga_android/widgets/label.py +++ b/android/src/toga_android/widgets/label.py @@ -10,7 +10,7 @@ from toga.constants import JUSTIFY from toga_android.colors import native_color -from .base import Widget, android_text_alignment +from .base import Widget, to_android_text_align def set_textview_font(tv, font, default_typeface, default_size): @@ -51,7 +51,7 @@ def set_textview_alignment(self, value, vertical_gravity): else Layout.JUSTIFICATION_MODE_NONE ) - self.native.setGravity(vertical_gravity | android_text_alignment(value)) + self.native.setGravity(vertical_gravity | to_android_text_align(value)) class Label(TextViewWidget): @@ -80,5 +80,5 @@ def rehint(self): at_least(self.native.getMeasuredWidth()), ROUND_UP ) - def set_text_alignment(self, value): + def set_text_align(self, value): self.set_textview_alignment(value, Gravity.TOP) diff --git a/android/src/toga_android/widgets/multilinetextinput.py b/android/src/toga_android/widgets/multilinetextinput.py index 8ca156ebf2..545a65127f 100644 --- a/android/src/toga_android/widgets/multilinetextinput.py +++ b/android/src/toga_android/widgets/multilinetextinput.py @@ -23,7 +23,7 @@ def _on_gain_focus(self): def _on_lose_focus(self): pass # The interface doesn't support this event. - def set_text_alignment(self, value): + def set_text_align(self, value): self.set_textview_alignment(value, Gravity.TOP) # This method is necessary to override the TextInput base class. diff --git a/android/src/toga_android/widgets/textinput.py b/android/src/toga_android/widgets/textinput.py index b90032426d..b7ef96bd58 100644 --- a/android/src/toga_android/widgets/textinput.py +++ b/android/src/toga_android/widgets/textinput.py @@ -98,7 +98,7 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.setHint(value) - def set_text_alignment(self, value): + def set_text_align(self, value): self.set_textview_alignment(value, Gravity.CENTER_VERTICAL) def set_error(self, error_message): diff --git a/android/tests_backend/widgets/base.py b/android/tests_backend/widgets/base.py index ecc8b5f1bb..81b1c9901a 100644 --- a/android/tests_backend/widgets/base.py +++ b/android/tests_backend/widgets/base.py @@ -37,8 +37,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.getParent() is None - def assert_text_alignment(self, expected): - actual = self.text_alignment + def assert_text_align(self, expected): + actual = self.text_align if expected == JUSTIFY and ( Build.VERSION.SDK_INT < 26 or not self.supports_justify ): @@ -46,7 +46,7 @@ def assert_text_alignment(self, expected): else: assert actual == expected - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): assert toga_vertical_alignment(self.native.getGravity()) == expected @property diff --git a/android/tests_backend/widgets/label.py b/android/tests_backend/widgets/label.py index 9f568313a5..21dda7535f 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class LabelProbe(SimpleProbe): @@ -26,8 +26,8 @@ def text_size(self): return self.native.getTextSize() @property - def text_alignment(self): + def text_align(self): justification_mode = ( None if Build.VERSION.SDK_INT < 26 else self.native.getJustificationMode() ) - return toga_text_alignment(self.native.getGravity(), justification_mode) + return to_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 b56eb8f36a..fa74eda5d0 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 toga_text_alignment(gravity, justification_mode=None): +def to_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/android/tests_backend/widgets/selection.py b/android/tests_backend/widgets/selection.py index 6c46f71094..9349ccb2cb 100644 --- a/android/tests_backend/widgets/selection.py +++ b/android/tests_backend/widgets/selection.py @@ -12,7 +12,7 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes on this backend") @property - def text_alignment(self): + def text_align(self): xfail("Can't change the text alignment of Selection on this backend") @property diff --git a/cocoa/src/toga_cocoa/widgets/base.py b/cocoa/src/toga_cocoa/widgets/base.py index d4e65eb05d..22bc50ba75 100644 --- a/cocoa/src/toga_cocoa/widgets/base.py +++ b/cocoa/src/toga_cocoa/widgets/base.py @@ -59,7 +59,7 @@ def set_bounds(self, x, y, width, height): # print(f"SET BOUNDS ON {self.interface} {width}x{height} @ ({x},{y})") self.constraints.update(x, y, width, height) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): pass def set_hidden(self, hidden): diff --git a/cocoa/src/toga_cocoa/widgets/label.py b/cocoa/src/toga_cocoa/widgets/label.py index 5b0bd2ce83..2c1dfd9c65 100644 --- a/cocoa/src/toga_cocoa/widgets/label.py +++ b/cocoa/src/toga_cocoa/widgets/label.py @@ -17,7 +17,7 @@ def create(self): # Add the layout constraints self.add_constraints() - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.alignment = NSTextAlignment(value) def set_color(self, value): diff --git a/cocoa/src/toga_cocoa/widgets/multilinetextinput.py b/cocoa/src/toga_cocoa/widgets/multilinetextinput.py index d6036f2349..4935060bd2 100644 --- a/cocoa/src/toga_cocoa/widgets/multilinetextinput.py +++ b/cocoa/src/toga_cocoa/widgets/multilinetextinput.py @@ -95,7 +95,7 @@ def set_background_color(self, color): self.native_text.drawsBackground = True self.native_text.backgroundColor = native_color(color) - def set_text_alignment(self, value): + def set_text_align(self, value): self.native_text.alignment = NSTextAlignment(value) def set_font(self, font): diff --git a/cocoa/src/toga_cocoa/widgets/numberinput.py b/cocoa/src/toga_cocoa/widgets/numberinput.py index 096e5a6829..64b956e884 100644 --- a/cocoa/src/toga_cocoa/widgets/numberinput.py +++ b/cocoa/src/toga_cocoa/widgets/numberinput.py @@ -214,7 +214,7 @@ def set_max_value(self, value): else: self.native_stepper.maxValue = float(value) - def set_text_alignment(self, value): + def set_text_align(self, value): self.native_input.alignment = NSTextAlignment(value) def set_font(self, font): diff --git a/cocoa/src/toga_cocoa/widgets/textinput.py b/cocoa/src/toga_cocoa/widgets/textinput.py index 68eba3535b..e3e5995b06 100644 --- a/cocoa/src/toga_cocoa/widgets/textinput.py +++ b/cocoa/src/toga_cocoa/widgets/textinput.py @@ -184,7 +184,7 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.cell.placeholderString = value - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.alignment = NSTextAlignment(value) # The alert label should be on the trailing edge if value == RIGHT: diff --git a/cocoa/tests_backend/widgets/base.py b/cocoa/tests_backend/widgets/base.py index 42689102a8..f02a05e19e 100644 --- a/cocoa/tests_backend/widgets/base.py +++ b/cocoa/tests_backend/widgets/base.py @@ -33,8 +33,8 @@ def assert_not_contained(self): assert self.native.superview is None assert self.native.window is None - def assert_text_alignment(self, expected): - assert self.text_alignment == expected + def assert_text_align(self, expected): + assert self.text_align == expected async def redraw(self, message=None, delay=0): """Request a redraw of the app, waiting until that redraw has completed.""" diff --git a/cocoa/tests_backend/widgets/label.py b/cocoa/tests_backend/widgets/label.py index 47316a900b..be6c448879 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class LabelProbe(SimpleProbe): @@ -16,9 +16,9 @@ def color(self): return toga_color(self.native.textColor) @property - def text_alignment(self): - return toga_text_alignment(self.native.alignment) + def text_align(self): + return to_toga_text_align(self.native.alignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/cocoa/tests_backend/widgets/multilinetextinput.py b/cocoa/tests_backend/widgets/multilinetextinput.py index 232d5b6da2..ec2e8de5af 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class MultilineTextInputProbe(SimpleProbe): @@ -58,10 +58,10 @@ def font(self): return self.native_text.font @property - def text_alignment(self): - return toga_text_alignment(self.native_text.alignment) + def text_align(self): + return to_toga_text_align(self.native_text.alignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextView pass diff --git a/cocoa/tests_backend/widgets/numberinput.py b/cocoa/tests_backend/widgets/numberinput.py index df6310c64a..e06b09bee3 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class NumberInputProbe(SimpleProbe): @@ -86,10 +86,10 @@ def font(self): return self.native_input.font @property - def text_alignment(self): - return toga_text_alignment(self.native_input.alignment) + def text_align(self): + return to_toga_text_align(self.native_input.alignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/cocoa/tests_backend/widgets/properties.py b/cocoa/tests_backend/widgets/properties.py index e000228f80..f9155556c7 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 toga_text_alignment(alignment): +def to_toga_text_align(alignment): return { NSLeftTextAlignment: LEFT, NSRightTextAlignment: RIGHT, diff --git a/cocoa/tests_backend/widgets/selection.py b/cocoa/tests_backend/widgets/selection.py index 58faafaa33..0523d57592 100644 --- a/cocoa/tests_backend/widgets/selection.py +++ b/cocoa/tests_backend/widgets/selection.py @@ -13,7 +13,7 @@ def assert_resizes_on_content_change(self): pass @property - def text_alignment(self): + def text_align(self): xfail("Can't change the text alignment of Selection on macOS") @property diff --git a/cocoa/tests_backend/widgets/textinput.py b/cocoa/tests_backend/widgets/textinput.py index fddcdda850..dd676d5e0c 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class TextInputProbe(SimpleProbe): @@ -60,15 +60,15 @@ def font(self): return self.native.font @property - def text_alignment(self): - result = toga_text_alignment(self.native.alignment) + def text_align(self): + result = to_toga_text_align(self.native.alignment) if result == RIGHT: assert self.impl.error_label.alignment == NSLeftTextAlignment else: assert self.impl.error_label.alignment == NSRightTextAlignment return result - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on NSTextField pass diff --git a/core/src/toga/style/applicator.py b/core/src/toga/style/applicator.py index 0a5d617e89..da4a81c537 100644 --- a/core/src/toga/style/applicator.py +++ b/core/src/toga/style/applicator.py @@ -45,8 +45,8 @@ def set_bounds(self) -> None: for child in self.widget.children: child.applicator.set_bounds() - def set_text_alignment(self, alignment: str) -> None: - self.widget._impl.set_text_alignment(alignment) + def set_text_align(self, alignment: str) -> None: + self.widget._impl.set_text_align(alignment) def set_hidden(self, hidden: bool) -> None: self.widget._impl.set_hidden(hidden) diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index 49f68a6464..3c1f0facf1 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -232,10 +232,10 @@ def apply(self, prop: str, value: object) -> None: value = RIGHT else: value = LEFT - self._applicator.set_text_alignment(value) + self._applicator.set_text_align(value) elif prop == "text_direction": if self.text_align is None: - self._applicator.set_text_alignment(RIGHT if value == RTL else LEFT) + self._applicator.set_text_align(RIGHT if value == RTL else LEFT) elif prop == "color": self._applicator.set_color(value) elif prop == "background_color": diff --git a/core/tests/style/pack/test_apply.py b/core/tests/style/pack/test_apply.py index 04a7b0826e..52d34ba96a 100644 --- a/core/tests/style/pack/test_apply.py +++ b/core/tests/style/pack/test_apply.py @@ -20,7 +20,7 @@ def test_set_default_right_textalign_when_rtl(): root.style.reapply() # Two calls; one caused by text_align, one because text_direction # implies a change to text alignment. - assert root._impl.set_text_alignment.mock_calls == [call(RIGHT), call(RIGHT)] + assert root._impl.set_text_align.mock_calls == [call(RIGHT), call(RIGHT)] def test_set_default_left_textalign_when_no_rtl(): @@ -28,13 +28,13 @@ def test_set_default_left_textalign_when_no_rtl(): root.style.reapply() # Two calls; one caused by text_align, one because text_direction # implies a change to text alignment. - assert root._impl.set_text_alignment.mock_calls == [call(LEFT), call(LEFT)] + assert root._impl.set_text_align.mock_calls == [call(LEFT), call(LEFT)] -def test_set_center_text_alignment(): +def test_set_center_text_align(): root = ExampleNode("app", style=Pack(text_align="center")) root.style.reapply() - root._impl.set_text_alignment.assert_called_once_with(CENTER) + root._impl.set_text_align.assert_called_once_with(CENTER) def test_set_color(): diff --git a/core/tests/style/test_applicator.py b/core/tests/style/test_applicator.py index 4091549118..cf7afad1db 100644 --- a/core/tests/style/test_applicator.py +++ b/core/tests/style/test_applicator.py @@ -67,9 +67,9 @@ def test_set_bounds(widget, child, grandchild): assert_action_performed_with(grandchild, "set bounds", x=1, y=2, width=3, height=4) -def test_text_alignment(widget): +def test_text_align(widget): """Text alignment can be set on a widget.""" - widget.applicator.set_text_alignment(RIGHT) + widget.applicator.set_text_align(RIGHT) assert_action_performed_with(widget, "set text alignment", alignment=RIGHT) diff --git a/dummy/src/toga_dummy/widgets/base.py b/dummy/src/toga_dummy/widgets/base.py index a3e76afd5d..47b0676172 100644 --- a/dummy/src/toga_dummy/widgets/base.py +++ b/dummy/src/toga_dummy/widgets/base.py @@ -44,7 +44,7 @@ def set_tab_index(self, tab_index): def set_bounds(self, x, y, width, height): self._action("set bounds", x=x, y=y, width=width, height=height) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): self._action("set text alignment", alignment=alignment) def set_hidden(self, hidden): diff --git a/gtk/src/toga_gtk/libs/utils.py b/gtk/src/toga_gtk/libs/utils.py index 2533d01347..c3f266a033 100644 --- a/gtk/src/toga_gtk/libs/utils.py +++ b/gtk/src/toga_gtk/libs/utils.py @@ -3,7 +3,7 @@ from . import Gtk -def gtk_text_alignment(alignment): +def gtk_text_align(alignment): """Convert Toga text alignments into arguments compatible with Gtk.""" return { LEFT: (0.0, Gtk.Justification.LEFT), diff --git a/gtk/src/toga_gtk/widgets/base.py b/gtk/src/toga_gtk/widgets/base.py index bbf2cb30f6..cb82809a87 100644 --- a/gtk/src/toga_gtk/widgets/base.py +++ b/gtk/src/toga_gtk/widgets/base.py @@ -141,7 +141,7 @@ def set_bounds(self, x, y, width, height): # Any position changes are applied by the container during do_size_allocate. self.container.make_dirty() - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): # By default, alignment can't be changed pass diff --git a/gtk/src/toga_gtk/widgets/label.py b/gtk/src/toga_gtk/widgets/label.py index 30874d2c3e..be2a9a88ea 100644 --- a/gtk/src/toga_gtk/widgets/label.py +++ b/gtk/src/toga_gtk/widgets/label.py @@ -1,6 +1,6 @@ from travertino.size import at_least -from ..libs import Gtk, gtk_text_alignment +from ..libs import Gtk, gtk_text_align from .base import Widget @@ -9,8 +9,8 @@ def create(self): self.native = Gtk.Label() self.native.set_line_wrap(False) - def set_text_alignment(self, value): - xalign, justify = gtk_text_alignment(value) + def set_text_align(self, value): + xalign, justify = gtk_text_align(value) self.native.set_xalign(xalign) # Aligns the whole text block within the widget. self.native.set_yalign(0.0) # Aligns the text block to the top self.native.set_justify( diff --git a/gtk/src/toga_gtk/widgets/multilinetextinput.py b/gtk/src/toga_gtk/widgets/multilinetextinput.py index d0c77692ea..b833baf051 100644 --- a/gtk/src/toga_gtk/widgets/multilinetextinput.py +++ b/gtk/src/toga_gtk/widgets/multilinetextinput.py @@ -5,7 +5,7 @@ get_background_color_css, get_color_css, get_font_css, - gtk_text_alignment, + gtk_text_align, ) from .base import Widget @@ -113,8 +113,8 @@ def set_placeholder(self, value): self.placeholder.get_end_iter(), ) # make the placeholder text gray. - def set_text_alignment(self, value): - _, justification = gtk_text_alignment(value) + def set_text_align(self, value): + _, justification = gtk_text_align(value) self.native_textview.set_justification(justification) def focus(self): diff --git a/gtk/src/toga_gtk/widgets/numberinput.py b/gtk/src/toga_gtk/widgets/numberinput.py index 14f891cfdb..59fc4a3217 100644 --- a/gtk/src/toga_gtk/widgets/numberinput.py +++ b/gtk/src/toga_gtk/widgets/numberinput.py @@ -5,7 +5,7 @@ from toga.widgets.numberinput import _clean_decimal -from ..libs import Gtk, gtk_text_alignment +from ..libs import Gtk, gtk_text_align from .base import Widget @@ -59,8 +59,8 @@ def set_value(self, value): else: self.native.set_value(value) - def set_text_alignment(self, value): - xalign, justify = gtk_text_alignment(value) + def set_text_align(self, value): + xalign, justify = gtk_text_align(value) self.native.set_alignment(xalign) def rehint(self): diff --git a/gtk/src/toga_gtk/widgets/textinput.py b/gtk/src/toga_gtk/widgets/textinput.py index b7bc75c6ac..141ec5de54 100644 --- a/gtk/src/toga_gtk/widgets/textinput.py +++ b/gtk/src/toga_gtk/widgets/textinput.py @@ -3,7 +3,7 @@ from toga.keys import Key from toga_gtk.keys import toga_key -from ..libs import Gtk, gtk_text_alignment +from ..libs import Gtk, gtk_text_align from .base import Widget @@ -41,8 +41,8 @@ def get_placeholder(self): def set_placeholder(self, value): self.native.set_placeholder_text(value) - def set_text_alignment(self, value): - xalign, justify = gtk_text_alignment(value) + def set_text_align(self, value): + xalign, justify = gtk_text_align(value) self.native.set_alignment( xalign ) # Aligns the whole text block within the widget. diff --git a/gtk/tests_backend/widgets/base.py b/gtk/tests_backend/widgets/base.py index cbea442708..2070762bae 100644 --- a/gtk/tests_backend/widgets/base.py +++ b/gtk/tests_backend/widgets/base.py @@ -38,8 +38,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.get_parent() is None - def assert_text_alignment(self, expected): - assert self.text_alignment == expected + def assert_text_align(self, expected): + assert self.text_align == expected def repaint_needed(self): return self.impl.container.needs_redraw or super().repaint_needed() diff --git a/gtk/tests_backend/widgets/label.py b/gtk/tests_backend/widgets/label.py index cc335ac41c..1f6069bc9c 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 toga_x_text_alignment, toga_y_text_alignment +from .properties import to_toga_x_text_align, to_toga_y_text_align class LabelProbe(SimpleProbe): @@ -12,14 +12,12 @@ def text(self): return self.native.get_label() @property - def text_alignment(self): - return toga_x_text_alignment( - self.native.get_xalign(), self.native.get_justify() - ) + def text_align(self): + return to_toga_x_text_align(self.native.get_xalign(), self.native.get_justify()) @property - def vertical_text_alignment(self): + def vertical_text_align(self): return - def assert_vertical_text_alignment(self, expected): - assert toga_y_text_alignment(self.native.get_yalign()) == expected + def assert_vertical_text_align(self, expected): + assert to_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 61fe063b8c..9f3a96d6ea 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 toga_color, toga_text_alignment_from_justification +from .properties import to_toga_text_align_from_justification, toga_color class MultilineTextInputProbe(SimpleProbe): @@ -88,12 +88,12 @@ def font(self): return sc.get_property("font", sc.get_state()) @property - def text_alignment(self): - return toga_text_alignment_from_justification( + def text_align(self): + return to_toga_text_align_from_justification( self.native_textview.get_justification(), ) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # GTK.TextView vertical alignment is non-configurable pass diff --git a/gtk/tests_backend/widgets/numberinput.py b/gtk/tests_backend/widgets/numberinput.py index cbe9050e9e..bb2516b8cd 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 toga_x_text_alignment +from .properties import to_toga_x_text_align class NumberInputProbe(SimpleProbe): @@ -31,16 +31,16 @@ async def decrement(self): ) @property - def text_alignment(self): - return toga_x_text_alignment(self.native.get_alignment()) + def text_align(self): + return to_toga_x_text_align(self.native.get_alignment()) - def assert_text_alignment(self, expected): + def assert_text_align(self, expected): if expected == JUSTIFY: - assert self.text_alignment == LEFT + assert self.text_align == LEFT else: - assert self.text_alignment == expected + assert self.text_align == expected - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # GTK.SpinButton vertical alignment is non-configurable pass diff --git a/gtk/tests_backend/widgets/properties.py b/gtk/tests_backend/widgets/properties.py index 78bf687182..d0b9debf6d 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 toga_x_text_alignment(xalign, justify=None): +def to_toga_x_text_align(xalign, justify=None): try: return { 0.0: JUSTIFY if justify == Gtk.Justification.FILL else LEFT, @@ -36,7 +36,7 @@ def toga_x_text_alignment(xalign, justify=None): ) -def toga_y_text_alignment(yalign): +def to_toga_y_text_align(yalign): try: return { 0.0: TOP, @@ -47,7 +47,7 @@ def toga_y_text_alignment(yalign): pytest.fail(f"Can't interpret GTK y text alignment {yalign}") -def toga_text_alignment_from_justification(justify): +def to_toga_text_align_from_justification(justify): return { Gtk.Justification.LEFT: LEFT, Gtk.Justification.RIGHT: RIGHT, diff --git a/gtk/tests_backend/widgets/selection.py b/gtk/tests_backend/widgets/selection.py index ba14f14eaa..3c19cc188f 100644 --- a/gtk/tests_backend/widgets/selection.py +++ b/gtk/tests_backend/widgets/selection.py @@ -16,7 +16,7 @@ def shrink_on_resize(self): return False @property - def text_alignment(self): + def text_align(self): xfail("Can't change the text alignment of Selection on GTK") @property diff --git a/gtk/tests_backend/widgets/textinput.py b/gtk/tests_backend/widgets/textinput.py index 27f02c78ac..3160981cc0 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 toga_x_text_alignment +from .properties import to_toga_x_text_align class TextInputProbe(SimpleProbe): @@ -33,16 +33,16 @@ def placeholder_hides_on_focus(self): return False @property - def text_alignment(self): - return toga_x_text_alignment(self.native.get_alignment()) + def text_align(self): + return to_toga_x_text_align(self.native.get_alignment()) - def assert_text_alignment(self, expected): + def assert_text_align(self, expected): if expected == JUSTIFY: - assert self.text_alignment == LEFT + assert self.text_align == LEFT else: - assert self.text_alignment == expected + assert self.text_align == expected - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # GTK.Entry vertical alignment is non-configurable pass diff --git a/iOS/src/toga_iOS/widgets/base.py b/iOS/src/toga_iOS/widgets/base.py index 2cc021f44d..5aa4861f12 100644 --- a/iOS/src/toga_iOS/widgets/base.py +++ b/iOS/src/toga_iOS/widgets/base.py @@ -73,7 +73,7 @@ def set_bounds(self, x, y, width, height): # print("SET BOUNDS", self, x, y, width, height, self.container.top_offset) self.constraints.update(x, y + self.container.top_offset, width, height) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): pass def set_hidden(self, hidden): diff --git a/iOS/src/toga_iOS/widgets/label.py b/iOS/src/toga_iOS/widgets/label.py index 38789810d2..e0a2e61d1e 100644 --- a/iOS/src/toga_iOS/widgets/label.py +++ b/iOS/src/toga_iOS/widgets/label.py @@ -41,7 +41,7 @@ def create(self): # Add the layout constraints self.add_constraints() - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.textAlignment = NSTextAlignment(value) def set_color(self, value): diff --git a/iOS/src/toga_iOS/widgets/multilinetextinput.py b/iOS/src/toga_iOS/widgets/multilinetextinput.py index 08081141fa..88395c1388 100644 --- a/iOS/src/toga_iOS/widgets/multilinetextinput.py +++ b/iOS/src/toga_iOS/widgets/multilinetextinput.py @@ -144,7 +144,7 @@ def set_color(self, value): def set_background_color(self, color): self.set_background_color_simple(color) - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.textAlignment = NSTextAlignment(value) def set_font(self, font): diff --git a/iOS/src/toga_iOS/widgets/numberinput.py b/iOS/src/toga_iOS/widgets/numberinput.py index bb967b9929..d0e6916f91 100644 --- a/iOS/src/toga_iOS/widgets/numberinput.py +++ b/iOS/src/toga_iOS/widgets/numberinput.py @@ -108,7 +108,7 @@ def set_value(self, value): self.native.text = str(value) self.interface.on_change() - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.textAlignment = NSTextAlignment(value) def set_font(self, font): diff --git a/iOS/src/toga_iOS/widgets/selection.py b/iOS/src/toga_iOS/widgets/selection.py index 96a4f841e0..02651d50c4 100644 --- a/iOS/src/toga_iOS/widgets/selection.py +++ b/iOS/src/toga_iOS/widgets/selection.py @@ -77,7 +77,7 @@ def create(self): self.add_constraints() - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.textAlignment = NSTextAlignment(value) def set_color(self, color): diff --git a/iOS/src/toga_iOS/widgets/textinput.py b/iOS/src/toga_iOS/widgets/textinput.py index 58b4c5554d..9711a76d37 100644 --- a/iOS/src/toga_iOS/widgets/textinput.py +++ b/iOS/src/toga_iOS/widgets/textinput.py @@ -128,7 +128,7 @@ def set_value(self, value): self.native.text = value self.interface._value_changed() - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.textAlignment = NSTextAlignment(value) if value == RIGHT: self.error_label.textAlignment = NSTextAlignment(LEFT) diff --git a/iOS/tests_backend/widgets/base.py b/iOS/tests_backend/widgets/base.py index 7aac1222c3..f4f4259501 100644 --- a/iOS/tests_backend/widgets/base.py +++ b/iOS/tests_backend/widgets/base.py @@ -63,8 +63,8 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.superview() is None - def assert_text_alignment(self, expected): - assert self.text_alignment == expected + def assert_text_align(self, expected): + assert self.text_align == expected async def redraw(self, message=None, delay=0): """Request a redraw of the app, waiting until that redraw has completed.""" diff --git a/iOS/tests_backend/widgets/label.py b/iOS/tests_backend/widgets/label.py index 93873b05af..90293647c3 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class LabelProbe(SimpleProbe): @@ -19,10 +19,10 @@ def color(self): return toga_color(self.native.textColor) @property - def text_alignment(self): - return toga_text_alignment(self.native.textAlignment) + def text_align(self): + return to_toga_text_align(self.native.textAlignment) - def assert_vertical_text_alignment(self, alignment): + def assert_vertical_text_align(self, alignment): # iOS has a custom draw method that always draw the text at the top; # this location isn't configurable pass diff --git a/iOS/tests_backend/widgets/numberinput.py b/iOS/tests_backend/widgets/numberinput.py index 094f7a98db..0c2df37538 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class NumberInputProbe(SimpleProbe): @@ -29,10 +29,10 @@ def color(self): return toga_color(self.native.textColor) @property - def text_alignment(self): - return toga_text_alignment(self.native.textAlignment) + def text_align(self): + return to_toga_text_align(self.native.textAlignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical alignment isn't configurable on a UITextField pass diff --git a/iOS/tests_backend/widgets/properties.py b/iOS/tests_backend/widgets/properties.py index 0a9a1aadc1..9777984afd 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 toga_text_alignment(alignment): +def to_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 fd5c6ced2b..1976dcecef 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class SelectionProbe(SimpleProbe): @@ -20,10 +20,10 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes") @property - def text_alignment(self): - return toga_text_alignment(self.native.textAlignment) + def text_align(self): + return to_toga_text_align(self.native.textAlignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable on UITextField pass diff --git a/iOS/tests_backend/widgets/textinput.py b/iOS/tests_backend/widgets/textinput.py index 5d0cac6842..cdce9c1fad 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 toga_color, toga_text_alignment +from .properties import to_toga_text_align, toga_color class TextInputProbe(SimpleProbe): @@ -43,10 +43,10 @@ def color(self): return toga_color(self.native.textColor) @property - def text_alignment(self): - return toga_text_alignment(self.native.textAlignment) + def text_align(self): + return to_toga_text_align(self.native.textAlignment) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable on UITextField pass diff --git a/testbed/tests/widgets/conftest.py b/testbed/tests/widgets/conftest.py index 873fc07b30..36464af728 100644 --- a/testbed/tests/widgets/conftest.py +++ b/testbed/tests/widgets/conftest.py @@ -78,7 +78,7 @@ def verify_focus_handlers(): @fixture -def verify_vertical_text_alignment(): +def verify_vertical_text_align(): """The widget's default vertical text alignment""" return TOP diff --git a/testbed/tests/widgets/properties.py b/testbed/tests/widgets/properties.py index fb17380309..6a882be6e8 100644 --- a/testbed/tests/widgets/properties.py +++ b/testbed/tests/widgets/properties.py @@ -414,41 +414,41 @@ async def test_background_color_transparent(widget, probe): assert_color(probe.background_color, TRANSPARENT if supports_alpha else original) -async def test_text_alignment(widget, probe, verify_vertical_text_alignment): +async def test_text_align(widget, probe, verify_vertical_text_align): """Widget honors alignment settings.""" # Use column direction to ensure widget uses all available width widget.parent.style.direction = COLUMN # Initial text alignment is LEFT, initial direction is LTR await probe.redraw("Text direction should be LTR") - probe.assert_text_alignment(LEFT) + probe.assert_text_align(LEFT) - for text_alignment in [RIGHT, CENTER, JUSTIFY]: - widget.style.text_align = text_alignment - await probe.redraw("Text alignment should be %s" % text_alignment) - probe.assert_text_alignment(text_alignment) - probe.assert_vertical_text_alignment(verify_vertical_text_alignment) + for text_align in [RIGHT, CENTER, JUSTIFY]: + widget.style.text_align = text_align + await probe.redraw("Text alignment should be %s" % text_align) + probe.assert_text_align(text_align) + probe.assert_vertical_text_align(verify_vertical_text_align) # Clearing the text alignment reverts to default text alignment of LEFT del widget.style.text_align await probe.redraw("Text alignment should be reverted to LEFT") - probe.assert_text_alignment(LEFT) + probe.assert_text_align(LEFT) # If text direction is RTL, default text alignment is RIGHT widget.style.text_direction = RTL await probe.redraw("Text direction is RTL, so text alignment should be RIGHT") - probe.assert_text_alignment(RIGHT) + probe.assert_text_align(RIGHT) # If text direction is expliclty LTR, default text alignment is LEFT widget.style.text_direction = LTR await probe.redraw("Text direction is LTR, so text alignment should be LEFT") - probe.assert_text_alignment(LEFT) + probe.assert_text_align(LEFT) # If the widget has an explicit height, the vertical text alignment of the widget # is unchanged. widget.style.height = 200 - await probe.redraw(f"Text should be at the {verify_vertical_text_alignment}") - probe.assert_vertical_text_alignment(verify_vertical_text_alignment) + await probe.redraw(f"Text should be at the {verify_vertical_text_align}") + probe.assert_vertical_text_align(verify_vertical_text_align) async def test_readonly(widget, probe): diff --git a/testbed/tests/widgets/test_label.py b/testbed/tests/widgets/test_label.py index 1eddea1dfc..5eb73c0248 100644 --- a/testbed/tests/widgets/test_label.py +++ b/testbed/tests/widgets/test_label.py @@ -15,7 +15,7 @@ test_font, test_font_attrs, test_text, - test_text_alignment, + test_text_align, test_text_width_change, ) diff --git a/testbed/tests/widgets/test_multilinetextinput.py b/testbed/tests/widgets/test_multilinetextinput.py index 49c23b5677..ed5b220205 100644 --- a/testbed/tests/widgets/test_multilinetextinput.py +++ b/testbed/tests/widgets/test_multilinetextinput.py @@ -19,7 +19,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, - test_text_alignment, + test_text_align, test_text_value, ) from .test_textinput import ( # noqa: F401 diff --git a/testbed/tests/widgets/test_numberinput.py b/testbed/tests/widgets/test_numberinput.py index 96e8b6ab86..29bfe3f386 100644 --- a/testbed/tests/widgets/test_numberinput.py +++ b/testbed/tests/widgets/test_numberinput.py @@ -19,10 +19,10 @@ test_font, test_font_attrs, test_readonly, - test_text_alignment, + test_text_align, ) from .test_textinput import ( # noqa: F401 - verify_vertical_text_alignment, + verify_vertical_text_align, ) diff --git a/testbed/tests/widgets/test_passwordinput.py b/testbed/tests/widgets/test_passwordinput.py index e38da84452..77786172ba 100644 --- a/testbed/tests/widgets/test_passwordinput.py +++ b/testbed/tests/widgets/test_passwordinput.py @@ -18,7 +18,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, - test_text_alignment, + test_text_align, ) from .test_textinput import ( # noqa: F401 placeholder, @@ -30,7 +30,7 @@ test_undo_redo, test_validation, verify_focus_handlers, - verify_vertical_text_alignment, + verify_vertical_text_align, ) diff --git a/testbed/tests/widgets/test_selection.py b/testbed/tests/widgets/test_selection.py index 4631064f7b..a5eb5a671e 100644 --- a/testbed/tests/widgets/test_selection.py +++ b/testbed/tests/widgets/test_selection.py @@ -17,7 +17,7 @@ test_flex_horizontal_widget_size, test_font, test_font_attrs, - test_text_alignment, + test_text_align, ) # FIXME: 2023-05-31 GTK's focus APIs are completely broken for GTK.ComboBox. The @@ -48,7 +48,7 @@ def verify_font_sizes(): @pytest.fixture -def verify_vertical_text_alignment(): +def verify_vertical_text_align(): return CENTER diff --git a/testbed/tests/widgets/test_textinput.py b/testbed/tests/widgets/test_textinput.py index 6855be9874..e9cf43464c 100644 --- a/testbed/tests/widgets/test_textinput.py +++ b/testbed/tests/widgets/test_textinput.py @@ -22,7 +22,7 @@ test_placeholder_color, test_placeholder_focus, test_readonly, - test_text_alignment, + test_text_align, ) @@ -32,7 +32,7 @@ async def widget(): @pytest.fixture -def verify_vertical_text_alignment(): +def verify_vertical_text_align(): return CENTER diff --git a/textual/src/toga_textual/widgets/base.py b/textual/src/toga_textual/widgets/base.py index 605065e926..91713cffce 100644 --- a/textual/src/toga_textual/widgets/base.py +++ b/textual/src/toga_textual/widgets/base.py @@ -143,7 +143,7 @@ def set_bounds(self, x, y, width, height): self.scale_in_horizontal(margin_left), ) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): pass def set_hidden(self, hidden): diff --git a/web/src/toga_web/widgets/base.py b/web/src/toga_web/widgets/base.py index 8ccedc0bab..a3aba6fae2 100644 --- a/web/src/toga_web/widgets/base.py +++ b/web/src/toga_web/widgets/base.py @@ -99,7 +99,7 @@ def _reapply_style(self): def set_bounds(self, x, y, width, height): self._reapply_style() - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): self._reapply_style() def set_hidden(self, hidden): diff --git a/web/src/toga_web/widgets/label.py b/web/src/toga_web/widgets/label.py index 854eb2cf6b..c85382f45d 100644 --- a/web/src/toga_web/widgets/label.py +++ b/web/src/toga_web/widgets/label.py @@ -11,7 +11,7 @@ def get_text(self): def set_text(self, value): self.native.innerHTML = value - def set_text_alignment(self, value): + def set_text_align(self, value): pass def rehint(self): diff --git a/web/src/toga_web/widgets/textinput.py b/web/src/toga_web/widgets/textinput.py index 93220ae29f..fa30b017fc 100644 --- a/web/src/toga_web/widgets/textinput.py +++ b/web/src/toga_web/widgets/textinput.py @@ -27,7 +27,7 @@ def set_value(self, value): def set_font(self, font): pass - def set_text_alignment(self, value): + def set_text_align(self, value): pass def rehint(self): diff --git a/winforms/src/toga_winforms/widgets/base.py b/winforms/src/toga_winforms/widgets/base.py index e9eda6b229..cf772f5e5e 100644 --- a/winforms/src/toga_winforms/widgets/base.py +++ b/winforms/src/toga_winforms/widgets/base.py @@ -120,7 +120,7 @@ def set_bounds(self, x, y, width, height): self.native.Size = Size(*map(self.scale_in, (width, height))) self.native.Location = Point(*map(self.scale_in, (x, y))) - def set_text_alignment(self, alignment): + def set_text_align(self, alignment): # By default, text alignment can't be changed pass diff --git a/winforms/src/toga_winforms/widgets/label.py b/winforms/src/toga_winforms/widgets/label.py index 85b598b114..bab8c7e001 100644 --- a/winforms/src/toga_winforms/widgets/label.py +++ b/winforms/src/toga_winforms/widgets/label.py @@ -13,7 +13,7 @@ def create(self): self.native = WinForms.Label() self.native.AutoSizeMode = WinForms.AutoSizeMode.GrowAndShrink - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.TextAlign = TextAlignment(value) def get_text(self): diff --git a/winforms/src/toga_winforms/widgets/multilinetextinput.py b/winforms/src/toga_winforms/widgets/multilinetextinput.py index 719c59469a..db12269b6c 100644 --- a/winforms/src/toga_winforms/widgets/multilinetextinput.py +++ b/winforms/src/toga_winforms/widgets/multilinetextinput.py @@ -89,7 +89,7 @@ def set_color(self, color): if not self._placeholder_visible: self.native.ForeColor = self._color - def set_text_alignment(self, value): + def set_text_align(self, value): original_selection = (self.native.SelectionStart, self.native.SelectionLength) self.native.SelectAll() self.native.SelectionAlignment = HorizontalTextAlignment(value) diff --git a/winforms/src/toga_winforms/widgets/numberinput.py b/winforms/src/toga_winforms/widgets/numberinput.py index 8f6aaf142a..6ba3a67890 100644 --- a/winforms/src/toga_winforms/widgets/numberinput.py +++ b/winforms/src/toga_winforms/widgets/numberinput.py @@ -63,7 +63,7 @@ def set_value(self, value): else: self.native.Value = native_decimal(value) - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.TextAlign = HorizontalTextAlignment(value) def rehint(self): diff --git a/winforms/src/toga_winforms/widgets/textinput.py b/winforms/src/toga_winforms/widgets/textinput.py index d958d17516..48a69dbf6d 100644 --- a/winforms/src/toga_winforms/widgets/textinput.py +++ b/winforms/src/toga_winforms/widgets/textinput.py @@ -61,7 +61,7 @@ def get_value(self): def set_value(self, value): self.native.Text = value - def set_text_alignment(self, value): + def set_text_align(self, value): self.native.TextAlign = HorizontalTextAlignment(value) def set_color(self, color): diff --git a/winforms/tests_backend/widgets/base.py b/winforms/tests_backend/widgets/base.py index ec30adbc57..7ed8ad95a7 100644 --- a/winforms/tests_backend/widgets/base.py +++ b/winforms/tests_backend/widgets/base.py @@ -31,9 +31,9 @@ def assert_not_contained(self): assert self.widget._impl.container is None assert self.native.Parent is None - def assert_text_alignment(self, expected): + def assert_text_align(self, expected): # Winforms doesn't have a "Justified" text alignment; it falls back to LEFT - actual = self.text_alignment + actual = self.text_align if expected == JUSTIFY: assert actual == LEFT else: diff --git a/winforms/tests_backend/widgets/label.py b/winforms/tests_backend/widgets/label.py index 768f39297c..c5de57ad06 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 toga_x_text_alignment, toga_y_text_alignment +from .properties import to_toga_x_text_align, to_toga_y_text_align class LabelProbe(SimpleProbe): @@ -12,8 +12,8 @@ def text(self): return self.native.Text @property - def text_alignment(self): - return toga_x_text_alignment(self.native.TextAlign) + def text_align(self): + return to_toga_x_text_align(self.native.TextAlign) - def assert_vertical_text_alignment(self, expected): - assert toga_y_text_alignment(self.native.TextAlign) == expected + def assert_vertical_text_align(self, expected): + assert to_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 d21a09de6d..172ff786d6 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 toga_x_text_alignment +from .properties import to_toga_x_text_align from .textinput import TextInputProbe @@ -56,6 +56,6 @@ async def wait_for_scroll_completion(self): # SelectionAlignment.Left when the text selection contains multiple paragraphs with # mixed alignment." @property - def text_alignment(self): + def text_align(self): self.native.SelectAll() - return toga_x_text_alignment(self.native.SelectionAlignment) + return to_toga_x_text_align(self.native.SelectionAlignment) diff --git a/winforms/tests_backend/widgets/numberinput.py b/winforms/tests_backend/widgets/numberinput.py index 45944fcf4b..8b3d60f257 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 toga_x_text_alignment +from .properties import to_toga_x_text_align class NumberInputProbe(SimpleProbe): @@ -33,10 +33,10 @@ async def decrement(self): await self.type_character("") @property - def text_alignment(self): - return toga_x_text_alignment(self.native.TextAlign) + def text_align(self): + return to_toga_x_text_align(self.native.TextAlign) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable in this native widget. pass diff --git a/winforms/tests_backend/widgets/properties.py b/winforms/tests_backend/widgets/properties.py index 5d459dab5c..8db6917534 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 toga_x_text_alignment(alignment): +def to_toga_x_text_align(alignment): return { ContentAlignment.TopLeft: LEFT, ContentAlignment.MiddleLeft: LEFT, @@ -27,7 +27,7 @@ def toga_x_text_alignment(alignment): }[alignment] -def toga_y_text_alignment(alignment): +def to_toga_y_text_align(alignment): return { ContentAlignment.TopLeft: TOP, ContentAlignment.TopCenter: TOP, diff --git a/winforms/tests_backend/widgets/selection.py b/winforms/tests_backend/widgets/selection.py index 823e580f19..9ae1f9fbb2 100644 --- a/winforms/tests_backend/widgets/selection.py +++ b/winforms/tests_backend/widgets/selection.py @@ -13,7 +13,7 @@ def assert_resizes_on_content_change(self): xfail("Selection doesn't resize on content changes on this backend") @property - def text_alignment(self): + def text_align(self): xfail("Can't change the text alignment of Selection on this backend") @property diff --git a/winforms/tests_backend/widgets/textinput.py b/winforms/tests_backend/widgets/textinput.py index ac165df5b1..af42ba4fa4 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 toga_x_text_alignment +from .properties import to_toga_x_text_align class TextInputProbe(SimpleProbe): @@ -48,10 +48,10 @@ def readonly(self): return self.native.ReadOnly @property - def text_alignment(self): - return toga_x_text_alignment(self.native.TextAlign) + def text_align(self): + return to_toga_x_text_align(self.native.TextAlign) - def assert_vertical_text_alignment(self, expected): + def assert_vertical_text_align(self, expected): # Vertical text alignment isn't configurable in this native widget. pass From 097db4350f91d94e99da3847b5cc446bd1dc813c Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Wed, 11 Dec 2024 22:28:07 -0500 Subject: [PATCH 11/12] Slightly easier-to-read __getattribute__ --- core/src/toga/style/pack.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/core/src/toga/style/pack.py b/core/src/toga/style/pack.py index 3c1f0facf1..e3c85fdf7a 100644 --- a/core/src/toga/style/pack.py +++ b/core/src/toga/style/pack.py @@ -142,16 +142,22 @@ def _warn_deprecated(old_name, new_name, stacklevel=3): # Dot lookup def __getattribute__(self, name): - get = super().__getattribute__ + if name in { + "direction", + "text_direction", + "_warn_deprecated", + "_update_property_name", + }: + return super().__getattribute__(name) # Align_items and alignment are paired. Both can never be set at the same time; # if one is requested, and the other one is set, compute the requested value # from the one that is set. - if name == ALIGN_ITEMS and (alignment := get(ALIGNMENT)): + if name == ALIGN_ITEMS and (alignment := super().__getattribute__(ALIGNMENT)): if alignment == CENTER: return CENTER - if get("direction") == ROW: + if self.direction == ROW: if alignment == TOP: return START if alignment == BOTTOM: @@ -162,32 +168,32 @@ def __getattribute__(self, name): # direction must be COLUMN if alignment == LEFT: - return START if get("text_direction") == LTR else END + return START if self.text_direction == LTR else END if alignment == RIGHT: - return START if get("text_direction") == RTL else END + return START if self.text_direction == RTL else END # No remaining valid combinations return None if name == ALIGNMENT: # Warn, whether it's set or not. - get("_warn_deprecated")(ALIGNMENT, ALIGN_ITEMS) + self._warn_deprecated(ALIGNMENT, ALIGN_ITEMS) - if align_items := get(ALIGN_ITEMS): + if align_items := super().__getattribute__(ALIGN_ITEMS): if align_items == START: - if get("direction") == COLUMN: - return LEFT if get("text_direction") == LTR else RIGHT + if self.direction == COLUMN: + return LEFT if self.text_direction == LTR else RIGHT return TOP # for ROW if align_items == END: - if get("direction") == COLUMN: - return RIGHT if get("text_direction") == LTR else LEFT + if self.direction == COLUMN: + return RIGHT if self.text_direction == LTR else LEFT return BOTTOM # for ROW # Only CENTER remains return CENTER - return get(get("_update_property_name")(name)) + return super().__getattribute__(self._update_property_name(name)) def __setattr__(self, name, value): # Only one of these can be set at a time. From 7a681cf1bd194034d0276c8015dfb0d8ed9f69b7 Mon Sep 17 00:00:00 2001 From: Charles Whittington Date: Thu, 12 Dec 2024 00:21:13 -0500 Subject: [PATCH 12/12] Updated changenote, and removed alignment doc section I'd missed --- changes/3033.removal.rst | 2 +- docs/reference/style/pack.rst | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/changes/3033.removal.rst b/changes/3033.removal.rst index e0419db3cd..4aa513248f 100644 --- a/changes/3033.removal.rst +++ b/changes/3033.removal.rst @@ -1 +1 @@ -Pack's padding and alignment properties have been renamed to margin and align_items, to match their CSS analogues. The old names are still present, but are deprecated. +Pack's ``padding`` and ``alignment`` properties have been renamed to ``margin`` and ``align_items``, to match their CSS analogues. ``align_items`` also now takes CSS-compatible values of ``START``, ``CENTER``, and ``END``, instead of ``alignment``'s' ``TOP``/``RIGHT``/``BOTTOM``/``LEFT``/``CENTER``. The old names are still present — and ``alignment`` still takes its existing values — but these are deprecated. diff --git a/docs/reference/style/pack.rst b/docs/reference/style/pack.rst index acbb5581b7..4ae7ea576f 100644 --- a/docs/reference/style/pack.rst +++ b/docs/reference/style/pack.rst @@ -317,15 +317,6 @@ The mapping that can be used to establish the reference implementation is: ============================= =================================================== Pack property CSS property ============================= =================================================== - ``align_items: top`` ``align-items: start`` if ``direction == row``; - otherwise ignored. - ``alignment: bottom`` ``align-items: end`` if ``direction == row``; - otherwise ignored. - ``alignment: left`` ``align-items: start`` if ``direction == column``; - otherwise ignored. - ``alignment: right`` ``align-items: end`` if ``direction == column``; - otherwise ignored. - ``alignment: center`` ``align-items: center`` ``direction: `` ``flex-direction: `` ``display: pack`` ``display: flex`` ``flex: `` If ``direction = row`` and ``width`` is set,