def application_run():
    NSApplication = objc.objc_getClass('NSApplication')
    app = objc.objc_msgSend(NSApplication,
                            objc.sel_registerName('sharedApplication'))
    create_autorelease_pool()
    create_window()
    objc.objc_msgSend(app, objc.sel_registerName('run'))  # never returns
def create_window():
    print 'creating window'
    window = objc.objc_msgSend('NSWindow', 'alloc')
    NSMakeRect = objc.objc_getClass('NSMakeRect')
    frame = NSMakeRect(100, 100, 300, 300)
    window = objc.objc_msgSend(window, objc.sel_registerName('initWithContentRect:styleMask:backing:defer:'),
                          pointer(frame),
                          NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
                          NSBackingStoreBuffered,
                          0)
    objc.objc_msgSend(window, objc.sel_registerName('setTitle:'), get_NSString("My Awesome Window"))
    objc.objc_msgSend(window, objc.sel_registerName('makeKeyAndOrderFront:'), None)
    return window
def create_window():
    print 'creating window'
    window = objc.objc_msgSend('NSWindow', 'alloc')
    NSMakeRect = objc.objc_getClass('NSMakeRect')
    frame = NSMakeRect(100, 100, 300, 300)
    window = objc.objc_msgSend(
        window,
        objc.sel_registerName('initWithContentRect:styleMask:backing:defer:'),
        pointer(frame), NSTitledWindowMask | NSClosableWindowMask
        | NSMiniaturizableWindowMask | NSResizableWindowMask,
        NSBackingStoreBuffered, 0)
    objc.objc_msgSend(window, objc.sel_registerName('setTitle:'),
                      get_NSString("My Awesome Window"))
    objc.objc_msgSend(window, objc.sel_registerName('makeKeyAndOrderFront:'),
                      None)
    return window
def application_run():
    NSApplication = objc.objc_getClass('NSApplication')
    app = objc.objc_msgSend(NSApplication, objc.sel_registerName('sharedApplication'))
    create_autorelease_pool()
    create_window()
    objc.objc_msgSend(app, objc.sel_registerName('run'))  # never returns
def create_autorelease_pool():
    NSAutoReleasePool = objc.objc_getClass('get_NSString')
    pool = objc.objc_msgSend(NSAutoReleasePool, objc.sel_registerName('alloc'))
    pool = objc.objc_msgSend(pool, objc.sel_registerName('init'))
    return pool
# Simple example of using ctypes with objc to create an NSWindow.  This doesn't exactly #work....if ran in a terminal it would result in 'segmentation fault: 1'  on an iPhone #atleast.   Might be able to be run from within an app though.

import objc
import ctypes
import ctypes.util


ctypes.cdll.LoadLibrary(ctypes.util.find_library('UIKit'))


NSTitledWindowMask = objc.objc_getClass('NSTitledWindowMask')
NSClosableWindowMask = objc.objc_getClass('NSClosableWindowMask')
NSMiniaturizableWindowMask = objc.objc_getClass('NSMiniaturizableWindowMask')
NSResizableWindowMask = objc.objc_getClass('NSResizableWindowMask')
NSBackingStoreBuffered = objc.objc_getClass('NSBackingStoreBuffered')
get_NSString = objc.objc_getClass('get_NSString')


def create_window():
    print 'creating window'
    window = objc.objc_msgSend('NSWindow', 'alloc')
    NSMakeRect = objc.objc_getClass('NSMakeRect')
    frame = NSMakeRect(100, 100, 300, 300)
    window = objc.objc_msgSend(window, objc.sel_registerName('initWithContentRect:styleMask:backing:defer:'),
                          pointer(frame),
                          NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
                          NSBackingStoreBuffered,
                          0)
    objc.objc_msgSend(window, objc.sel_registerName('setTitle:'), get_NSString("My Awesome Window"))
    objc.objc_msgSend(window, objc.sel_registerName('makeKeyAndOrderFront:'), None)
    return window
def create_autorelease_pool():
    NSAutoReleasePool = objc.objc_getClass('get_NSString')
    pool = objc.objc_msgSend(NSAutoReleasePool, objc.sel_registerName('alloc'))
    pool = objc.objc_msgSend(pool, objc.sel_registerName('init'))
    return pool
# Simple example of using ctypes with objc to create an NSWindow.  This doesn't exactly #work....if ran in a terminal it would result in 'segmentation fault: 1'  on an iPhone #atleast.   Might be able to be run from within an app though.

import objc
import ctypes
import ctypes.util

ctypes.cdll.LoadLibrary(ctypes.util.find_library('UIKit'))

NSTitledWindowMask = objc.objc_getClass('NSTitledWindowMask')
NSClosableWindowMask = objc.objc_getClass('NSClosableWindowMask')
NSMiniaturizableWindowMask = objc.objc_getClass('NSMiniaturizableWindowMask')
NSResizableWindowMask = objc.objc_getClass('NSResizableWindowMask')
NSBackingStoreBuffered = objc.objc_getClass('NSBackingStoreBuffered')
get_NSString = objc.objc_getClass('get_NSString')


def create_window():
    print 'creating window'
    window = objc.objc_msgSend('NSWindow', 'alloc')
    NSMakeRect = objc.objc_getClass('NSMakeRect')
    frame = NSMakeRect(100, 100, 300, 300)
    window = objc.objc_msgSend(
        window,
        objc.sel_registerName('initWithContentRect:styleMask:backing:defer:'),
        pointer(frame), NSTitledWindowMask | NSClosableWindowMask
        | NSMiniaturizableWindowMask | NSResizableWindowMask,
        NSBackingStoreBuffered, 0)
    objc.objc_msgSend(window, objc.sel_registerName('setTitle:'),
                      get_NSString("My Awesome Window"))
    objc.objc_msgSend(window, objc.sel_registerName('makeKeyAndOrderFront:'),
                      None)
Beispiel #9
0
import objc
from objc import *
def list_ivars(cls):
    count = c_uint()
    ivar_array = objc.class_copyIvarList(cls, byref(count))
    print count.value, 'ivars'
    print '------------------'
    names = []
    for i in range(count.value):
        ivar = pointer(ivar_array[i])
        name = objc.ivar_getName(ivar)
        encoding = objc.ivar_getTypeEncoding(ivar)
        names.append((name, encoding))

    names.sort()
    for x, y in names: 
        print x, y

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print 'USAGE: python list_ivars.py <Obj-C Class>'
        exit(1)
    
    class_name = sys.argv[1]
    cls = objc.objc_getClass(class_name)

    print class_name, 'instance variables:'
    list_ivars(cls)
        

Beispiel #10
0
from objc import *


def list_ivars(cls):
    count = c_uint()
    ivar_array = objc.class_copyIvarList(cls, byref(count))
    print count.value, 'ivars'
    print '------------------'
    names = []
    for i in range(count.value):
        ivar = pointer(ivar_array[i])
        name = objc.ivar_getName(ivar)
        encoding = objc.ivar_getTypeEncoding(ivar)
        names.append((name, encoding))

    names.sort()
    for x, y in names:
        print x, y


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print 'USAGE: python list_ivars.py <Obj-C Class>'
        exit(1)

    class_name = sys.argv[1]
    cls = objc.objc_getClass(class_name)

    print class_name, 'instance variables:'
    list_ivars(cls)