def stupid_stuff(class_name): NSObject = ObjCClass(class_name) print(NSObject) print(libobjc.object_getClassName(NSObject.ptr)) x = NSObject.alloc() # PYCHOK expected print(libobjc.object_getClassName(x.ptr)) print('x', x) print('x.init', x.init) print('x.init()', x.init()) print('x.objc_class', x.objc_class) print(x.retainCount()) print(x.retain()) print(x.retainCount()) print(x.retain()) print(x.retainCount()) print(x.retain()) print(x.retainCount()) if class_name == 'NSApplication': # only one NSApplication allowed return y = NSObject.alloc() # PYCHOK expected print('y', y) print('y.init', y.init) print('y.init()', y.init()) print('y.objc_class', y.objc_class) print(y.retainCount()) print(y.retain()) print(y.retainCount())
def main(timeout=None): # prepare and set our delegate app = NSApplication.sharedApplication() TheDelegate = ObjCClass('TheDelegate') # the actual class delegate = TheDelegate.alloc().init() # PYCHOK expected app.setDelegate_(delegate) delegate.app = app delegate.badge = app.dockTile() delegate.writer(0) # on a separate thread, run the scheduler t = threading.Thread(target=schedule, args=(delegate.writer, )) t.setDaemon(1) t.start() # set up the timeout if timeout is not None: try: # PyCocoa/test from test import terminating terminating(app, timeout) except ImportError: pass # let her rip!-) app.run() # AppHelper.runEventLoop()
def main(timeout=None): # prepare and set our delegate app = NSApplication.sharedApplication() TheDelegate = ObjCClass('TheDelegate') # the actual class delegate = TheDelegate.alloc().init() # PYCHOK expected app.setDelegate_(delegate) delegate.app = app delegate.badge = app.dockTile() delegate.writer(0) # on a separate thread, run the scheduler t = threading.Thread(target=schedule, args=(delegate.writer,)) if sys.version_info[0] > 2: t.deamon = True else: # throws DeprecationWarning t.setDaemon(1) t.start() # set up the timeout terminating(app, timeout) # let her rip!-) app.run() # AppHelper.runEventLoop()
@MySubclass.method('v') # return void, no args def dealloc(self): print('dealloc %r' % (self,)) send_super(self, 'dealloc') @MySubclass.method('vi') # return void, int arg def method(self, number): print('method %r %r' % (self, number)) if __name__ == '__main__': MySubclass = ObjCClass('MySubclass') # the actual class myobject1 = MySubclass.alloc().init() print('after init: myobject1 = % r\n' % (myobject1,)) myobject1.doSomething() myobject1.method(100) myobject1.takePyObject(1) print() myobject2 = MySubclass.alloc().init() print('after init: myobject2 = %r' % (myobject2,)) myobject2.doSomething() # myobject2.doSomething() # myobject2.doSomethingElse()
print(y.retain()) print(y.retainCount()) if __name__ == '__main__': import sys if len(sys.argv) < 2: print('USAGE: python class_wrapper4.py <Obj-C Class>') exit(1) class_name = sys.argv[1] MySubclass = ObjCClass('MySubclass') print(MySubclass) x = MySubclass.alloc().init() print(x) x.doSomething() x.doSomething() x.doSomething() print(len(ObjCInstance._objc_cache)) x.release() del x print(len(ObjCInstance._objc_cache)) stupid_stuff(class_name) # run_window()