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')
class NSAlertStyle(Enum): Warning = 0 # NSAlertStyleWarning Informational = 1 # NSAlertStyleInformational Critical = 2 # NSAlertStyleCritical NSAlertFirstButtonReturn = 1000 NSAlertSecondButtonReturn = 1001 NSAlertThirdButtonReturn = 1002 ###################################################################### # NSApplication.h NSApplication = ObjCClass('NSApplication') NSApplication.declare_class_property('sharedApplication') NSApplicationPresentationDefault = 0 NSApplicationPresentationHideDock = 1 << 1 NSApplicationPresentationHideMenuBar = 1 << 3 NSApplicationPresentationDisableProcessSwitching = 1 << 5 NSApplicationPresentationDisableHideApplication = 1 << 8 NSEventTrackingRunLoopMode = c_void_p.in_dll(appkit, 'NSEventTrackingRunLoopMode') NSApplicationDidHideNotification = c_void_p.in_dll( appkit, 'NSApplicationDidHideNotification') NSApplicationDidUnhideNotification = c_void_p.in_dll( appkit, 'NSApplicationDidUnhideNotification')
########################################################################## 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') ######################################################################
FastForward = 20 Undo = 21 Redo = 22 PageCurl = 23 ###################################################################### # UIButton.h UIButton = ObjCClass('UIButton') ###################################################################### # UIColor.h UIColor = ObjCClass('UIColor') # System colors UIColor.declare_class_property('darkTextColor') UIColor.declare_class_property('lightTextColor') UIColor.declare_class_property('groupTableViewBackgroundColor') # Predefined colors UIColor.declare_class_property('blackColor') UIColor.declare_class_property('blueColor') UIColor.declare_class_property('brownColor') UIColor.declare_class_property('clearColor') UIColor.declare_class_property('cyanColor') UIColor.declare_class_property('darkGrayColor') UIColor.declare_class_property('grayColor') UIColor.declare_class_property('greenColor') UIColor.declare_class_property('lightGrayColor') UIColor.declare_class_property('magentaColor') UIColor.declare_class_property('orangeColor')
blue = colorRef return (red, green, blue) getPixel = _winGetPixel elif sys.platform == 'darwin': from rubicon.objc import ObjCClass, CGPoint from rubicon.objc.types import register_preferred_encoding ##################################################################### appkit = cdll.LoadLibrary(util.find_library('AppKit')) NSEvent = ObjCClass('NSEvent') NSEvent.declare_class_property('mouseLocation') # NSSystemDefined = ObjCClass('NSSystemDefined') ##################################################################### core_graphics = cdll.LoadLibrary(util.find_library('CoreGraphics')) CGDirectDisplayID = c_uint32 CGEventRef = c_void_p register_preferred_encoding(b'^{__CGEvent=}', CGEventRef) CGEventSourceRef = c_void_p register_preferred_encoding(b'^{__CGEventSource=}', CGEventSourceRef) CGEventTapLocation = c_uint32
UIBarButtonSystemItemPause = 18 UIBarButtonSystemItemRewind = 19 UIBarButtonSystemItemFastForward = 20 UIBarButtonSystemItemUndo = 21 UIBarButtonSystemItemRedo = 22 UIBarButtonSystemItemPageCurl = 23 ###################################################################### # UIButton.h UIButton = ObjCClass('UIButton') ###################################################################### # UIColor.h UIColor = ObjCClass('UIColor') # System colors UIColor.declare_class_property('darkTextColor') UIColor.declare_class_property('lightTextColor') UIColor.declare_class_property('groupTableViewBackgroundColor') # Predefined colors UIColor.declare_class_property('blackColor') UIColor.declare_class_property('blueColor') UIColor.declare_class_property('brownColor') UIColor.declare_class_property('clearColor') UIColor.declare_class_property('cyanColor') UIColor.declare_class_property('darkGrayColor') UIColor.declare_class_property('grayColor') UIColor.declare_class_property('greenColor') UIColor.declare_class_property('lightGrayColor') UIColor.declare_class_property('magentaColor') UIColor.declare_class_property('orangeColor')