@@ -94,41 +94,36 @@ def _set_cfunctions(self):
9494 # type: () -> None
9595 """ Set all ctypes functions and attach them to attributes. """
9696
97- def cfactory (func , argtypes , restype ):
98- # type: (str, List[Any], Any) -> None
99- """ Factorize ctypes creations. """
100- self ._cfactory (
101- attr = self .core , func = func , argtypes = argtypes , restype = restype
102- )
103-
10497 uint32 = ctypes .c_uint32
10598 void = ctypes .c_void_p
10699 pointer = ctypes .POINTER
100+ cfactory = self ._cfactory
101+ core = self .core
107102
108- cfactory (
109- func = "CGGetActiveDisplayList" ,
110- argtypes = [ uint32 , pointer ( uint32 ), pointer ( uint32 )] ,
111- restype = ctypes . c_int32 ,
112- )
113- cfactory ( func = "CGDisplayBounds " , argtypes = [ uint32 ], restype = CGRect )
114- cfactory ( func = "CGRectStandardize " , argtypes = [ CGRect ], restype = CGRect )
115- cfactory ( func = "CGRectUnion " , argtypes = [ CGRect , CGRect ], restype = CGRect )
116- cfactory ( func = "CGDisplayRotation " , argtypes = [ uint32 ], restype = ctypes . c_float )
117- cfactory (
118- func = "CGWindowListCreateImage " ,
119- argtypes = [ CGRect , uint32 , uint32 , uint32 ],
120- restype = void ,
121- )
122- cfactory ( func = "CGImageGetWidth " , argtypes = [void ], restype = int )
123- cfactory ( func = "CGImageGetHeight " , argtypes = [void ], restype = int )
124- cfactory ( func = "CGImageGetDataProvider" , argtypes = [void ], restype = void )
125- cfactory ( func = "CGDataProviderCopyData " , argtypes = [void ], restype = void )
126- cfactory ( func = "CFDataGetBytePtr " , argtypes = [void ], restype = void )
127- cfactory ( func = "CFDataGetLength " , argtypes = [ void ], restype = ctypes . c_uint64 )
128- cfactory ( func = "CGImageGetBytesPerRow " , argtypes = [ void ], restype = int )
129- cfactory ( func = "CGImageGetBitsPerPixel " , argtypes = [ void ], restype = int )
130- cfactory ( func = "CGDataProviderRelease" , argtypes = [ void ], restype = void )
131- cfactory (func = "CFRelease" , argtypes = [ void ] , restype = void )
103+ # Note: keep it sorted
104+ for func , argtypes , restype in (
105+ ( "CGDataProviderCopyData" , [ void ], void ) ,
106+ ( "CGDisplayBounds" , [ uint32 ], CGRect ) ,
107+ ( "CGDisplayRotation" , [ uint32 ], ctypes . c_float ),
108+ ( "CFDataGetBytePtr " , [ void ], void ),
109+ ( "CFDataGetLength " , [ void ], ctypes . c_uint64 ),
110+ ( "CFRelease " , [ void ], void ),
111+ ( "CGDataProviderRelease " , [ void ], void ),
112+ (
113+ "CGGetActiveDisplayList " ,
114+ [ uint32 , pointer ( uint32 ), pointer ( uint32 ) ],
115+ ctypes . c_int32 ,
116+ ),
117+ ( "CGImageGetBitsPerPixel " , [void ], int ),
118+ ( "CGImageGetBytesPerRow " , [void ], int ),
119+ ( "CGImageGetDataProvider" , [void ], void ),
120+ ( "CGImageGetHeight " , [void ], int ),
121+ ( "CGImageGetWidth " , [void ], int ),
122+ ( "CGRectStandardize " , [ CGRect ], CGRect ),
123+ ( "CGRectUnion " , [ CGRect , CGRect ], CGRect ),
124+ ( "CGWindowListCreateImage " , [ CGRect , uint32 , uint32 , uint32 ], void ),
125+ ):
126+ cfactory (attr = core , func = func , argtypes = argtypes , restype = restype ) # type: ignore
132127
133128 def _monitors_impl (self ):
134129 # type: () -> None
0 commit comments