a
    Ifk                     @   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