beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.19k stars 655 forks source link

Update syntax for ObjC constraint API usage to avoid long lines. #2682

Open freakboy3742 opened 2 days ago

freakboy3742 commented 2 days ago

With the fix for beeware/rubicon-objc#148 being introduced in Rubicon 0.4.9, we can now remove the unwieldy long lines when creating NSLayoutConstraint objects.

This was fixed in the process of trying to narrow down an intermittent segfault I was seeing in the testing for #2666. The underlying fix for that issue is included here (a window cleanup autouse fixture, with explicit GC passes in the app and window cleanup fixtures). That segfault was caused by garbage collection of NSWindow (and related) objects in the pytest thread; we previously added a GC pass in the Window tests to allow for this class of issue, but we've recently added app tests that also create windows; and the main window is also (sometimes) prone to this issue.

Updating the constraint syntax is mostly incidental to the test stability fix - but I spent a lot of time poking around constraints, so I did some housekeeping while I was in the area.

This also corrects an edge case around testbed startup that I've now seen a couple of times on iOS. If the pytest thread starts quickly, the main window may not have been assigned yet, resulting in an exception being raised in testbed startup.

PR Checklist: