a XC?hz @sdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z dadddZGd d d ZGd d d e ZGd dde ZddZedkreejdkrddlmZeddddddlmZeedS)a8Module 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 - finish removing limitation to x.py files (ModuleBrowserTreeItem) N)idleConf)pyshell)TreeNodeTreeItemScrolledCanvas)ListedToplevelcCsg}|D]\}}|dus&|j|kr t|dr|jr|j|krg}|jD]F}t|tdurd|}n"|j}|j|jkr|jd|}||qJ|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, ) itemsmodulehasattrrnametypeappendformatjoin)Z child_dictmodnameZobskeyobjZsupersZsupZsnamer4/opt/alt/python39/lib64/python3.9/idlelib/browser.pytransform_childrens     rc@sBeZdZdZdddddZdddZd d Zd d Zd dZdS) ModuleBrowserz1Browse module classes and functions in IDLE. F)_htest_utestcCs$||_||_||_||_|dS)azCreate 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 .py extension. Used in creating ModuleBrowserTreeItem as the rootnode for the tree and subsequently in the children. N)masterpathrrinit)selfrrrrrrr__init__As zModuleBrowser.__init__NcCs|j|jdS)z&Dismiss the window and the tree nodes.N)topZdestroynode)rZeventrrrcloseYs zModuleBrowser.closec Cs|j}|js|jstjnt|}|jatj t ||_ }| d|j|d|j|jr|d||df||t}t|dd}t||ddd }|jjdd d |}t|jd ||_}|js|| d S) z3Create browser tkinter widgets, including the tree.ZWM_DELETE_WINDOWzz+%d+%dZnormal backgroundr)ZbgZhighlightthicknessZ takefocusZboth)expandZfillN)!rrrrflistZPyShellFileListopen file_openpyclbrZ_modulesclearrr!Zprotocolr#ZbindZgeometryZ winfo_rootxZ winfo_rootysettitleZ focus_setrZ CurrentThemeZ GetHighlightrframeZpackrootnoderZcanvasr"updater') rrootr(r!Zthemer%Zscitemr"rrrr^s4 zModuleBrowser.initcCs*|jdtj|j|jddS)zSet the window title.zModule Browser - zModule BrowserN)r!Zwm_titleosrbasenameZ wm_iconnamerrrrr-}szModuleBrowser.settitlecCs t|jS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemrr5rrrr/szModuleBrowser.rootnode)N) __name__ __module__ __qualname____doc__r r#rr-r/rrrrr:s  rc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)r6z~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)rr;rrrr szModuleBrowserTreeItem.__init__cCstj|jS)z5Return the module name as the text string to display.)r3rr4r;r5rrrGetTextszModuleBrowserTreeItem.GetTextcCsdS)'Return the name of the icon to display.pythonrr5rrr GetIconNamesz!ModuleBrowserTreeItem.GetIconNamecCsdd|DS)*Return ChildBrowserTreeItems for children.cSsg|] }t|qSrChildBrowserTreeItem.0rrrr z4ModuleBrowserTreeItem.GetSubList..) listchildrenr5rrr GetSubListsz ModuleBrowserTreeItem.GetSubListcCs>tj|jdddkrdStj|js0dSt|jdS)z6Open a module in an editor window when double clicked.N.py)r3rnormcaser;existsr*r5rrr OnDoubleClicks z#ModuleBrowserTreeItem.OnDoubleClickcCstj|jdddkS)z!Return True if Python (.py) file.rINrJ)r3rrKr;r5rrr IsExpandablesz"ModuleBrowserTreeItem.IsExpandablecCsptj|j\}}tj|\}}tj|dkr6gSzt||gtj}Wnt ydgYS0t ||S)z5Return sequenced classes and functions in the module.rJ) r3rsplitr;splitextrKr+Z readmodule_exsys ImportErrorr)rdirbaserZextZtreerrrrGs  z"ModuleBrowserTreeItem.listchildrenN) r7r8r9r:r r<r?rHrMrNrGrrrrr6sr6c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)rBzsBrowser 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)rr isinstancer+ZFunction isfunction)rrrrrr szChildBrowserTreeItem.__init__cCs$|j}|jrd|dSd|SdS)z1Return the name of the function/class to display.zdef z(...)zclass N)rrV)rrrrrr<s zChildBrowserTreeItem.GetTextcCs|jr dSdSdS)r=r>ZfolderN)rVr5rrrr?sz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)rchildrenr5rrrrNsz!ChildBrowserTreeItem.IsExpandablecCsddt|jjDS)r@cSsg|] }t|qSrrArCrrrrEsz3ChildBrowserTreeItem.GetSubList..)rrrWr5rrrrHs zChildBrowserTreeItem.GetSubListc Cs:zt|jj}||jjWnttfy4Yn0dS)z2Open module with file_open and position to lineno.N)r*rr;ZgotolinelinenoOSErrorAttributeError)rZeditrrrrMs  z"ChildBrowserTreeItem.OnDoubleClickN) r7r8r9r:r r<r?rNrHrMrrrrrBsrBcCsHttjdkrtjd}nt}Gdddt}dd}t||dddS)Nr&c@seZdZddZdS)z'_module_browser..Nested_in_funccSsdS)Nrrrrrnested_in_classrFz7_module_browser..Nested_in_func.nested_in_classN)r7r8r9r[rrrrNested_in_funcsr\cSsGddd}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r7r8r9rrrrNested_in_closurerFr]r)r]rrrclosuresz _module_browser..closureT)r)lenrQargv__file__rr)parentr;r\r^rrr_module_browsers  rc__main__r&)mainzidlelib.idle_test.test_browserF) verbosityexit)run)N)r:r3r+rQZidlelib.configrZidlelibrZ idlelib.treerrrZidlelib.windowrr*rrr6rBrcr7r_r`ZunittestreZidlelib.idle_test.htestrirrrrs&     M4-