
    ^j                       d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZ erddlmZ ddlmZ dd	lmZ  eed
          oej        Z G d de          Z G d de          Z G d de          Z G d dej                  Z G d d          Z G d de          Ze                    d            G d de          Z G d de          Z  G d de          Z!e!                    d           e!                    d            G d  d!e          Z"e"                    d"           e"                    d#           e"                    d$           e"                    d%            G d& d'e          Z#e#                    d(           e#                    d)           e#                    d*           e#                    d+           e#                    d,            G d- d.e          Z$e$                    d(           e$                    d)            G d/ d0          Z% G d1 d2e          Z&e&                    d3           e&                    d4           e&                    d5            G d6 d7          Z' G d8 d9e          Z(e(                    d:           e(                    d;           dS )<z=Interface classes for `pyglet.input`.

.. versionadded:: 1.2
    )annotationsN)TYPE_CHECKINGLiteral)Vec2)EventDispatcher)
BaseWindow)Display)Relationis_pyglet_doc_runc                      e Zd ZdS )DeviceExceptionN__name__
__module____qualname__     L/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/input/base.pyr   r              Dr   r   c                      e Zd ZdS )DeviceOpenExceptionNr   r   r   r   r   r      r   r   r   c                      e Zd ZdS )DeviceExclusiveExceptionNr   r   r   r   r   r       r   r   r   c                      e Zd Z ej                    Z ej                    Z ej                    Z ej                    ZdS )SignN)	r   r   r   enumautoPOSITIVENEGATIVEINVERTEDDEFAULTr   r   r   r   r   $   sB        ty{{Hty{{Hty{{HdikkGGGr   r   c                  h    e Zd ZU dZded<   dd
Zedd            ZdddZddZ	ddZ
ddZddZdS )DevicezLow level input device.bool	connecteddisplayr	   namestrreturnNonec                >    || _         || _        d| _        d| _        dS )zCreate a Device to receive input from.

        Args:
            display:
                The Display this device is connected to.
            name:
                The name of the device, as described by the device firmware.
        NF)r&   r'   manufacturer_is_open)selfr&   r'   s      r   __init__zDevice.__init__0   s'     	 )-#r   c                    | j         S Nr-   r.   s    r   is_openzDevice.is_open@   s
    }r   NFwindowNone | BaseWindow	exclusivec                @    | j         rt          d          d| _         dS )a  Open the device to begin receiving input from it.

        Args:
            window:
                Optional window to associate with the device.  The behaviour
                of this parameter is device and operating system dependent.
                It can usually be omitted for most devices.
            exclusive:
                If ``True`` the device will be opened exclusively so that no
                other application can use it.

        Raises:
            DeviceOpenException:
                If the device cannot be opened in exclusive mode, usually
                due to being opened exclusively by another application.
        zDevice is already open.TN)r-   r   r.   r5   r7   s      r   openzDevice.openD   s)    $ = 	A%&?@@@r   c                    d| _         dS )zClose the device.FNr2   r3   s    r   closezDevice.close[   s    r   list[Control]c                     t          d          )z.Get a list of controls provided by the device.abstractNotImplementedErrorr3   s    r   get_controlszDevice.get_controls_       !*---r   c                     t          d          )aI  Get the device GUID, in SDL2 format.

        Return a str containing a unique device identification
        string. This is generated from the hardware identifiers,
        and is in the same format as was popularized by SDL2.
        GUIDs differ between platforms, but are generally 32
        hexadecimal characters.
        r?   r@   r3   s    r   get_guidzDevice.get_guidc   s     "*---r   c                0    | j         j         d| j         dS N(name=)	__class__r   r'   r3   s    r   __repr__zDevice.__repr__n        .)======r   )r&   r	   r'   r(   r)   r*   r)   r$   NFr5   r6   r7   r$   r)   r*   r)   r*   )r)   r=   r)   r(   )r   r   r   __doc____annotations__r/   propertyr4   r:   r<   rB   rE   rL   r   r   r   r#   r#   +   s         !!OOO$ $ $ $     X    .   . . . .	. 	. 	. 	.> > > > > >r   r#   c                  f    e Zd ZdZddd	Zedd            Zej        dd            ZddZddZ	dS )ControlaX  Single value input provided by a device.

    A control's value can be queried when the device is open.  Event handlers
    can be attached to the control to be called when the value changes.

    The ``min`` and ``max`` properties are provided as advertised by the
    device; in some cases the control's value will be outside this range.
    NFr'   
None | strraw_nameinvertedr$   c                >    || _         || _        || _        d| _        dS )a  Create a Control to receive input.

        Args:
            name:
                The name of the control, or ``None`` if unknown.
            raw_name:
                Optional unmodified name of the control, as presented by the operating
                system; or ``None`` if unknown.
            inverted:
                If ``True``, the value reported is actually inverted from what the
                device reported; usually this is to provide consistency across
                operating systems.
        N)r'   rY   rZ   _value)r.   r'   rY   rZ   s       r   r/   zControl.__init__|   s$     	  r   r)   floatc                    | j         S )a  Current value of the control.

        The range of the value is device-dependent; for absolute controls
        the range is given by ``min`` and ``max`` (however the value may exceed
        this range); for relative controls the range is undefined.
        r\   r3   s    r   valuezControl.value   s     {r   newvaluec                Z    || j         k    rd S || _         |                     d|           d S N	on_changer\   dispatch_eventr.   ra   s     r   r`   zControl.value   s7    t{""FK22222r   r(   c                |    | j         r| j        j         d| j          d| j         dS | j        j         d| j         dS )NrH   z, raw_name=rI   z
(raw_name=)r'   rK   r   rY   r3   s    r   rL   zControl.__repr__   sS    9 	Jn-[[TY[[4=[[[[n-IIIIIIr   c                    dS )zThe value changed.Nr   r.   r`   s     r   rd   zControl.on_change         r   rO   )r'   rX   rY   rX   rZ   r$   r)   r]   )ra   r]   rR   )
r   r   r   rS   r/   rU   r`   setterrL   rd   r   r   r   rW   rW   r   s             &    X \3 3 3 \3J J J J! ! ! ! ! !r   rW   rd   c                      e Zd ZU dZdZded<   dZded<   dZded<   d	Zded
<   dZ	ded<   dZ
ded<   dZded<   edd            Zej        dd            ZdS )RelativeAxisa  An axis whose value represents a relative change from the previous value.

    This type of axis is used for controls that can scroll or move
    continuously, such as a scrolling or pointing input. The value
    is read as a delta change from the previous value.
    xr(   XyYzZrxRXryRYrzRZwheelWHEELr)   r]   c                    | j         S r1   r_   r3   s    r   r`   zRelativeAxis.value   s
    {r   r`   c                @    || _         |                     d|           d S rc   re   rj   s     r   r`   zRelativeAxis.value   s%    K/////r   Nrl   )r`   r]   )r   r   r   rS   rq   rT   rs   ru   rw   ry   r{   r}   rU   r`   rm   r   r   r   ro   ro      s           ALLLLALLLLALLLLBNNNNBNNNNBNNNNE   X \0 0 0 \0 0 0r   ro   c                       e Zd ZU dZdZded<   dZded<   dZded<   d	Zded
<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   d d! fdZ xZS )"AbsoluteAxiszAn axis whose value represents the current measurement from the device.

    This type of axis is used for controls that have minimum and maximum
    positions. The value is a range between the ``min`` and ``max``.
    rp   r(   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   hatHAThat_xHAT_Xhat_yHAT_YNFr'   minimumr]   maximumrY   rX   rZ   r$   c                j    t                                          |||           || _        || _        d S r1   )superr/   minmax)r.   r'   r   r   rY   rZ   rK   s         r   r/   zAbsoluteAxis.__init__   s1    x222r   rO   )
r'   r(   r   r]   r   r]   rY   rX   rZ   r$   )r   r   r   rS   rq   rT   rs   ru   rw   ry   r{   r   r   r   r/   __classcell__)rK   s   @r   r   r      s          
 ALLLLALLLLALLLLBNNNNBNNNNBNNNNCEE          r   r   c                  `    e Zd ZdZedd            Zej        dd            Zerd Zd	 Z	d
S d
S )Buttonz"A control whose value is boolean. r)   r$   c                *    t          | j                  S r1   )r$   r\   r3   s    r   r`   zButton.value   s    DK   r   ra   
bool | intc                    || j         k    rd S || _         |                     dt          |                     |r|                     d           d S |                     d           d S )Nrd   on_press
on_release)r\   rf   r$   rg   s     r   r`   zButton.value   ss    t{""FKh888 	.
+++++-----r   c                    dS )zThe button was pressed.Nr   r3   s    r   r   zButton.on_press   rk   r   c                    dS )zThe button was released.Nr   r3   s    r   r   zButton.on_release   rk   r   NrN   )ra   r   )
r   r   r   rS   rU   r`   rm   _is_pyglet_doc_runr   r   r   r   r   r   r      s        ,,! ! ! X! \. . . \.  +	* 	* 	*	+ 	+ 	+ 	+ 	++ +r   r   r   r   c                     e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d Zd0d1d$Zd2d%Zd3d*Zd4d,Z	d4d-Z
d5d.Zd6d/ZdS )7Joystickah  High-level interface for joystick-like devices.  This includes a wide
    range of analog and digital joysticks, gamepads, controllers, and possibly
    even steering wheels and other input devices. There is unfortunately no
    easy way to distinguish between most of these different device types.

    For a simplified subset of Joysticks, see the :py:class:`~pyglet.input.Controller`
    interface. This covers a variety of popular game console controllers. Unlike
    Joysticks, Controllers have strictly defined layouts and inputs.

    To use a joystick, first call `open`, then in your game loop examine
    the values of `x`, `y`, and so on.  These values are normalized to the
    range [-1.0, 1.0]. 

    To receive events when the value of an axis changes, attach an
    on_joyaxis_motion event handler to the joystick. The :py:class:`~pyglet.input.Joystick`
    instance, axis name, and current value are passed as parameters to this event.

    To handle button events, you should attach on_joybutton_press and on_joy_button_release
    event handlers to the joystick. Both the :py:class:`~pyglet.input.Joystick` instance
    and the index of the changed button are passed as parameters to these events.

    Alternately, you may attach event handlers to each individual button in 
    `button_controls` to receive on_press or on_release events.
    
    To use the hat switch, attach an on_joyhat_motion event handler to the joystick.
    The handler will be called with both the hat_x and hat_y values whenever the value
    of the hat switch changes.

    The device name can be queried to get the name of the joystick.
    r#   devicer]   rp   rr   rt   rv   rx   rz   intr   r   z
