Re: how to add methods to this class in this case?

Robert Klep <[email protected]> Sat, 9 Nov 2013 21:52:13 +0100
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
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 <[email protected]> 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
>

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev