PyObjC DiscRecordingUI Framework
PyObjC is a bidirectional bridge that allows Python programs to interact with Objective-C frameworks on macOS. This package, `pyobjc-framework-discrecordingui`, provides Python wrappers for the DiscRecordingUI framework, enabling developers to integrate disc burning and erasing user interfaces into their macOS applications. The library is actively maintained, currently at version 12.1, with releases often tied to new macOS SDK updates and Python version support cycles.
Warnings
- breaking PyObjC frequently drops support for older Python versions. Version 12.0 dropped support for Python 3.9, and version 11.0 dropped Python 3.8. Ensure your Python environment is compatible with the installed PyObjC version. Current releases generally support Python 3.10 and later.
- breaking Changes in `__init__` and `__new__` behavior when subclassing Objective-C classes from Python. PyObjC 10.3 introduced changes that broke `__init__` for some user-implemented `__new__` patterns, partially reverted in 10.3.1. Complex interactions with Objective-C's two-step instantiation (alloc/init) require careful handling.
- gotcha PyObjC 11.1 aligned its Automatic Reference Counting (ARC) behavior with `clang`'s documentation for initializer methods. Methods in the 'init' family now correctly model stealing a reference to `self` and returning a new reference. This might subtly change reference counting expectations in Python code interacting with Objective-C initializers.
- gotcha Subclassing `NSString` or `NSMutableString` directly from Python is not supported and will lead to crashes. These classes are marked as 'final' in PyObjC due to their special handling in the bridge.
- gotcha Objective-C method names containing colons (`:`) are translated into Python method names with underscores (`_`). For example, `someMethod:withArg:` becomes `someMethod_withArg_`. This mangling is fundamental to PyObjC interaction.
- gotcha PyObjC 11.0 introduced experimental support for free-threading (PEP 703) in Python 3.13. However, PyObjC does not fully support running without the Global Interpreter Lock (GIL), and some functionality explicitly marked as not thread-safe (e.g., defining Objective-C classes concurrently in multiple threads) may lead to issues.
Install
-
pip install pyobjc-framework-discrecordingui
Imports
- DRBurnSetup
from DiscRecordingUI import DRBurnSetup
- DRBurnSession
from DiscRecordingUI import DRBurnSession
- DRBurnSetupPanel
from DiscRecordingUI import DRBurnSetupPanel
Quickstart
import objc
from Foundation import NSObject, NSApplication
from AppKit import NSApplicationActivationPolicyRegular
from PyObjCTools import AppHelper
from DiscRecordingUI import DRBurnSetupPanel, DRBurnSetup, DRBurnCompletionAction
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, notification):
print("Application started.")
# Create a burn setup panel (example usage)
panel = DRBurnSetupPanel.new()
# In a real application, you'd present this panel and handle its delegate methods
# For demonstration, we'll just show its existence.
print(f"Created DRBurnSetupPanel: {panel}")
# To prevent the app from immediately quitting in a simple script,
# a real UI event loop is needed. For CLI demo, we can just let it exit.
# If you were to present a panel, you'd typically do something like:
# panel.beginSetupSheetForWindow_modalDelegate_didEndSelector_contextInfo_(
# None, self, 'burnSetupSheetDidEnd_returnCode_contextInfo:', None)
# For a truly minimal UI app to stay open:
# NSApp.run()
def applicationWillTerminate_(self, notification):
print("Application will terminate.")
if __name__ == '__main__':
# Initialize the NSApplication
app = NSApplication.sharedApplication()
app.setActivationPolicy_(NSApplicationActivationPolicyRegular)
# Create and set the delegate
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
# Run the application event loop
# For a real GUI app, this keeps it running.
# For this minimal example, it might exit quickly if no windows are shown.
AppHelper.runEventLoop()