list[bool]buttonszNone | AbsoluteAxis	x_control	y_control	z_control
rx_control
ry_control
rz_controlhat_x_controlhat_y_controlzlist[Button]button_controlsc                &    | _         d _        d _        d _        d _        d _        d _        d _        d _        g  _	        d  _
        d  _        d  _        d  _        d  _        d  _        d  _        d  _        g  _        d
 fd}d fd}d
 fd}|                                D ]c}t)          |t*                    r,|j        dv r ||           ,|j        d	k    r ||           Ct)          |t.                    r ||           dd S )Nr   controlr   c                    | j         s&| j        st          j        d| j         d           d S | j        d| j        | j         z
  z  d| j         z  z
  | j        r  t          dz   |            | j        fd            }d S )N	Control(')') min & max values are both 0. Skipping.       @      _controlc                j    | z  z   }t          |                               d|           d S )Non_joyaxis_motionsetattrrf   )r`   normalized_valuebiasr'   scaler.   s     r   rd   z6Joystick.__init__.<locals>.add_axis.<locals>.on_changes  sG    #(5=4#7 d$4555##$7tEUVVVVVr   )r   r   warningswarnr'   rZ   r   event)r   rd   r   r'   r   r.   s     @@@r   add_axisz#Joystick.__init__.<locals>.add_axisg  s    K 7; a',aaabbb<D7;45E'+--D uD$+W555]W W W W W W W ]W W Wr   r   c                   t          j                  j                            d           j                            |            | j        fd            }| j        fd            }| j        fd            }d S )NFc                    | j         <   d S r1   )r   )r`   ir.   s    r   rd   z8Joystick.__init__.<locals>.add_button.<locals>.on_change~  s    "'Qr   c                 6                         d            d S )Non_joybutton_pressrf   r   r.   s   r   r   z7Joystick.__init__.<locals>.add_button.<locals>.on_press  s"    ##$8$BBBBBr   c                 6                         d            d S )Non_joybutton_releaser   r   s   r   r   z9Joystick.__init__.<locals>.add_button.<locals>.on_release  s"    ##$:D!DDDDDr   )lenr   appendr   r   )r   rd   r   r   r   r.   s       @r   
add_buttonz%Joystick.__init__.<locals>.add_buttony  s    DL!!AL&&& ''000]( ( ( ( ( ]( ]C C C C C ]C ]E E E E E ]E E Er   c                   | _         | _        t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          f}d t          t	          t          | j                  t          | j        dz                       |          D             | j        fd            }d S )N              ?r   c                    i | ]\  }}||	S r   r   .0keyvals      r   
<dictcomp>z6Joystick.__init__.<locals>.add_hat.<locals>.<dictcomp>  s    mmmxsC#smmmr      c                                         | t          dd                    \  _        _                            dj        j                   d S )Nr   on_joyhat_motion)getr   r   r   rf   )r`   
_input_mapr.   s    r   rd   z5Joystick.__init__.<locals>.add_hat.<locals>.on_change  sL    )3tC~~)N)N&
DJ##$6dj$*UUUUUr   )	r   r   r   zipranger   r   r   r   )r   _vecsrd   r   r.   s      @r   add_hatz"Joystick.__init__.<locals>.add_hat  s    !(D!(D#s^^T#s^^T#s^^T#t__#t__d4&6&6T3dTWZEmm3uS=M=MsSZS^abSbOcOc7d7dfk3l3lmmmJ]V V V V V ]V V Vr   )rp   rr   rt   rv   rx   rz   r   r   r   )r   r   )r   r   )r   rp   rr   rt   rv   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   rB   
isinstancer   r'   r   )r.   r   r   r   r   ctrls   `     r   r/   zJoystick.__init__P  s   

