PyObjC Framework Quartz
PyObjC Framework Quartz provides Python bindings and wrappers for the Quartz frameworks on macOS, enabling Python applications to interact with macOS's core graphics, windowing, and display services. It is part of the larger PyObjC bridge, building upon pyobjc-core. The current version is 12.1, and new versions are typically released in alignment with macOS SDK updates.
Warnings
- breaking PyObjC has dropped support for older Python versions. Version 12.0 dropped support for Python 3.9, and version 11.0 dropped Python 3.8. Ensure your environment meets the current minimum requirement (Python >=3.10).
- breaking Version 11.1 introduced a significant change in how PyObjC handles memory management for Objective-C 'init' family methods, aligning with clang's Automatic Reference Counting (ARC) documentation. This change in object ownership semantics can lead to memory leaks or crashes in existing code that manually manages references.
- gotcha The interaction between Python's `__init__` and `__new__` methods when subclassing Objective-C classes can be complex. While `v10.3` initially restricted `__init__` calls, `v10.3.1` partially re-enabled it for classes with a user-implemented `__new__`. However, classes relying on PyObjC's default `__new__` still cannot use `__init__`.
- gotcha PyObjC v11.0 introduced experimental support for Python's free-threading (PEP 703) for Python 3.13+. However, earlier versions (e.g., v10.3) explicitly stated no support for free threading. Using PyObjC with free-threading, especially outside Python 3.13+ or in ways not fully tested, might lead to unstable behavior.
Install
-
pip install pyobjc-framework-quartz
Imports
- Quartz
import Quartz
- CGMainDisplayID
from Quartz import CGMainDisplayID
Quickstart
import Quartz
# Get the main display ID
main_display_id = Quartz.CGMainDisplayID()
# Get the bounds of the main display
main_display_bounds = Quartz.CGDisplayBounds(main_display_id)
print(f"Main Display ID: {main_display_id}")
print(f"Main Display Bounds: {main_display_bounds}")
print(f"Origin: ({main_display_bounds.origin.x}, {main_display_bounds.origin.y})")
print(f"Size: ({main_display_bounds.size.width}, {main_display_bounds.size.height})")