
    \
jZf                        d Z ddl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          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!            G d" d#          Z G d$ d%e          Ze                    d&           e                    d'           e                    d(            G d) d*          ZdS )+z=Interface classes for `pyglet.input`.

.. versionadded:: 1.2
    N)EventDispatcheris_pyglet_doc_runc                       e Zd ZdS )DeviceExceptionN__name__
__module____qualname__     K/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/input/base.pyr   r   0           Dr   r   c                       e Zd ZdS )DeviceOpenExceptionNr   r   r   r   r   r   4   r   r   r   c                       e Zd ZdS )DeviceExclusiveExceptionNr   r   r   r   r   r   8   r   r   r   c                   2    e Zd ZdZd Zd	dZd Zd Zd ZdS )
Devicea\  Input device.

    :Ivariables:
        display : `pyglet.canvas.Display`
            Display this device is connected to.
        name : str
            Name of the device, as described by the device firmware.
        manufacturer : str
            Name of the device manufacturer, or ``None`` if the information is
            not available.
    c                 >    || _         || _        d | _        d| _        d S NF)displaynamemanufactureris_open)selfr   r   s      r   __init__zDevice.__init__I   s%    	  r   NFc                 @    | j         rt          d          d| _         dS )a  Open the device to begin receiving input from it.

        :Parameters:
            `window` : Window
                Optional window to associate with the device.  The behaviour
                of this parameter is device and operating system dependant.
                It can usually be omitted for most devices.
            `exclusive` : bool
                If ``True`` the device will be opened exclusively so that no
                other application can use it.  The method will raise
                `DeviceExclusiveException` if the device cannot be opened this
                way (for example, because another application has already
                opened it).
        zDevice is already open.TN)r   r   r   window	exclusives      r   openzDevice.openQ   s)      < 	A%&?@@@r   c                     d| _         dS )zClose the device. FN)r   r   s    r   closezDevice.closef   s    r   c                      t          d          )zZGet a list of controls provided by the device.

        :rtype: list of `Control`
        abstractNotImplementedErrorr#   s    r   get_controlszDevice.get_controlsj   s    
 "*---r   c                 0    | j         j        d| j        dS )N(name=)	__class__r   r   r#   s    r   __repr__zDevice.__repr__q   s     $ 7 7 7CCr   r   )	r   r	   r
   __doc__r   r!   r$   r)   r/   r   r   r   r   r   <   ss        
 
     *  . . .D D D D Dr   r   c                   d    e Zd ZdZddZed             Zej        d             Zd Ze	rd Z
dS dS )	Controla  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.

    :Ivariables:
        `name` : str
            Name of the control, or ``None`` if unknown
        `raw_name` : str
            Unmodified name of the control, as presented by the operating
            system; or ``None`` if unknown.
        `inverted` : bool
            If ``True``, the value reported is actually inverted from what the
            device reported; usually this is to provide consistency across
            operating systems.
    Nc                 >    || _         || _        d| _        d | _        d S r   )r   raw_nameinverted_value)r   r   r4   s      r   r   zControl.__init__   s"    	 r   c                     | 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.

        :type: float
        r6   r#   s    r   valuezControl.value   s     {r   c                 Z    || j         k    rd S || _         |                     d|           d S N	on_changer6   dispatch_eventr   newvalues     r   r9   zControl.value   s7    t{""FK22222r   c                 |    | j         r| j        j        d| j         d| j        dS | j        j        d| j        dS )Nr+   z, raw_name=r,   z
(raw_name=)r   r.   r   r4   r#   s    r   r/   zControl.__repr__   sU    9 	P'''DMMMC C )-(?(?(?OOr   c                     dS )zThe value changed.

            :Parameters:
                `value` : float
                    Current value of the control.

            :event:
            Nr   )r   r9   s     r   r<   zControl.on_change         r   N)r   r	   r
   r0   r   propertyr9   setterr/   _is_pyglet_doc_runr<   r   r   r   r2   r2   u   s         (    	 	 X	 \3 3 \3P P P  		 	 	 	 		 	r   r2   r<   c                   d    e Zd ZdZdZdZdZdZdZdZ	dZ
ed	             Zej        d
             ZdS )RelativeAxiszRAn axis whose value represents a relative change from the previous
    value.
    xyzrxryrzwheelc                     | j         S rD   r8   r#   s    r   r9   zRelativeAxis.value   s
    {r   c                 @    || _         |                     d|           d S r;   r=   r?   s     r   r9   zRelativeAxis.value   s%    K22222r   N)r   r	   r
   r0   XYZRXRYRZWHEELrE   r9   rF   r   r   r   rI   rI      sy         
 	AAA	B	B	BE  X \3 3 \3 3 3r   rI   c                   H     e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zd fd	Z xZS )AbsoluteAxisa  An axis whose value represents a physical measurement from the device.

    The value is advertised to range over ``min`` and ``max``.

    :Ivariables:
        `min` : float
            Minimum advertised value.
        `max` : float 
            Maximum advertised value.
    rJ   rK   rL   rM   rN   rO   hathat_xhat_yNc                 v    t          t          |                               ||           || _        || _        d S rD   )superr[   r   minmax)r   r   ra   rb   r4   r.   s        r   r   zAbsoluteAxis.__init__   s5    lD!!**4:::r   rD   )r   r	   r
   r0   rS   rT   rU   rV   rW   rX   HATHAT_XHAT_Yr   __classcell__)r.   s   @r   r[   r[      s|        	 	 	AAA	B	B	B C E E         r   r[   c                   \    e Zd ZdZed             Zej        d             Zerd Zd Z	dS dS )Buttonz"A control whose value is boolean. c                 *    t          | j                  S rD   )boolr6   r#   s    r   r9   zButton.value  s    DK   r   c                     || j         k    rd S || _         |                     dt          |                     |r|                     d           d S |                     d           d S )Nr<   on_press
on_release)r6   r>   rj   r?   s     r   r9   zButton.value  ss    t{""FKh888 	.
+++++-----r   c                     dS )z9The button was pressed.

            :event:
            Nr   r#   s    r   rl   zButton.on_press  rC   r   c                     dS )z:The button was released.

            :event:
            Nr   r#   s    r   rm   zButton.on_release  rC   r   N)
r   r	   r
   r0   rE   r9   rF   rG   rl   rm   r   r   r   rh   rh      s        ,,! ! X! \. . \.  	 	 		 	 	 	 	 r   rh   rl   rm   c                   >    e Zd ZdZd ZddZd Zd Zd Zd	 Z	d
 Z
dS )Joysticka<  High-level interface for joystick-like devices.  This includes analogue
    and digital joysticks, gamepads, game controllers, and possibly even
    steering wheels and other input devices.  There is unfortunately no way to
    distinguish between these different device types.

    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.

    :Ivariables:
        `device` : `Device`
            The underlying device used by this joystick interface.
        `x` : float
            Current X (horizontal) value ranging from -1.0 (left) to 1.0
            (right).
        `y` : float
            Current y (vertical) value ranging from -1.0 (top) to 1.0
            (bottom).
        `z` : float
            Current Z value ranging from -1.0 to 1.0.  On joysticks the Z
            value is usually the throttle control.  On game controllers the Z
            value is usually the secondary thumb vertical axis.
        `rx` : float
            Current rotational X value ranging from -1.0 to 1.0.
        `ry` : float
            Current rotational Y value ranging from -1.0 to 1.0.
        `rz` : float
            Current rotational Z value ranging from -1.0 to 1.0.  On joysticks
            the RZ value is usually the twist of the stick.  On game
            controllers the RZ value is usually the secondary thumb horizontal
            axis.
        `hat_x` : int
            Current hat (POV) horizontal position; one of -1 (left), 0
            (centered) or 1 (right).
        `hat_y` : int
            Current hat (POV) vertical position; one of -1 (bottom), 0
            (centered) or 1 (top).
        `buttons` : list of bool
            List of boolean values representing current states of the buttons.
            These are in order, so that button 1 has value at ``buttons[0]``,
            and so on.
        `x_control` : `AbsoluteAxis`
            Underlying control for `x` value, or ``None`` if not available.
        `y_control` : `AbsoluteAxis`
            Underlying control for `y` value, or ``None`` if not available.
        `z_control` : `AbsoluteAxis`
            Underlying control for `z` value, or ``None`` if not available.
        `rx_control` : `AbsoluteAxis`
            Underlying control for `rx` value, or ``None`` if not available.
        `ry_control` : `AbsoluteAxis`
            Underlying control for `ry` value, or ``None`` if not available.
        `rz_control` : `AbsoluteAxis`
            Underlying control for `rz` value, or ``None`` if not available.
        `hat_x_control` : `AbsoluteAxis`
            Underlying control for `hat_x` value, or ``None`` if not available.
        `hat_y_control` : `AbsoluteAxis`
            Underlying control for `hat_y` value, or ``None`` if not available.
        `button_controls` : list of `Button`
            Underlying controls for `buttons` values.
    c                      | _         d _        d _        d _        d _        d _        d _        d _        d _        g  _	        d  _
        d  _        d  _        d  _        d  _        d  _        d  _        d  _        g  _         fd} fd} fd}|                                D ]c}t)          |t*                    r,|j        dv r ||           ,|j        dk    r ||           Ct)          |t.                    r ||           dd S )Nr   c                     | j         d| j        | j        z
  z  d| j        z  z
  | j        r  t	          dz   |            | j        fd            }d S )Ng       @g      _controlc                 j    | z  z   }t          |                               d|           d S )Non_joyaxis_motion)setattrr>   )r9   normalized_valuebiasr   scaler   s     r   r<   z6Joystick.__init__.<locals>.add_axis.<locals>.on_change  sG    #(5=4#7 d$4555##$7tEUVVVVVr   )r   rb   ra   r5   rw   event)controlr<   ry   r   rz   r   s     @@@r   add_axisz#Joystick.__init__.<locals>.add_axis  s    <D7;45E'+--D uD$+W555]W W W W W W W ]W W Wr   c                    t          j                  j                            d           j                            |            | j        fd            }| j        fd            }| j        fd            }d S )NFc                     | j         <   d S rD   )buttons)r9   ir   s    r   r<   z8Joystick.__init__.<locals>.add_button.<locals>.on_change  s    "'Qr   c                  6                         d            d S )Non_joybutton_pressr>   r   r   s   r   rl   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   rm   z9Joystick.__init__.<locals>.add_button.<locals>.on_release  s"    ##$:D!DDDDDr   )lenr   appendbutton_controlsr{   )r|   r<   rl   rm   r   r   s       @r   
