3 ^: @s"ddlZddlTddlmZddlmZddlmZdZyej j ej j e eZ Wnek rjeZ YnXej je r~e Znej jesedefefdd ZGd d d ZGd d d ZGdddeZGdddZddZedkrddlmZeddddddlmZeedS)N)*) Scrollbar)idleConf) zoomheightZIconszcan't find icon directory (%r)c Cst}ddl}|jtjj|d}|jg}d}}x|D]}tjjtjj|d}t||d} |j | t || ddd} | j ||dt ||d} | j |d|d|d}|d kr<|d }d}qs zTreeNode.__init__cCs6x*|jddD]}|jj||jqWd|_dS)N)r*removedestroyr&)r.cr r r!r1Hs  zTreeNode.destroyc Csfy |j|Stk rYnXtjj|\}}|p6d}tjjt||}t|j|d}||j|<|S)Nz.gif)rr) r-KeyErrorrrrrICONDIRrr%)r.rrZextfullnamer r r r! geticonimageNs  zTreeNode.geticonimageNcCs:|jr dS|jd|_|jj|j|j|jdS)NT)r) deselectallr%deleteimage_iddrawicondrawtext)r.eventr r r!selectZszTreeNode.selectcCs2|js dSd|_|jj|j|j|jdS)NF)r)r%r8r9r:r;)r.r<r r r!deselectcs zTreeNode.deselectcCs|jr|jjn|jdS)N)r&r7 deselecttree)r.r r r!r7ks zTreeNode.deselectallcCs*|jr|jx|jD] }|jqWdS)N)r)r>r*r?)r.childr r r!r?qs zTreeNode.deselecttreecCs*|jdkr|jn|j|jjdS)Nexpandedbreak)r(collapseexpandr' OnDoubleClick)r.r<r r r!flipws    z TreeNode.flipcCs2|jjsdS|jdkr.d|_|j|jdS)NrA)r' _IsExpandabler(updateview)r.r<r r r!rDs   zTreeNode.expandcCs|jdkrd|_|jdS)Nr$)r(rH)r.r<r r r!rCs zTreeNode.collapsec Cs|jd}|jjd}||}|jjd}|jj}|jj|}||krV||krVdS|jj|jd\}}} } ||kr||kr|||} n|} t| | } |jj| dS)Nrr scrollregion)r,lastvisiblechildr%ZcanvasyZ winfo_heightZ_getintsfloatZ yview_moveto) r.topZbottomZheightZ visible_topZvisible_heightZvisible_bottomx0y0x1y1Zfractionr r r!rIs     z TreeNode.viewcCs&|jr|jdkr|jdjS|SdS)NrAr)r*r(rL)r.r r r!rLszTreeNode.lastvisiblechildcCs|jr|jjnj|jd}d|jd<|jj|jjt|jdd|jjt\}}}}|jjdd||fd||jd<dS)NZcursorZwatchrr)rK)r&rHr%r8ZALLdrawbbox configure)r.Z oldcursorrOrPrQrRr r r!rHs      zTreeNode.updatecCsxd}|||_|_|j|j|jdkr4||S|jsz|jj}|sP|dSx(|D] }|j|j ||}|jj |qVW|d}||}d} x|jD]}|} |j j |d|d||ddd|j ||}|jj r|jdkrd } |j} n d } |j} |j| } |j j|d| d| d } |j j| d | |j j| d ddqW|j j |d|d|d| ddd} |j j| |S)NrArJr rTZgray50)fillZ minusnodeZplusnode)r z<1>z cSsdS)Nr )r+r r r!szTreeNode.draw..r)r+r,r:r;r(r*r' _GetSubList __class__r%rZ create_linerUrGrCrDr6 create_imagetag_bindZ tag_lower)r.r+r,Zdysublistr'r@ZcxZcyZcylastZiconnamecallbackr idr r r!rUsD    "     z TreeNode.drawcCs~|jr |jjp|jjpd}n|jjp,d}|j|}|jj|j|jd|d}||_ |jj |d|j |jj |d|j dS)NZ openfolderZfoldernw)anchorr z<1>z ) r)r'GetSelectedIconName GetIconNamer6r%r^r+r,r9r_r=rF)r.Z imagenamer rbr r r!r:s   zTreeNode.drawiconc Csf|jdd}|jd}|jj}|r|jj||d|d}|jj|d|j|jj|d|j|jj |\}}}}t |dd }|jj pd } y |j Wnt k rYn X|jy |jWn*t k rt|j| d d d d |_YnXtj} |jr|jjtj| dn|jjtj| d|jj||d|jd}|jjd|j|jjd|j||_dS)NrXrrc)rdr z<1>z rz rr)r r ZpadxZpadyZhiliteZnormal)rdZwindow)r+r,r' GetLabelTextr%Z create_textr_r=rFrVmaxGetTextentryAttributeError edit_finishrrrZ CurrentThemer)rWZ GetHighlightZ create_windowbindselect_or_editZtext_id) r.ZtextxZtextyZ labeltextrbrOrPrQrRr Zthemer r r!r;s:       zTreeNode.drawtextcCs*|jr|jjr|j|n |j|dS)N)r)r' IsEditableeditr=)r.r<r r r!rp s zTreeNode.select_or_editcCsrt|jdddd|_|jjd|jd|jjdt|jjdd|jj|jjd|j |jjd|j dS) Nrr)r highlightthicknesswidthr )Zipadxzz) ZEntryrrlinsertZselection_rangeZENDpack focus_setrorn edit_cancel)r.r<r r r!rrs z TreeNode.editc Cs|y|j}|`Wntk r"dSX|j}|j|rR||jjkrR|jj||jj}||jd<|j|j j dS)Nr ) rlrmgetr1r'rkSetTextrr;r%rx)r.r<rlr r r r!rns   zTreeNode.edit_finishc CsBy|j}|`Wntk r"dSX|j|j|jjdS)N)rlrmr1r;r%rx)r.r<rlr r r!ry'szTreeNode.edit_cancel)N)N)N)N)N)N)N)N)N)__name__ __module__ __qualname__r/r1r6r=r>r7r?rFrDrCrIrLrHrUr:r;rprrrnryr r r r!r#<s(      * "  r#c@speZdZddZddZddZdZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS)TreeItemcCsdS)Nr )r.r r r!r/;szTreeItem.__init__cCsdS)Nr )r.r r r!rk>szTreeItem.GetTextcCsdS)Nr )r.r r r!riAszTreeItem.GetLabelTextNcCs|jdkr|j|_|jS)N) expandable IsExpandable)r.r r r!rGFs  zTreeItem._IsExpandablecCsdS)Nrr )r.r r r!rLszTreeItem.IsExpandablecCs"|js gS|j}|sd|_|S)Nr)r GetSubListr)r.r`r r r!r\Ps zTreeItem._GetSubListcCsdS)Nr )r.r r r!rqYszTreeItem.IsEditablecCsdS)Nr )r.r r r r!r{\szTreeItem.SetTextcCsdS)Nr )r.r r r!rf_szTreeItem.GetIconNamecCsdS)Nr )r.r r r!rebszTreeItem.GetSelectedIconNamecCsdS)Nr )r.r r r!reszTreeItem.GetSubListcCsdS)Nr )r.r r r!rEhszTreeItem.OnDoubleClick)r|r}r~r/rkrirrGrr\rqr{rfrerrEr r r r!r2s  rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) FileTreeItemcCs ||_dS)N)r)r.rr r r!r/rszFileTreeItem.__init__cCstjj|jp|jS)N)rrr)r.r r r!rkuszFileTreeItem.GetTextcCstjj|jdkS)N)rrr)r.r r r!rqxszFileTreeItem.IsEditablec Csltjj|j}tjj||}tjj|tjj|jkr:dSytj|j|||_Wntk rfYnXdS)N)rrdirnamerrenameOSError)r.r newpathr r r!r{{s zFileTreeItem.SetTextcCs|js dSdS)Npython)r)r.r r r!rfszFileTreeItem.GetIconNamecCstjj|jS)N)rrisdir)r.r r r!rszFileTreeItem.IsExpandablec Csjytj|j}Wntk r$gSX|jtjjdg}x*|D]"}ttjj|j|}|j|q@W|S)N)key) rlistdirrrrnormcaserrr)r.namesr`rr'r r r!rs zFileTreeItem.GetSubListN) r|r}r~r/rkrqr{rfrrr r r r!rns rc@s<eZdZddZddZddZddZd d Zd d Zd S)ScrolledCanvascKs>d|krd|d<||_t||_|jjddd|jjdddt|jf||_|jjddddt|jdd |_ |j jddd dt|jd d d |_ |j jdddd|j j |jd<|jj |j d<|j j |jd<|jj |j d<|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjdS)NZyscrollincrementrJrr)ZweightZnsew)r r Zstickyvbar)rZnsehbarZ horizontal)rZorientZewsZyscrollcommandZcommandZxscrollcommandz z zz z )rZFrameframeZ rowconfigureZcolumnconfigureZCanvasr%rrrrsetZyviewZxviewropage_up page_downunit_up unit_down zoom_heightrx)r.rZoptsr r r!r/s, zScrolledCanvas.__init__cCs|jjdddS)NrpagerBrS)r% yview_scroll)r.r<r r r!rszScrolledCanvas.page_upcCs|jjdddS)NrrrB)r%r)r.r<r r r!rszScrolledCanvas.page_downcCs|jjdddS)NrunitrBrS)r%r)r.r<r r r!rszScrolledCanvas.unit_upcCs|jjdddS)NrrrB)r%r)r.r<r r r!rszScrolledCanvas.unit_downcCstj|jdS)NrB)rrr)r.r<r r r!rs zScrolledCanvas.zoom_heightN) r|r}r~r/rrrrrr r r r!rs rcCst|}tt|jjddd\}}|jd|d|dft|dddd}|jjdd td t t }t |j d|}|j dS) N+rz+%d+%d2Zwhiter)ZbgrsZ takefocusZboth)rDrZZside)ZToplevelmapintZgeometrysplitrrrwZLEFTrr4r#r%rD)r&rNr+r,Zscr'Znoder r r! _tree_widgets r__main__)mainzidlelib.idle_test.test_treerF) verbosityexit)run)rZtkinterZ tkinter.ttkrZidlelib.configrZidlelibrr4rrr__file__Z_icondir NameErrorr RuntimeErrorr"r#rrrrr|ZunittestrZidlelib.idle_test.htestrr r r r!s2       w<.*