
    _e6              
          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
j2                  d      Zej6                  d	k(  rej9                  d
        edej:                        Z e	j>                  de	j                  j
                  d ej@                  ej:                         ej@                  ejB                        egdd      Z" e	j>                  de	j                  j
                  ej:                  ejB                  egdd      Z# e	j>                  de	j                  j
                  ej:                   edej:                        egdd      Z$ndZ"e"r ddlZ eejJ                        Z&d Z'd Z(d Z)nP e	jT                  ded ej@                  ej:                         ej@                  ejB                        fdde+d      Z' e,edd      Z- G d de.      Z/ G d d e/      Z0 G d! d"e.      Z1e1jR                  Z)e1jd                  Z2 e/d#ej:                  ej:                  fd$      Z3 e/d%ej:                  ej:                  fd&      Z4 e/d'd(d(      Z5 e/d)ej:                  fd*      Z6 e/d+d(d(      Z7 e/d,ejp                  ej:                  ej:                  ej:                  fd-      Z9 e/d.ejt                  ej:                  ej:                  fd/      Z; e/d0ejt                  ej:                  ej:                  fd/      Z< e/d1ej:                  ej:                  ej:                  fd2      Z= e/d3ej:                  fd4      Z> e/d5ej:                  ej:                  fd6      Z? e/d7ej:                  ej:                  ej:                  ej:                  fd8      Z@ e/d9d(d(      ZA e/d:ej:                  ej:                  fd6      ZB e/d;ej:                  ej:                  fd<      ZC e/d=ej:                  ej:                  fd$      ZD e/d>ej:                  ej:                  ej:                  fd?      ZE e/d@ej:                  ej:                  ej:                  fd?      ZF e/dAej:                  ej:                  ej:                  fd/      ZG e/dBej:                  ej:                  ej:                  fd/      ZH e/dCej:                  ej:                  ej:                  ej:                  fd8      ZI e/dCej:                  ej:                  ej:                  ej:                  fd8      ZI e/dDej:                  ej:                  fd6      ZJ e/dEej:                  fd*      ZK e/dFej:                  fd*      ZL e0dGej:                  fdH      ZMdIaNdJ ZOej                  eO_P        dK ZQej                  eQ_P        y)La  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pargcargv)dll
resultTypeargTypesdocargNames__glutCreateWindowWithExitz*glutCreateWindow( STRING(title) ) -> c_inttitle__glutCreateMenuWithExitz?glutCreateMenu( FUNCTION_TYPE(None, c_int)(callback) ) -> c_intcallbackc                 $    t        | |t              S )z9Overrides base glut init with exit-function-aware version)r   	_exitfuncr   s     5/usr/lib/python3/dist-packages/OpenGL/GLUT/special.py_base_glutInitr#   @   s    !%y99    c                 "    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   s    r"   glutCreateWindowr&   C   s     *%;;r$   c                 "    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   s    r"   glutCreateMenur(   J   s     ()<<r$   glutInitzInitialize the GLUT library)argcpr   )r   r   r   r   moduleerror_checkerglutDestroyWindowc                        e Zd ZdZd ZdZd Zy)GLUTCallbackz7Class implementing GLUT Callback registration functionsc                 V   | _         d }dddj                  t        ||      D cg c]  \  }} |||       c}}      d| _        	 t	        t
        dz        | _        t        dg| | _	        d	d
| _
        yc c}}w # t        $ r}fd}|| _        Y d}~=d}~ww xY w)z%Initialise the glut callback instancec                     d|z  S )Nz(int) %s )typnames     r"   describez'GLUTCallback.__init__.<locals>.describee   s    t$$r$   zSpecify handler for GLUT z events
    def handler( z, z ):
        return None
