a
    ij6                  
   @   s&  d Z ddlmZmZmZ ejZddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZ ddlZddlZddlZddlZe	jZejZddlmZmZ e
dZejd	kr:ed
 edejZe	jde	jjde eje ej!egdddZ"e	jde	jjejej!egdddZ#e	jde	jjejedejegdddZ$ndZ"e"rpddlZeej%Z&dd Z'dd Z(dd Z)n.e	j*dede eje ej!fdde+ddZ'e,eddZ-G d d! d!e.Z/G d"d# d#e/Z0G d$d% d%e.Z1e1j)Z)e1j2Z2e/d&ejejfd'Z3e/d(ejejfd)Z4e/d*d+d+Z5e/d,ejfd-Z6e/d.d+d+Z7e/d/ej8ejejejfd0Z9e/d1ej:ejejfd2Z;e/d3ej:ejejfd2Z<e/d4ejejejfd5Z=e/d6ejfd7Z>e/d8ejejfd9Z?e/d:ejejejejfd;Z@e/d<d+d+ZAe/d=ejejfd9ZBe/d>ejejfd?ZCe/d@ejejfd'ZDe/dAejejejfdBZEe/dCejejejfdBZFe/dDejejejfd2ZGe/dEejejejfd2ZHe/dFejejejejfd;ZIe/dFejejejejfd;ZIe/dGejejfd9ZJe/dHejfd-ZKe/dIejfd-ZLe0dJejfdKZMdLaNdMd ZOejOeO_PdNd ZQejQeQ_PdS )Oa  GLUT functions requiring special handling to provide Pythonic wrappers

Note:
    GLUT callbacks are controlled by a flag in the platform module.  The
    GLUT_GUARD_CALLBACKS flag controls whether to wrap passed functions
    with error-checking and context-validity checking code so that the
    callbacks will only trigger if there is a valid context.  This is done
    so that systems such as Win32 will not continue running GLUT callbacks
    after the system has exited.

    Note:
        This is not a problem with FreeGLUT on Linux, so Linux does not
        add the extra overhead of the wrapper function.
    Note:
        This hack does *not* prevent hanging if there is no GLUT callback
        being triggered.  I.e. if you create a GLUT program that doesn't
        explicitly call exit and doesn't call display or the like in a timer
        then your app will hang on exit on Win32.

XXX the platform-specific stuff should be getting done in the 
platform module *not* in the module here!
    )CurrentContextIsValidGLUT_GUARD_CALLBACKSPLATFORM)contextdataerrorplatformlogs)GLUT)bytesunicodeas_8_bitN)longinteger_typeszOpenGL.GLUT.specialntz0Using NT-specific GLUT calls with exit callbacks__glutInitWithExitz@glutInit( POINTER(c_int)(pargc), POINTER(STRING)(argv) ) -> NoneZpargcargv)Zdll
resultTypeargTypesdocargNames__glutCreateWindowWithExitz*glutCreateWindow( STRING(title) ) -> c_inttitle__glutCreateMenuWithExitz?glutCreateMenu( FUNCTION_TYPE(None, c_int)(callback) ) -> c_intcallbackc                 C   s   t | |tS )z9Overrides base glut init with exit-function-aware version)r   	_exitfuncr    r   Q/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/GLUT/special.py_base_glutInit@   s    r    c                 C   s
   t | tS )zCreate window with given title
        
        This is the Win32-specific version that handles
        registration of an exit-function handler 
        )r   r   r   r   r   r   glutCreateWindowC   s    r!   c                 C   s
   t | tS )zCreate menu with given callback 
        
        This is the Win32-specific version that handles 
        registration of an exit-function callback.
        )r   r   r   r   r   r   glutCreateMenuJ   s    r"   glutInitzInitialize the GLUT library)Zargcpr   )r   r   r   r   moduleZerror_checkerglutDestroyWindowc                   @   s$   e Zd ZdZdd ZdZdd ZdS )GLUTCallbackz7Class implementing GLUT Callback registration functionsc              
      s   | _ dd  dd fddt||D f | _zttd | _W n6 ty } zfdd	}|| _W Y d
}~n
d
}~0 0 td
g|R  | _	df | _
d
S )z%Initialise the glut callback instancec                 S   s   d| S )Nz(int) %sr   )typnamer   r   r   describee   s    z'GLUTCallback.__init__.<locals>.describezMSpecify handler for GLUT %r events
    def handler( %s ):
        return Nonez, c                    s   g | ]\}} ||qS r   r   ).0r'   r(   )r)   r   r   
<listcomp>i   s   z)GLUTCallback.__init__.<locals>.<listcomp>
glut%sFuncc                     s&   ddl m} |d d  f d S )Nr   )r   zFUndefined GLUT callback function %s, check for bool(%s) before callingr,   )OpenGLr   ZNullFunctionError)argsnamedr   )typeNamer   r   failFunctionp   s    z+GLUTCallback.__init__.<locals>.failFunctionN)r0   joinzip__doc__getattrr	   wrappedOperationAttributeErrorFUNCTION_TYPEcallbackTypeCONTEXT_DATA_KEY)selfr0   ZparameterTypesZparameterNameserrr1   r   )r)   r0   r   __init__b   s    zGLUTCallback.__init__)functionc                    sd   t r"t dr" fdd}|}n }t|dr<|}n }tj| j|g|R   |S )N__call__c                     sv   zt  std | i |W S  typ } z:t  tjdj | ||f  t	
d W Y d}~n
d}~0 0 dS )z0Safe calling of GUI callbacks, exits on failureszNo valid context!z9GLUT %s callback %s with %s,%s failed: returning None %s
   N)r   RuntimeError	Exception	traceback	print_excsysstderrwriter0   os_exit)r.   r/   r<   r>   r;   r   r   safeCall}   s    z'GLUTCallback.__call__.<locals>.safeCall)r   hasattrr9   r   setValuer:   r6   )r;   r>   r.   rK   ZfinalFunction	cCallbackr   rJ   r   r?   {   s    
