Beispiel #1
0
    def test_property_forcing(self):
        "An instance or property method can be explicitly declared as a property."
        Example = ObjCClass('Example')
        Example.declare_class_property('classMethod')
        Example.declare_class_property('classAmbiguous')
        Example.declare_property('instanceMethod')
        Example.declare_property('instanceAmbiguous')

        # A class method can be turned into a property
        self.assertEqual(Example.classMethod, 37)

        # An actual class property can be accessed as a property
        self.assertEqual(Example.classAmbiguous, 37)

        # An instance property can be accessed
        obj1 = Example.alloc().init()

        # An instance method can be turned into a property
        self.assertEqual(obj1.instanceMethod, 42)

        # An actual property can be accessed as a property
        self.assertEqual(obj1.instanceAmbiguous, 42)

        # Practical example: In Sierra, mainBundle was turned into a class property.
        # Previously, it was a method.
        NSBundle = ObjCClass('NSBundle')
        NSBundle.declare_class_property('mainBundle')
        self.assertFalse(callable(NSBundle.mainBundle), 'NSBundle.mainBundle should not be a method')
Beispiel #2
0
    def test_property_forcing(self):
        "An instance or property method can be explicitly declared as a property."
        Example = ObjCClass('Example')
        Example.declare_class_property('classMethod')
        Example.declare_class_property('classAmbiguous')
        Example.declare_property('instanceMethod')
        Example.declare_property('instanceAmbiguous')

        # A class method can be turned into a property
        self.assertEqual(Example.classMethod, 37)

        # An actual class property can be accessed as a property
        self.assertEqual(Example.classAmbiguous, 37)

        # An instance property can be accessed
        obj1 = Example.alloc().init()

        # An instance method can be turned into a property
        self.assertEqual(obj1.instanceMethod, 42)

        # An actual property can be accessed as a property
        self.assertEqual(obj1.instanceAmbiguous, 42)

        # Practical example: In Sierra, mainBundle was turned into a class property.
        # Previously, it was a method.
        NSBundle = ObjCClass('NSBundle')
        NSBundle.declare_class_property('mainBundle')
        self.assertFalse(callable(NSBundle.mainBundle),
                         'NSBundle.mainBundle should not be a method')
Beispiel #3
0
NSApplicationActivationPolicyRegular = 0
NSApplicationActivationPolicyAccessory = 1
NSApplicationActivationPolicyProhibited = 2

######################################################################
# NSSavePanel.h
NSSavePanel = ObjCClass('NSSavePanel')

NSFileHandlingPanelOKButton = 1

######################################################################
# NSScreen.h
NSScreen = ObjCClass('NSScreen')
NSScreen.declare_class_property('mainScreen')
NSScreen.declare_property('visibleFrame')

######################################################################
# NSScrollView.h
NSScrollView = ObjCClass('NSScrollView')

NSScrollElasticityAutomatic = 0
NSScrollElasticityNone = 1
NSScrollElasticityAllowed = 2

######################################################################
# NSSecureTextField.h
NSSecureTextField = ObjCClass('NSSecureTextField')

######################################################################
# NSSlider.h
Beispiel #4
0
from ctypes import c_bool, cdll, util

from rubicon.objc import NSPoint, NSRect, ObjCClass

######################################################################
foundation = cdll.LoadLibrary(util.find_library('Foundation'))
######################################################################

foundation.NSMouseInRect.restype = c_bool
foundation.NSMouseInRect.argtypes = [NSPoint, NSRect, c_bool]

######################################################################
# NSBundle.h
NSBundle = ObjCClass('NSBundle')
NSBundle.declare_class_property('mainBundle')
NSBundle.declare_property('bundlePath')

######################################################################
# NSFileWrapper.h
NSFileWrapper = ObjCClass('NSFileWrapper')

######################################################################
# NSNotification.h
NSNotificationCenter = ObjCClass('NSNotificationCenter')

######################################################################
NSNotification = ObjCClass('NSNotification')
NSNotification.declare_property('object')

######################################################################
# NSURL.h