0

I'm converting a Objective-C program to PyObjC and lack experience in both.

Here is the Objective-C portion

WebPreferences *p = [webview preferences];
if([p respondsToSelector:@selector(setWebGLEnabled:)]){
[p performSelector:@selector(setWebGLEnabled:) withObject:[NSNumber numberWithBool:YES]];
}

This is basically an undocumented method (yes I know I can't submit to app store) to enable WebGL in the WebView

I can't figure out how to translate this portion to PyObjC

jitcoder
  • 41
  • 1
  • 2

2 Answers2

1

You don't have to use performSelector, just call the method:

p = webview.preferences()
p.setWebGLEnabled_(True)

This works because PyObjC doesn't look at header files but at the Objective-C runtime to find out which methods are present.

Ronald Oussoren
  • 2,715
  • 20
  • 29
0

One of the magic bits of the bridge. You can just use the selector's string -- the method name (with colons, not underscores):

>>> from AppKit import *
>>> s = NSString.stringWithString_("Lemon curry?")
>>> s.respondsToSelector_("length")
True
>>> s.respondsToSelector_("count")
False
>>> s.respondsToSelector_("writeToFile:atomically:encoding:error:")
True
>>> s.performSelector_("lowercaseString")
u'lemon curry?'
jscs
  • 63,694
  • 13
  • 151
  • 195