> On 21 Sep 2018, at 23:24, Glyph <gl...@twistedmatrix.com> wrote:
>
>
>
>> On Sep 21, 2018, at 4:50 AM, Ronald Oussoren <ronaldousso...@mac.com
>> <mailto:ronaldousso...@mac.com>> wrote:
>>
>>
>>
>>> On 21 Sep 2018, at 05:59, Glyph <gl...@twistedmatrix.com
>>> <mailto:gl...@twistedmatrix.com>> wrote:
>>>
>>> On Sep 18, 2018, at 1:22 PM, Ronald Oussoren via Pythonmac-SIG
>>> <pythonmac-sig@python.org <mailto:pythonmac-sig@python.org>> wrote:
>>>>
>>>> PyObjC 5.0 is out
>>>
>>> Thanks again for your tireless (or at least apparently tireless)
>>> maintenance, Ronald!
>>>
>>>> * Added bindings for the “CarbonCore” subframework of the “CoreServices”
>>>> framework.
>>>>
>>>> Most APIs in this subframework are not available to Python, only those
>>>> APIs that are not deprecated and seem interesting are exposed.
>>>
>>> One thing I wondered about when I saw "carbon" here is that I wonder if the
>>> APIs that could make
>>> https://pythonhosted.org/pyobjc/examples/Cocoa/AppKit/HotKeyPython/index.html
>>>
>>> <https://pythonhosted.org/pyobjc/examples/Cocoa/AppKit/HotKeyPython/index.html>
>>> are exposed again?
>>
>> The API used in that example is not exposed through PyObjC at this time
>> (AFAIK it is part of “Carbon.framework”, not the CarbonCore sub framework of
>> “CoreServices.framework”.
>>
>> I’m open to adding bindings to interesting APIs, but note that
>> “RegisterEventHotKey” is not documented on Apple’s website and might not be
>> the right solution for modern code. I don’t know yet what the right solution
>> is though (a number of APIs that are exposed through PyObjC can be used to
>> implement similar functionality).
>
> If there were a more modern solution I'd gladly use it rather than asking you
> to expose gross and ancient Carbon APIs :). Which APIs that are already
> exposed can do this?
Good question :-). I thought CGEventTapCreate and related APIs could be used
for this, but now that I’ve reread the documentation I no longer think so.
MASShortCut still uses the Carbon APIs in its implementation, which seems to
confirm that there is no good modern alternative for the RegisterEventHotKey
API.
>
>>> The cautions that the relevant Carbon APIs require 32-bit mode are
>>> inaccurate;
>>> https://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
>>> <https://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html>
>>> explains that they're still supported in sandboxed Mac App Store apps, so
>>> they're just poorly documented, not deprecated. (It seems that there's
>>> never been a proper Cocoa replacement for this functionality, just a couple
>>> of popular wrappers floating around out there…)
>>>
>>> This is something I have wanted to do in Python many times, but never quite
>>> badly enough to figure out all the build gymnastics required to get the
>>> bindings for https://github.com/shpakovski/MASShortcut
>>> <https://github.com/shpakovski/MASShortcut> built and bundled with my
>>> application.
>>
>> I’ll look into exposing this API for PyObjC 5.1, even if that means adding a
>> very limited set of bindings for Carbon.framework.
>
> Thanks!
>
>>> -glyph
>>>
>>> P.S.: speaking of build gymnastics, does anyone on this list happen to have
>>> a way to use CocoaPods or something similar to pull in open source Cocoa
>>> frameworks to a PyObjC application?
>>
>> I haven’t looked into this yet. I guess the hardest part is creating the
>> metadata for constants and pointer arguments. Could you file and issue for
>> this?
>
> Sure, sometime this weekend I'll try to write it up.
I have created an experimental binding to MASShortcut on my bitbucket account:
https://bitbucket.org/ronaldoussoren/pyobjc-masshortcut
<https://bitbucket.org/ronaldoussoren/pyobjc-masshortcut>. This library can be
installed using “pip install pyobjc-MASShortcut==1.0a0” (and has a wheel if you
use a 64-bit installation of Python 3.7)
This “works” in the sense that I ran my unit tests with Python 3.6 (64-bit),
but I have done no testing beyond that.
Creating the bindings was fairly easy, but harder than it should be because the
tooling I use to create bindings is primarily created for Apple’s system
frameworks and has some issues with 3th-party frameworks. I do want to improve
the tooling for this, but don’t know when I’ll get around to actually doing
this.
Ronald
_______________________________________________
Pythonmac-SIG maillist - Pythonmac-SIG@python.org
https://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG