<s> '''<STR_LIT>''' <EOL> import os <EOL> from ctypes import cdll , Structure , c_ulong , c_int , c_ushort , c_void_p , pointer , POINTER , byref <EOL> libmtdev = cdll . LoadLibrary ( '<STR_LIT>' ) <EOL> MTDEV_CODE_SLOT = <NUM_LIT> <EOL> MTDEV_CODE_TOUCH_MAJOR = <NUM_LIT> <EOL> MTDEV_CODE_TOUCH_MINOR = <NUM_LIT> <EOL> MTDEV_CODE_WIDTH_MAJOR = <NUM_LIT> <EOL> MTDEV_CODE_WIDTH_MINOR = <NUM_LIT> <EOL> MTDEV_CODE_ORIENTATION = <NUM_LIT> <EOL> MTDEV_CODE_POSITION_X = <NUM_LIT> <EOL> MTDEV_CODE_POSITION_Y = <NUM_LIT> <EOL> MTDEV_CODE_TOOL_TYPE = <NUM_LIT> <EOL> MTDEV_CODE_BLOB_ID = <NUM_LIT> <EOL> MTDEV_CODE_TRACKING_ID = <NUM_LIT> <EOL> MTDEV_CODE_PRESSURE = <NUM_LIT> <EOL> MTDEV_CODE_ABS_X = <NUM_LIT> <EOL> MTDEV_CODE_ABS_Y = <NUM_LIT> <EOL> MTDEV_CODE_ABS_Z = <NUM_LIT> <EOL> MTDEV_CODE_BTN_DIGI = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_PEN = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_RUBBER = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_BRUSH = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_PENCIL = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_AIRBRUSH = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_FINGER = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_MOUSE = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_LENS = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOUCH = <NUM_LIT> <EOL> MTDEV_CODE_BTN_STYLUS = <NUM_LIT> <EOL> MTDEV_CODE_BTN_STYLUS2 = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_DOUBLETAP = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_TRIPLETAP = <NUM_LIT> <EOL> MTDEV_CODE_BTN_TOOL_QUADTAP = <NUM_LIT> <EOL> MTDEV_TYPE_EV_ABS = <NUM_LIT> <EOL> MTDEV_TYPE_EV_SYN = <NUM_LIT> <EOL> MTDEV_TYPE_EV_KEY = <NUM_LIT> <EOL> MTDEV_TYPE_EV_REL = <NUM_LIT> <EOL> MTDEV_TYPE_EV_ABS = <NUM_LIT> <EOL> MTDEV_TYPE_EV_MSC = <NUM_LIT> <EOL> MTDEV_TYPE_EV_SW = <NUM_LIT> <EOL> MTDEV_TYPE_EV_LED = <NUM_LIT> <EOL> MTDEV_TYPE_EV_SND = <NUM_LIT> <EOL> MTDEV_TYPE_EV_REP = <NUM_LIT> <EOL> MTDEV_TYPE_EV_FF = <NUM_LIT> <EOL> MTDEV_TYPE_EV_PWR = <NUM_LIT> <EOL> MTDEV_TYPE_EV_FF_STATUS = <NUM_LIT> <EOL> MTDEV_ABS_TRACKING_ID = <NUM_LIT:9> <EOL> MTDEV_ABS_POSITION_X = <NUM_LIT:5> <EOL> MTDEV_ABS_POSITION_Y = <NUM_LIT:6> <EOL> MTDEV_ABS_TOUCH_MAJOR = <NUM_LIT:0> <EOL> MTDEV_ABS_TOUCH_MINOR = <NUM_LIT:1> <EOL> MTDEV_ABS_WIDTH_MAJOR = <NUM_LIT:2> <EOL> MTDEV_ABS_WIDTH_MINOR = <NUM_LIT:3> <EOL> MTDEV_ABS_ORIENTATION = <NUM_LIT:4> <EOL> MTDEV_ABS_SIZE = <NUM_LIT:11> <EOL> class timeval ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_ulong ) , <EOL> ( '<STR_LIT>' , c_ulong ) <EOL> ] <EOL> class input_event ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT:time>' , timeval ) , <EOL> ( '<STR_LIT:type>' , c_ushort ) , <EOL> ( '<STR_LIT:code>' , c_ushort ) , <EOL> ( '<STR_LIT:value>' , c_int ) <EOL> ] <EOL> class input_absinfo ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT:value>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) <EOL> ] <EOL> class mtdev_caps ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int ) , <EOL> ( '<STR_LIT>' , c_int * MTDEV_ABS_SIZE ) , <EOL> ( '<STR_LIT>' , input_absinfo ) , <EOL> ( '<STR_LIT>' , input_absinfo * MTDEV_ABS_SIZE ) <EOL> ] <EOL> class mtdev ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , mtdev_caps ) , <EOL> ( '<STR_LIT:state>' , c_void_p ) <EOL> ] <EOL> mtdev_open = libmtdev . mtdev_open <EOL> mtdev_open . argtypes = [ POINTER ( mtdev ) , c_int ] <EOL> mtdev_get = libmtdev . mtdev_get <EOL> mtdev_get . argtypes = [ POINTER ( mtdev ) , c_int , POINTER ( input_event ) , c_int ] <EOL> mtdev_idle = libmtdev . mtdev_idle <EOL> mtdev_idle . argtypes = [ POINTER ( mtdev ) , c_int , c_int ] <EOL> mtdev_close = libmtdev . mtdev_close <EOL> mtdev_close . argtypes = [ POINTER ( mtdev ) ] <EOL> class Device : <EOL> def __init__ ( self , filename ) : <EOL> self . _filename = filename <EOL> self . _fd = - <NUM_LIT:1> <EOL> self . _device = mtdev ( ) <EOL> self . _fd = os . open ( filename , os . O_NONBLOCK | os . O_RDONLY ) <EOL> ret = mtdev_open ( pointer ( self . _device ) , self . _fd ) <EOL> if ret != <NUM_LIT:0> : <EOL> os . close ( self . _fd ) <EOL> self . _fd = - <NUM_LIT:1> <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def close ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> return <EOL> mtdev_close ( POINTER ( self . _device ) ) <EOL> os . close ( self . _fd ) <EOL> self . _fd = - <NUM_LIT:1> <EOL> def idle ( self , ms ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return bool ( mtdev_idle ( pointer ( self . _device ) , self . _fd , ms ) ) <EOL> def get ( self ) : <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> ev = input_event ( ) <EOL> if mtdev_get ( pointer ( self . _device ) , self . _fd , byref ( ev ) , <NUM_LIT:1> ) <= <NUM_LIT:0> : <EOL> return None <EOL> return ev <EOL> def has_mtdata ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return bool ( self . _device . caps . has_mtdata ) <EOL> def has_slot ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> return bool ( self . _device . caps . has_slot ) <EOL> def has_abs ( self , index ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if index < <NUM_LIT:0> or index >= MTDEV_ABS_SIZE : <EOL> raise IndexError ( '<STR_LIT>' ) <EOL> return bool ( self . _device . caps . has_abs [ index ] ) <EOL> def get_max_abs ( self ) : <EOL> '''<STR_LIT>''' <EOL> return MTDEV_ABS_SIZE <EOL> def get_slot ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if self . _device . caps . has_slot == <NUM_LIT:0> : <EOL> return <EOL> return self . _device . caps . slot <EOL> def get_abs ( self , index ) : <EOL> '''<STR_LIT>''' <EOL> if self . _fd == - <NUM_LIT:1> : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> if index < <NUM_LIT:0> or index >= MTDEV_ABS_SIZE : <EOL> raise IndexError ( '<STR_LIT>' ) <EOL> return self . _device . caps . abs [ index ] </s>
