Skip to content

Commit

Permalink
to_toga -> toga, marked ALIGNMENT_CHOICES deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfWhitt committed Dec 13, 2024
1 parent 7a681cf commit 9fc4d69
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 47 deletions.
4 changes: 2 additions & 2 deletions android/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from java import jclass

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand Down Expand Up @@ -30,4 +30,4 @@ def text_align(self):
justification_mode = (
None if Build.VERSION.SDK_INT < 26 else self.native.getJustificationMode()
)
return to_toga_text_align(self.native.getGravity(), justification_mode)
return toga_text_align(self.native.getGravity(), justification_mode)
2 changes: 1 addition & 1 deletion android/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def toga_color(color_int):
)


def to_toga_text_align(gravity, justification_mode=None):
def toga_text_align(gravity, justification_mode=None):
horizontal_gravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK
if (Build.VERSION.SDK_INT < 26) or (
justification_mode in (None, Layout.JUSTIFICATION_MODE_NONE)
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from toga_cocoa.libs import NSTextField

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -17,7 +17,7 @@ def color(self):

@property
def text_align(self):
return to_toga_text_align(self.native.alignment)
return toga_text_align(self.native.alignment)

def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from toga_cocoa.libs import NSRange, NSScrollView, NSTextView

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class MultilineTextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -59,7 +59,7 @@ def font(self):

@property
def text_align(self):
return to_toga_text_align(self.native_text.alignment)
return toga_text_align(self.native_text.alignment)

def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextView
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class NumberInputProbe(SimpleProbe):
Expand Down Expand Up @@ -87,7 +87,7 @@ def font(self):

@property
def text_align(self):
return to_toga_text_align(self.native_input.alignment)
return toga_text_align(self.native_input.alignment)

def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
Expand Down
2 changes: 1 addition & 1 deletion cocoa/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def toga_color(color):
return None


def to_toga_text_align(alignment):
def toga_text_align(alignment):
return {
NSLeftTextAlignment: LEFT,
NSRightTextAlignment: RIGHT,
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class TextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -61,7 +61,7 @@ def font(self):

@property
def text_align(self):
result = to_toga_text_align(self.native.alignment)
result = toga_text_align(self.native.alignment)
if result == RIGHT:
assert self.impl.error_label.alignment == NSLeftTextAlignment
else:
Expand Down
7 changes: 4 additions & 3 deletions core/src/toga/style/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
VISIBILITY_CHOICES = Choices(VISIBLE, HIDDEN)
DIRECTION_CHOICES = Choices(ROW, COLUMN)
ALIGN_ITEMS_CHOICES = Choices(START, CENTER, END)
ALIGNMENT_CHOICES = Choices(TOP, RIGHT, BOTTOM, LEFT, CENTER)
# Deprecated, but maintained for backwards compatibility with Toga <= 0.4.8
ALIGNMENT_CHOICES = Choices(LEFT, RIGHT, TOP, BOTTOM, CENTER)

SIZE_CHOICES = Choices(NONE, integer=True)
FLEX_CHOICES = Choices(number=True)
Expand Down Expand Up @@ -1053,9 +1054,9 @@ def __css__(self) -> str:
Pack.validated_property("display", choices=DISPLAY_CHOICES, initial=PACK)
Pack.validated_property("visibility", choices=VISIBILITY_CHOICES, initial=VISIBLE)
Pack.validated_property("direction", choices=DIRECTION_CHOICES, initial=ROW)
Pack.validated_property("alignment", choices=ALIGNMENT_CHOICES)
# Legacy "alias" (ish) of align_items
Pack.validated_property("align_items", choices=ALIGN_ITEMS_CHOICES)
# Deprecated, but maintained for backwards compatibility with Toga <= 0.4.8
Pack.validated_property("alignment", choices=ALIGNMENT_CHOICES)

Pack.validated_property("width", choices=SIZE_CHOICES, initial=NONE)
Pack.validated_property("height", choices=SIZE_CHOICES, initial=NONE)
Expand Down
6 changes: 3 additions & 3 deletions gtk/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from toga_gtk.libs import Gtk

from .base import SimpleProbe
from .properties import to_toga_x_text_align, to_toga_y_text_align
from .properties import toga_x_text_align, toga_y_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -13,11 +13,11 @@ def text(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.get_xalign(), self.native.get_justify())
return toga_x_text_align(self.native.get_xalign(), self.native.get_justify())

@property
def vertical_text_align(self):
return

def assert_vertical_text_align(self, expected):
assert to_toga_y_text_align(self.native.get_yalign()) == expected
assert toga_y_text_align(self.native.get_yalign()) == expected
4 changes: 2 additions & 2 deletions gtk/tests_backend/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from toga_gtk.libs import Gtk

from .base import SimpleProbe
from .properties import to_toga_text_align_from_justification, toga_color
from .properties import toga_color, toga_text_align_from_justification


class MultilineTextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -89,7 +89,7 @@ def font(self):

@property
def text_align(self):
return to_toga_text_align_from_justification(
return toga_text_align_from_justification(
self.native_textview.get_justification(),
)

Expand Down
4 changes: 2 additions & 2 deletions gtk/tests_backend/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from toga_gtk.libs import Gtk

from .base import SimpleProbe
from .properties import to_toga_x_text_align
from .properties import toga_x_text_align


class NumberInputProbe(SimpleProbe):
Expand Down Expand Up @@ -32,7 +32,7 @@ async def decrement(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.get_alignment())
return toga_x_text_align(self.native.get_alignment())

def assert_text_align(self, expected):
if expected == JUSTIFY:
Expand Down
6 changes: 3 additions & 3 deletions gtk/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def toga_color(color):
return None


def to_toga_x_text_align(xalign, justify=None):
def toga_x_text_align(xalign, justify=None):
try:
return {
0.0: JUSTIFY if justify == Gtk.Justification.FILL else LEFT,
Expand All @@ -36,7 +36,7 @@ def to_toga_x_text_align(xalign, justify=None):
)


def to_toga_y_text_align(yalign):
def toga_y_text_align(yalign):
try:
return {
0.0: TOP,
Expand All @@ -47,7 +47,7 @@ def to_toga_y_text_align(yalign):
pytest.fail(f"Can't interpret GTK y text alignment {yalign}")


def to_toga_text_align_from_justification(justify):
def toga_text_align_from_justification(justify):
return {
Gtk.Justification.LEFT: LEFT,
Gtk.Justification.RIGHT: RIGHT,
Expand Down
4 changes: 2 additions & 2 deletions gtk/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from toga_gtk.libs import Gtk

from .base import SimpleProbe
from .properties import to_toga_x_text_align
from .properties import toga_x_text_align


class TextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -34,7 +34,7 @@ def placeholder_hides_on_focus(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.get_alignment())
return toga_x_text_align(self.native.get_alignment())

def assert_text_align(self, expected):
if expected == JUSTIFY:
Expand Down
4 changes: 2 additions & 2 deletions iOS/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from toga_iOS.libs import UILabel

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -20,7 +20,7 @@ def color(self):

@property
def text_align(self):
return to_toga_text_align(self.native.textAlignment)
return toga_text_align(self.native.textAlignment)

def assert_vertical_text_align(self, alignment):
# iOS has a custom draw method that always draw the text at the top;
Expand Down
4 changes: 2 additions & 2 deletions iOS/tests_backend/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from toga_iOS.libs import UITextField

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class NumberInputProbe(SimpleProbe):
Expand All @@ -30,7 +30,7 @@ def color(self):

@property
def text_align(self):
return to_toga_text_align(self.native.textAlignment)
return toga_text_align(self.native.textAlignment)

def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on a UITextField
Expand Down
2 changes: 1 addition & 1 deletion iOS/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def toga_color(color):
return None


def to_toga_text_align(alignment):
def toga_text_align(alignment):
return {
NSLeftTextAlignment: LEFT,
NSRightTextAlignment: RIGHT,
Expand Down
4 changes: 2 additions & 2 deletions iOS/tests_backend/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from toga_iOS.libs import UIPickerView, UITextField

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class SelectionProbe(SimpleProbe):
Expand All @@ -21,7 +21,7 @@ def assert_resizes_on_content_change(self):

@property
def text_align(self):
return to_toga_text_align(self.native.textAlignment)
return toga_text_align(self.native.textAlignment)

def assert_vertical_text_align(self, expected):
# Vertical text alignment isn't configurable on UITextField
Expand Down
4 changes: 2 additions & 2 deletions iOS/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from toga_iOS.libs import UITextField

from .base import SimpleProbe
from .properties import to_toga_text_align, toga_color
from .properties import toga_color, toga_text_align


class TextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -44,7 +44,7 @@ def color(self):

@property
def text_align(self):
return to_toga_text_align(self.native.textAlignment)
return toga_text_align(self.native.textAlignment)

def assert_vertical_text_align(self, expected):
# Vertical text alignment isn't configurable on UITextField
Expand Down
6 changes: 3 additions & 3 deletions winforms/tests_backend/widgets/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import System.Windows.Forms

from .base import SimpleProbe
from .properties import to_toga_x_text_align, to_toga_y_text_align
from .properties import toga_x_text_align, toga_y_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -13,7 +13,7 @@ def text(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.TextAlign)
return toga_x_text_align(self.native.TextAlign)

def assert_vertical_text_align(self, expected):
assert to_toga_y_text_align(self.native.TextAlign) == expected
assert toga_y_text_align(self.native.TextAlign) == expected
4 changes: 2 additions & 2 deletions winforms/tests_backend/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import System.Windows.Forms
from System.Drawing import SystemColors

from .properties import to_toga_x_text_align
from .properties import toga_x_text_align
from .textinput import TextInputProbe


Expand Down Expand Up @@ -58,4 +58,4 @@ async def wait_for_scroll_completion(self):
@property
def text_align(self):
self.native.SelectAll()
return to_toga_x_text_align(self.native.SelectionAlignment)
return toga_x_text_align(self.native.SelectionAlignment)
4 changes: 2 additions & 2 deletions winforms/tests_backend/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from System.Windows.Forms import NumericUpDown

from .base import SimpleProbe
from .properties import to_toga_x_text_align
from .properties import toga_x_text_align


class NumberInputProbe(SimpleProbe):
Expand Down Expand Up @@ -34,7 +34,7 @@ async def decrement(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.TextAlign)
return toga_x_text_align(self.native.TextAlign)

def assert_vertical_text_align(self, expected):
# Vertical text alignment isn't configurable in this native widget.
Expand Down
4 changes: 2 additions & 2 deletions winforms/tests_backend/widgets/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def toga_color(color):
return rgba(color.R, color.G, color.B, color.A / 255)


def to_toga_x_text_align(alignment):
def toga_x_text_align(alignment):
return {
ContentAlignment.TopLeft: LEFT,
ContentAlignment.MiddleLeft: LEFT,
Expand All @@ -27,7 +27,7 @@ def to_toga_x_text_align(alignment):
}[alignment]


def to_toga_y_text_align(alignment):
def toga_y_text_align(alignment):
return {
ContentAlignment.TopLeft: TOP,
ContentAlignment.TopCenter: TOP,
Expand Down
4 changes: 2 additions & 2 deletions winforms/tests_backend/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from System.Windows.Forms import TextBox

from .base import SimpleProbe
from .properties import to_toga_x_text_align
from .properties import toga_x_text_align


class TextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -49,7 +49,7 @@ def readonly(self):

@property
def text_align(self):
return to_toga_x_text_align(self.native.TextAlign)
return toga_x_text_align(self.native.TextAlign)

def assert_vertical_text_align(self, expected):
# Vertical text alignment isn't configurable in this native widget.
Expand Down

0 comments on commit 9fc4d69

Please sign in to comment.