<s> '''<STR_LIT:U+0020>''' <EOL> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> import pyglet <EOL> from pyglet . input . base import Tablet , TabletCanvas , TabletCursor , DeviceOpenException <EOL> from pyglet . input . x11_xinput import get_devices , XInputWindowEventDispatcher , DeviceResponder <EOL> try : <EOL> from pyglet . libs . x11 import xinput as xi <EOL> _have_xinput = True <EOL> except : <EOL> _have_xinput = False <EOL> class XInputTablet ( Tablet ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , cursors ) : <EOL> self . cursors = cursors <EOL> def open ( self , window ) : <EOL> return XInputTabletCanvas ( window , self . cursors ) <EOL> class XInputTabletCanvas ( DeviceResponder , TabletCanvas ) : <EOL> def __init__ ( self , window , cursors ) : <EOL> super ( XInputTabletCanvas , self ) . __init__ ( window ) <EOL> self . cursors = cursors <EOL> dispatcher = XInputWindowEventDispatcher . get_dispatcher ( window ) <EOL> self . display = window . display <EOL> self . _open_devices = [ ] <EOL> self . _cursor_map = { } <EOL> for cursor in cursors : <EOL> device = cursor . device <EOL> device_id = device . _device_id <EOL> self . _cursor_map [ device_id ] = cursor <EOL> cursor . max_pressure = device . axes [ <NUM_LIT:2> ] . max <EOL> if self . display . _display != device . display . _display : <EOL> raise DeviceOpenException ( '<STR_LIT>' ) <EOL> open_device = xi . XOpenDevice ( device . display . _display , device_id ) <EOL> if not open_device : <EOL> continue <EOL> self . _open_devices . append ( open_device ) <EOL> dispatcher . open_device ( device_id , open_device , self ) <EOL> def close ( self ) : <EOL> for device in self . _open_devices : <EOL> xi . XCloseDevice ( self . display . _display , device ) <EOL> def _motion ( self , e ) : <EOL> cursor = self . _cursor_map . get ( e . deviceid ) <EOL> x = e . x <EOL> y = self . window . height - e . y <EOL> pressure = e . axis_data [ <NUM_LIT:2> ] / float ( cursor . max_pressure ) <EOL> self . dispatch_event ( '<STR_LIT>' , cursor , x , y , pressure , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) <EOL> def _proximity_in ( self , e ) : <EOL> cursor = self . _cursor_map . get ( e . deviceid ) <EOL> self . dispatch_event ( '<STR_LIT>' , cursor ) <EOL> def _proximity_out ( self , e ) : <EOL> cursor = self . _cursor_map . get ( e . deviceid ) <EOL> self . dispatch_event ( '<STR_LIT>' , cursor ) <EOL> class XInputTabletCursor ( TabletCursor ) : <EOL> def __init__ ( self , device ) : <EOL> super ( XInputTabletCursor , self ) . __init__ ( device . name ) <EOL> self . device = device <EOL> def get_tablets ( display = None ) : <EOL> cursors = [ ] <EOL> devices = get_devices ( display ) <EOL> for device in devices : <EOL> if device . name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) and len ( device . axes ) >= <NUM_LIT:3> : <EOL> cursors . append ( XInputTabletCursor ( device ) ) <EOL> if cursors : <EOL> return [ XInputTablet ( cursors ) ] <EOL> return [ ] </s>