glut%sFuncc                  H    ddl m}  |j                  dddz  d      )Nr   )r   z!Undefined GLUT callback function z, check for bool(r6   z) before calling)OpenGLr   NullFunctionError)argsnamedr   typeNames      r"   failFunctionz+GLUTCallback.__init__.<locals>.failFunctionp   s*    (-e-- ,"9 r$   NglutFunc)r<   joinzip__doc__getattrr
   wrappedOperationAttributeErrorFUNCTION_TYPEcallbackTypeCONTEXT_DATA_KEY)	selfr<   parameterTypesparameterNamesr5   r3   r4   errr=   s	    `       r"   __init__zGLUTCallback.__init__b   s     	% "499!>>C.
T c$ .
 $
	1$+T<3J$LD! *4B.B.6 9!.
  	1 %1D!!	1s   BB	 		B(B##B()functionc                      t         rt        d      r	 fd}|}n}t        |d      r j                  |      }n}t        j                   j
                  |         j                  |g|  |S )N__call__c                  0   	 t               st        d       | i |S # t        $ rl}t        j                          t
        j                  j                  dj                  dd| d|d|d       t        j                  d       Y d	}~y	d	}~ww xY w)
z0Safe calling of GUI callbacks, exits on failureszNo valid context!zGLUT z
 callback z with ,z failed: returning None 
   N)r   RuntimeError	Exception	traceback	print_excsysstderrwriter<   os_exit)r:   r;   rL   rN   rI   s      r"   safeCallz'GLUTCallback.__call__.<locals>.safeCall}   s{    	 02*,CEE#d5e55   '')JJ$$xuc'  HHQKK s     	BA"BB)r   hasattrrG   r   setValuerH   rD   )rI   rN   r:   r^   finalFunction	cCallbacks   ``    r"   rP   zGLUTCallback.__call__{   sr    GXj$B  %M$MM*.))=:I I 	d33Y@y141r$   N)__name__
__module____qualname__rB   rM   r   rP   r2   r$   r"   r/   r/   `   s    A:0 Hr$   r/   c                       e Zd ZdZd Zy)GLUTTimerCallbackzFGLUT timer callbacks (completely nonstandard wrt other GLUT callbacks)c                 >     j                        }t        j                   j                        "g t        j                   j                          fd j                        }|_        j                  |        j                  |||       |S )Nc                 f   	  |        D ]*  }|j                   u sj                  |       d |_          n s t        j                  j                         y y # D ]*  }|j                   u sj                  |       d |_          n s t        j                  j                         w w xY w)N)rN   remover   delValuerH   )valueitem	callbacks
deregisterrN   rI   s     r"   ro   z.GLUTTimerCallback.__call__.<locals>.deregister   s    	B%!% D}}
2!(($0(,	
 !(($*?*?A ! & D}}
2!(($0(,	
 !(($*?*?A !s   A B02>B0)rG   r   getValuerH   r`   rN   appendrD   )rI   millisecondsrN   rl   rb   rn   ro   s   ` `  @@r"   rP   zGLUTTimerCallback.__call__   s    %%x1	
  (($*?*?A	I  $"7"7D
	B %%z3	'	)%|Y?r$   N)rc   rd   re   rB   rP   r2   r$   r"   rg   rg      s
    Pr$   rg   c                       e Zd ZdZ eej                  ej                        Zd Zdge_	         e
e      Zd Zdge_	         e
e      Zy)GLUTMenuCallbackz8Place to collect the GLUT Menu manipulation special codec                     | j                  |      }t        j                  |      }t        j                  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)rG   _simpler(   r   r`   )clsfuncrb   menus       r"   r(   zGLUTMenuCallback.glutCreateMenu   sC     $$d,	%%y2~d3i5EGr$   ry   c                 ^    t        j                  |      }t        j                  d|f       |S )zDestroy (cleanup) the given menu
        
        Deregister's the interal pointer to the menu callback 
        
        returns None
        rv   )rw   glutDestroyMenur   rk   )rx   rz   results      r"   r|   z GLUTMenuCallback.glutDestroyMenu   s,     (($0~d35r$   rz   N)rc   rd   re   rB   rF   ctypesc_intrG   r(   r   classmethodr|   r2   r$   r"   rt   rt      sO    B &,,>L !'jN .2N	 "(zO!?4Or$   rt   	ButtonBox)buttonstateDials)dialrl   Displayr2   Entry)r   IdleJoystick)
buttonMaskxyzKeyboard)keyr   r   
KeyboardUp
MenuStatus)statusr   r   	MenuState)r   Motion)r   r   Mouse)r   r   r   r   OverlayDisplayPassiveMotionReshape)widthheightSpaceballButtonSpaceballMotion)r   r   r   SpaceballRotateSpecial	SpecialUpTabletButtonTabletMotion
VisibilityWindowStatusTimer)rl   Fc                  &   t         r| S da | r| d   | dd } }d}t        |t              r-|}|t        |       k7  rWt	        d|dt        |       d|       t        |t
        t        f      r|f| z   } t        |       }n|} t        |       }nd}g } | D cg c]  }t        |       } }|sdt        d      g} }t        j                  t        |       z         }t        |       D ]
  \  }}|||<    t        j                  |      }ddl} |j                         }	 t        t        j                  |      |        |j                   |       t#        |j$                        D cg c]  }||   	 c}S c c}w #  |j                   |       w xY wc c}w )	zInitialise the GLUT libraryTr   rT   NzSpecified count of z does not match length (z) of argument list foo)INITIALIZED