add_buttonz%Joystick.__init__.<locals>.add_button  s    DL!!AL&&& ''000]( ( ( ( ( ]( ]C C C C C ]C ]E E E E E ]E E Er   c                 L      _          _         j         fd            }d S )Nc                    | dz  dk    rdx_         _        nDj        dk    r| dz  } d| cxk    rdk     rn nd|          \  _         _        ndx_         _                            dj         j                   d S )Ni  r      i  ))r      )r   r   )r   r   )r   )r   r   )r   r   )r   r   )r   r   on_joyhat_motion)r]   r^   rb   r>   )r9   r|   r   s    r   r<   z5Joystick.__init__.<locals>.add_hat.<locals>.on_change  s    6>V++.//DJ{Q%E~~~~A~~~~~2< =B2C.
DJJ 343
TZ##$6dj$*UUUUUr   )hat_x_controlhat_y_controlr{   )r|   r<   r   s   ` r   add_hatz"Joystick.__init__.<locals>.add_hat  sP    !(D!(D]V V V V V ]V V Vr   )rJ   rK   rL   rM   rN   rO   r]   r^   r\   )devicerJ   rK   rL   rM   rN   rO   r]   r^   r   	x_control	y_control	z_control
rx_control
ry_control
rz_controlr   r   r   r)   
isinstancer[   r   rh   )r   r   r}   r   r   r|   s   `     r   r   zJoystick.__init__r  s   

!!!	W 	W 	W 	W 	W	E 	E 	E 	E 	E"	V 	V 	V 	V 	V4 **,, 	$ 	$G'<00 $<#VVVHW%%%%\U**GG$$$GV,, $
7###	$ 	$r   NFc                 <    | j                             ||           dS )z.Open the joystick device.  See `Device.open`. Nr   r!   r   s      r   r!   zJoystick.open       +++++r   c                 8    | j                                          dS )z0Close the joystick device.  See `Device.close`. Nr   r$   r#   s    r   r$   zJoystick.close      r   c                     dS )aQ  The value of a joystick axis changed.

        :Parameters:
            `joystick` : `Joystick`
                The joystick device whose axis changed.
            `axis` : string
                The name of the axis that changed.
            `value` : float
                The current value of the axis, normalized to [-1, 1].
        Nr   )r   joystickaxisr9   s       r   rv   zJoystick.on_joyaxis_motion  rC   r   c                     dS )a  A button on the joystick was pressed.

        :Parameters:
            `joystick` : `Joystick`
                The joystick device whose button was pressed.
            `button` : int
                The index (in `button_controls`) of the button that was pressed.
        Nr   r   r   buttons      r   r   zJoystick.on_joybutton_press  rC   r   c                     dS )a  A button on the joystick was released.

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

        :Parameters:
            `joystick` : `Joystick`
                The joystick device whose hat control changed.
            `hat_x` : int
                Current hat (POV) horizontal position; one of -1 (left), 0
                (centered) or 1 (right).
            `hat_y` : int
                Current hat (POV) vertical position; one of -1 (bottom), 0
                (centered) or 1 (top).
        Nr   )r   r   r]   r^   s       r   r   zJoystick.on_joyhat_motion  rC   r   r   )r   r	   r
   r0   r   r!   r$   rv   r   r   r   r   r   r   rq   rq   "  s        M M^X$ X$ X$t, , , ,  
 
 
        r   rq   rv   r   r   r   c                   2    e Zd ZdZd Zd	dZd Zd Zd ZdS )
AppleRemotea  High-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.

    :Ivariables:
        `device` : `Device`
            The underlying device used by this interface.
        `left_control` : `Button`
            Button control for the left (prev) button.
        `left_hold_control` : `Button`
            Button control for holding the left button (rewind).
        `right_control` : `Button`
            Button control for the right (next) button.
        `right_hold_control` : `Button`
            Button control for holding the right button (fast forward).
        `up_control` : `Button`
            Button control for the up (volume increase) button.
        `down_control` : `Button`
            Button control for the down (volume decrease) button.
        `select_control` : `Button`
            Button control for the select (play/pause) button.
        `select_hold_control` : `Button`
            Button control for holding the select button.
        `menu_control` : `Button`
            Button control for the menu button.
        `menu_hold_control` : `Button`
            Button control for holding the menu button.
    c                 v      fd}| _         |                                D ]}|j        dv r ||           d S )Nc                      t           j        dz                j         fd            } j         fd            }d S )Nrt   c                  >                         d j                   d S )Non_button_pressr>   r   r|   r   s   r   rl   z:AppleRemote.__init__.<locals>.add_button.<locals>.on_press,  s"    ##$5w|DDDDDr   c                  >                         d j                   d S )Non_button_releaser   r   s   r   rm   z<AppleRemote.__init__.<locals>.add_button.<locals>.on_release0  s"    ##$7FFFFFr   )rw   r   r{   )r|   rl   rm   r   s   `  r   r   z(AppleRemote.__init__.<locals>.add_button)  s    D',3W===]E E E E E ]E ]G G G G G ]G G Gr   )
left	left_holdright
right_holdupdownmenuselect	menu_holdselect_hold)r   r)   r   )r   r   r   r|   s   `   r   r   zAppleRemote.__init__(  sw    		G 		G 		G 		G 		G **,, 	$ 	$G|  N N N
7###	$ 	$r   NFc                 <    | j                             ||           dS )z%Open the device.  See `Device.open`. Nr   r   s      r   r!   zAppleRemote.open:  r   r   c                 8    | j                                          dS )z'Close the device.  See `Device.close`. Nr   r#   s    r   r$   zAppleRemote.close>  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.

        :Parameters:
            `button` : unicode
                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'
                
        :event:
        Nr   r   r   s     r   r   zAppleRemote.on_button_pressB  rC   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 or not the user has released the button.

        :Parameters:
            `button` : unicode
                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'

        :event:
        Nr   r   s     r   r   zAppleRemote.on_button_releaseS  rC   r   r   )	r   r	   r
   r0   r   r!   r$   r   r   r   r   r   r   r     sn         >$ $ $$, , , ,    "    r   r   r   r   c                       e Zd ZdZ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.
    c                      t          d          )zOpen a tablet device for a window.

        :Parameters:
            `window` : `Window`
                The window on which the tablet will be used.

        :rtype: `TabletCanvas`
        r&   r'   r   r   s     r   r!   zTablet.opens  s     "*---r   N)r   r	   r
   r0   r!   r   r   r   r   r   g  s-        	 		. 	. 	. 	. 	.r   r   c                   8    e Zd ZdZd Zd Zerd Zd Zd Z	dS dS )TabletCanvasa=  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.

    :Ivariables:
        `window` : Window
            The window on which this tablet was opened.
    c                     || _         d S rD   )r   r   s     r   r   zTabletCanvas.__init__  s    r   c                      t          d          )z1Close the tablet device for this window.
        r&   r'   r#   s    r   r$   zTabletCanvas.close  s     "*---r   c                     dS )a1  A cursor entered the proximity of the window.  The cursor may
            be hovering above the tablet surface, but outside of 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.

            :Parameters:
                `cursor` : `TabletCursor`
                    The cursor that entered proximity.

            :event:
            Nr   r   cursors     r   on_enterzTabletCanvas.on_enter  rC   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.

            :Parameters:
                `cursor` : `TabletCursor`
                    The cursor that left proximity.

            :event:
            Nr   r   s     r   on_leavezTabletCanvas.on_leave  rC   r   c                     dS )a0  The cursor moved on the tablet surface.

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

            :Parameters:
                `cursor` : `TabletCursor`
                    The cursor that moved.
                `x` : int
                    The X position of the cursor, in window coordinates.
                `y` : int
                    The Y position of the cursor, in window coordinates.
                `pressure` : float
                    The pressure applied to the cursor, in range 0.0 (no
                    pressure) to 1.0 (full pressure).
                `tilt_x` : float
                    Currently undefined.
                `tilt_y` : float
                    Currently undefined.

            :event:
            Nr   )r   r   rJ   rK   pressuretilt_xtilt_ys          r   	on_motionzTabletCanvas.on_motion  rC   r   N)
r   r	   r
   r0   r   r$   rG   r   r   r   r   r   r   r   r     s~         (  . . .
  7	 	 	 	 	 	 	 	 	 	 	C7 7r   r   r   r   r   c                       e Zd ZdZd Zd ZdS )TabletCursora  A distinct cursor used on a tablet.

    Most tablets support at least a *stylus* and an *erasor* cursor; this
    object is used to distinguish them when tablet events are generated.

    :Ivariables:
        `name` : str
            Name of the cursor.
    c                     || _         d S rD   )r   )r   r   s     r   r   zTabletCursor.__init__  s    			r   c                 0    | j         j        d| j        dS )N(r,   r-   r#   s    r   r/   zTabletCursor.__repr__  s    >222DIII>>r   N)r   r	   r
   r0   r   r/   r   r   r   r   r     s<           ? ? ? ? ?r   r   )r0   syspyglet.eventr   hasattrr   rG   	Exceptionr   r   r   r   r2   register_event_typerI   r[   rh   rq   r   r   r   r   r   r   r   <module>r      s  H 
 


 ( ( ( ( ( (WS"566P3;P 	 	 	 	 	i 	 	 		 	 	 	 	/ 	 	 		 	 	 	 	 	 	 	6D 6D 6D 6D 6D 6D 6D 6Dr> > > > >o > > >@   K ( ( (3 3 3 3 37 3 3 3<& & & & &7 & & &R    W   >   : & & &   < ( ( (^ ^ ^ ^ ^ ^ ^ ^@ 	  0 1 1 1   1 2 2 2   3 4 4 4   / 0 0 0Y Y Y Y Y/ Y Y Yv    1 2 2 2    3 4 4 4. . . . . . . .0T T T T T? T T Tl      , , ,      , , ,      - - -? ? ? ? ? ? ? ? ? ?r   