a
    }Œ@hk  ã                   @   sp   d Z ddlZddlZddlZG dd„ deƒZG dd„ dƒZdd„ Zd	d
„ Ze	dkrlddl
mZ edddd� dS )z Zoom a window to maximum height.é    Nc                   @   s   e Zd ZdS )ÚWmInfoGatheringErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú#lib/python3.9/idlelib/zoomheight.pyr      s   r   c                   @   s2   e Zd Zi Zdd„ Zd
dd„Zdd„ Zdd	„ ZdS )Ú
ZoomHeightc                 C   s   || _ | j j| _d S )N)ÚeditwinÚtop)Úselfr	   r   r   r   Ú__init__   s    zZoomHeight.__init__Nc                 C   sD   |   ¡ }|d u r| j ¡  n$|r$dnd}| jjdd|› d�d� dS )NZRestoreZZoomZoptionsz* Heightz Height)ZmenuÚindexZlabelÚbreak)Úzoom_heightr
   Zbellr	   Zupdate_menu_label)r   ZeventÚzoomedZmenu_statusr   r   r   Úzoom_height_event   s    
ÿzZoomHeight.zoom_height_eventc                 C   s|   | j }t|ƒ\}}}}| ¡ dkr&d S z|  ¡ \}}W n tyJ   Y d S 0 ||krjt|||||fƒ dS | d¡ dS d S )NÚnormalTÚ F)r
   Úget_window_geometryÚwm_stateÚget_max_height_and_y_coordr   Úset_window_geometryÚwm_geometry)r   r
   ÚwidthZheightÚxÚyÚ	maxheightÚmaxyr   r   r   r   !   s    
zZoomHeight.zoom_heightc                 C   s   | j }| ¡ | ¡ f}|| jvrö| ¡ }z| d¡ W n tjyR   tdƒ‚Y n0 | ¡  t	|ƒ\}}}}t
jdkrzd}| ¡ }| d¡ | ¡  t	|ƒ}	|	d d… |f }
t||
ƒ | ¡  | ¡ }||| 7 }||f| j|< t||	ƒ | |¡ | j| S )Nr   z_Failed getting geometry of maximized windows, because the "zoomed" window state is unavailable.Zwin32r   r   é   )r
   Zwinfo_screenwidthZwinfo_screenheightÚ_max_height_and_y_coordsr   ÚtkinterZTclErrorr   Úupdater   ÚsysÚplatformZwinfo_rootyr   )r   r
   Zscreen_dimensionsZ
orig_stateZmaxwidthr   Zmaxxr   ZmaxrootyZ	orig_geomZ
max_y_geomZmax_y_geom_rootyr   r   r   r   <   s:    ÿ
ÿ





z%ZoomHeight.get_max_height_and_y_coord)N)r   r   r   r   r   r   r   r   r   r   r   r   r      s
   
r   c                 C   s&   |   ¡ }t d|¡}ttt| ¡ ƒƒS )Nz(\d+)x(\d+)\+(-?\d+)\+(-?\d+))r   ÚreÚmatchÚtupleÚmapÚintÚgroups)r
   ZgeomÚmr   r   r   r   n   s    r   c                 C   s   |   dj|Ž ¡ d S )Nz{:d}x{:d}+{:d}+{:d})r   Úformat)r
   Zgeometryr   r   r   r   t   s    r   Ú__main__)Úmainz!idlelib.idle_test.test_zoomheighté   F)Ú	verbosityÚexit)Ú__doc__r$   r"   r    Ú	Exceptionr   r   r   r   r   Zunittestr-   r   r   r   r   Ú<module>   s   b