Skip to content

Commit

Permalink
Merge pull request #2682 from freakboy3742/constraint-cleanup
Browse files Browse the repository at this point in the history
Update syntax for ObjC constraint API usage to avoid long lines.
  • Loading branch information
mhsmith authored Jul 2, 2024
2 parents b82f7a4 + d91eeee commit e343028
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 221 deletions.
1 change: 1 addition & 0 deletions changes/2682.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An intermittent failure in macOS CI was corrected, and usage of Rubicon syntax was upgraded.
2 changes: 1 addition & 1 deletion cocoa/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ root = ".."
[tool.setuptools_dynamic_dependencies]
dependencies = [
"fonttools >= 4.42.1, < 5.0.0",
"rubicon-objc >= 0.4.7, < 0.5.0",
"rubicon-objc >= 0.4.9, < 0.5.0",
"toga-core == {version}",
]

Expand Down
56 changes: 28 additions & 28 deletions cocoa/src/toga_cocoa/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,47 +62,47 @@ def container(self, value):
self._container = value
if value is not None:
# print(f"Add constraints for {self.widget} in {self.container} {self.widget.interface.layout})
self.left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.left_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
NSLayoutAttributeLeft,
NSLayoutRelationEqual,
self.container.native,
NSLayoutAttributeLeft,
1.0,
10, # Use a dummy, non-zero value for now
attribute__1=NSLayoutAttributeLeft,
relatedBy=NSLayoutRelationEqual,
toItem=self.container.native,
attribute__2=NSLayoutAttributeLeft,
multiplier=1.0,
constant=10, # Use a dummy, non-zero value for now
).retain()
self.container.native.addConstraint(self.left_constraint)

self.top_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.top_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
NSLayoutAttributeTop,
NSLayoutRelationEqual,
self.container.native,
NSLayoutAttributeTop,
1.0,
5, # Use a dummy, non-zero value for now
attribute__1=NSLayoutAttributeTop,
relatedBy=NSLayoutRelationEqual,
toItem=self.container.native,
attribute__2=NSLayoutAttributeTop,
multiplier=1.0,
constant=5, # Use a dummy, non-zero value for now
).retain()
self.container.native.addConstraint(self.top_constraint)

self.width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.width_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
NSLayoutAttributeRight,
NSLayoutRelationEqual,
self.widget.native,
NSLayoutAttributeLeft,
1.0,
50, # Use a dummy, non-zero value for now
attribute__1=NSLayoutAttributeRight,
relatedBy=NSLayoutRelationEqual,
toItem=self.widget.native,
attribute__2=NSLayoutAttributeLeft,
multiplier=1.0,
constant=50, # Use a dummy, non-zero value for now
).retain()
self.container.native.addConstraint(self.width_constraint)

self.height_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.widget.native,
NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self.height_constraint = NSLayoutConstraint.constraintWithItem(
self.widget.native,
NSLayoutAttributeTop,
1.0,
30, # Use a dummy, non-zero value for now
attribute__1=NSLayoutAttributeBottom,
relatedBy=NSLayoutRelationEqual,
toItem=self.widget.native,
attribute__2=NSLayoutAttributeTop,
multiplier=1.0,
constant=30, # Use a dummy, non-zero value for now
).retain()
self.container.native.addConstraint(self.height_constraint)

