
    gf)                         d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 	 	 d
dZ
ddZe j                  j                  e j                  j                  e            fdZddZdd	Zy)    N)tk)msgdbg)Geometryc                 b   t        | t              r@|r0|r.t        j                  | ||      rt        j                  | ||      } 	 t        |       }|S | }|S # t        t        f$ rJ 	 t        |       }n9# t        t        f$ r' 	 t        |       }n# t        t        f$ r | }Y nw xY wY nw xY wY |S w xY w)a  
    Convert value to numeric if possible, or strip delimiters from string.

    Args:
        text (str|int|float|complex): The text input string.
        pre_delim (str): initial string decorator.
        post_delim (str): final string decorator.

    Returns:
        val (int|float|complex): The numeric value of the string.

    Examples:
        >>> auto_convert('<100>', '<', '>')
        100
        >>> auto_convert('<100.0>', '<', '>')
        100.0
        >>> auto_convert('100.0+50j')
        (100+50j)
        >>> auto_convert('1e3')
        1000.0
        >>> auto_convert(1000)
        1000
        >>> auto_convert(1000.0)
        1000.0
    )

isinstancestrfc	has_delimstrip_delimint	TypeError
ValueErrorfloatcomplex)text	pre_delim
post_delimvals       a/var/dept/share/cheung/public_html/OutSchool/python/env/lib/python3.12/site-packages/pytk/util.pyauto_convertr      s    : $T9j9>>$	:>D		d)C J J :& 	Dkz* !$-C!:. C J	sZ   A B.%A10B.1B'BB'B!B' B!!B'$B.&B''B.-B.c                 F   t        j                         }| r7|j                         }|j                         }t	        t        ||            }nC|j                          |j                  dd       |j                  d       |j                         }|j                          |S )z
    Workaround to get the size of the current screen in a multi-screen setup.

    Returns:
        geometry (str): The standard Tk geometry string.
            [width]x[height]+[left]+[top]
    )widthheightz-fullscreenTiconic)r   Tkwinfo_screenwidthwinfo_screenheightr	   r   update_idletasks
attributesstatewinfo_geometrydestroy)from_allrootr   r   geometrys        r   get_screen_geometryr'   =   s     557D&&(((*xeF;<t,

8&&(LLNO    c                    |r t         j                  j                  ||      n|}dD ]a  }|j                  d|z         s	|dz   |z   }n|}	 t	        j
                  |      }| j                  j                  dd| j                  |        y  | j                  j                  dd      }|j                  d	      r|d
z   }nd|z   dz   }	 | j                  |       y # t        j                  $ r' t        j                  dj                  |             Y w xY w# t        j                  $ r' t        j                  dj                  |             Y y w xY w)N)pnggif.)filewm	iconphotozE: Could not use icon `{}`r   windowingsystemwinz.ico@z.xbmzE: Could not use icon `{}`.)ospathjoinendswithr   
PhotoImagecall_wTclErrorwarningswarnformat
startswith
iconbitmap)r%   basenamedirpathbasepathfile_extfilepathicontk_syss           r   set_iconrG   T   s4    3:rww||GX.xH #   x0#~0HH	==h/DGGLL{DGGT:  WW\\$ 12Ff$>F*! 	! {{ 	IMM6==hGH	I ;; F3::8DEFs$   
>CD 7DD7EEc                 j   | j                          |t               }n9t        |t        t        f      s!|j                          |j                         }n|}t        |t              rt	        |      }t	        | j                               }| j                  t        |j                  |                   y N)r   r'   r   r	   r   r"   r&   set_to_center)target	referencer&   target_geometrys       r   centerrN   w   s    
&(	C?3""$++-(C H%v4467O
OOC55h?@Ar(   c                 <      fd}j                  d|       y )Nc                     | j                   }t        | j                   z        }|| j                  kD  r$| j                  }t        | j                  z        }j                  dd||       y )Nr   )in_xyr   r   )r   r   r   place)eventr   r   aspectparentrK   s      r   enforce_aspect_ratioz(set_aspect.<locals>.enforce_aspect_ratio   sc    U[[6)*ELL \\Fv-.E!qf 	 	>r(   z<Configure>)bind)rK   rW   rV   rX   s   ``` r   
set_aspectrZ      s    > KK34r(   )NN)FrI   )g      ?)r3   r;   flyingcircusr
   pytkr   r   r   pytk.Geometryr   r   r'   r4   abspathdirname__file__rG   rN   rZ    r(   r   <module>rb      sZ    	     " -b4  9:FB 
5r(   