Пример #1
0
 def __init__(self, **kwargs):
     super(IOSKeyboard, self).__init__()
     self.kheight = 0
     NSNotificationCenter = autoclass("NSNotificationCenter")
     center = NSNotificationCenter.defaultCenter()
     center.addObserver_selector_name_object_(
         self, selector("keyboardWillShow"),
         "UIKeyboardWillShowNotification", None)
     center.addObserver_selector_name_object_(
         self, selector("keyboardDidHide"), "UIKeyboardDidHideNotification",
         None)
Пример #2
0
 def __init__(self, **kwargs):
     super(IOSKeyboard, self).__init__()
     self.kheight = 0
     NSNotificationCenter = autoclass("NSNotificationCenter")
     center = NSNotificationCenter.defaultCenter()
     center.addObserver_selector_name_object_(
         self, selector("keyboardWillShow"),
         "UIKeyboardWillShowNotification",
         None)
     center.addObserver_selector_name_object_(
         self, selector("keyboardDidHide"),
         "UIKeyboardDidHideNotification",
         None)
Пример #3
0
# Also, if you want to know only names, you can get it on following way
print ret_type.getMembers(only_types=True)

# If you want to use returned type to pass it as argument to some function there will be some problems. 
# Pyobjus is using ctypes structures, so we can get actual pointer to c structure from python object,
# but if we want to get working correct values of passed arg, we need to cast pointer to appropriate type
# If type is defined in pyobjus/objc_cy_types pyobjus will cost it for us, but if it isn't, we will need to convert
# it by ourselfs, for example internaly in function where we are passing struct value. Lets see example of this:

# - (void) useUnknownStr:(void*)str_vp {
#   unknown_str *str_p = (unknown_str*)str_vp;
#   unknown_str str = str_p[0];
#   printf("%f\n", str.rect.origin.x);
# }

car.useUnknownStr_(ret_type)

# We can see that we are casting to appropriate type (inside of useUnknownStr_ method)

# Another use-case of unknown type signature is with pointers to implementations of methods. 
# As you known every method has pointer to IMP type, which is actual implementation of that method.
# So, if we need to get IMP of some method, we can do sommething like this:
imp = car.methodForSelector_(selector('getSumOf:and:'))

# Method signature for return type of this function is ^?, so that is also some unknown type.
# As you knows, when we have IMP of method, we can also pass IMP as argument, and call method behind IMP pointer
# - (int) useImp:(IMP)imp withA:(int)a andB:(int)b {
#   return (int)imp(self, @selector(getSumOf:and:), a, b);
# })
print car.useImp_withA_andB_(imp, 5, 7)
Пример #4
0
NSObject = autoclass("NSObject")
NSArray = autoclass("NSArray")
NSString = autoclass('NSString')

text = NSString.alloc().initWithUTF8String_("some text")
text_n = NSString.alloc().initWithUTF8String_("other text")
array = NSArray.arrayWithObject_(text)

# equivalent to [NSString class];
objc_class = NSString.oclass()
print(NSString.isKindOfClass_(NSObject.oclass()))
print(NSString.isKindOfClass_(NSArray.oclass()))
print(text.isKindOfClass_(NSObject.oclass()))
print(text.isKindOfClass_(array.oclass()))
print(text.isKindOfClass_(text_n.oclass()))

# equivalent to @selector(UTF8String)
sel_one = selector("UTF8String")
sel_two = selector("objectAtIndex:")

# examples with NSString
print(NSString.instancesRespondToSelector_(sel_one))
print(text.respondsToSelector_(sel_one))
print(text.respondsToSelector_(sel_two))
print(text.respondsToSelector_(selector("init")))

# examples with NSArray
print(array.respondsToSelector_(sel_one))
print(array.respondsToSelector_(sel_two))
Пример #5
0
 def test_usingIMP(self):
     imp = car.methodForSelector_(selector('getSumOf:and:'))
     self.assertEqual(car.useImp_withA_andB_(imp, 5, 7), 12)
     imp = car.getImp()
     self.assertEqual(car.useImp_withA_andB_(imp, 10, 12), 22)
Пример #6
0
NSObject = autoclass("NSObject")
NSArray = autoclass("NSArray")
NSString = autoclass('NSString')

text = NSString.alloc().initWithUTF8String_("some text")
text_n = NSString.alloc().initWithUTF8String_("other text")
array = NSArray.arrayWithObject_(text)