!!!	W 	W 	W 	W 	W 	W$	E 	E 	E 	E 	E 	E"	V 	V 	V 	V 	V 	V '')) 	! 	!D$-- !9 SSSHTNNNNY%''GDMMMD&)) !
4   	! 	!r   NFr5   BaseWindow | Noner7   r$   r)   r*   c                <    | j                             ||           dS )z.Open the joystick device.  See `Device.open`. Nr   r:   r9   s      r   r:   zJoystick.open       +++++r   c                8    | j                                          dS )z0Close the joystick device.  See `Device.close`. Nr   r<   r3   s    r   r<   zJoystick.close      r   joystickaxisr(   r`   c                    dS )a)  The value of a joystick axis changed.

        Args:
            joystick:
                The joystick device whose axis changed.
            axis:
                The name of the axis that changed.
            value:
                The current value of the axis, normalized to [-1, 1].
        Nr   )r.   r   r   r`   s       r   r   zJoystick.on_joyaxis_motion  rk   r   buttonc                    dS )zA button on the joystick was pressed.

        Args:
            joystick:
                The joystick device whose button was pressed.
            button:
                The index (in `button_controls`) of the button that was pressed.
        Nr   r.   r   r   s      r   r   zJoystick.on_joybutton_press  rk   r   c                    dS )zA button on the joystick was released.

        Args:
            joystick:
                The joystick device whose button was released.
            button:
                The index (in `button_controls`) of the button that was released.
        Nr   r   s      r   r   zJoystick.on_joybutton_release  rk   r   c                    dS )a  The value of the joystick hat switch changed.

        Args:
            joystick:
                The joystick device whose hat control changed.
            hat_x:
                Current hat (POV) horizontal position; one of -1.0 (left), 0.0
                (centered) or 1.0 (right).
            hat_y:
                Current hat (POV) vertical position; one of -1.0 (bottom), 0.0
                (centered) or 1.0 (top).
        Nr   )r.   r   r   r   s       r   r   zJoystick.on_joyhat_motion  rk   r   c                "    d| j         j         dS )NzJoystick(device=rI   )r   r'   r3   s    r   rL   zJoystick.__repr__  s    5$+"25555r   rO   )r5   r   r7   r$   r)   r*   rQ   )r   r   r   r(   r`   r]   )r   r   r   r   )r   r   r   r]   r   r]   rR   )r   r   r   rS   rT   r/   r:   r<   r   r   r   r   rL   r   r   r   r   r      s         > NNN HHHHHH HHH IIIIII III JJJJJJ  #""""""""""" $########### '&&&&&&& "!!!O! O! O!b, , , , ,   
 
 
 
         6 6 6 6 6 6r   r   r   r   r   r   c                      e Zd ZdZd5dZed6d	            Zd7dZd8dZd9dZ	d:dZ
d;d<dZd:dZd=d>d$Zd=d>d%Zd:d&Zd:d'Zd?d,Zd@d-ZdAd0ZdBd2ZdBd3ZdCd4ZdS )D
Controllera  High-level interface for Game Controllers.

    Unlike Joysticks, Controllers have a strictly defined set of inputs
    that matches the layout of popular home video game console Controllers.
    This includes a variety of face and shoulder buttons, analog sticks and
    triggers, a directional pad, and optional rumble (force feedback) effects.

    To use a Controller, you must first call ``open``. Controllers will then
    dispatch various events whenever the inputs change. They can also be polled
    manually at any time to find the current value of any inputs. Analog stick
    inputs are normalized to the range [-1.0, 1.0], and triggers are normalized
    to the range [0.0, 1.0]. All other inputs are digital.

    Note: A running application event loop is required

    The following event types are dispatched:
        `on_button_press`
        `on_button_release`
        `on_stick_motion`
        `on_dpad_motion`
        `on_trigger_motion`

    r   r#   mappingdictc                t   || _         || _        |                    d          | _        |                    d          | _        d| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        d| _        d| _        d| _        t%                      | _        t%                      | _        t%                      | _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        g | _        d| _        d| _        d| _         | !                                 dS )zXCreate a Controller instance mapped to a Device.

        .. versionadded:: 2.0
        r'   guidFr   N)"r   _mappingr   r'   r   abrp   rr   backstartguideleftshoulderrightshoulder	leftstick
rightsticklefttriggerrighttriggerr   dpad
leftanalogrightanalogleftxleftyrightxrightydpadxdpady_button_controls_axis_controls_hat_control_hat_x_control_hat_y_control_initialize_controls)r.   r   r   s      r   r/   zController.__init__  s'    % !V,,	 V,,	 	 
 
"'#($ %"%#&&&	 $!%

  

&($&,0.2.2!!#####r   r)   Literal['PS', 'XB', 'GENERIC']c                    d}| j         dk    rdS t          | j        d          x}rt          |d          }|dv rdS |d	v rdS d
S )uR  The type, or family, of the Controller

        This property uses a simple heuristic query to attempt
        to determine which general family the controller falls
        into. For example, the controller may have Ⓐ,Ⓑ,Ⓧ,Ⓨ,
        or ✕,○,□,△ labels on the face buttons. Using this
        information, you can choose to display matching button
        prompt images in your game. For example::

            if controller.type == 'PS':
                a_glyph = 'ps_cross_button.png'
                b_glyph = 'ps_circle_button.png'
                ...
            elif controller.type == 'XB':
                a_glyph = 'ms_a_button.png'
                b_glyph = 'ms_b_button.png'
                ...
            else:
                ...

        Returns:
            A string, currently one of "PS", "XB", or "GENERIC".
        NXINPUTCONTROLLERXB
id_productr   )base)i  PS)i^  GENERIC)r'   getattrr   r   )r.   
product_idr  s      r   typezController.type-  sp    2 
 9***4 !l;;;: 	1Za000J!!49$$4yr   relationr
   r   r   	axis_namer(   r*   c                   	 |j         s&|j        st          j        d|j         d           d S d|j        |j         z
  z  	d|j        |j         z
  z  d|j         z  z
  d|j        r  t          j        t          j        t          j        t          j        d}|j	        t          j
        |                              fvrddv r|j         fd            }d S d	v r|j         fd
            }d S dv r|j         	fd            }d S dv r|j         fd            }d S dv r|j         fd            }d S d S )Nr   r   r   r   r   )dpupdpdowndpleftdpright)r  r  c                    t          | z  z             z  _        t          j        j                  _                            dt          j        j                             d S Non_dpad_motion)roundr  r   r  r   rf   r`   r   r   r.   signs    r   rd   z0Controller._bind_axis_control.<locals>.on_changen  b    "55=4#7884?
 TZ88	##$4dDTZ<X<XYYYYYr   )r  r  c                    t          | z  z             z  _        t          j        j                  _                            dt          j        j                             d S r  )r   r  r   r  r   rf   r!  s    r   rd   z0Controller._bind_axis_control.<locals>.on_changeu  r#  r   )r   r   c                d    | z  }t          |                               d|           d S )Non_trigger_motionr   )r`   r   r  r.   tscales     r   rd   z0Controller._bind_axis_control.<locals>.on_change|  sB    #(6> i)9:::##$7yJZ[[[[[r   )r   r   c                    | z  z   }t          |           t          j        j                   _                            ddj                   d S )Non_stick_motionr   )r   r   r   r   left_analogrf   r`   r   r  r   r   r.   s     r   rd   z0Controller._bind_axis_control.<locals>.on_change  sa    #(5=4#7 i)9:::#'
TZK#@#@ ##$5t[$JZ[[[[[r   )r  r  c                    | z  z   }t          |           t          j        j                   _                            ddj                   d S )Nr)  r   )r   r   r  r  right_analogrf   r+  s     r   rd   z0Controller._bind_axis_control.<locals>.on_change  sa    #(5=4#7 i)9:::$(t{l$C$C!##$5t\4K\]]]]]r   )r   r   r   r   r'   rZ   r   r   r   r"  r!   r   r   )
r.   r  r   r  dpad_defaultsrd   r   r   r"  r'  s
   `  `  @@@@r   _bind_axis_controlzController._bind_axis_controlX  s    	w{ 	M]gl]]]^^^Fgk12w{W[01gkE)) 	FE5D "&$-#'=T]L L =}/@/@/K/K LLLD***]Z Z Z Z Z Z Z ]Z Z Z
 ///]Z Z Z Z Z Z Z ]Z Z Z
 999]\ \ \ \ \ \ ]\ \ \
 ,,,]\ \ \ \ \ \ \ ]\ \ \ ...]^ ^ ^ ^ ^ ^ ^ ]^ ^ ^ /.r   r   button_namec                     dv rddddd|j          fd            }d S |j          fd            }|j          fd	            }|j          fd
            }d S )N)r  r  r  r  )r  r   )r  r   )r  r   )r  r   )r  r  r  r  c                             \  }}t          ||| z             t          j        j                  _                            dj                   d S r  )r   r   r  r  r   rf   )r`   targetr   r0  defaultsr.   s      r   rd   z2Controller._bind_button_control.<locals>.on_change  s]    '4fdUl333 TZ88	##$4dDIFFFFFr   c                *    t          |            d S r1   )r   )r`   r0  r.   s    r   rd   z2Controller._bind_button_control.<locals>.on_change  s    k511111r   c                 6                         d            d S Non_button_pressr   r0  r.   s   r   r   z1Controller._bind_button_control.<locals>.on_press  s"    ##$5t[IIIIIr   c                 6                         d            d S Non_button_releaser   r9  s   r   r   z3Controller._bind_button_control.<locals>.on_release  s"    ##$7{KKKKKr   )r   )r.   r  r   r0  rd   r   r   r4  s   `  `   @r   _bind_button_controlzController._bind_button_control  s	   AAA"1n"1>K KH ]G G G G G G ]G G G ]2 2 2 2 2 ]2 ]J J J J J ]J ]L L L L L ]L L Lr   c                    t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          t          dd          f}d t          t          t          |j                  t          |j        dz                       |          D             |j        dk    rdnd|j         fd            }d S )	Nr   r   r   c                    i | ]\  }}||	S r   r   r   s      r   r   z2Controller._bind_dedicated_hat.<locals>.<dictcomp>  s    iii83c3iiir   r      i  c                                         | z  t          dd                    }|_                            d|           d S )Nr   r  )r   r   r   rf   )r`   vectorr   _scaler.   s     r   rd   z1Controller._bind_dedicated_hat.<locals>.on_change  sH    ^^EVOT#s^^DDFDI 0$?????r   )r   r   r   r   r   r   r   )r.   r  r   r   rd   r   rC  s   `    @@r   _bind_dedicated_hatzController._bind_dedicated_hat  s    c3c3c3c4c4$tT"2"2DsOOT$PS__Viis5W[9I9I3w{]^K_K_3`3`bg/h/hiii
 "+//q		@ 	@ 	@ 	@ 	@ 	@ 
	@ 	@ 	@r   c           	     
   | j                                         D ]}t          |t                    r| j                            |           2t          |t                    rS|j        dk    r|| _        Z|j        dk    r|| _	        m|j        dk    r|| _
        | j                            |           | j                                        D ]3\  }}|t          |t                    r	 |j        dk    r(|                     || j        |j                 |           n|j        dk    r(|                     || j        |j                 |           nv|j        dk    rk| j
        r|                     || j
                   nH| j	        df| j        d	f| j	        d
f| j        dfd|j                 \  }}|                     |||           # t(          t*          t,          f$ r t/          j        d| d| d           Y 1w xY wdS )zInitialize and bind the Device Controls

        This method first categorizes all the Device Controls,
        then binds them to the appropriate "virtual" controls
        as defined in the mapped relations.
        r   r   r   Nr   r   hat0r  r  r  r  )r         r@  z Could not map physical Control 'z' to '')r   rB   r   r   r  r   r   r'   r  r	  r  r  r   itemsr(   control_typer=  indexr/  rD  
