
    kj2                     j    d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZ  G d de
          ZdS )	    )Path)Any)QtCoreQtGuiQtOpenGL	QtWidgets)
BaseWindow)Keysc                   8    e Zd ZdZdZeZddddZdef fdZ	d	e
d
dfdZd	e
d
dfdZed
eeef         fd            Zej        d	eeef         d
dfd            Zed
eeef         fd            Zej        d	eeef         d
dfd            Zed
e
fd            Zej        d	e
d
dfd            Zd,dZed
e
fd            Zej        d	e
d
dfd            Zed
efd            Zej        d	ed
dfd            Zdeded
df fdZded
dfdZded
dfdZd ej        d
dfd!Zd ej        d
dfd"Zd ej        d
dfd#Z d ej        d
dfd$Z!d ej        d
dfd%Z"d ej        d
dfd&Z#d ej        d
dfd'Z$d, fd(Z%d ej        d
dfd)Z&d ej        d
dfd*Z'd,d+Z( xZ)S )-Windowa  
    A basic window implementation using PyQt5 with the goal of
    creating an OpenGL context and handle keyboard and mouse input.

    This window bypasses Qt's own event loop to make things as flexible as possible.

    If you need to use the event loop and are using other features
    in Qt as well, this example can still be useful as a reference
    when creating your own window.
    pyqt5         )r   r      kwargsc                 	    t                      j        di | t          j                    }|                    | j        d         | j        d                    |                    t          j        j                   |                    d           |	                    d           |
                    d           |                    | j        rdnd           | j        dk    r<|                    d           |                    t!          | j                             t#          j        g           | _        t          j        |          | _        | j        | _        | j        rt#          j                                                    }|                                | _        |                                | _        |                                | j                                        z  | _         |                                | j                                        z  | _!        | j"        rst#          j#        t"          j#        j$        t"          j#        j$                  }| j        %                    |           | j        &                    | j        | j                   n%| j        '                    | j        | j                   | j(        s| j        )                                 | j        sYt!          | j*        d         | j        dz  z
            t!          | j*        d         | j        dz  z
            f} | j        j+        |  | j&        | j        _,        | j-        | _.        | j        r| j        /                                 n| j        0                                 | j        1                    d           | j2        | j        _3        | j4        | j        _5        | j6        | j        _7        | j8        | j        _9        | j:        | j        _;        | j<        | j        _=        | j>        | j        _?        | j@        | j        _A        | jB        | j        _C        | D                                 | j        | j                                        z  | _         | j        | j                                        z  | _!        | E                                 d S )Nr   r         Tr    )Fsuper__init__r   	QGLFormat
setVersion
gl_version
setProfileCoreProfilesetDepthBufferSizesetStencilBufferSizesetDoubleBuffersetSwapInterval_vsyncsamplessetSampleBuffers
setSamplesintr   QApplication_app	QGLWidget_widget_titletitle
fullscreenQDesktopWidgetscreenGeometrywidth_widthheight_heightdevicePixelRatio_buffer_width_buffer_height	resizableQSizePolicy	ExpandingsetSizePolicyresizesetFixedSizevisiblehidepositionmoveresizeGL_cursorcursorshowFullScreenshowsetMouseTrackingkey_pressed_eventkeyPressEventkey_release_eventkeyReleaseEventmouse_move_eventmouseMoveEventmouse_press_eventmousePressEventmouse_release_eventmouseReleaseEventmouse_wheel_event
wheelEventclose_event
closeEvent
show_event	showEvent
hide_event	hideEventinit_mgl_contextset_default_viewport)selfr   glrectsize_policycenter_window_position	__class__s         _/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/context/pyqt5/window.pyr   zWindow.__init__"   s   ""6""" !!
doa($/!*<===
h(4555
b!!!
"""
4   
211333 <!%%%MM#dl++,,, *2..	  )"--[
 ? 	R+--<<>>D**,,DK;;==DL!%0M0M0O0O!OD"&++--$,2O2O2Q2Q"QD> 		?#/%/%/ K L&&{333L
DK8888L%%dj$+>>>| 	 L  	7DM!$tzA~566DM!$t{Q677&" DL566 !%l? 	 L''))))L 	%%d+++ &*%;"'+'=$&*&;#'+'=$)-)A&"&"8"&"2!%!% 	 "[4<+H+H+J+JJ"lT\-J-J-L-LL!!#####    valuereturnNc                 r    |r| j                                          d S | j                                          d S N)r*   rD   
showNormalr[   rc   s     ra   _set_fullscreenzWindow._set_fullscreenz   s>     	&L'')))))L##%%%%%rb   c                     d S rf   r   rh   s     ra   
_set_vsynczWindow._set_vsync   s    rb   c                     | j         | j        fS )ztuple[int, int]: current window size.

        This property also support assignment::

            # Resize the window to 1000 x 1000
            window.size = 1000, 1000
        )r1   r3   r[   s    ra   sizezWindow.size   s     {DL((rb   c                 ~    | j         }| j                            |d         |d         |d         |d                    d S Nr   r   )r?   r*   setGeometry)r[   rc   poss      ra   rn   zWindow.size   s;    m  QQq58DDDDDrb   c                     | j                                         }|                                |                                fS )ztuple[int, int]: The current window position.

        This property can also be set to move the window::

            # Move window to 100, 100
            window.position = 100, 100
        )r*   geometryxy)r[   geos     ra   r?   zWindow.position   s2     l##%%uuwwrb   c                 l    | j                             |d         |d         | j        | j                   d S rp   )r*   rq   r1   r3   rh   s     ra   r?   zWindow.position   s0      q58T[$,OOOOOrb   c                     | j         S )zbool: Is the window visible?

        This property can also be set::

            # Hide or show the window
            window.visible = False
        )_visiblerm   s    ra   r=   zWindow.visible   s     }rb   c                     || _         |r| j                                         d S | j                                         d S rf   )rz   r*   rE   r>   rh   s     ra   r=   zWindow.visible   sE     	 LLrb   c                     | j                                          |                                  | j                                         | xj        dz  c_        dS )zFSwap buffers, set viewport, trigger events and increment frame counterr   N)r*   swapBuffersrZ   r(   processEvents_framesrm   s    ra   swap_bufferszWindow.swap_buffers   sP      """!!###	!!!rb   c                     | j         S )zbool: Should the mouse cursor be visible inside the window?

        This property can also be assigned to::

            # Disable cursor
            window.cursor = False
        )rB   rm   s    ra   rC   zWindow.cursor   s     |rb   c                     |du r*| j                             t          j        j                   n)| j                             t          j        j                   || _        d S )NT)r*   	setCursorr   QtArrowCursorBlankCursorrB   rh   s     ra   rC   zWindow.cursor   sO    D==L""69#89999L""69#8999rb   c                     | j         S )zlstr: Window title.

        This property can also be set::

            window.title = "New Title"
        )r+   rm   s    ra   r,   zWindow.title   s     {rb   c                 H    | j                             |           || _        d S rf   )r*   setWindowTitler+   rh   s     ra   r,   zWindow.title   s#    ##E***rb   r0   r2   c                 6   || j                                         z  | _        || j                                         z  | _        || _        || _        | j        r|                                  t                      	                    | j        | j                   dS )zReplacement for Qt's ``resizeGL`` method.

        Args:
            width: New window width
            height: New window height
        N)
r*   r4   r1   r3   r5   r6   _ctxrZ   r   r;   )r[   r0   r2   r`   s      ra   r;   zWindow.resize   s     t|<<>>>!>!>!@!@@"$9 	(%%''' 	t)4+>?????rb   modsc                    t          |t          j        j        z            | j        _        t          |t          j        j        z            | j        _        t          |t          j        j        z            | j        _	        dS )zUpdate modifiersN)
boolr   r   ShiftModifier
_modifiersshiftControlModifierctrlAltModifieralt)r[   r   s     ra   _handle_modifierszWindow._handle_modifiers   s\     $TFI,C%C D D#D69+D$DEE"4&)*?#?@@rb   	icon_pathc                 ^    | j                             t          j        |                     d S rf   )r*   setWindowIconr   QIcon)r[   r   s     ra   	_set_iconzWindow._set_icon   s(    ""5;y#9#9:::::rb   eventc                    | j         1|                                | j         k    r|                                  | j        *|                                | j        k    r| j         | _        |                     |                                           d| j        |                                <   |                     |                                | j	        j
        | j                   |                                }|                                s"|                                | j	        j        k    r|                     |           dS dS )zProcess Qt key press events forwarding them to standard methods

        Args:
            event: The qtevent instance
        NT)	_exit_keykeyclose_fs_keyr-   r   	modifiers_key_pressed_map_key_event_funckeysACTION_PRESSr   textstripSPACE_unicode_char_entered_func)r[   r   r   s      ra   rG   zWindow.key_pressed_event   s    >%%))++*G*GJJLLL<#		t|(C(C"&/1DOu00111-1eiikk*UYY[[$)*@$/RRRzz||::<< 	2599;;$)/99++D11111 :9rb   c                     |                      |                                           d| j        |                                <   |                     |                                | j        j        | j                   dS )zProcess Qt key release events forwarding them to standard methods

        Args:
            event: The qtevent instance
        FN)r   r   r   r   r   r   ACTION_RELEASEr   r[   r   s     ra   rI   zWindow.key_release_event  sd     	u00111-2eiikk*UYY[[$)*BDOTTTTTrb   c                    |                                 |                                }}|                     ||          \  }}| j        j        r|                     ||||           dS |                     ||||           dS )zxForward mouse cursor position events to standard methods

        Args:
            event: The qtevent instance
        N)ru   rv   _calc_mouse_deltamouse_statesany_mouse_drag_event_func_mouse_position_event_func)r[   r   ru   rv   dxdys         ra   rK   zWindow.mouse_move_event  s     wwyy%''))1''1--B  	:''1b"55555++Aq"b99999rb   c                 V   |                      |                                           | j                            |                                          }|dS |                     |d           |                     |                                |                                |           dS )znForward mouse press events to standard methods

        Args:
            event: The qtevent instance
        NT)	r   r   _mouse_button_mapgetbutton!_handle_mouse_button_state_change_mouse_press_event_funcru   rv   r[   r   r   s      ra   rM   zWindow.mouse_press_event(  s     	u00111'++ELLNN;;>F..vt<<<$$UWWYY		6BBBBBrb   c                 V   |                      |                                           | j                            |                                          }|dS |                     |d           |                     |                                |                                |           dS )zpForward mouse release events to standard methods

        Args:
            event: The qtevent instance
        NF)	r   r   r   r   r   r   _mouse_release_event_funcru   rv   r   s      ra   rO   zWindow.mouse_release_event6  s     	u00111'++ELLNN;;>F..vu===&&uwwyy%''))VDDDDDrb   c                     |                      |                                           |                                }|                     |                                dz  |                                dz             dS )a  Forward mouse wheel events to standard metods.

        From Qt docs:

        Returns the distance that the wheel is rotated, in eighths of a degree.
        A positive value indicates that the wheel was rotated forwards away from the user;
        a negative value indicates that the wheel was rotated backwards toward the user.

        Most mouse types work in steps of 15 degrees, in which case the delta value is a
        multiple of 120; i.e., 120 units * 1/8 = 15 degrees.

        However, some mice have finer-resolution wheels and send delta values that are less
        than 120 units (less than 15 degrees). To support this possibility, you can either
        cumulatively add the delta values from events until the value of 120 is reached,
        then scroll the widget, or you can partially scroll the widget in response to each
        wheel event.

        Args:
            event (QWheelEvent): Mouse wheel event
        g      ^@N)r   r   
angleDelta_mouse_scroll_event_funcru   rv   )r[   r   points      ra   rQ   zWindow.mouse_wheel_eventD  si    * 	u00111  ""%%eggii%&7U9JKKKKKrb   c                 .    |                                   dS )z^The standard PyQt close events

        Args:
            event: The qtevent instance
        N)r   r   s     ra   rS   zWindow.close_event]  s     	

rb   c                 p    t                                                       |                                  dS )zClose the windowN)r   r   _close_func)r[   r`   s    ra   r   zWindow.closee  s,    rb   c                 >    d| _         |                     d           dS )zThe standard Qt show eventTFNrz   _iconify_funcr   s     ra   rU   zWindow.show_eventj  s#    5!!!!!rb   c                 >    d| _         |                     d           dS )zThe standard Qt hide eventFTNr   r   s     ra   rW   zWindow.hide_evento  s#    4     rb   c                 f    t           j                                                                         dS )z5Quit the Qt application to exit the window gracefullyN)r   QCoreApplicationinstancequitrm   s    ra   destroyzWindow.destroyt  s)    ((**//11111rb   )rd   N)*__name__
__module____qualname____doc__namer
   r   r   r   r   r   ri   rk   propertytupler&   rn   setterr?   r=   r   rC   strr,   r;   r   r   r   r   QEventrG   rI   rK   rM   rO   rQ   rS   r   rU   rW   r   __classcell__)r`   s   @ra   r   r   
   s       	 	 DD  V$ V$ V$ V$ V$ V$ V$p&T &d & & & &      )eCHo ) ) ) X) 
[E%S/ Ed E E E [E 	 %S/ 	  	  	  X	  _PeCHo P$ P P P _P     X ^ T  d       ^         X ]D T    ] s    X \3 4    \@C @ @ @ @ @ @ @ @$Ac Ad A A A A;4 ;D ; ; ; ;2v} 2 2 2 2 2(Uv} U U U U U:fm : : : : :Cv} C C C C CE E4 E E E ELv} L L L L L2 4         
" "$ " " " "
! !$ ! ! ! !
2 2 2 2 2 2 2 2rb   r   N)pathlibr   typingr   PyQt5r   r   r   r   moderngl_window.context.baser	   "moderngl_window.context.pyqt5.keysr
   r   r   rb   ra   <module>r      s                4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3l2 l2 l2 l2 l2Z l2 l2 l2 l2 l2rb   