zGLUTCallback.__call__N)__name__
__module____qualname__r4   r=   r   r?   r   r   r   r   r&   `   s   r&   c                   @   s   e Zd ZdZdd ZdS )GLUTTimerCallbackzFGLUT timer callbacks (completely nonstandard wrt other GLUT callbacks)c                    sn    }tj  d u r0g  tj   fdd }|_ | ||| |S )Nc              
      s   zD|  W  D ]"}|j u r | d |_  q4q stj n: D ]"}|j u rJ | d |_  qnqJ s~tj 0 d S )N)r>   remover   delValuer:   )valueitem	callbacks
deregisterr>   r;   r   r   rY      s     




z.GLUTTimerCallback.__call__.<locals>.deregister)r9   r   ZgetValuer:   rM   r>   appendr6   )r;   Zmillisecondsr>   rU   rN   r   rW   r   r?      s    


zGLUTTimerCallback.__call__N)rO   rP   rQ   r4   r?   r   r   r   r   rR      s   rR   c                   @   sN   e Zd ZdZeejejZdd Zdge_	e
eZdd Zdge_	e
eZdS )	GLUTMenuCallbackz8Place to collect the GLUT Menu manipulation special codec                 C   s,   |  |}t|}td|f||f |S )a  Create a new (current) menu, return small integer identifier
        
        func( int ) -- Function taking a single integer reflecting
            the user's choice, the value passed to glutAddMenuEntry
        
        return menuID (small integer)
        menucallback)r9   _simpler"   r   rM   )clsfuncrN   menur   r   r   r"      s    

zGLUTMenuCallback.glutCreateMenur_   c                 C   s   t |}td|f |S )zDestroy (cleanup) the given menu
        
        Deregister's the interal pointer to the menu callback 
        
        returns None
        r\   )r]   glutDestroyMenur   rT   )r^   r`   resultr   r   r   ra      s    
z GLUTMenuCallback.glutDestroyMenur`   N)rO   rP   rQ   r4   r8   ctypesc_intr9   r"   r   classmethodra   r   r   r   r   r[      s   
r[   Z	ButtonBox)buttonstateZDials)ZdialrU   ZDisplayr   ZEntry)rg   IdleZJoystick)Z
buttonMaskxyzZKeyboard)keyri   rj   Z
KeyboardUpZ
MenuStatus)statusri   rj   Z	MenuState)rm   ZMotion)ri   rj   ZMouse)rf   rg   ri   rj   ZOverlayDisplayZPassiveMotionZReshape)widthheightZSpaceballButtonZSpaceballMotion)ri   rj   rk   ZSpaceballRotateSpecialZ	SpecialUpZTabletButtonZTabletMotionZ
VisibilityZWindowStatusTimer)rU   Fc               	      s>  t r| S da | r| d | dd  }} d}t|tr\|}|t| krtd|t| | f qt|ttfr~|f|  } t| }q|} t| }nd}g } dd | D } |sdtdg }} tj	t|    t
| D ]\}}| |< qt|}ddl}| }ztt|  W || n|| 0  fd	dt|jD S )
zInitialise the GLUT libraryTr   r@   NzDSpecified count of %s does not match length (%s) of argument list %sc                 S   s   g | ]}t |qS r   )r   )r*   ri   r   r   r   r+   B      zglutInit.<locals>.<listcomp>Zfooc                    s   g | ]} | qS r   r   )r*   iZholderr   r   r+   P  s   )INITIALIZED
isinstancer   len
ValueErrorr
   r   r   rc   c_char_p	enumeraterd   rH   getcwdr    ZbyrefchdirrangerU   )r.   argcountrs   rH   ZcurrentDirectoryr   rt   r   r#   (  sD    








c              
   C   sn   d}z.t |  t }t|}td| | W n2 tyd } ztd| | W Y d}~n
d}~0 0 t	| S )z9Want to destroy the window, we need to do some cleanup...r   z*Cleaning up context data for window %s: %sz@Error attempting to clean up context data for GLUT window %s: %sN)
r	   ZglutSetWindowr   Z
getContextZcleanupContext_loginforB   r   _base_glutDestroyWindow)Zwindowcontextrb   r<   r   r   r   r%   U  s    

$)Rr4   ZOpenGL.platformr   r   r   r	   r-   r   r   r   r   Z
OpenGL.rawr]   ZOpenGL._bytesr
   r   r   rc   rH   rE   rC   ZCALLBACK_FUNCTION_TYPEr8   r   r   ZgetLogr   r(   r   rd   Z_exitfunctypeZcreateBaseFunctionZPOINTERry   r   r   r   exitr   r    r!   r"   ZnullFunctionrO   r5   r   objectr&   rR   r[   ra   ZglutButtonBoxFuncZglutDialsFuncZglutDisplayFuncZglutEntryFuncZglutIdleFuncZc_uintZglutJoystickFuncZc_charZglutKeyboardFuncZglutKeyboardUpFuncZglutMenuStatusFuncZglutMenuStateFuncZglutMotionFuncZglutMouseFuncZglutOverlayDisplayFuncZglutPassiveMotionFuncZglutReshapeFuncZglutSpaceballButtonFuncZglutSpaceballMotionFuncZglutSpaceballRotateFuncZglutSpecialFuncZglutSpecialUpFuncZglutTabletButtonFuncZglutTabletMotionFuncZglutVisibilityFuncZglutWindowStatusFuncZglutTimerFuncru   r#   r6   r%   r   r   r   r   <module>   s   




6




+