
    \
jC                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  G d de          Z
 G d	 d
e
          Ze                    d           e                    d            G d de          Ze                    d            G d de
          Ze                    d            G d de
          Ze                    d           dS )z0Display different types of interactive widgets.
    N)EventDispatcher)OrderedGroup)Caret)IncrementalTextLayoutc                   p   e Zd Zd Zd Zed             Zej        d             Zed             Zej        d             Zed             Z	e	j        d             Z	ed	             Z
ed
             Zed             Zed             Zej        d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )
WidgetBasec                 h    || _         || _        || _        || _        d | _        d | _        d| _        d S NT)_x_y_width_height	_bg_group	_fg_groupenabled)selfxywidthheights        L/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/gui/widgets.py__init__zWidgetBase.__init__1   s7        c                     d S N r   orders     r   update_groupszWidgetBase.update_groups:       r   c                     | j         S )z8X coordinate of the widget.

        :type: int
        )r   r   s    r   r   zWidgetBase.x=        wr   c                 <    || _         |                                  d S r   )r   _update_positionr   values     r   r   zWidgetBase.xE   !    r   c                     | j         S )z8Y coordinate of the widget.

        :type: int
        )r   r"   s    r   r   zWidgetBase.yJ   r#   r   c                 <    || _         |                                  d S r   )r   r%   r&   s     r   r   zWidgetBase.yR   r(   r   c                     | j         | j        fS )zVThe x, y coordinate of the widget as a tuple.

        :type: tuple(int, int)
        )r   r   r"   s    r   positionzWidgetBase.positionW   s     wr   c                 L    |\  | _         | _        |                                  d S r   )r   r   r%   )r   valuess     r   r,   zWidgetBase.position_   s(    !r   c                     | j         S )z1Width of the widget.

        :type: int
        )r   r"   s    r   r   zWidgetBase.widthd   s     {r   c                     | j         S )z2Height of the widget.

        :type: int
        )r   r"   s    r   r   zWidgetBase.heightl   s     |r   c                 V    | j         | j        | j         | j        z   | j        | j        z   fS )z~Bounding box of the widget.

        Expresesed as (x, y, x + width, y + height)

        :type: (int, int, int, int)
        )r   r   r   r   r"   s    r   aabbzWidgetBase.aabbt   s)     w4;!6$,8NNNr   c                      t          d          )a  Query or set the Widget's value.
        
        This property allows you to set the value of a Widget directly, without any
        user input.  This could be used, for example, to restore Widgets to a
        previous state, or if some event in your program is meant to naturally
        change the same value that the Widget controls.  Note that events are not
        dispatched when changing this property.
        Value depends on control type!NotImplementedErrorr"   s    r   r'   zWidgetBase.value~   s     ""BCCCr   c                      t          d          )Nr4   r5   r&   s     r   r'   zWidgetBase.value   s    !"BCCCr   c                     | j         |cxk     o| j         | j        z   k     nc o!| j        |cxk     o| j        | j        z   k     nc S r   r   r   r   r   r   r   r   s      r   
_check_hitzWidgetBase._check_hit   [    w2222TWt{22222[tw7[7[7[7[TWt|E[7[7[7[7[[r   c                      t          d          )Nz Unable to reposition this Widgetr5   r"   s    r   r%   zWidgetBase._update_position   s    !"DEEEr   c                     d S r   r   r   r   r   buttons	modifierss        r   on_mouse_presszWidgetBase.on_mouse_press   r    r   c                     d S r   r   r?   s        r   on_mouse_releasezWidgetBase.on_mouse_release   r    r   c                     d S r   r   r   r   r   dxdyr@   rA   s          r   on_mouse_dragzWidgetBase.on_mouse_drag   r    r   c                     d S r   r   r   r   r   rG   rH   s        r   on_mouse_motionzWidgetBase.on_mouse_motion   r    r   c                     d S r   r   r   r   r   mouse	directions        r   on_mouse_scrollzWidgetBase.on_mouse_scroll   r    r   c                     d S r   r   r   texts     r   on_textzWidgetBase.on_text   r    r   c                     d S r   r   r   motions     r   on_text_motionzWidgetBase.on_text_motion   r    r   c                     d S r   r   rW   s     r   on_text_motion_selectz WidgetBase.on_text_motion_select   r    r   N)__name__
__module____qualname__r   r   propertyr   setterr   r,   r   r   r2   r'   r;   r%   rB   rD   rI   rL   rQ   rU   rY   r[   r   r   r   r   r   /   s              X X    X    X X    X      X  _    _    X   X O O XO 	D 	D X	D \D D \D\ \ \F F F                  r   r   c                   ~     e Zd ZdZd fd	Zd Zed             Zej        d             Zd Z	d Z
d	 Zd
 Zd Z xZS )
PushButtonzInstance of a push button.

    Triggers the event 'on_press' when it is clicked by the mouse.
    Triggers the event 'on_release' when the mouse is released.
    Nc                 v   t                                          |||j        |j                   || _        || _        |p|| _        |pt          j        	                                | _
        || _        t          d|          }t          j                            | j        ||||          | _        d| _        dS )a  Create a push button.

        :Parameters:
            `x` : int
                X coordinate of the push button.
            `y` : int
                Y coordinate of the push button.
            `pressed` : `~pyglet.image.AbstractImage`
                Image to display when the button is pressed.
            `depresseed` : `~pyglet.image.AbstractImage`
                Image to display when the button isn't pressed.
            `hover` : `~pyglet.image.AbstractImage`
                Image to display when the button is being hovered over.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the push button to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of the push button.
        r   parentbatchgroupFN)superr   r   r   _pressed_img_depressed_img
_hover_imgpygletgraphicsBatch_batch_user_groupr   spriteSprite_sprite_pressed)
r   r   r   pressed	depressedhoverrg   rh   bg_group	__class__s
            r   r   zPushButton.__init__   s    & 	Ay	0@AAA#',9 6v4466 %000}++D,?AUZb+ccr   c                 6    | j         | j        f| j        _        d S r   )r   r   rt   r,   r"   s    r   r%   zPushButton._update_position   s     $ 0r   c                     | j         S r   )ru   r"   s    r   r'   zPushButton.value   s
    }r   c                     t          |          t          u s
J d            || _        | j        r| j        n| j        | j        _        d S )Nz*This Widget's value must be True or False.)typeboolru   rj   rk   rt   imager&   s     r   r'   zPushButton.value   sK    E{{d"""$P"""26-XT..TEXr   c                 J    t          |dz   | j                  | j        _        d S )N   )r   rq   rt   rh   r   s     r   r   zPushButton.update_groups   s#    )%!)T5EFFr   c                     | j         r|                     ||          sd S | j        | j        _        d| _        |                     d           d S )NTon_press)r   r;   rj   rt   r   ru   dispatch_eventr?   s        r   rB   zPushButton.on_mouse_press   sT    | 	4??1a#8#8 	F!.J'''''r   c                     | j         r| j        sd S |                     ||          r| j        n| j        | j        _        d| _        |                     d           d S )NF
on_release)r   ru   r;   rl   rk   rt   r   r   r?   s        r   rD   zPushButton.on_mouse_release   sa    | 	4= 	F0410E0E^T__4K^L)))))r   c                     | j         r| j        rd S |                     ||          r| j        n| j        | j        _        d S r   r   ru   r;   rl   rk   rt   r   rK   s        r   rL   zPushButton.on_mouse_motion   F    | 	t} 	F0410E0E^T__4K^r   c                     | j         r| j        rd S |                     ||          r| j        n| j        | j        _        d S r   r   rF   s          r   rI   zPushButton.on_mouse_drag   r   r   )NNN)r\   r]   r^   __doc__r   r%   r_   r'   r`   r   rB   rD   rL   rI   __classcell__rz   s   @r   rb   rb      s              @1 1 1   X \Y Y \Y
G G G( ( (* * *_ _ _
_ _ _ _ _ _ _r   rb   r   r   c                   $    e Zd ZdZd Zd Zd ZdS )ToggleButtonzlInstance of a toggle button.

    Triggers the event 'on_toggle' when the mouse is pressed or released.
    c                 J    |                      ||          r| j        n| j        S r   )r;   rl   rk   r:   s      r   _get_release_imagezToggleButton._get_release_image  s$    "&//!Q"7"7PtT=PPr   c                     | j         r|                     ||          sd S | j         | _        | j        r| j        n|                     ||          | j        _        |                     d| j                   d S )N	on_toggle)r   r;   ru   rj   r   rt   r   r   r?   s        r   rB   zToggleButton.on_mouse_press
  s{    | 	4??1a#8#8 	F M)26-bT..TE\E\]^`aEbEbK77777r   c                 f    | j         r| j        rd S |                     ||          | j        _        d S r   )r   ru   r   rt   r   r?   s        r   rD   zToggleButton.on_mouse_release  s:    | 	t} 	F!44Q::r   N)r\   r]   r^   r   r   rB   rD   r   r   r   r   r     sN         
Q Q Q8 8 8; ; ; ; ;r   r   r   c                        e Zd ZdZd fd	Zed             Zej        d             Zd Zed             Z	ed	             Z
ed
             Zed             Zd Zd Zd Zd Zd Zd Z xZS )SliderzInstance of a slider made of a base and a knob image.

    Triggers the event 'on_change' when the knob position is changed.
    The knob position can be changed by dragging with the mouse, or
    scrolling the mouse wheel.
    r   Nc                 |   t                                          |||j        |j                   || _        || _        || _        |j        dz  | _        |j        dz  | _        |j        dz  | j        _	        ||z   | _
        ||j        z   |j        z
  |z
  | _        || _        t          d|          }t          d|          }	t          j                            | j        ||||          | _        t          j                            | j        ||z   ||j        dz  z   ||	          | _        d| _        d| _        dS )a  Create a slider.

        :Parameters:
            `x` : int
                X coordinate of the slider.
            `y` : int
                Y coordinate of the slider.
            `base` : `~pyglet.image.AbstractImage`
                Image to display as the background to the slider.
            `knob` : `~pyglet.image.AbstractImage`
                Knob that moves to show the position of the slider.
            `edge` : int
                Pixels from the maximum and minimum position of the slider,
                to the edge of the base image.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the slider to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of the slider.
           r   rd   r   rf   FN)ri   r   r   r   _edge	_base_img	_knob_img_half_knob_width_half_knob_heightanchor_y_min_knob_x_max_knob_xrq   r   rm   rr   rs   	_base_spr	_knob_spr_value
_in_update)r   r   r   baseknobedgerg   rh   ry   fg_grouprz   s             r   r   zSlider.__init__"  s&   ( 	Atz4;777
 $
Q!%q"&+/t8tz>DJ6= %000%000--dna%W_-``--dnafaTUo]bjr-ssr   c                     | j         S r   )r   r"   s    r   r'   zSlider.valueJ  s
    {r   c                     t          |          t          t          fv s
J d            || _        | j        | j        z
  |z  dz  | j        z   | j        z   }t          | j        t          || j        z
  | j                            | j	        _
        d S )Nz,This Widget's value must be an int or float.d   )r~   intfloatr   r   r   r   maxminr   r   )r   r'   r   s      r   r'   zSlider.valueN  s    E{{sEl***,Z*** 00E9C?$BRRUYUjjt/Q9N5NPTP`1a1abbr   c                     t          |dz   | j                  | j        _        t          |dz   | j                  | j        _        d S Nr   r   )r   rq   r   rh   r   r   s     r   r   zSlider.update_groupsU  s>    +EAIt7GHH+EAIt7GHHr   c                      | j         | j        z   S r   )r   r   r"   s    r   _min_xzSlider._min_xY  s    w##r   c                 0    | j         | j        z   | j        z
  S r   )r   r   r   r"   s    r   _max_xzSlider._max_x]  s    w$tz11r   c                      | j         | j        z
  S r   )r   r   r"   s    r   _min_yzSlider._min_ya  s    w///r   c                 @    | j         | j        z   | j        j        dz  z   S )Nr   )r   r   r   r   r"   s    r   _max_yzSlider._max_ye  s!    w//$.2G!2KKKr   c                 j    | j         |cxk     o
| j        k     nc o| j        |cxk     o
| j        k     nc S r   )r   r   r   r   r:   s      r   r;   zSlider._check_hiti  sM    {Q,,,,,,,,Nq1N1N1N1N4;1N1N1N1NNr   c                 "   t          | j        t          || j        z
  | j                            | j        _        t          | j        j        | j        z
  dz  | j        | j        z
  z            | _        | 	                    d| j                   d S )Nr   	on_change)
r   r   r   r   r   r   r   absr   r   )r   r   s     r   _update_knobzSlider._update_knobl  s    t/Q9N5NPTP`1a1abbDN,t/??3F4K[^b^nKnoppK55555r   c                     | j         sd S |                     ||          rd| _        |                     |           d S d S r
   )r   r;   r   r   r?   s        r   rB   zSlider.on_mouse_pressq  sR    | 	F??1a   	!"DOa     	! 	!r   c                 T    | j         sd S | j        r|                     |           d S d S r   )r   r   r   rF   s          r   rI   zSlider.on_mouse_dragx  s?    | 	F? 	!a     	! 	!r   c                     | j         sd S |                     ||          r,|                     | j        j        | j        z   |z              d S d S r   )r   r;   r   r   r   r   rN   s        r   rQ   zSlider.on_mouse_scroll~  s`    | 	F??1a   	Tdn.1FFRSSSSS	T 	Tr   c                 &    | j         sd S d| _        d S NF)r   r   r?   s        r   rD   zSlider.on_mouse_release  s    | 	Fr   )r   NN)r\   r]   r^   r   r   r_   r'   r`   r   r   r   r   r   r;   r   rB   rI   rQ   rD   r   r   s   @r   r   r     sd        &  &  &  &  &  & P   X \c c \cI I I $ $ X$ 2 2 X2 0 0 X0 L L XLO O O6 6 6
! ! !! ! !T T T             r   r   r   c                        e Zd ZdZ	 	 d fd	Zd Zed             Zej        d	             Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Z xZS )	TextEntryzTInstance of a text entry widget.

    Allows the user to enter and submit text.
       r   r   r   r   r   r   r   r   r   r   Nc
           	      N   t           j        j                            |          | _        | j                            dt          | j        j                  t          |                     | j                                        }
|
j	        |
j
        z
  }|	| _        t          d|	          }t          d|	          }dx| _        }t           j                            ||z
  ||z
  ||z   |z   ||z   |z   |dd         ||          | _        |d         | j        _        t%          | j        ||d||	          | _        || j        _        || j        _        t-          | j        |          | _        d| j        _        d| _        t5                                          ||||           dS )
am  Create a text entry widget.

        :Parameters:
            `text` : str
                Initial text to display.
            `x` : int
                X coordinate of the text entry widget.
            `y` : int
                Y coordinate of the text entry widget.
            `width` : int
                The width of the text entry widget.
            `color` : (int, int, int, int)
                The color of the outline box in RGBA format.
            `text_color` : (int, int, int, int)
                The color of the text in RGBA format.
            `text_color` : (int, int, int)
                The color of the caret in RGB format.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the text entry widget to.
            `group` : `~pyglet.graphics.Group`
                Optional parent group of text entry widget.
        r   )colorrd   r   r   N   F)	multilinerg   rh   )rm   rT   documentUnformattedDocument_doc	set_stylelendictget_fontascentdescentrq   r   _padshapes	Rectangle_outlineopacityr   _layoutr   r   r   _caretvisible_focusri   r   )r   rT   r   r   r   r   
text_colorcaret_colorrg   rh   fontr   ry   r   prz   s                  r   r   zTextEntry.__init__  s   2 K(<<TBB		As49>22Dz4J4J4JKKKy!!##t|+ %000%000 	A//!QqS%'!)VAXaZQVWYXYWYQZ\ackll %a -TYvQV^ckstttDL<<<#Auf-----r   c                     | j         | j        f| j        _        | j         | j        z
  | j        | j        z
  f| j        _        d S r   )r   r   r   r,   r   r   r"   s    r   r%   zTextEntry._update_position  s<     $ 0!%49!4dg	6I!Ir   c                     | j         j        S r   )r   rT   r"   s    r   r'   zTextEntry.value  s    y~r   c                 ^    t          |          t          u s
J d            || j        _        d S )Nz%This Widget's value must be a string.)r~   strr   rT   r&   s     r   r'   zTextEntry.value  s/    E{{c!!!#J!!!	r   c                     | j         |cxk     o| j         | j        z   k     nc o!| j        |cxk     o| j        | j        z   k     nc S r   r9   r:   s      r   r;   zTextEntry._check_hit  r<   r   c                 ,    || _         || j        _        d S r   )r   r   r   r&   s     r   
_set_focuszTextEntry._set_focus  s    #r   c                     t          |dz   | j                  | j        _        t          |dz   | j                  | j        _        d S r   )r   rq   r   rh   r   r   s     r   r   zTextEntry.update_groups  s>    *519d6FGG)%!)T5EFFr   c                 r    | j         sd S |                     ||          s|                     d           d S d S r   )r   r;   r   rK   s        r   rL   zTextEntry.on_mouse_motion  sI    | 	Fq!$$ 	#OOE"""""	# 	#r   c                 h    | j         sd S | j        r!| j                            ||||||           d S d S r   )r   r   r   rI   rF   s          r   rI   zTextEntry.on_mouse_drag  sN    | 	F; 	HK%%aBGYGGGGG	H 	Hr   c                     | j         sd S |                     ||          r4|                     d           | j                            ||||           d S d S r
   )r   r;   r   r   rB   r?   s        r   rB   zTextEntry.on_mouse_press  sh    | 	F??1a   	AOOD!!!K&&q!Wi@@@@@	A 	Ar   c                     | j         sd S | j        r\|dv r<|                     d| j        j        j                   |                     d           d S | j                            |           d S d S )N)
	on_commitF)	r   r   r   r   r   rT   r   r   rU   rS   s     r   rU   zTextEntry.on_text  s    | 	F; 	&|####K1F1KLLL&&&K%%%%%	& 	&r   c                 ^    | j         sd S | j        r| j                            |           d S d S r   )r   r   r   rY   rW   s     r   rY   zTextEntry.on_text_motion  sA    | 	F; 	/K&&v.....	/ 	/r   c                 ^    | j         sd S | j        r| j                            |           d S d S r   )r   r   r   r[   rW   s     r   r[   zTextEntry.on_text_motion_select   sA    | 	F; 	6K--f55555	6 	6r   c                     | j         sd S d S r   )r   rS   s     r   r   zTextEntry.on_commit  s    | 	F::r   )r   r   r   NN)r\   r]   r^   r   r   r%   r_   r'   r`   r;   r   r   rL   rI   rB   rU   rY   r[   r   r   r   s   @r   r   r     s>         U^#'0. 0. 0. 0. 0. 0.dJ J J   X \  \\ \ \$ $ $G G G# # #H H HA A A& & &/ / /6 6 6; ; ; ; ; ; ;r   r   r   )r   rm   pyglet.eventr   pyglet.graphicsr   pyglet.text.caretr   pyglet.text.layoutr   r   rb   register_event_typer   r   r   r   r   r   <module>r      s  H   ( ( ( ( ( ( ( ( ( ( ( ( # # # # # # 4 4 4 4 4 4{ { { { { { { {|M_ M_ M_ M_ M_ M_ M_ M_`   z * * * 
  | , , ,; ; ; ; ;: ; ; ;,      - - -m  m  m  m  m Z m  m  m `   ; ' ' '|; |; |; |; |;
 |; |; |;~ 
  k * * * * *r   