IndexErrorAttributeErrorKeyErrorr   r   )r.   r   r'   r  r   dpnames         r   r
  zController._initialize_controls  sY    K,,.. 	5 	5D$'' 5%,,T2222D,// 59''*.D''Y'))*.D''Y%''(,D%%'..t444"m1133 	 	ND(:h#<#<(H44--h8Mhn8]_cdddd*f44++Hd6I(.6Y[_````*f44( K004;LMMMM/3/BF.K/3/BI.N/3/BH.M/3/BH.M+O +O PX~+_
 //'6JJJ9   XXXQUXXXYYY/	 	s   -CG

2H ?H NFr5   r6   r7   r$   c                <    | j                             ||           dS )z)Open the controller.  See `Device.open`. Nr   r9   s      r   r:   zController.open  r   r   c                8    | j                                          dS )z+Close the controller.  See `Device.close`. Nr   r3   s    r   r<   zController.close  r   r   r         ?strengthr]   durationc                    dS )zPlay a rumble effect on the weak motor.

        Args:
            strength:
                The strength of the effect, from 0 to 1.
            duration:
                The duration of the effect in seconds.
        Nr   r.   rT  rU  s      r   rumble_play_weakzController.rumble_play_weak  rk   r   c                    dS )zPlay a rumble effect on the strong motor.

        Args:
            strength:
                The strength of the effect, from 0 to 1.
            duration:
                The duration of the effect in seconds.
        Nr   rW  s      r   rumble_play_strongzController.rumble_play_strong  rk   r   c                    dS )z.Stop playing rumble effects on the weak motor.Nr   r3   s    r   rumble_stop_weakzController.rumble_stop_weak  rk   r   c                    dS )z0Stop playing rumble effects on the strong motor.Nr   r3   s    r   rumble_stop_strongzController.rumble_stop_strong
  rk   r   
