o =?h!@sdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZdadZd d Zdd d ZGd ddZGddde ZGddde ZddZedkr|eejdkrpddlmZeddddddlmZeedSdS)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.pyicCs,tj|\}}tj|}|tvo|tvSN)ospathsplitextnormcaserbrowseable_extension_blocklist)r _Zextr6/opt/alt/python310/lib64/python3.10/idlelib/browser.pyis_browseable_extensions rcCsg}|D]R\}}|dus|j|krXt|drS|jrS|j|krSg}|jD] }t|tr/|}n|j}|j|jkr@|jd|}||q%|jdd |7_||q|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)Z child_dictmodnameZobskeyobjZsupersZsupZsnamerrrtransform_children#s       r!c@sBeZdZdZdddddZdddZd d Zd d Zd dZdS) ModuleBrowserz1Browse module classes and functions in IDLE. F)_htest_utestcCs$||_||_||_||_|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)selfr%r r#r$rrr__init__Js  zModuleBrowser.__init__NcCs|j|jdS)z&Dismiss the window and the tree nodes.N)topZdestroynode)r'Zeventrrrclosebs zModuleBrowser.closec Cs|j}|js |js tjnt|}|jatj t ||_ }| d|j|d|j|jr@|d||df||t}t|dd}t||ddd }|jjdd d |}t|jd ||_}|js|| d Sd S) z3Create browser tkinter widgets, including the tree.ZWM_DELETE_WINDOWzz+%d+%dZnormal backgroundr)ZbgZhighlightthicknessZ takefocusZboth)expandZfillN)!r%r#r$rflistZPyShellFileListopen file_openpyclbrZ_modulesclearrr)Zprotocolr+ZbindZgeometryZ winfo_rootxZ winfo_rootysettitleZ focus_setrZ CurrentThemeZ GetHighlightrframeZpackrootnoderZcanvasr*updater/) r'rootr0r)Zthemer-Zscitemr*rrrr&gs6  zModuleBrowser.initcCs*|jdtj|j|jddS)zSet the window title.zModule Browser - zModule BrowserN)r)Zwm_titler r basenameZ wm_iconnamer'rrrr5szModuleBrowser.settitlecC t|jS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemr r<rrrr7 zModuleBrowser.rootnoder ) __name__ __module__ __qualname____doc__r(r+r&r5r7rrrrr"Cs  r"c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)r>z~Browser tree for Python module. Uses TreeItem as the basis for the structure of the tree. Used by both browsers. cCs ||_dS)zdCreate a TreeItem for the file. Args: file: Full path and module name. N)file)r'rDrrrr(s zModuleBrowserTreeItem.__init__cCstj|jS)z5Return the module name as the text string to display.)r r r;rDr<rrrGetTextszModuleBrowserTreeItem.GetTextcCsdS)'Return the name of the icon to display.pythonrr<rrr GetIconNamesz!ModuleBrowserTreeItem.GetIconNamecCsdd|DS)*Return ChildBrowserTreeItems for children.cSg|]}t|qSrChildBrowserTreeItem.0r rrr sz4ModuleBrowserTreeItem.GetSubList..) listchildrenr<rrr GetSubListsz ModuleBrowserTreeItem.GetSubListcCs.t|jsdStj|jsdSt|jdS)z6Open a module in an editor window when double clicked.N)rrDr r existsr2r<rrr OnDoubleClicks z#ModuleBrowserTreeItem.OnDoubleClickcCr=)zReturn True if Python file.)rrDr<rrr IsExpandabler?z"ModuleBrowserTreeItem.IsExpandablecCsjt|jsgStj|j\}}tj|\}}z t||gtj}Wn t y/gYSwt ||S)z5Return sequenced classes and functions in the module.) rrDr r splitr r3Z readmodule_exsys ImportErrorr!)r'dirbaserrZtreerrrrPs   z"ModuleBrowserTreeItem.listchildrenN) r@rArBrCr(rErHrQrSrTrPrrrrr>s r>c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)rLzsBrowser tree for child nodes within the module. Uses TreeItem as the basis for the structure of the tree. cCs ||_|j|_t|tj|_dS)z5Create a TreeItem for a pyclbr class/function object.N)r rrr3ZFunction isfunction)r'r rrrr(szChildBrowserTreeItem.__init__cCs |j}|jr d|dSd|S)z1Return the name of the function/class to display.zdef z(...)zclass )rrZ)r'rrrrrEs zChildBrowserTreeItem.GetTextcCs|jrdSdS)rFrGZfolder)rZr<rrrrHsz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)r childrenr<rrrrTs z!ChildBrowserTreeItem.IsExpandablecCsddt|jjDS)rIcSrJrrKrMrrrrOs z3ChildBrowserTreeItem.GetSubList..)r!r r[r<rrrrQs zChildBrowserTreeItem.GetSubListc Cs:zt|jj}||jjWdSttfyYdSw)z2Open module with file_open and position to lineno.N)r2r rDZgotolinelinenoOSErrorAttributeError)r'ZeditrrrrSs  z"ChildBrowserTreeItem.OnDoubleClickN) r@rArBrCr(rErHrTrQrSrrrrrLs rLcCsHttjdkr tjd}nt}Gdddt}dd}t||dddS)Nr.c@seZdZddZdS)z'_module_browser..Nested_in_funccSsdSr rrrrrnested_in_classsz7_module_browser..Nested_in_func.nested_in_classN)r@rArBr_rrrrNested_in_funcs r`cSsGddd}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r@rArBrrrrNested_in_closures rar)rarrrclosuresz _module_browser..closureT)r#)lenrVargv__file__rr")parentrDr`rbrrr_module_browsers  rg__main__r.)mainzidlelib.idle_test.test_browserF) verbosityexit)runr )rCr r3rVZidlelib.configrZidlelibrZ idlelib.treerrrZ idlelib.utilrZidlelib.windowrr2rrr!r"r>rLrgr@rcrdZunittestriZidlelib.idle_test.htestrmrrrrs0       M4-