Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/idlelib/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/idlelib/__pycache__/tree.cpython-310.pyc

o

0�i�?�@s0ddlZddlTddlmZmZddlmZddlmZdZ	z
ej
�ej
�e
�e	�ZWney6e	ZYnwej
�e�r@eZ	n
ej
�e	�sMede	f��e	fdd	�Zdd
d�ZGdd
�d
�ZGdd�d�ZGdd�de�ZGdd�d�Zdd�Zedkr�ddlmZedddd�ddlmZee�dSdS)�N)�*)�Frame�	Scrollbar)�idleConf)�
zoomheightZIconszcan't find icon directory (%r)cCs�t�}ddl}|�tj�|�|�d��}|��g}d}}|D]E}tj�tj�|��d}t	||d�}	|�
|	�t||	ddd�}
|
j||d�t||d	�}
|
j|d|d�|d}|d
kre|d}d}q ||_
dS)z'Utility to display the available icons.rNz*.gif)�file�master�Zraised)�image�bdZrelief)�row�column)�text�
�)ZTk�glob�os�path�join�escape�sort�splitext�basename�
PhotoImage�append�Label�grid�images)Zicondir�rootr�listrrr
r�namer
�label�r"�3/opt/alt/python310/lib64/python3.10/idlelib/tree.py�	listicons%s(
�
r$cCsRtj|jdktj|jdki}||jrdnd}|dur|jn|}|�t|d�dS)a6Handle scrollwheel event.

    For wheel up, event.delta = 120*n on Windows, -1*n on darwin,
    where n can be > 1 if one scrolls fast.  Flicking the wheel
    generates up to maybe 20 events with n up to 10 or more 1.
    Macs use wheel down (delta = 1*n) to scroll up, so positive
    delta means to scroll up on both systems.

    X-11 sends Control-Button-4,5 events instead.

    The widget parameter is needed so browser label bindings can pass
    the underlying canvas.

    This function depends on widget.yview to not be overridden by
    a subclass.
    r�����NZunits�break)	Z	EventTypeZ
MouseWheelZdeltaZButtonPressZnum�type�widget�yviewZSCROLL)�eventr*Zup�linesr"r"r#�wheel_event;s�r.c@s�eZdZdd�Zdd�Zdd�Zd*dd	�Zd*d
d�Zdd
�Zdd�Z	d*dd�Z
d*dd�Zd*dd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd*d"d#�Zd*d$d%�Zd*d&d'�Zd*d(d)�ZdS)+�TreeNodecCs:||_||_||_d|_d|_g|_d|_|_i|_dS)N�	collapsedF)	�canvas�parent�item�state�selected�children�x�y�
iconimages)�selfr1r2r3r"r"r#�__init__Vs
zTreeNode.__init__cCs2|jdd�D]}|j�|�|��qd|_dS�N)r6�remove�destroyr2)r:�cr"r"r#r>`s

zTreeNode.destroycCsfz|j|WStyYnwtj�|�\}}|pd}tj�t||�}t|j|d�}||j|<|S)Nz.gif)rr)	r9�KeyErrorrrrr�ICONDIRrr1)r:r rZext�fullnamer
r"r"r#�geticonimagefs�
zTreeNode.geticonimageNcCs:|jrdS|��d|_|j�|j�|��|��dS)NT)r5�deselectallr1�delete�image_id�drawicon�drawtext�r:r,r"r"r#�selectrszTreeNode.selectcCs2|jsdSd|_|j�|j�|��|��dS)NF)r5r1rErFrGrHrIr"r"r#�deselect{szTreeNode.deselectcCs |jr
|j��dS|��dSr<)r2rD�deselecttree�r:r"r"r#rD�szTreeNode.deselectallcCs&|jr|��|jD]}|��q
dSr<)r5rKr6rL)r:�childr"r"r#rL�s


�zTreeNode.deselecttreecCs*|jdkr
|��n|��|j��dS)N�expandedr()r4�collapse�expandr3�
OnDoubleClickrIr"r"r#�flip�s



z
TreeNode.flipcCs6|j��sdS|jdkrd|_|��|��dSdS)NrO)r3�
_IsExpandabler4�update�viewrIr"r"r#rQ�s

�zTreeNode.expandcCs |jdkrd|_|��dSdS)Nr0)r4rUrIr"r"r#rP�s
�zTreeNode.collapsecCs�|jd}|��jd}||}|j�d�}|j��}|j�|�}||kr+||kr+dS|j�|jd�\}}}	}
||krG||krG|||}n|}t|�|
}|j�|�dS)Nr�r�scrollregion)r8�lastvisiblechildr1ZcanvasyZwinfo_heightZ_getints�floatZyview_moveto)r:�topZbottomZheightZvisible_topZvisible_heightZvisible_bottom�x0�y0�x1�y1Zfractionr"r"r#rV�s

z
TreeNode.viewcCs"|jr|jdkr|jd��S|S)NrO���)r6r4rYrMr"r"r#rY�szTreeNode.lastvisiblechildcCs�|jr
|j��dS|jd}d|jd<|j��|j�t�|�dd�|j�t�\}}}}|jjdd||fd�||jd<dS)NZcursorZwatch�rr)rX)r2rUr1rEZALL�draw�bbox�	configure)r:Z	oldcursorr\r]r^r_r"r"r#rU�s


zTreeNode.updatecCspd}|||_|_|��|��|jdkr||S|js;|j��}|s(|dS|D]}|�|j	||�}|j�
|�q*|d}||}d}	|jD]T}|}	|j	j|d|d||ddd�|�||�}|j�
�r�|jdkrsd	}
|j}nd
}
|j}|�|
�}|j	j|d|	d|d�}
|j	�|
d|�|j	�|
d
dd��qH|j	j|d|d|d|	ddd�}
|j	�|
�|S)N�rOrWr�	raZgray50)�fillZ	minusnodeZplusnode)r
�<1>�
<Double-1>cSsdSr<r")r7r"r"r#�<lambda>��zTreeNode.draw.<locals>.<lambda>r)r7r8rGrHr4r6r3�_GetSubList�	__class__r1rZcreate_linerbrTrPrQrC�create_image�tag_bindZ	tag_lower)r:r7r8Zdy�sublistr3rNZcxZcyZcylastZiconname�callbackr
�idr"r"r#rb�sH


"


��z
TreeNode.drawcCs~|jr|j��p|j��pd}n|j��pd}|�|�}|jj|j|jd|d�}||_	|j�
|d|j�|j�
|d|j�dS)NZ
openfolderZfolder�nw)�anchorr
rhri)
r5r3�GetSelectedIconName�GetIconNamerCr1rnr7r8rFrorJrS)r:Z	imagenamer
rrr"r"r#rG�s
��
zTreeNode.drawiconc
s��jdd}�jd}�j��}|r@�jj||d|d�}�j�|d�j��j�|d�j��j�	|�\}}}}t
|d�d	}�j��pFd
}	z�jWn	t
yUYnw���z�jWnt
yst�j|	dddd
��_Ynwt��}
�jr��j�t�|
d��n
�j�t�|
d���jj||d�jd�}�j�d�j��j�d�j��j�d�fdd���j�d�fdd���j�d�fdd��|�_dS)Nrer	r%rs)rtrrhri��rz	<no text>rr)rrZpadxZpadyZhiliteZnormal)rtZwindow�<MouseWheel>c�t|�j�Sr<�r.r1��erMr"r#rj�z#TreeNode.drawtext.<locals>.<lambda>�
<Button-4>cryr<rzr{rMr"r#rj r}�
<Button-5>cryr<rzr{rMr"r#rj!r})r7r8r3�GetLabelTextr1Zcreate_textrorJrSrc�max�GetText�entry�AttributeError�edit_finishr!rrZCurrentThemer5rdZGetHighlightZ
create_window�bind�select_or_editZtext_id)r:ZtextxZtextyZ	labeltextrrr\r]r^r_rZthemer"rMr#rH�sH

�
�
�
�
zTreeNode.drawtextcCs,|jr|j��r|�|�dS|�|�dSr<)r5r3�
IsEditable�editrJrIr"r"r#r�$szTreeNode.select_or_editcCsrt|jdddd�|_|j�d|jd�|j�dt�|jjdd�|j��|j�d|j	�|j�d|j
�dS)	Nrr	)r�highlightthickness�widthrr')Zipadxz<Return>z<Escape>)ZEntryr!r��insertZselection_rangeZEND�pack�	focus_setr�r��edit_cancelrIr"r"r#r�*s
z
TreeNode.editcCs|z|j}|`Wn
tyYdSw|��}|��|r)||j��kr)|j�|�|j��}||jd<|��|j	�
�dS)Nr)r�r��getr>r3r��SetTextr!rHr1r�)r:r,r�rr"r"r#r�3s�

zTreeNode.edit_finishcCsBz|j}|`Wn
tyYdSw|��|��|j��dSr<)r�r�r>rHr1r�)r:r,r�r"r"r#r�Bs�zTreeNode.edit_cancelr<)�__name__�
__module__�__qualname__r;r>rCrJrKrDrLrSrQrPrVrYrUrbrGrHr�r�r�r�r"r"r"r#r/Ts*


	



*
%

	r/c@steZdZdZdd�Zdd�Zdd�ZdZd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�TreeItemz�Abstract class representing tree items.

    Methods should typically be overridden, otherwise a default action
    is used.

    cC�dS)z)Constructor.  Do whatever you need to do.Nr"rMr"r"r#r;VrkzTreeItem.__init__cCr�)zReturn text string to display.Nr"rMr"r"r#r�YrkzTreeItem.GetTextcCr�)z>Return label text string to display in front of text (if any).Nr"rMr"r"r#r�\rkzTreeItem.GetLabelTextNcCs|jdur
|��|_|jS)�%Do not override!  Called by TreeNode.N)�
expandable�IsExpandablerMr"r"r#rTas

zTreeItem._IsExpandablecCr�)z"Return whether there are subitems.r	r"rMr"r"r#r�gszTreeItem.IsExpandablecCs"|��sgS|��}|sd|_|S)r�r)r��
GetSubListr�)r:rpr"r"r#rlkszTreeItem._GetSubListcCr�)z-Return whether the item's text may be edited.Nr"rMr"r"r#r�trkzTreeItem.IsEditablecCr�)z+Change the item's text (if it is editable).Nr")r:rr"r"r#r�wrkzTreeItem.SetTextcCr�)z-Return name of icon to be displayed normally.Nr"rMr"r"r#rvzrkzTreeItem.GetIconNamecCr�)z2Return name of icon to be displayed when selected.Nr"rMr"r"r#ru}rkzTreeItem.GetSelectedIconNamecCr�)z%Return list of items forming sublist.Nr"rMr"r"r#r��rkzTreeItem.GetSubListcCr�)z%Called on a double-click on the item.Nr"rMr"r"r#rR�rkzTreeItem.OnDoubleClick)r�r�r��__doc__r;r�r�r�rTr�rlr�r�rvrur�rRr"r"r"r#r�Ms	r�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�FileTreeItemz4Example TreeItem subclass -- browse the file system.cCs
||_dSr<)r)r:rr"r"r#r;�s
zFileTreeItem.__init__cCstj�|j�p	|jSr<�rrrrMr"r"r#r��szFileTreeItem.GetTextcCstj�|j�dkS)N�r�rMr"r"r#r��szFileTreeItem.IsEditablecCsjtj�|j�}tj�||�}tj�|�tj�|j�krdSz
t�|j|�||_WdSty4YdSwr<)rr�dirnamer�rename�OSError)r:r�newpathr"r"r#r��s�zFileTreeItem.SetTextcCs|��sdSdS)NZpython)r�rMr"r"r#rv�s�zFileTreeItem.GetIconNamecCstj�|j�Sr<)rr�isdirrMr"r"r#r��szFileTreeItem.IsExpandablecCshzt�|j�}WntygYSw|jtjjd�g}|D]}ttj�|j|��}|�|�q |S)N)�key)	r�listdirrr�r�normcaser�rr)r:�namesrpr r3r"r"r#r��s�zFileTreeItem.GetSubListN)r�r�r�r�r;r�r�r�rvr�r�r"r"r"r#r��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ScrolledCanvascKsld|vrd|d<||_t|�|_|jjddd�|jjddd�t|jfi|��|_|jjdddd�t|jdd	�|_	|j	jddd
d�t|jddd
�|_
|j
jdddd�|j	j|jd<|jj|j	d<|j
j|jd<|jj
|j
d<|j�d|j�|j�d|j�|j�d|j�|j�d|j�|j�dt�|j�dt�|j�dt�|j�d|j�|j��dS)NZyscrollincrementrWrr	)ZweightZnsew)rr
Zsticky�vbar)r Znse�hbarZ
horizontal)r ZorientZewsZyscrollcommandZcommandZxscrollcommandz<Key-Prior>z
<Key-Next>z<Key-Up>z
<Key-Down>rxr~rz<Alt-Key-2>)rr�frameZrowconfigureZcolumnconfigureZCanvasr1rrr�r��setr+Zxviewr��page_up�	page_down�unit_up�	unit_downr.�zoom_heightr�)r:rZoptsr"r"r#r;�s2
zScrolledCanvas.__init__cC�|j�dd�dS)Nr`�pager(�r1Zyview_scrollrIr"r"r#r���zScrolledCanvas.page_upcCr�)Nr	r�r(r�rIr"r"r#r��r�zScrolledCanvas.page_downcCr�)Nr`�unitr(r�rIr"r"r#r��r�zScrolledCanvas.unit_upcCr�)Nr	r�r(r�rIr"r"r#r��r�zScrolledCanvas.unit_downcCst�|j�dS)Nr()rr�rrIr"r"r#r��szScrolledCanvas.zoom_heightN)	r�r�r�r;r�r�r�r�r�r"r"r"r#r��sr�cCs�t|�}tt|���d�dd��\}}|�d|d|df�t|dddd�}|jjdd	td
�t	t
�}t|jd|�}|�
�dS)N�+r	z+%d+%d�2�Zwhiter)Zbgr�Z	takefocusZboth)rQrgZside)ZToplevel�map�intZgeometry�splitr�r�r�ZLEFTr�rAr/r1rQ)r2r[r7r8Zscr3Znoder"r"r#�_tree_widget�s r��__main__)�mainzidlelib.idle_test.test_treerF)�	verbosity�exit)�runr<)rZtkinterZtkinter.ttkrrZidlelib.configrZidlelibrrArrr��__file__Z_icondir�	NameErrorr��RuntimeErrorr$r.r/r�r�r�r�r�Zunittestr�Zidlelib.idle_test.htestr�r"r"r"r#�<module>s:�
z<..
