cnsoft / pyobjus

Access to Objective-C class from Python !

Home Page:https://pyobjus.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pyobjus

Python module to access Objective-C class as Python class, using Objective-C runtime reflection.

(Work in progress.)

Quick overview

import ctypes
ctypes.CDLL(‘/System/Library/Frameworks/AppKit.framework/Versions/C/Resources/BridgeSupport/AppKit.dylib’)

from pyobjus import autoclass

# get both nsalert and nsstring class
NSAlert = autoclass('NSAlert')
NSString = autoclass('NSString')

# shortcut to mimic the @"hello" in objective C
ns = lambda x: NSString.alloc().initWithUTF8String_(x)

# create an NSAlert object, and show it.
alert = NSAlert.alloc().init()
alert.setMessageText_(ns('Hello world!'))
alert.runModal()

About

Access to Objective-C class from Python !

https://pyobjus.readthedocs.org/en/latest/