pyobjc
pyobjc copied to clipboard
Investigate UIKit bindings
Recent versions of macOS have a UIKit.framework next to the older AppKit.framework for GUIs. Investigate what's needed to provide bindings for this.
Open questions:
- Can UIKit.framework be used from a regular Python build (python.org installer)?
- Can UIKit.framework and AppKit.framework be used at the same time (in the way to PyObjC accesses these libraries!)?
- "iOSSupport" frameworks directory contains more than just UIKit, are those other frameworks compatible with there PyObjC bindings (for those frameworks that are available for in the regular frameworks directory as well)
Actually providing bindings will be quite a lot of work, there are about 30K lines of code in the UIKit framework headers. Most should be handled automatically (either directly or through the metadata tool), but I'll have to look at all of this at some point.
Note that I won't look into this before I've finished work on rewriting the metadata generator.
How is the work going on that? I wish I could use UIKit to make a action for one of my UNNotificationActionOptions
as .foreground. This is what I want to call I think but I can't. Appkit doesnt have anything like it.
The API you link to is deprecated an shouldn't really be used. You could use -[NSApplication activateIgnoringOtherApps:]
to bring the application to the foreground using AppKit.
To answer you question: there is no progress on this issue, and I don't have a timeline on when I'll get around to this (if ever). There's two challenges with this library: (1) UIKit is pretty large. and (2) UIKit is part of Catalyst using Catalyst libraries might require other changes to PyObjC than just creating a framework wrapper. Both mean that creating a binding is a significant effort, and I don't have to bandwidth to work on this now (and also don't have a use case for this myself).
Ahh I understand, since I made this comment I used UNNotificationActionOptionForeground
as an action here:
# Actions for notification
action_open = UN.UNNotificationAction.actionWithIdentifier_title_options_(
"check",
"Check",
UN.UNNotificationActionOptions(UN.UNNotificationActionOptionForeground)) # Brings app to foreground
Would this be good too by chance? I haven't compiled this code into the XIB app with py2app but would you guarantee this would work too?
See the discussion in #501. Loading UIKit.framework into an AppKit app is not possible (https://developer.apple.com/forums/thread/692356). Wrapping UIKit would require creating a Catalyst version of Python and PyObjC.
That's something I'd like to look into, but is a lot more work than I can manage at the moment.
A Catalyst version of Python would have a new platform tag in Python wheels and hence couldn't use existing binary wheels. That's a major downside, even if a Catalyst Python would open up some interesting new capabilities (such as controlling HomeKit from Python).
I've added an issue about a Catalyst build to the CPython project: https://github.com/python/cpython/issues/98297
To be honest I expect little progress on that until I get around to work on this myself (assuming I do get around to that).
first time using pyobjc. i'm trying to build a python script that listens for brightness changes and reacts. I dug up this notification https://developer.apple.com/documentation/uikit/uiscreen/1617832-brightnessdidchangenotification
but it's in UIKit, does that mean this won't be possible for now?
@gerald-lnj I think, You need create bridge between UIKit and Python.
first time using pyobjc. i'm trying to build a python script that listens for brightness changes and reacts. I dug up this notification
https://developer.apple.com/documentation/uikit/uiscreen/1617832-brightnessdidchangenotification
but it's in UIKit, does that mean this won't be possible for now?
Looks like it. I've looked at the AppKit and CoreGraphics documentation for displays and those don't seem to have similar functionality. That said, I'd expect that there is an API in AppKit or one of the lower-level frameworks to get this information. It is just not something I've had a need for myself.
@gerald-lnj I think, You need create bridge between UIKit and Python.
That's what this issue is about ;-)
PyObjC could be used for this, but for this we first need to have Python build that targets Catalyst instead of regular macOS. See https://github.com/ronaldoussoren/pyobjc/issues/352#issuecomment-1279825063.
@gerald-lnj As I know, AppKit
mainly needed for graphics interface(GUI). I advice you use Quartz
framework.At least, I don't know appkit
classes for working with display settings.