Expand Down
28 changes: 14 additions & 14 deletions cocoa/src/toga_cocoa/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ def __init__(
# bigger. If the window is resizable, using >= allows the window to
# be dragged larger; if not resizable, it enforces the smallest
# size that can be programmatically set on the window.
self._min_width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self._min_width_constraint = NSLayoutConstraint.constraintWithItem(
self.native,
NSLayoutAttributeRight,
NSLayoutRelationGreaterThanOrEqual,
self.native,
NSLayoutAttributeLeft,
1.0,
min_width,
attribute__1=NSLayoutAttributeRight,
relatedBy=NSLayoutRelationGreaterThanOrEqual,
toItem=self.native,
attribute__2=NSLayoutAttributeLeft,
multiplier=1.0,
constant=min_width,
).retain()
self.native.addConstraint(self._min_width_constraint)

self._min_height_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
self.native,
NSLayoutAttributeBottom,
NSLayoutRelationGreaterThanOrEqual,
self._min_height_constraint = NSLayoutConstraint.constraintWithItem(
self.native,
NSLayoutAttributeTop,
1.0,
min_height,
attribute__1=NSLayoutAttributeBottom,
relatedBy=NSLayoutRelationGreaterThanOrEqual,
toItem=self.native,
attribute__2=NSLayoutAttributeTop,
multiplier=1.0,
constant=min_height,
).retain()
self.native.addConstraint(self._min_height_constraint)

Expand Down
84 changes: 42 additions & 42 deletions cocoa/src/toga_cocoa/widgets/internal/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,64 +50,64 @@ def setup(self):
self.textField.translatesAutoresizingMaskIntoConstraints = False

# center icon vertically in cell
self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.iv_vertical_constraint = NSLayoutConstraint.constraintWithItem(
self.imageView,
NSLayoutAttributeCenterY,
NSLayoutRelationEqual,
self,
NSLayoutAttributeCenterY,
1,
0,
attribute__1=NSLayoutAttributeCenterY,
relatedBy=NSLayoutRelationEqual,
toItem=self,
attribute__2=NSLayoutAttributeCenterY,
multiplier=1,
constant=0,
)
# align left edge of icon with left edge of cell
self.iv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.iv_left_constraint = NSLayoutConstraint.constraintWithItem(
self.imageView,
NSLayoutAttributeLeft,
NSLayoutRelationEqual,
self,
NSLayoutAttributeLeft,
1,
0,
attribute__1=NSLayoutAttributeLeft,
relatedBy=NSLayoutRelationEqual,
toItem=self,
attribute__2=NSLayoutAttributeLeft,
multiplier=1,
constant=0,
)
# set fixed width of icon
self.iv_width_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.iv_width_constraint = NSLayoutConstraint.constraintWithItem(
self.imageView,
NSLayoutAttributeWidth,
NSLayoutRelationEqual,
None,
NSLayoutAttributeNotAnAttribute,
1,
16,
attribute__1=NSLayoutAttributeWidth,
relatedBy=NSLayoutRelationEqual,
toItem=None,
attribute__2=NSLayoutAttributeNotAnAttribute,
multiplier=1,
constant=6,
)
# align text vertically in cell
self.tv_vertical_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.tv_vertical_constraint = NSLayoutConstraint.constraintWithItem(
self.textField,
NSLayoutAttributeCenterY,
NSLayoutRelationEqual,
self,
NSLayoutAttributeCenterY,
1,
0,
attribute__1=NSLayoutAttributeCenterY,
relatedBy=NSLayoutRelationEqual,
toItem=self,
attribute__2=NSLayoutAttributeCenterY,
multiplier=1,
constant=0,
)
# align left edge of text with right edge of icon
self.tv_left_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.tv_left_constraint = NSLayoutConstraint.constraintWithItem(
self.textField,
NSLayoutAttributeLeft,
NSLayoutRelationEqual,
self.imageView,
NSLayoutAttributeRight,
1,
5, # 5 pixels padding between icon and text
attribute__1=NSLayoutAttributeLeft,
relatedBy=NSLayoutRelationEqual,
toItem=self.imageView,
attribute__2=NSLayoutAttributeRight,
multiplier=1,
constant=5, # 5 pixels padding between icon and text
)
# align right edge of text with right edge of cell
self.tv_right_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # NOQA:E501
self.tv_right_constraint = NSLayoutConstraint.constraintWithItem(
self.textField,
NSLayoutAttributeRight,
NSLayoutRelationEqual,
self,
NSLayoutAttributeRight,
1,
-5,
attribute__1=NSLayoutAttributeRight,
relatedBy=NSLayoutRelationEqual,
toItem=self,
attribute__2=NSLayoutAttributeRight,
multiplier=1,
constant=-5,
)

self.addConstraint(self.iv_vertical_constraint)
Expand Down
70 changes: 35 additions & 35 deletions cocoa/src/toga_cocoa/widgets/internal/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,58 +193,58 @@ def initWithDocument_(self, documentView):
self.contentView.addSubview(self.refresh_view)

# set layout constraints
indicatorHCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
indicatorHCenter = NSLayoutConstraint.constraintWithItem(
self.refresh_indicator,
NSLayoutAttributeCenterX,
NSLayoutRelationEqual,
self.refresh_view,
NSLayoutAttributeCenterX,
1.0,
0,
attribute__1=NSLayoutAttributeCenterX,
relatedBy=NSLayoutRelationEqual,
toItem=self.refresh_view,
attribute__2=NSLayoutAttributeCenterX,
multiplier=1.0,
constant=0,
)
self.refresh_view.addConstraint(indicatorHCenter)

indicatorVCenter = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
indicatorVCenter = NSLayoutConstraint.constraintWithItem(
self.refresh_indicator,
NSLayoutAttributeCenterY,
NSLayoutRelationEqual,
self.refresh_view,
NSLayoutAttributeCenterY,
1.0,
0,
attribute__1=NSLayoutAttributeCenterY,
relatedBy=NSLayoutRelationEqual,
toItem=self.refresh_view,
attribute__2=NSLayoutAttributeCenterY,
multiplier=1.0,
constant=0,
)
self.refresh_view.addConstraint(indicatorVCenter)

refreshWidth = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
refreshWidth = NSLayoutConstraint.constraintWithItem(
self.refresh_view,
NSLayoutAttributeWidth,
NSLayoutRelationEqual,
self.contentView,
NSLayoutAttributeWidth,
1.0,
0,
attribute__1=NSLayoutAttributeWidth,
relatedBy=NSLayoutRelationEqual,
toItem=self.contentView,
attribute__2=NSLayoutAttributeWidth,
multiplier=1.0,
constant=0,
)
self.contentView.addConstraint(refreshWidth)

refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
refreshHeight = NSLayoutConstraint.constraintWithItem(
self.refresh_view,
NSLayoutAttributeHeight,
NSLayoutRelationEqual,
None,
NSLayoutAttributeNotAnAttribute,
1.0,
HEADER_HEIGHT,
attribute__1=NSLayoutAttributeHeight,
relatedBy=NSLayoutRelationEqual,
toItem=None,
attribute__2=NSLayoutAttributeNotAnAttribute,
multiplier=1.0,
constant=HEADER_HEIGHT,
)
self.contentView.addConstraint(refreshHeight)

refreshHeight = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
refreshHeight = NSLayoutConstraint.constraintWithItem(
self.refresh_view,
NSLayoutAttributeTop,
NSLayoutRelationEqual,
self.contentView,
NSLayoutAttributeTop,
1.0,
-HEADER_HEIGHT,
attribute__1=NSLayoutAttributeTop,
relatedBy=NSLayoutRelationEqual,
toItem=self.contentView,
attribute__2=NSLayoutAttributeTop,
multiplier=1.0,
constant=-HEADER_HEIGHT,
)
self.contentView.addConstraint(refreshHeight)

Expand Down
42 changes: 21 additions & 21 deletions cocoa/src/toga_cocoa/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,32 @@ def add_error_label(self):
self.error_label.textColor = NSColor.systemRedColor
self.native.addSubview(self.error_label)

leading_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
leading_constraint = NSLayoutConstraint.constraintWithItem(
self.native,
NSLayoutAttributeLeading,
NSLayoutRelationEqual,
self.error_label,
NSLayoutAttributeLeading,
1.0,
4.0,
attribute__1=NSLayoutAttributeLeading,
relatedBy=NSLayoutRelationEqual,
toItem=self.error_label,
attribute__2=NSLayoutAttributeLeading,
multiplier=1.0,
constant=4.0,
)
trailing_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
trailing_constraint = NSLayoutConstraint.constraintWithItem(
self.native,
NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
self.error_label,
NSLayoutAttributeTrailing,
1.0,
4.0,
attribute__1=NSLayoutAttributeTrailing,
relatedBy=NSLayoutRelationEqual,
toItem=self.error_label,
attribute__2=NSLayoutAttributeTrailing,
multiplier=1.0,
constant=4.0,
)
center_y_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_( # noqa: E501
center_y_constraint = NSLayoutConstraint.constraintWithItem(
self.error_label,
NSLayoutAttributeCenterY,
NSLayoutRelationEqual,
self.native,
NSLayoutAttributeCenterY,
1.0,
0.0,
attribute__1=NSLayoutAttributeCenterY,
relatedBy=NSLayoutRelationEqual,
toItem=self.native,
attribute__2=NSLayoutAttributeCenterY,
multiplier=1.0,
constant=0.0,
)
self.native.addConstraints(
[
Expand Down
2 changes: 1 addition & 1 deletion iOS/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ root = ".."
[tool.setuptools_dynamic_dependencies]
dependencies = [
"fonttools >= 4.42.1, < 5.0.0",
"rubicon-objc >= 0.4.7, < 0.5.0",
"rubicon-objc >= 0.4.9, < 0.5.0",
"toga-core == {version}",
]

Expand Down
Loading

0 comments on commit e343028

Please sign in to comment.