Example #1
0
 def setUp(self):
     global Car, car
     load_dylib('testlib.dylib', usr_path=False)
     Car = autoclass('Car')
     car = Car.alloc().init()
Example #2
0
 def setUp(self):
     global Car, car
     load_dylib('testlib.dylib', usr_path=False)
     Car = autoclass('Car')
     car = Car.alloc().init()
Example #3
0
 def setUp(self):
     load_dylib('testlib.dylib', usr_path=False)
     global Car
     Car = autoclass('Car')
Example #4
0
from pyobjus import autoclass, dereference
from pyobjus.dylib_manager import load_dylib

load_dylib('testlib.dylib', usr_path=False)
Car = autoclass('Car')
car = Car.alloc().init()

# In pyobjus you can use properties in the same way as in native objective c
# So if we have property defined on this way:
# @property (assign) int propInt;
# .
# .
# .
# @synthesize propInt;

# You can assign some value to property on this way
car.propInt = 12345

# So, after assigning you can see actual value of property:
print(car.propInt)

# If you have property which is pointer to some type, pyobjus also can deal with those properties
# @property (assign) double *propDoublePtr;
# .
# .
# .
# @synthesize propDoublePtr;
car.prop_double_ptr = 345.543

# As you can see, you don't need to worry about dereferencing pointer when you asigning value,
# pyobjus will do it for you :)
Example #5
0
 def setUp(self):
     global _instance
     load_dylib('CArrayTestlib.dylib', usr_path=False)
     CArrayTestlib = autoclass("CArrayTestlib")
     _instance = CArrayTestlib.alloc()
Example #6
0
 def setUp(self):
     load_dylib('testlib.dylib', usr_path=False)
     global Car
     Car = autoclass('Car')
Example #7
0
from pyobjus import autoclass
from pyobjus.dylib_manager import load_framework, make_dylib, load_dylib, INCLUDE

load_framework(INCLUDE.AppKit)
# this is loaded by default
load_framework(INCLUDE.Foundation)
# if you run this on osx, it will throw ObjcException, because this is iOS framework
# load_framework(INCLUDE.UIKit)

# If framework this you want to load is not present with this quick load method,
# you can load it by providing path to .framework
# load_framework('/path/to/framework')

# with this function pyobjus will make .dylib for us
make_dylib('objc_lib.m', frameworks=['Foundation'], options=['-current_version', '1.0'])
# after he made it, we can load .dylib into out program
load_dylib('objc_lib.dylib')
# and we can use classes from loaded .dylib
ObjcClass = autoclass('ObjcClass')
# and call methods of loaded classes
ObjcClass.alloc().init().printFromObjectiveC()
Example #8
0
import ctypes
from pyobjus import autoclass, selector, dereference, CArray, CArrayCount
from pyobjus.dylib_manager import load_dylib

load_dylib('CArrayTestlib.dylib', usr_path=False)

CArrayTestlib = autoclass("CArrayTestlib")

_instance = CArrayTestlib.alloc()

################################# INT ARRAY ####################################################
# Objective-C method signatures:
# - (void) setIntValues: (int[10]) val_arr;
# - (int*) getIntValues;
# - (void) printIntValues;
# - (int*) getIntValuesWithCount: (unsigned int*) n;

nums = [0, 2, 1, 5, 4, 3, 6, 7, 8,
        9]  # we can set values with Python List(nums) or CArray style(array)
array = (ctypes.c_int * 10)(
    *nums)  # this is optional, another way of passing carray to pyobjus
_instance.setIntValues_(
    array)  #Do not forget for _ to signify no. of arguments
#_instance.printIntValues()
returned_PyList = dereference(_instance.getIntValues(),
                              of_type=CArray,
                              return_count=10)
print returned_PyList
# If method returns values/ArrayCount over reference and you don't provide CArrayCount
# on the right position in the method signature, you will get "IndexError: tuple index out of range"
# or segmentation fault, so don't forget to provide CArrayCount on the right position
Example #9
0
import ctypes
from pyobjus import autoclass, selector, dereference, CArray, CArrayCount
from pyobjus.dylib_manager import load_dylib


load_dylib('CArrayTestlib.dylib', usr_path=False)

CArrayTestlib = autoclass("CArrayTestlib")