controllerstickrB  r   c                    dS )a|  The value of a controller analogue stick changed.

        Args:
            controller:
                The controller whose analogue stick changed.
            stick:
                The name of the stick that changed.
            vector:
                A 2D vector representing the stick position.
                Each individual axis will be normalized from [-1, 1],
        Nr   )r.   r_  r`  rB  s       r   r)  zController.on_stick_motion  rk   r   c                    dS )a'  The direction pad of the controller changed.

        Args:
            controller:
                The controller whose hat control changed.
            vector:
                A 2D vector, representing the dpad position.
                Each individual axis will be one of [-1, 0, 1].
        Nr   )r.   r_  rB  s      r   r  zController.on_dpad_motion  rk   r   triggerr`   c                    dS )aD  The value of a controller analogue stick changed.

        Args:
            controller:
                The controller whose analogue stick changed.
            trigger:
                The name of the trigger that changed.
            value:
                The current value of the trigger, normalized to [0, 1].
        Nr   )r.   r_  rc  r`   s       r   r&  zController.on_trigger_motion'  rk   r   r   c                    dS )zA button on the controller was pressed.

        Args:
            controller:
                The controller whose button was pressed.
            button:
                The name of the button that was pressed.
        Nr   r.   r_  r   s      r   r8  zController.on_button_press3  rk   r   c                    dS )zA button on the joystick was released.

        Args:
            controller:
                The controller whose button was released.
            button:
                The name of the button that was released.
        Nr   rf  s      r   r<  zController.on_button_release=  rk   r   c                0    | j         j         d| j         dS rG   rJ   r3   s    r   rL   zController.__repr__G  rM   r   )r   r#   r   r   )r)   r  )r  r
   r   r   r  r(   r)   r*   )r  r
   r   r   r0  r(   r)   r*   )r  r
   r   r   r)   r*   rQ   rO   rP   )r   rS  )rT  r]   rU  r]   r)   r*   )r_  r   r`  r(   rB  r   )r_  r   rB  r   )r_  r   rc  r(   r`   r]   )r_  r   r   r(   rR   )r   r   r   rS   r/   rU   r  r/  r=  rD  r
  r:   r<   rX  rZ  r\  r^  r)  r  r&  r8  r<  rL   r   r   r   r   r     s        0/$ /$ /$ /$b ( ( ( X(T8^ 8^ 8^ 8^tL L L L0@ @ @ @0 0 0 0d, , , , ,           = = = =? ? ? ?
   	 	 	 	
 
 
 
      > > > > > >r   r   r8  r<  r)  r  r&  c                      e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   d ZdddZd ZddZddZ	dS )AppleRemotezHigh-level interface for Apple remote control.

    This interface provides access to the 6 button controls on the remote.
    Pressing and holding certain buttons on the remote is interpreted as
    a separate control.
    r#   r   r   left_controlleft_hold_controlright_controlright_hold_control
up_controldown_controlselect_controlselect_hold_controlmenu_controlmenu_hold_controlc                x     | _         d fd}|                                D ]}|j        dv r ||           d S )Nr   r   c                     t           j        dz                j         fd            } j         fd            }d S )Nr   c                 >                         d j                   d S r7  rf   r'   r   r.   s   r   r   z;AppleRemote.__init__.<locals>._add_button.<locals>.on_pressl  s"    ##$5v{CCCCCr   c                 >                         d j                   d S r;  rx  ry  s   r   r   z=AppleRemote.__init__.<locals>._add_button.<locals>.on_releasep  s"    ##$7EEEEEr   )r   r'   r   )r   r   r   r.   s   `  r   _add_buttonz)AppleRemote.__init__.<locals>._add_buttoni  s    D&+
2F;;;\D D D D D \D \F F F F F \F F Fr   )
left	left_holdright
right_holdupdownmenuselect	menu_holdselect_hold)r   r   )r   rB   r'   )r.   r   r{  r   s   `   r   r/   zAppleRemote.__init__f  s}    		F 		F 		F 		F 		F 		F **,, 	% 	%G|  N N NG$$$	% 	%r   Fr5   r   r7   r$   c                <    | j                             ||           dS )z%Open the device.  See `Device.open`. Nr   r9   s      r   r:   zAppleRemote.openy  r   r   c                8    | j                                          dS )z'Close the device.  See `Device.close`. Nr   r3   s    r   r<   zAppleRemote.close}  r   r   r   r(   c                    dS )a,  A button on the remote was pressed.

        Only the 'up' and 'down' buttons will generate an event when the
        button is first pressed.  All other buttons on the remote will wait
        until the button is released and then send both the press and release
        events at the same time.

        Args:
            button:
                The name of the button that was pressed. The valid names are
                'up', 'down', 'left', 'right', 'left_hold', 'right_hold',
                'menu', 'menu_hold', 'select', and 'select_hold'
        Nr   r.   r   s     r   r8  zAppleRemote.on_button_press  rk   r   c                    dS )a  A button on the remote was released.

        The 'select_hold' and 'menu_hold' button release events are sent
        immediately after the corresponding press events regardless of
        whether the user has released the button.

        Args:
            button:
                The name of the button that was released. The valid names are
                'up', 'down', 'left', 'right', 'left_hold', 'right_hold',
                'menu', 'menu_hold', 'select', and 'select_hold'
        Nr   r  s     r   r<  zAppleRemote.on_button_release  rk   r   N)F)r5   r   r7   r$   )r   r(   )
