Frage

When I call setDelegate_ within my pyObjC code I get an AttributeError: 'tuple' object has no attribute 'setDelegate_'.

My Code looks like this:

def createMovie(self):
        attribs = NSMutableDictionary.dictionary()
        attribs['QTMovieFileNameAttribute'] = '<My Filename>'
        movie = QTMovie.alloc().initWithAttributes_error_(attribs, objc.nil)
        movie.setDelegate_(self)

Edit

I Found out that i can't use any instance methods with the movie object.

War es hilfreich?

Lösung

From your comment, it looks like QTMovie.alloc().initWithAttributes_error_ actually returns a two-element tuple, with the object you want as first element and some other object in the second element (possibly an error ?)

You should be able to access your object like that:

(movie, error) = QTMovie.alloc().initWithAttributes_error_(attribs, objc.nil)

Andere Tipps

The selector "initWithAttributes:error:" has two arguments in Objective-C, the second of which is a pass-by-reference output parameter. Python does not have pass-by-reference arguments, therefore PyObjC returns the value as a second return value, which is why the python wrapper for this selector returns a tuple. This is a general mechanism that's also used with other methods that have pass-by-reference arguments.

In Objective-C:

QTMovie* movie;
NSError* error = nil;

movie = [[QTMovie alloc] initWithAttributes: attribs error:&error]
if (movie == nil) {
   // do something with error 
}

In Python:

movie, error = QTMovie.alloc().initWithAttributes_error_(attribs, None)
if movie is None:
  # do something with error
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top