_instance = CArrayTestlib.alloc()


################################# INT ARRAY ####################################################
# Objective-C method signatures:
# - (void) setIntValues: (int[10]) val_arr;
# - (int*) getIntValues;
# - (void) printIntValues;
# - (int*) getIntValuesWithCount: (unsigned int*) n;

nums = [0, 2, 1, 5, 4, 3, 6, 7, 8, 9]  # we can set values with Python List(nums) or CArray style(array)
array = (ctypes.c_int * 10)(*nums)  # this is optional, another way of passing carray to pyobjus
_instance.setIntValues_(array)  #Do not forget for _ to signify no. of arguments
#_instance.printIntValues()
returned_PyList = dereference(_instance.getIntValues(), of_type=CArray, return_count=10)
print returned_PyList 
# If method returns values/ArrayCount over reference and you don't provide CArrayCount 
# on the right position in the method signature, you will get "IndexError: tuple index out of range" 
# or segmentation fault, so don't forget to provide CArrayCount on the right position
returned_PyList_withCount = dereference(_instance.getIntValuesWithCount_(CArrayCount), of_type=CArray)
print returned_PyList_withCount
Example #10
0
from pyobjus import autoclass
from pyobjus.dylib_manager import load_framework, make_dylib, load_dylib, INCLUDE

load_framework(INCLUDE.AppKit)
# this is loaded by default
load_framework(INCLUDE.Foundation)
# if you run this on osx, it will throw ObjcException, because this is iOS framework
# load_framework(INCLUDE.UIKit)

# If framework this you want to load is not present with this quick load method,
# you can load it by providing path to .framework
# load_framework('/path/to/framework')

# with this function pyobjus will make .dylib for us
make_dylib('objc_lib.m',
           frameworks=['Foundation'],
           options=['-current_version', '1.0'])
# after he made it, we can load .dylib into out program
load_dylib('objc_lib.dylib')
# and we can use classes from loaded .dylib
ObjcClass = autoclass('ObjcClass')
# and call methods of loaded classes
ObjcClass.alloc().init().printFromObjectiveC()
Example #11
0
from pyobjus import autoclass, dereference
from pyobjus.dylib_manager import load_dylib

load_dylib("testlib.dylib", usr_path=False)
Car = autoclass("Car")
car = Car.alloc().init()

# In pyobjus you can use properties in the same way as in native objective c
# So if we have property defined on this way:
# @property (assign) int propInt;
# .
# .
# .
# @synthesize propInt;

# You can assign some value to property on this way
car.propInt = 12345

# So, after assigning you can see actual value of property:
print car.propInt

# If you have property which is pointer to some type, pyobjus also can deal with those properties
# @property (assign) double *propDoublePtr;
# .
# .
# .
# @synthesize propDoublePtr;
car.prop_double_ptr = 345.543

# As you can see, you don't need to worry about dereferencing pointer when you asigning value,
# pyobjus will do it for you :)
Example #12
0
from pyobjus import autoclass, dereference, objc_py_types as opy, ObjcSelector
from pyobjus.dylib_manager import load_dylib

load_dylib('testlib.dylib', usr_path=False)
NSString = autoclass('NSString')
NSValue = autoclass('NSValue')
# this is class defined in user dynamic lib (objc_test/testlib.m)
Car = autoclass('Car')
car = Car.alloc().init()

# first, let's call method which returns SEL value...
# - (SEL) makeSelector {
#   SEL sel = @selector(print);
#   return sel;
# }
sel = car.makeSelector()

# then call method useSelector with returned value from previous call
# - (void) useSelector:(SEL)sel {
#   [self performSelector:sel];
# }
car.useSelector_(sel)

# we can also call method which returns pointer to selector -> SEL*
# when we call method which returns pointer to some type, it will be saved into ObjcReferenceToType class instance 
# - (SEL*) makeSelectorPtr {
#   SEL sel = @selector(print);
#   SEL *sel_ptr = malloc(sizeof(SEL));
#   *sel_ptr = sel;
#   return sel_ptr;
# }
Example #13
0
 def setUp(self):
     global _instance
     load_dylib('CArrayTestlib.dylib', usr_path=False)
     CArrayTestlib = autoclass("CArrayTestlib")
     _instance = CArrayTestlib.alloc()