o
     JAfk                     @   st   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r8ddl
mZ edddd dS dS )z Zoom a window to maximum height.    Nc                   @   s   e Zd ZdS )WmInfoGatheringErrorN)__name__
__module____qualname__ r   r   )/usr/lib/python3.10/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   sF   |   }|d u r| j  dS |rdnd}| jjdd| dd dS )NZRestoreZZoomoptionsz* Heightz Height)ZmenuindexZlabelbreak)zoom_heightr   Zbellr
   Zupdate_menu_label)r   eventzoomedZmenu_statusr   r   r   zoom_height_event   s   

zZoomHeight.zoom_height_eventc                 C   sx   | j }t|\}}}}| dkrd S z|  \}}W n
 ty%   Y d S w ||kr5t|||||f dS |d 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ry| }z|d W n tjy'   tdw |  t	|\}}}}t
jdkr;d}| }|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.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_coordr	   )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unittestr1   r   r   r   r   <module>   s    b