<s> '''<STR_LIT:U+0020>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> import ctypes <EOL> import pyglet <EOL> from pyglet . input . base import Tablet , TabletCanvas , TabletCursor <EOL> from pyglet . window . carbon import CarbonEventHandler <EOL> from pyglet . libs . darwin import * <EOL> from pyglet . libs . darwin import _oscheck <EOL> class CarbonTablet ( Tablet ) : <EOL> name = '<STR_LIT>' <EOL> def open ( self , window ) : <EOL> return CarbonTabletCanvas ( window ) <EOL> _carbon_tablet = CarbonTablet ( ) <EOL> class CarbonTabletCanvas ( TabletCanvas ) : <EOL> def __init__ ( self , window ) : <EOL> super ( CarbonTabletCanvas , self ) . __init__ ( window ) <EOL> for funcname in dir ( self ) : <EOL> func = getattr ( self , funcname ) <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> window . _install_event_handler ( func ) <EOL> self . _cursors = { } <EOL> self . _cursor = None <EOL> def close ( self ) : <EOL> pass <EOL> def _get_cursor ( self , proximity_rec ) : <EOL> key = ( proximity_rec . vendorID , <EOL> proximity_rec . tabletID , <EOL> proximity_rec . pointerID , <EOL> proximity_rec . deviceID , <EOL> proximity_rec . systemTabletID , <EOL> proximity_rec . vendorPointerType , <EOL> proximity_rec . pointerSerialNumber , <EOL> proximity_rec . uniqueID , <EOL> proximity_rec . pointerType ) <EOL> if key in self . _cursors : <EOL> cursor = self . _cursors [ key ] <EOL> else : <EOL> self . _cursors [ key ] = cursor = CarbonTabletCursor ( proximity_rec . pointerType ) <EOL> self . _cursor = cursor <EOL> return cursor <EOL> @ CarbonEventHandler ( kEventClassTablet , kEventTabletProximity ) <EOL> @ CarbonEventHandler ( kEventClassTablet , kEventTabletPoint ) <EOL> @ CarbonEventHandler ( kEventClassMouse , kEventMouseDragged ) <EOL> @ CarbonEventHandler ( kEventClassMouse , kEventMouseDown ) <EOL> @ CarbonEventHandler ( kEventClassMouse , kEventMouseUp ) <EOL> @ CarbonEventHandler ( kEventClassMouse , kEventMouseMoved ) <EOL> def _tablet_event ( self , next_handler , ev , data ) : <EOL> '''<STR_LIT>''' <EOL> event_type = ctypes . c_uint32 ( ) <EOL> r = carbon . GetEventParameter ( ev , kEventParamTabletEventType , <EOL> typeUInt32 , None , <EOL> ctypes . sizeof ( event_type ) , None , <EOL> ctypes . byref ( event_type ) ) <EOL> if r != noErr : <EOL> return False <EOL> if event_type . value == kEventTabletProximity : <EOL> proximity_rec = TabletProximityRec ( ) <EOL> _oscheck ( <EOL> carbon . GetEventParameter ( ev , kEventParamTabletProximityRec , <EOL> typeTabletProximityRec , None , <EOL> ctypes . sizeof ( proximity_rec ) , None , <EOL> ctypes . byref ( proximity_rec ) ) <EOL> ) <EOL> cursor = self . _get_cursor ( proximity_rec ) <EOL> if proximity_rec . enterProximity : <EOL> self . dispatch_event ( '<STR_LIT>' , cursor ) <EOL> else : <EOL> self . dispatch_event ( '<STR_LIT>' , cursor ) <EOL> elif event_type . value == kEventTabletPoint : <EOL> point_rec = TabletPointRec ( ) <EOL> _oscheck ( <EOL> carbon . GetEventParameter ( ev , kEventParamTabletPointRec , <EOL> typeTabletPointRec , None , <EOL> ctypes . sizeof ( point_rec ) , None , <EOL> ctypes . byref ( point_rec ) ) <EOL> ) <EOL> x , y = self . window . _get_mouse_position ( ev ) <EOL> pressure = point_rec . pressure / float ( <NUM_LIT> ) <EOL> self . dispatch_event ( '<STR_LIT>' , self . _cursor , x , y , pressure , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> carbon . CallNextEventHandler ( next_handler , ev ) <EOL> return noErr <EOL> class CarbonTabletCursor ( TabletCursor ) : <EOL> def __init__ ( self , cursor_type ) : <EOL> if cursor_type == <NUM_LIT:1> : <EOL> name = '<STR_LIT>' <EOL> elif cursor_type == <NUM_LIT:3> : <EOL> name = '<STR_LIT>' <EOL> super ( CarbonTabletCursor , self ) . __init__ ( name ) <EOL> def get_tablets ( display = None ) : <EOL> return [ _carbon_tablet ] </s>
