Skip to content

Commit

Permalink
Merge branch 'main' into winforms-location
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause authored Dec 20, 2024
2 parents 8bb9752 + c69f5e4 commit de30f0b
Show file tree
Hide file tree
Showing 167 changed files with 1,832 additions and 744 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ jobs:
- backend: "linux-x11"
platform: "linux"
runs-on: "ubuntu-24.04"
# The package list should be the same as in tutorial-0.rst, and the BeeWare
# The package list should be the same as in unix-prerequisites.rst, and the BeeWare
# tutorial, plus blackbox to provide a window manager. We need a window
# manager that is reasonably lightweight, honors full screen mode, and
# treats the window position as the top-left corner of the *window*, not the
Expand All @@ -275,7 +275,7 @@ jobs:
sudo apt update -y
sudo apt install -y --no-install-recommends \
blackbox pkg-config python3-dev libgirepository1.0-dev libcairo2-dev \
gir1.2-webkit2-4.1 gir1.2-xapp-1.0
gir1.2-webkit2-4.1 gir1.2-xapp-1.0 gir1.2-geoclue-2.0 gir1.2-flatpak-1.0
# Start Virtual X Server
echo "Start X server..."
Expand All @@ -293,13 +293,13 @@ jobs:
- backend: "linux-wayland"
platform: "linux"
runs-on: "ubuntu-24.04"
# The package list should be the same as in tutorial-0.rst, and the BeeWare
# The package list should be the same as in unix-prerequisites.rst, and the BeeWare
# tutorial, plus mutter to provide a window manager.
pre-command: |
sudo apt update -y
sudo apt install -y --no-install-recommends \
mutter pkg-config python3-dev libgirepository1.0-dev libcairo2-dev \
gir1.2-webkit2-4.1 gir1.2-xapp-1.0
gir1.2-webkit2-4.1 gir1.2-xapp-1.0 gir1.2-geoclue-2.0 gir1.2-flatpak-1.0
# Start Virtual X Server
echo "Start X server..."
Expand Down
4 changes: 2 additions & 2 deletions android/src/toga_android/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, alignment):
pass # If appropriate, a widget subclass will implement this.

def set_color(self, color):
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions android/src/toga_android/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -80,5 +80,5 @@ def rehint(self):
at_least(self.native.getMeasuredWidth()), ROUND_UP
)

def set_alignment(self, value):
def set_text_align(self, value):
self.set_textview_alignment(value, Gravity.TOP)
2 changes: 1 addition & 1 deletion android/src/toga_android/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, value):
self.set_textview_alignment(value, Gravity.TOP)

# This method is necessary to override the TextInput base class.
Expand Down
2 changes: 1 addition & 1 deletion android/src/toga_android/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, value):
self.set_textview_alignment(value, Gravity.CENTER_VERTICAL)

def set_error(self, error_message):
Expand Down
9 changes: 9 additions & 0 deletions android/tests_backend/hardware/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


class LocationProbe(HardwareProbe):
supports_background_permission = True

def __init__(self, monkeypatch, app_probe):
super().__init__(monkeypatch, app_probe.app)

Expand Down Expand Up @@ -100,3 +102,10 @@ async def simulate_location_error(self, location):
await self.redraw("Wait for location error")

pytest.xfail("Android's location service doesn't raise errors on failure")

def setup_location_error(self):
# location error simulation handled by ``simulate_location_error``
pass

def setup_tracking_start_error(self):
pytest.xfail("Tracking start cannot fail on Android")
6 changes: 3 additions & 3 deletions android/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ 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_align(self, expected):
actual = self.text_align
if expected == JUSTIFY and (
Build.VERSION.SDK_INT < 26 or not self.supports_justify
):
assert actual == LEFT
else:
assert actual == expected

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
assert toga_vertical_alignment(self.native.getGravity()) == expected

@property
Expand Down
6 changes: 3 additions & 3 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 toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -26,8 +26,8 @@ def text_size(self):
return self.native.getTextSize()