r   r   r   rS   rT   r/   r:   r<   r8  r<  r   r   r   rj  rj  R  s          NNN% % %&, , , , ,          r   rj  c                      e Zd ZdZddZdS )	Tableta  High-level interface to tablet devices.

    Unlike other devices, tablets must be opened for a specific window,
    and cannot be opened exclusively.  The `open` method returns a
    `TabletCanvas` object, which supports the events provided by the tablet.

    Currently only one tablet device can be used, though it can be opened on
    multiple windows.  If more than one tablet is connected, the behaviour is
    undefined.
    r5   r   r)   TabletCanvasc                     t          d          )zOpen a tablet device for a window.

        Args:
            window:
                The window on which the tablet will be used.
        r?   r@   r.   r5   s     r   r:   zTablet.open  s     "*---r   N)r5   r   r)   r  )r   r   r   rS   r:   r   r   r   r  r    s2        	 	. . . . . .r   r  c                  B    e Zd ZdZddZddZerdd
ZddZddZ	dS dS )r  a  Event dispatcher for tablets.

    Use `Tablet.open` to obtain this object for a particular tablet device and
    window.  Events may be generated even if the tablet stylus is outside of
    the window; this is operating-system dependent.

    The events each provide the `TabletCursor` that was used to generate the
    event; for example, to distinguish between a stylus and an eraser.  Only
    one cursor can be used at a time, otherwise the results are undefined.
    r5   r   c                    || _         dS )z~Create a TabletCanvas.

        Args:
            window:
                The window on which this tablet was opened.
        N)r5   r  s     r   r/   zTabletCanvas.__init__  s     r   r)   r*   c                     t          d          )z(Close the tablet device for this window.r?   r@   r3   s    r   r<   zTabletCanvas.close  rC   r   cursorTabletCursorc                    dS )a  A cursor entered the proximity of the window.  The cursor may
            be hovering above the tablet surface, but outside the window
            bounds, or it may have entered the window bounds.

            Note that you cannot rely on `on_enter` and `on_leave` events to
            be generated in pairs; some events may be lost if the cursor was
            out of the window bounds at the time.

            :event:
            Nr   r.   r  s     r   on_enterzTabletCanvas.on_enter  rk   r   c                    dS )a  A cursor left the proximity of the window.  The cursor may have
            moved too high above the tablet surface to be detected, or it may
            have left the bounds of the window.

            Note that you cannot rely on `on_enter` and `on_leave` events to
            be generated in pairs; some events may be lost if the cursor was
            out of the window bounds at the time.
            Nr   r  s     r   on_leavezTabletCanvas.on_leave  rk   r   rp   r   rr   pressurer]   tilt_xtilt_yr   c                    dS )aj  The cursor moved on the tablet surface.

            If `pressure` is 0, then the cursor is actually hovering above the
            tablet surface, not in contact.

            Args:
                cursor:
                    The cursor that moved.
                x:
                    The X position of the cursor, in window coordinates.
                y:
                    The Y position of the cursor, in window coordinates.
                pressure:
                    The pressure applied to the cursor, in range 0.0
                    (no pressure) to 1.0 (full pressure).
                tilt_x:
                    Currently undefined.
                tilt_y:
                    Currently undefined.
                buttons:
                    Button state may be provided if the platform supports it.
                    Supported on: Windows
            Nr   )r.   r  rp   rr   r  r  r  r   s           r   	on_motionzTabletCanvas.on_motion  rk   r   N)r5   r   rQ   )r  r  )r  r  rp   r   rr   r   r  r]   r  r]   r  r]   r   r   )