# equivalent to [NSString class];
objc_class = NSString.oclass()
print NSString.isKindOfClass_(NSObject.oclass())
print NSString.isKindOfClass_(NSArray.oclass())
print text.isKindOfClass_(NSObject.oclass())
print text.isKindOfClass_(array.oclass())
print text.isKindOfClass_(text_n.oclass())

# equivalent to @selector(UTF8String)
sel_one = selector("UTF8String")
sel_two = selector("objectAtIndex:")

# examples with NSString
print NSString.instancesRespondToSelector_(sel_one)
print text.respondsToSelector_(sel_one)
print text.respondsToSelector_(sel_two)
print text.respondsToSelector_(selector("init"))

# examples with NSArray
print array.respondsToSelector_(sel_one)
print array.respondsToSelector_(sel_two)
Пример #7
0
    print NSNumber.isKindOfClass_(returned_classes[i])
returned_classes_WithCount = dereference(
    _instance.getClassValuesWithCount_(CArrayCount), of_type=CArray)
for i in xrange(len(returned_classes_WithCount)):
    print NSNumber.isKindOfClass_(returned_classes_WithCount[i])

#################################################################################################

################################# SIGNATURE: :, SELECTOR ARRAY ###################################
# Objective-C method signatures:
# - (void) printSelector;
# - (void) setSELValues: (SEL[10]) val_arr;
# - (SEL*) getSELValues;
# - (SEL*) getSELValuesWithCount: (unsigned int*) n;

sel = selector("printSelector")
sel_array = [sel for i in xrange(0, 10)]
print sel_array
_instance.setSELValues_(sel_array)
returned_selectors = dereference(_instance.getSELValues(),
                                 of_type=CArray,
                                 return_count=10)
print returned_selectors
returned_selectors_WithCount = dereference(
    _instance.getSELValuesWithCount_(CArrayCount), of_type=CArray)
print returned_selectors_WithCount

# TODO: performSelector example

#################################################################################################
Пример #8
0
returned_classes_WithCount = dereference(_instance.getClassValuesWithCount_(CArrayCount), of_type=CArray)
for i in xrange(len(returned_classes_WithCount)):
    print NSNumber.isKindOfClass_(returned_classes_WithCount[i])

#################################################################################################


################################# SIGNATURE: :, SELECTOR ARRAY ###################################
# Objective-C method signatures:
# - (void) printSelector;
# - (void) setSELValues: (SEL[10]) val_arr;
# - (SEL*) getSELValues;
# - (SEL*) getSELValuesWithCount: (unsigned int*) n;


sel = selector("printSelector")
sel_array = [sel for i in xrange(0, 10)]
print sel_array
_instance.setSELValues_(sel_array)
returned_selectors = dereference(_instance.getSELValues(), of_type=CArray, return_count=10)
print returned_selectors
returned_selectors_WithCount = dereference(_instance.getSELValuesWithCount_(CArrayCount), of_type=CArray)
print returned_selectors_WithCount

# TODO: performSelector example

#################################################################################################


############################# SIGNATURE: [], Multidimensional array #############################
# Objective-C method signatures:
Пример #9
0
# Also, if you want to know only names, you can get it on following way
print ret_type.getMembers(only_types=True)

# If you want to use returned type to pass it as argument to some function there will be some problems.
# Pyobjus is using ctypes structures, so we can get actual pointer to c structure from python object,
# but if we want to get working correct values of passed arg, we need to cast pointer to appropriate type
# If type is defined in pyobjus/objc_cy_types pyobjus will cost it for us, but if it isn't, we will need to convert
# it by ourselfs, for example internaly in function where we are passing struct value. Lets see example of this:

# - (void) useUnknownStr:(void*)str_vp {
#   unknown_str *str_p = (unknown_str*)str_vp;
#   unknown_str str = str_p[0];
#   printf("%f\n", str.rect.origin.x);
# }

car.useUnknownStr_(ret_type)

# We can see that we are casting to appropriate type (inside of useUnknownStr_ method)

# Another use-case of unknown type signature is with pointers to implementations of methods.
# As you known every method has pointer to IMP type, which is actual implementation of that method.
# So, if we need to get IMP of some method, we can do sommething like this:
imp = car.methodForSelector_(selector('getSumOf:and:'))

# Method signature for return type of this function is ^?, so that is also some unknown type.
# As you knows, when we have IMP of method, we can also pass IMP as argument, and call method behind IMP pointer
# - (int) useImp:(IMP)imp withA:(int)a andB:(int)b {
#   return (int)imp(self, @selector(getSumOf:and:), a, b);
# })
print car.useImp_withA_andB_(imp, 5, 7)