1. Ronald Oussoren
  2. pyobjc

Issues

Issue #77 resolved

NSWorkSpace.recycleURLs_completionHandler_ - completionHandler callback can't be classmethod

christof klaus
created an issue

The Docs say the mentioned function must be called with a list of NSURL-instances as the first argument, and the second argument can be a handler callback, called upon completion of deleting the files with information about the new file URLs and a error-message if any occured.

However - defining a callback like this (as demanded by current nsworkspace docs)

def mycallback(self, newURLs, error):
   pass

calling the function like this:

 NSWorkSpace.recycleURLs_completionHandler_([someNSURLs,..], self.mycallbackhandler)

throws an exception, because of mismatching argument-counts..

014-02-19 14:59:19.800 DzSrv[3312:507] <class 'objc.BadPrototypeError'>: Objective-C expects 2 arguments, Python argument has 3 arguments for <selector mycallbackhandler of <DzSrvController: 0x7ffee46ad2e0>>
2014-02-19 14:59:19.804 DzSrv[3312:507] (
    0   CoreFoundation                      0x00007fff8aec841c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff869efe75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8aec7fc9 -[NSException raise] + 9
    3   _objc.so                            0x0000000101cb4c61 PyObjCErr_ToObjCWithGILState + 46
    4   _objc.so                            0x0000000101ca20b5 method_stub + 4866
    5   _objc.so                            0x0000000101c9656f ffi_closure_unix64_inner + 509
    6   _objc.so                            0x0000000101c95c36 ffi_closure_unix64 + 70
    7   AppKit                              0x00007fff860ca348 -[NSMenuItem _corePerformAction] + 394
    8   AppKit                              0x00007fff860ca084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
    9   AppKit                              0x00007fff860c91fc -[NSMenu performKeyEquivalent:] + 289
    10  AppKit                         

versions in use: python 2.7.5, pyobjc 2.5.1, osx 10.9.1

Comments (5)

  1. Ronald Oussoren repo owner

    I can reproduce the issue in a unit test, that should make it fairly easy to fix.

    I had hoped that defining the callback as if it were a selector would help, but that doesn't seem to help:

    def urlsRecycled_error_(self, newURLS, error):
         ...
    
  2. Ronald Oussoren repo owner

    The workaround is to define a python function that forwards the call, something like:

       NSWorkSpace.recycleURLs_completionHandler_([someNSURLs,..], lambda a, b: self.mycallbackhandler(a, b))
    

    I'm about to check in a proper fix to the trunk as well, but this should at least get you going again

  3. Log in to comment