@property
def alignment(self):
def text_align(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_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 toga_alignment(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 android/tests_backend/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self):
xfail("Can't change the text alignment of Selection on this backend")

@property
def color(self):
Expand Down
1 change: 1 addition & 0 deletions changes/1943.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the ``gap`` style, which adds space between adjacent children of a box.
1 change: 1 addition & 0 deletions changes/2990.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Toga GTK now supports location services via integration with GeoClue and the XDG Location Portal.
1 change: 1 addition & 0 deletions changes/3033.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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.
1 change: 1 addition & 0 deletions changes/3039.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated pytest-asyncio from 0.24.0 to 0.25.0 in /core.
1 change: 1 addition & 0 deletions changes/3040.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated pytest-freezer from 0.4.8 to 0.4.9 in /core.
1 change: 1 addition & 0 deletions changes/3041.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated pytest-asyncio from 0.24.0 to 0.25.0 in /testbed.
1 change: 1 addition & 0 deletions changes/3042.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated fonttools from 4.55.2 to 4.55.3 in /testbed.
1 change: 1 addition & 0 deletions changes/3044.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``Pack.margin`` property (and its deprecated alias, ``padding``) can now be accessed via bracket notation, as in ``style["margin"]``. (Previously this worked for the "sub-properties" of ``margin_top`` etc., but not for ``margin``/``padding`` itself.)
1 change: 1 addition & 0 deletions changes/3044.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An issue with PR #3033 that allowed bracket access of invalid style names on a Pack object has been fixed.
1 change: 1 addition & 0 deletions changes/3045.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The hardware example app's now correctly demonstrates usage of the location services method ``current_location``.
1 change: 1 addition & 0 deletions changes/3048.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An issue with PR #3033 that failed when providing ``padding`` to ``Pack()`` and ``Pack.update()`` was fixed.
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/hardware/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, alignment):
pass

def set_hidden(self, hidden):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create(self):
# Add the layout constraints
self.add_constraints()

def set_alignment(self, value):
def set_text_align(self, value):
self.native.alignment = NSTextAlignment(value)

def set_color(self, value):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, value):
self.native_text.alignment = NSTextAlignment(value)

def set_font(self, font):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, value):
self.native_input.alignment = NSTextAlignment(value)

def set_font(self, font):
Expand Down
2 changes: 1 addition & 1 deletion cocoa/src/toga_cocoa/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self, value):
self.native.alignment = NSTextAlignment(value)
# The alert label should be on the trailing edge
if value == RIGHT:
Expand Down
10 changes: 10 additions & 0 deletions cocoa/tests_backend/hardware/location.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import Mock, PropertyMock

import pytest
from rubicon.objc import ObjCClass

from toga_cocoa import libs as cocoa
Expand All @@ -16,6 +17,8 @@


class LocationProbe(AppProbe):
supports_background_permission = True

def __init__(self, monkeypatch, app_probe):
super().__init__(app_probe.app)

Expand Down Expand Up @@ -173,3 +176,10 @@ async def simulate_location_error(self, location):
)

return await location

def setup_location_error(self):
# location error simulation handled by ``simulate_location_error``
pass

def setup_tracking_start_error(self):
pytest.xfail("Tracking start cannot fail on macOS")
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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."""
Expand Down
8 changes: 4 additions & 4 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 toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class LabelProbe(SimpleProbe):
Expand All @@ -16,9 +16,9 @@ def color(self):
return toga_color(self.native.textColor)

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

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
pass
8 changes: 4 additions & 4 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 toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class MultilineTextInputProbe(SimpleProbe):
Expand Down Expand Up @@ -58,10 +58,10 @@ def font(self):
return self.native_text.font

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

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextView
pass

Expand Down
8 changes: 4 additions & 4 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 toga_alignment, toga_color
from .properties import toga_color, toga_text_align


class NumberInputProbe(SimpleProbe):
Expand Down Expand Up @@ -86,10 +86,10 @@ def font(self):
return self.native_input.font

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

def assert_vertical_alignment(self, expected):
def assert_vertical_text_align(self, expected):
# Vertical alignment isn't configurable on NSTextField
pass

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 toga_alignment(alignment):
def toga_text_align(alignment):
return {
NSLeftTextAlignment: LEFT,
NSRightTextAlignment: RIGHT,
Expand Down
4 changes: 2 additions & 2 deletions cocoa/tests_backend/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_align(self):
xfail("Can't change the text alignment of Selection on macOS")

@property
def color(self):
Expand Down
Loading

0 comments on commit de30f0b

Please sign in to comment.