r   r   r   rS   r/   r<   r   r  r  r  r   r   r   r  r    s        	 	"   . . . .  1
	 
	 
	 
		 	 	 		 	 	 	 	 	31 1r   r  r  r  r  c                  "    e Zd ZdZddZd	dZdS )
r  zA distinct cursor used on a Tablet device.

    Most tablets support at least a ``stylus`` and an ``erasor`` cursor;
    this object is used to distinguish them when tablet events are generated.
    r'   r(   c                    || _         dS )ziCreate a cursor object.

        Args:
            name:
                The name of the cursor.
        N)r'   )r.   r'   s     r   r/   zTabletCursor.__init__  s     			r   r)   c                0    | j         j         d| j         dS rG   rJ   r3   s    r   rL   zTabletCursor.__repr__%  rM   r   N)r'   r(   rR   )r   r   r   rS   r/   rL   r   r   r   r  r    sF            > > > > > >r   r  c                  *    e Zd ZdZd	dZd
dZd
dZdS )ControllerManagera  High level interface for managing game Controllers.

    This class provides a convenient way to handle the
    connection and disconnection of devices. A list of all
    connected Controllers can be queried at any time with the
    `get_controllers` method. For hot-plugging, events are
    dispatched for `on_connect` and `on_disconnect`.
    To use the ControllerManager, first make an instance::

        controller_man = pyglet.input.ControllerManager()

    At the start of your game, query for any Controllers
    that are already connected::

        controllers = controller_man.get_controllers()

    To handle Controllers that are connected or disconnected
    after the start of your game, register handlers for the
    appropriate events::

        @controller_man.event
        def on_connect(controller):
            # code to handle newly connected
            # (or re-connected) controllers
            controller.open()
            print("Connect:", controller)

        @controller_man.event
        def on_disconnect(controller):
            # code to handle disconnected Controller
            print("Disconnect:", controller)

    .. versionadded:: 2.0
    r)   list[Controller]c                    t           )z'Get a list of all connected Controllersr@   r3   s    r   get_controllersz!ControllerManager.get_controllersM  s    !!r   r   c                    dS )zA Controller has been connected. If this is
        a previously disconnected Controller that is
        being re-connected, the same Controller instance
        will be returned.
        Nr   r.   r_  s     r   
on_connectzControllerManager.on_connectS  rk   r   c                    dS )z#A Controller has been disconnected.Nr   r  s     r   on_disconnectzControllerManager.on_disconnectZ  rk   r   N)r)   r  )r)   r   )r   r   r   rS   r  r  r  r   r   r   r  r  )  s[        ! !F" " " "   2 2 2 2 2 2r   r  r  r  ))rS   
__future__r   sysr   r   typingr   r   pyglet.mathr   pyglet.eventr   pyglet.windowr   pyglet.display.baser	   pyglet.input.controllerr
   hasattrr   r   	Exceptionr   r   r   Enumr   r#   rW   register_event_typero   r   r   r   r   rj  r  r  r  r  r   r   r   <module>r     s9    # " " " " " 



   ) ) ) ) ) ) ) )       ( ( ( ( ( ( 1((((((++++++000000WS"566P3;P 	 	 	 	 	i 	 	 		 	 	 	 	/ 	 	 		 	 	 	 	 	 	 	    49   D> D> D> D> D> D> D> D>N7! 7! 7! 7! 7!o 7! 7! 7!t   K ( ( (0 0 0 0 07 0 0 02    7   ,+ + + + +W + + +8   : & & &   < ( ( (\6 \6 \6 \6 \6 \6 \6 \6~ 	  0 1 1 1   1 2 2 2   3 4 4 4   / 0 0 0e> e> e> e> e> e> e> e>P   0 1 1 1 
  2 3 3 3 
  0 1 1 1 
  / 0 0 0 
  2 3 3 3L L L L L/ L L L^    1 2 2 2    3 4 4 4. . . . . . . .,P P P P P? P P Pf      , , ,      , , ,      - - -> > > > > > > >,22 22 22 22 22 22 22 22j  % %l 3 3 3  % %o 6 6 6 6 6r   