\d!VdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZdadZd Zdd ZGd d ZGd de ZGdde ZdZedkr;eejdkrddlmZedddddlmZeedSdS)zModule browser. XXX TO DO: - reparse when source changed (maybe just a button would be OK?) (or recheck on window popup) - add popup menu with more options (e.g. doc strings, base classes, imports) - add base classes to class browser tree N)idleConf)pyshell)TreeNodeTreeItemScrolledCanvas) py_extensions)ListedToplevel)z.pyictj|\}}tj|}|tvo|t vSN)ospathsplitextnormcaserbrowseable_extension_blocklist)r _exts ..\python\lib\idlelib\browser.pyis_browseable_extensionrsF W  d # #FAs '  3  C -  MC/M$MMcg}|D]\}}| |j|krt|dr|jr|j|krg}|jD]R}t |t r|}n#|j}|j|jkr |jd|}||S|xjdd |z c_|||S)aTransform a child dictionary to an ordered sequence of objects. The dictionary maps names to pyclbr information objects. Filter out imported objects. Augment class names with bases. The insertion order of the dictionary is assumed to have been in line number order, so sorting is not necessary. The current tree only calls this once per child_dict as it saves TreeItems once created. A future tree and tests might violate this, so a check prevents multiple in-place augmentations. Nsuper.z({})z, ) itemsmodulehasattrrname isinstancestrappendformatjoin) child_dictmodnameobskeyobjsuperssupsnames rtransform_childrenr*#s  C$$&&S ?cjG33sG$$ = =sx39))C!#s++< # #:33'*z$;$;E$;$;EMM%((((FMM$))F*;*;<<< JJsOOO Jrc:eZdZdZddddZd dZdZdZd ZdS) ModuleBrowserz1Browse module classes and functions in IDLE. F)_htest_utestcf||_||_||_||_|dS)aCreate a window for browsing a module's structure. Args: master: parent for widgets. path: full path of file to browse. _htest - bool; change box location when running htest. -utest - bool; suppress contents when running unittest. Global variables: file_open: Function used for opening a file. Instance variables: name: Module name. file: Full path and module with supported extension. Used in creating ModuleBrowserTreeItem as the rootnode for the tree and subsequently in the children. N)masterr r-r.init)selfr0r r-r.s r__init__zModuleBrowser.__init__Js1$     rNcj|j|jdS)z&Dismiss the window and the tree nodes.N)topdestroynode)r2events rclosezModuleBrowser.closebs0  rc|j}|js|js tjntj|}|jatj t|x|_ }| d|j|d|j|jrA|d||dzfz||t+j}t+j|dd}t1||dd }|jdd |}t9|jd |x|_}|js*|| d Sd S) z3Create browser tkinter widgets, including the tree.WM_DELETE_WINDOWzz+%d+%dnormal backgroundr)bghighlightthickness takefocusboth)expandfillN)!r0r-r.rflistPyShellFileListopen file_openpyclbr_modulesclearr r5protocolr9bindgeometry winfo_rootx winfo_rootysettitle focus_setr CurrentTheme GetHighlightrframepackrootnodercanvasr7updaterD) r2rootrFr5themer>scitemr7s rr1zModuleBrowser.initgs{'+{4dk4-d33 J (---3 '444 TZ((( ; @ LL!!##T%5%5%7%7#%=>? @ @ @  %''*5(;;LI CJ1&')))  QV ,,,}}#BItT::: D{  KKMMM KKMMMMM  rc|jdtj|jz|jddS)zSet the window title.zModule Browser - zModule BrowserN)r5wm_titler r basename wm_iconnamer2s rrRzModuleBrowser.settitlesM -0@0@0K0KKLLL -.....rc*t|jS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemr rcs rrXzModuleBrowser.rootnodes$TY///rr ) __name__ __module__ __qualname____doc__r3r9r1rRrXrrr,r,Cs 05U0 >/// 00000rr,c<eZdZdZdZdZdZdZdZdZ dZ d S) rez~Browser tree for Python module. Uses TreeItem as the basis for the structure of the tree. Used by both browsers. c||_dS)zdCreate a TreeItem for the file. Args: file: Full path and module name. N)file)r2rms rr3zModuleBrowserTreeItem.__init__s  rcJtj|jS)z5Return the module name as the text string to display.)r r rarmrcs rGetTextzModuleBrowserTreeItem.GetTextsw ***rcdS)'Return the name of the icon to display.pythonrjrcs r GetIconNamez!ModuleBrowserTreeItem.GetIconNamesxrc>d|DS)*Return ChildBrowserTreeItems for children.c,g|]}t|SrjChildBrowserTreeItem.0r&s r z4ModuleBrowserTreeItem.GetSubList..s!IIIc$S))IIIr) listchildrenrcs r GetSubListz ModuleBrowserTreeItem.GetSubLists"IIT5F5F5H5HIIIIrct|jsdStj|jsdSt |jdS)z6Open a module in an editor window when double clicked.N)rrmr r existsrIrcs r OnDoubleClickz#ModuleBrowserTreeItem.OnDoubleClicksL&ty11  Fw~~di((  F$)rc*t|jS)zReturn True if Python file.)rrmrcs r IsExpandablez"ModuleBrowserTreeItem.IsExpandables&ty111rcNt|jsgStj|j\}}tj|\}} t j||gtjz}n#t$rgcYSwxYwt||S)z5Return sequenced classes and functions in the module.) rrmr r splitrrJ readmodule_exsys ImportErrorr*)r2dirbaserrtrees rr|z"ModuleBrowserTreeItem.listchildrens&ty11 IGMM$),, T'""4((a 'sech.>??DD   III !$---s!#B BBN) rfrgrhrir3rorsr}rrr|rjrrreres +++JJJ222 . . . . .rrec6eZdZdZdZdZdZdZdZdZ dS) rxzsBrowser tree for child nodes within the module. Uses TreeItem as the basis for the structure of the tree. cj||_|j|_t|tj|_dS)z5Create a TreeItem for a pyclbr class/function object.N)r&rrrJFunction isfunction)r2r&s rr3zChildBrowserTreeItem.__init__s)H $S&/::rc8|j}|jrd|zdzSd|zS)z1Return the name of the function/class to display.zdef z(...)zclass )rr)r2rs rrozChildBrowserTreeItem.GetTexts,y ? #D=7* *d? "rc|jrdSdS)rqrrfolder)rrcs rrsz ChildBrowserTreeItem.GetIconNames ? 88rc"|jjikS)z+Return True if self.obj has nested objects.)r&childrenrcs rrz!ChildBrowserTreeItem.IsExpandablesx B&&rcHdt|jjDS)ruc,g|]}t|Srjrwrys rr{z3ChildBrowserTreeItem.GetSubList..s6BBB%S))BBBr)r*r&rrcs rr}zChildBrowserTreeItem.GetSubLists6BB-dh.?@@BBB Brc t|jj}||jjdS#t t f$rYdSwxYw)z2Open module with file_open and position to lineno.N)rIr&rmgotolinelinenoOSErrorAttributeError)r2edits rrz"ChildBrowserTreeItem.OnDoubleClicks[ TX]++D MM$(/ * * * * *(    DD s8<AAN) rfrgrhrir3rorsrr}rrjrrrxrxs{ ;;; ###'''BBB rrxcttjdkrtjd}nt}Gddt}d}t ||ddS)Nr?ceZdZdZdS)'_module_browser..Nested_in_funccdSr rjrjrrnested_in_classz7_module_browser..Nested_in_func.nested_in_classsrN)rfrgrhrrjrrNested_in_funcrs ' ' ' ' 'rrc Gdd}dS)NceZdZdS);_module_browser..closure..Nested_in_closureN)rfrgrhrjrrNested_in_closurersrrrj)rs rclosurez _module_browser..closures ) ) ) ) ) ) ) ) ) )rT)r-)lenrargv__file__rr,)parentrmrrs r_module_browserrs{ 38}}qx{ ( ( ( ( (X ( ( ( * * *&$t,,,,,,r__main__r?)mainzidlelib.idle_test.test_browserF) verbosityexit)runr )rir rJridlelib.configridlelibr idlelib.treerrr idlelib.utilridlelib.windowr rIrrr*r,rerxrrfrrunittestridlelib.idle_test.htestrrjrrrs ######;;;;;;;;;;&&&&&&))))))  "+NNN @J0J0J0J0J0J0J0J0Z1.1.1.1.1.H1.1.1.h*****8***Z - - - z s38}}!!!!!!  -GGGG++++++C r