1+ # THIS SCRIPT ONLY WORKS ON DARWIN
2+
3+ # We are using this script to initialize GUI before loading the DelphiFMX library.
4+ # This approach prevents the dead-lock that happens when we start GUI with the dynamic-linker initializer.
5+
6+ try :
7+ import ctypes
8+ except ImportError :
9+ raise NotImplementedError ("DelphiFMX requires ctypes, which doesn't seem to be available." )
10+
11+ from ctypes import cdll , c_void_p , c_char_p
12+
13+ framework_name = '/System/Library/Frameworks/AppKit.framework/AppKit'
14+ class_name = 'NSScreen'
15+ method_name = 'mainScreen'
16+
17+ try :
18+ c = cdll .LoadLibrary (framework_name )
19+ except OSError :
20+ raise ValueError ('No framework named \' %s\' found.' % (framework_name ,))
21+
22+ objc_getClass = c .objc_getClass
23+ objc_getClass .argtypes = [c_char_p ]
24+ objc_getClass .restype = c_void_p
25+
26+ class_getClassMethod = c .class_getClassMethod
27+ class_getClassMethod .restype = c_void_p
28+ class_getClassMethod .argtypes = [c_void_p , c_void_p ]
29+
30+ sel_registerName = c .sel_registerName
31+ sel_registerName .restype = c_void_p
32+ sel_registerName .argtypes = [c_char_p ]
33+
34+ ptr = objc_getClass (class_name .encode ('ascii' ))
35+ if ptr is None :
36+ raise ValueError ('No Objective-C class named \' %s\' found.' % (class_name ,))
37+
38+ method = class_getClassMethod (ptr , sel_registerName (method_name .encode ('ascii' )))
39+ if not method :
40+ raise AttributeError ('No class method found for selector "%s".' % (sel_registerName (method_name .encode ('ascii' ))))
41+
42+ objc_msgSend = c ['objc_msgSend' ]
43+ objc_msgSend .argtypes = [c_void_p , c_void_p ]
44+ objc_msgSend .restype = c_void_p
45+ objc_msgSend (ptr , sel_registerName (method_name .encode ('ascii' )), None )
0 commit comments