Re: [Pyobjc-dev] how to add methods to this class in this case?
Brought to you by:
ronaldoussoren
From: Robert K. <rob...@gm...> - 2013-11-09 20:52:23
|
Hi Burak, The signature of that specific method is different: applicationShouldHandleReopen:hasVisibleWindows: Sent by the application to the delegate prior to default behavior to reopen (rapp) AppleEvents. - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag (full documentation here) Here's a minimal example that works for me: #!/usr/bin/env python from AppKit import NSObject, NSApplication from Foundation import NSLog import objc class TestApp(NSObject): @objc.signature('B@:#B') def applicationShouldHandleReopen_hasVisibleWindows_(self, app, flag): NSLog('Hello!') return True def applicationDidFinishLaunching_(self, notification): NSLog('App running') if __name__ == '__main__': sharedapp = NSApplication.sharedApplication() testapp = TestApp.alloc().init() sharedapp.setDelegate_(testapp) sharedapp.run() Regards, Robert Burak Nehbit <bu...@ne...> wrote on Sat Nov 09 2013 at 20:45:40: > (Sorry for the double post, my mail client glitched—this is the full one.) > > Hi there, > > I am building a Qt application called Aether (www.getaether.net). > > For its Mac version, I have run into the problem of Qt not being able to detect and raise events to Mac’s dock icon clicks. This is an essential and widely used feature on OS X that is completely ignored by Qt, and I want to provide my users this functionality. > > I have found a way to do this on C++ here: > http://aksenkin.blogspot.com/2012/02/how-to-handle-click-on-app-icon-in-mac.html > > I am using Python, so I need to accomplish it using PyObjC. I have written the following piece of code so far: > > @objc.signature('B@:') > def applicationShouldHandleReopen_hasVisibleWindows_(self, sender): > print('hello!') > app.onClickOnDock() > return True > > cls = objc.lookUpClass('NSApplication') > appInstance = cls.sharedApplication # I'm doing some real crazy runtime shit there. > #print(cls, appInstance) > delegate = appInstance.definingClass.delegate > delClass = delegate.definingClass > objc.classAddMethods(cls, [applicationShouldHandleReopen_hasVisibleWindows_]) > > But this has no effect. No method gets triggered, nothing happens. I have little to no C++ knowledge, so I am probably missing a nuance in the translation. Can anyone point me in the right direction? > > Regards, > Burak > |