isinstancer   len
ValueErrorr   r   r   r~   c_char_p	enumerater   r\   getcwdr#   byrefchdirrangerl   )r:   argcountr   holderir\   currentDirectorys           r"   r)   r)   (  s    K748Dc=)ED	! 3t9d#   uWo.6$;DIEDIE!%&AHQK&D&(5/*tooD	),F4 #q	LL%!E ryy{%U+V5"$ %++/q	  ' 	"$s   E2E7 #F7Fc                 6   d}	 t         j                  |        t        j                         }t        j                  |      }t
        j                  d| |       t        |       S # t        $ r+}t
        j                  d|        Y d}~t        |       S d}~ww xY w)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
   glutSetWindowr   
getContextcleanupContext_loginforV   r   _base_glutDestroyWindow)windowcontextr}   rL   s       r"   r-   r-   U  s    Gm6"((*++W6		CVVU #F,,  m

Z\bdjll"F,,ms   AA$ $	B-BB)RrB   OpenGL.platformr   r   r   r
   r8   r   r   r   r	   
OpenGL.rawrw   OpenGL._bytesr   r   r   r~   r\   rY   rW   CALLBACK_FUNCTION_TYPErF   r   r   getLogr   r4   r   r   _exitfunctypecreateBaseFunctionPOINTERr   r   r   r   exitr!   r#   r&   r(   nullFunctionrc   rC   r   objectr/   rg   rt   r|   glutButtonBoxFuncglutDialsFuncglutDisplayFuncglutEntryFuncglutIdleFuncc_uintglutJoystickFuncc_charglutKeyboardFuncglutKeyboardUpFuncglutMenuStatusFuncglutMenuStateFuncglutMotionFuncglutMouseFuncglutOverlayDisplayFuncglutPassiveMotionFuncglutReshapeFuncglutSpaceballButtonFuncglutSpaceballMotionFuncglutSpaceballRotateFuncglutSpecialFuncglutSpecialUpFuncglutTabletButtonFuncglutTabletMotionFuncglutVisibilityFuncglutWindowStatusFuncglutTimerFuncr   r)   rD   r-   r2   r$   r"   <module>r      s  , R Q}} 5 5 & 1 1 ! !.. -t{{)+77d?IIEG!47M444("3"3"8"8T &...~v~~foo/N}]N"	 "=!<!<$(*;*;*@*@V\\//-08	"  ;x::"(9(9(>(>6<<fll3MBM	  chh'I:<= +X**D &...~v~~v/PQ+8HN "$(;TB 5F 5l :5 5< "00"22 !&,,v||,.@  fll6<<(*: r2 fll_j 
B  v||FLLFHb   v||FLL9?  "6==fll;_  "6<<V\\:<N  !&,,+  v||FLL)9 fll6<<V\\BD^ &b"  %fll6<<0)  V\\*,> 'V\\24F  'V\\&,,?  'V\\&,,?  V\\&,,7 !&,,v||FLL9?  $V\\&,,v||FLLIKf  $V\\&,,v||FLLIKf  $V\\&,,/  "6<</:  $V\\OZ 
 "fll_j *V $,, 
- &-%>%>  "r$   