3 ^:c @s"ddlZddlTddlmZddlmZddlmZdZyej j ej j e eZ Wnek rjeZ YnXej je r~e Znej jesedefefdd ZGd d d ZGd d d ZGdddeZGdddZddZedkrddlmZeddddddlmZeedS)N)Z*) 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|_dSN)r&Zremovedestroyr")r*Zcrrrr-Hs  zTreeNode.destroyc Csfy |j|Stk rYnXtjj|\}}|p6d}tjjt||}t|j|d}||j|<|S)Nz.gif)rr) r)ZKeyErrorrrrrICONDIRrr!)r*rrZextZfullnamerrrr geticonimageNs  zTreeNode.geticonimageNcCs:|jr dS|jd|_|jj|j|j|jdS)NT)r% deselectallr!deleteimage_iddrawicondrawtextr*eventrrrselectZszTreeNode.selectcCs2|js dSd|_|jj|j|j|jdS)NF)r%r!r1r2r3r4r5rrrdeselectcs zTreeNode.deselectcCs|jr|jjn|jdSr,)r"r0 deselecttreer*rrrr0ks zTreeNode.deselectallcCs*|jr|jx|jD] }|jqWdSr,)r%r8r&r9)r*childrrrr9qs zTreeNode.deselecttreecCs*|jdkr|jn|j|jjdS)Nexpandedbreak)r$collapseexpandr# OnDoubleClickr5rrrflipws    z TreeNode.flipcCs2|jjsdS|jdkr.d|_|j|jdS)Nr<)r# _IsExpandabler$updateviewr5rrrr?s   zTreeNode.expandcCs|jdkrd|_|jdS)Nr )r$rCr5rrrr>s zTreeNode.collapsec Cs|jd}|jjd}||}|jjd}|jj}|jj|}||krV||krVdS|jj|jd\}}} } ||kr||kr|||} n|} t| | } |jj| dS)Nr r scrollregion)r(lastvisiblechildr!ZcanvasyZ winfo_heightZ_getintsZfloatZ yview_moveto) r*topZbottomZheightZ visible_topZvisible_heightZvisible_bottomx0y0x1y1ZfractionrrrrDs     z TreeNode.viewcCs&|jr|jdkr|jdjS|SdS)Nr<r)r&r$rGr:rrrrGszTreeNode.lastvisiblechildcCs|jr|jjnj|jd}d|jd<|jj|jjt|jdd|jjt\}}}}|jjdd||fd||jd<dS)NZcursorZwatchr r)rF)r"rCr!r1ZALLdrawbbox configure)r*Z oldcursorrIrJrKrLrrrrCs      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)Nr<rEri rNZgray50)fillZ minusnodeZplusnode)r<1> cSdSr,r)r'rrrZzTreeNode.draw..r )r'r(r3r4r$r&r# _GetSubListZ __class__r!rZ create_linerOrBr>r?r/ create_imagetag_bindZ tag_lower)r*r'r(Zdysublistr#r;ZcxZcyZcylastZiconnameZcallbackridrrrrOsD    "     z TreeNode.drawcCs~|jr |jjp|jjpd}n|jjp,d}|j|}|jj|j|jd|d}||_ |jj |d|j |jj |d|j dS)NZ openfolderZfoldernw)anchorrrTrU) r%r#GetSelectedIconName GetIconNamer/r!rYr'r(r2rZr7rA)r*Z imagenamerr\rrrr3s   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)NrRrir])r^r rTrUir z rr )r rZpadxZpadyZhiliteZnormal)r^Zwindow)r'r(r# GetLabelTextr!Z create_textrZr7rArPZmaxGetTextentryAttributeError edit_finishrrrZ CurrentThemer%rQZ GetHighlightZ create_windowbindselect_or_editZtext_id) r*ZtextxZtextyZ labeltextr\rIrJrKrLr Zthemerrrr4s:       zTreeNode.drawtextcCs*|jr|jjr|j|n |j|dSr,)r%r# IsEditableeditr7r5rrrrg s zTreeNode.select_or_editcCsrt|jdddd|_|jjd|jd|jjdt|jjdd|jj|jjd|j |jjd|j dS) Nrr)rhighlightthicknessZwidthr i)Zipadxzz) ZEntryrrcZinsertZselection_rangeZENDpack focus_setrfre edit_cancelr5rrrris z TreeNode.editc Cs|y|j}|`Wntk r"dSX|j}|j|rR||jjkrR|jj||jj}||jd<|j|j j dS)Nr ) rcrdZgetr-r#rbSetTextrr4r!rl)r*r6rcr rrrres   zTreeNode.edit_finishc CsBy|j}|`Wntk r"dSX|j|j|jjdSr,)rcrdr-r4r!rl)r*r6rcrrrrm'szTreeNode.edit_cancelr,r,r,r,r,r,r,r,r,)__name__ __module__ __qualname__r+r-r/r7r8r0r9rAr?r>rDrGrCrOr3r4rgrirermrrrrr<s(      * "  rc@speZdZddZddZddZdZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS)TreeItemcCrVr,rr:rrrr+;rWzTreeItem.__init__cCrVr,rr:rrrrb>rWzTreeItem.GetTextcCrVr,rr:rrrraArWzTreeItem.GetLabelTextNcCs|jdkr|j|_|jSr,) expandable IsExpandabler:rrrrBFs  zTreeItem._IsExpandablecCsdS)Nrrr:rrrrtLszTreeItem.IsExpandablecCs"|js gS|j}|sd|_|S)Nr)rt GetSubListrs)r*r[rrrrXPs zTreeItem._GetSubListcCrVr,rr:rrrrhYrWzTreeItem.IsEditablecCrVr,r)r*r rrrrn\rWzTreeItem.SetTextcCrVr,rr:rrrr`_rWzTreeItem.GetIconNamecCrVr,rr:rrrr_brWzTreeItem.GetSelectedIconNamecCrVr,rr:rrrruerWzTreeItem.GetSubListcCrVr,rr:rrrr@hrWzTreeItem.OnDoubleClick)rorprqr+rbrarsrBrtrXrhrnr`r_rur@rrrrrr2s  rrc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) FileTreeItemcCs ||_dSr,)r)r*rrrrr+rzFileTreeItem.__init__cCstjj|jp|jSr,rrrr:rrrrburwzFileTreeItem.GetTextcCstjj|jdkS)NZrxr:rrrrhxrwzFileTreeItem.IsEditablec Csltjj|j}tjj||}tjj|tjj|jkr:dSytj|j|||_Wntk rfYnXdSr,)rrdirnamerZrenameOSError)r*r Znewpathrrrrn{s zFileTreeItem.SetTextcCs|js dSdS)NZpython)rtr:rrrr`szFileTreeItem.GetIconNamecCstjj|jSr,)rrisdirr:rrrrtrwzFileTreeItem.IsExpandablec Csjytj|j}Wntk r$gSX|jtjjdg}x*|D]"}ttjj|j|}|j|q@W|S)N)Zkey) rZlistdirrrzrZnormcaservrr)r*Znamesr[rr#rrrrus zFileTreeItem.GetSubListN) rorprqr+rbrhrnr`rtrurrrrrvns rvc@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)NZyscrollincrementrErr)ZweightZnsew)r r Zstickyvbar)rZnsehbarZ horizontal)rZorientZewsZyscrollcommandZcommandZxscrollcommandz z zz z )rZFrameframeZ rowconfigureZcolumnconfigureZCanvasr!rrr}r~ZsetZyviewZxviewrfpage_up page_downunit_up unit_down zoom_heightrl)r*rZoptsrrrr+s, zScrolledCanvas.__init__cC|jjdddS)Nrpager=rMr!Z yview_scrollr5rrrrzScrolledCanvas.page_upcC|jjdddS)Nrrr=rr5rrrrrzScrolledCanvas.page_downcCr)Nrunitr=rMrr5rrrrrzScrolledCanvas.unit_upcCr)Nrrr=rr5rrrrrzScrolledCanvas.unit_downcCstj|jdS)Nr=)rrrr5rrrrs zScrolledCanvas.zoom_heightN) rorprqr+rrrrrrrrrr|s r|cCst|}tt|jjddd\}}|jd|d|dft|dddd}|jjdd td t t }t |j d|}|j dS) Nz+rz+%d+%di2iZwhiter)ZbgrjZ takefocusZboth)r?rSZside)ZToplevelZmapZintZgeometryZsplitr|rrkZLEFTrvr.rr!r?)r"rHr'r(Zscr#Znoderrr _tree_widgets rZ__main__)mainzidlelib.idle_test.test_treer F)Z verbosityZexit)run)rZtkinterZ tkinter.ttkrZidlelib.configrZidlelibrr.rrryZ__file__Z_icondirZ NameErrorr{Z RuntimeErrorrrrrrvr|rroZunittestrZidlelib.idle_test.htestrrrrrZs2       w<.*