B „ fz ã@sàdZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl m Z daddd„ZGd d „d ƒZGd d „d e ƒZGd d„de ƒZdd„ZedkrÜeejƒdkrÈddlmZedddd�ddlmZeeƒdS)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)ÚTreeNodeÚTreeItemÚScrolledCanvas)ÚListedToplevelcCsÄg}xº| ¡D]®\}}|dks(|j|krt|dƒr²|jr²|j|kr²g}xP|jD]F}t|ƒtdƒkrh|}n"|j}|j|jkrŠ|j›d|›�}| |¡qNW|jd d |¡¡7_| |¡qW|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. NÚsuperÚÚ.z({})z, ) ÚitemsÚmoduleÚhasattrrÚnameÚtypeÚappendÚformatÚjoin)Z child_dictÚmodnameZobsÚkeyÚobjZsupersZsupZsname©rú4/opt/alt/python37/lib64/python3.7/idlelib/browser.pyÚtransform_childrens   rc@sBeZdZdZdddœdd„Zddd„Zd d „Zd d „Zd d„ZdS)Ú 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)ÚmasterÚpathrrÚinit)ÚselfrrrrrrrÚ__init__As zModuleBrowser.__init__NcCs|j ¡|j ¡dS)z&Dismiss the window and the tree nodes.N)ÚtopZdestroyÚnode)rZeventrrrÚcloseYs zModuleBrowser.closec Csþ|j}|js|jstjnt |¡}|jatj   ¡t |ƒ|_ }|  d|j¡| d|j¡|jr€| d| ¡| ¡df¡| ¡| ¡t ¡}t |d¡d}t||ddd �}|jjdd d �| ¡}t|jd |ƒ|_}|jsú| ¡|  ¡d S) z3Create browser tkinter widgets, including the tree.ZWM_DELETE_WINDOWzz+%d+%déÈZnormalÚ backgroundré)ZbgZhighlightthicknessZ takefocusZboth)ÚexpandZfillN)!rrrrÚflistZPyShellFileListÚopenÚ file_openÚpyclbrZ_modulesÚclearrr!Zprotocolr#ZbindZgeometryZ winfo_rootxZ winfo_rootyÚsettitleZ focus_setrZ CurrentThemeZ GetHighlightrÚframeZpackÚrootnoderZcanvasr"Úupdater') rÚrootr(r!Zthemer%ZscÚitemr"rrrr^s.  zModuleBrowser.initcCs*|j dtj |j¡¡|j d¡dS)zSet the window title.zModule Browser - zModule BrowserN)r!Zwm_titleÚosrÚbasenameZ wm_iconname)rrrrr-}szModuleBrowser.settitlecCs t|jƒS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ÚModuleBrowserTreeItemr)rrrrr/‚szModuleBrowser.rootnode)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r r#rr-r/rrrrr:s  rc@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)r5z~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 |j¡S)z5Return the module name as the text string to display.)r3rr4r:)rrrrÚGetText–szModuleBrowserTreeItem.GetTextcCsdS)z'Return the name of the icon to display.Úpythonr)rrrrÚ GetIconNamešsz!ModuleBrowserTreeItem.GetIconNamecCsdd„| ¡DƒS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|ƒ‘qSr)ÚChildBrowserTreeItem)Ú.0rrrrú  sz4ModuleBrowserTreeItem.GetSubList..)Ú listchildren)rrrrÚ GetSubListžsz ModuleBrowserTreeItem.GetSubListcCs>tj |jdd…¡dkrdStj |j¡s0dSt|jƒdS)z6Open a module in an editor window when double clicked.éýÿÿÿNz.py)r3rÚnormcaser:Úexistsr*)rrrrÚ OnDoubleClick¢s z#ModuleBrowserTreeItem.OnDoubleClickcCstj |jdd…¡dkS)z!Return True if Python (.py) file.rCNz.py)r3rrDr:)rrrrÚ IsExpandableªsz"ModuleBrowserTreeItem.IsExpandablecCsntj |j¡\}}tj |¡\}}tj |¡dkr6gSyt ||gtj¡}Wnt k rbgSXt ||ƒS)z5Return sequenced classes and functions in the module.z.py) r3rÚsplitr:ÚsplitextrDr+Z readmodule_exÚsysÚ ImportErrorr)rÚdirÚbaserZextZtreerrrrA®sz"ModuleBrowserTreeItem.listchildrenN) r6r7r8r9r r;r=rBrFrGrArrrrr5‡sr5c@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)r>zsBrowser 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)rrO)rrrrrr;Çs zChildBrowserTreeItem.GetTextcCs|jr dSdSdS)z'Return the name of the icon to display.r<ZfolderN)rO)rrrrr=Ïsz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)rÚchildren)rrrrrGÖsz!ChildBrowserTreeItem.IsExpandablecCsdd„t|jjƒDƒS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|ƒ‘qSr)r>)r?rrrrr@Üsz3ChildBrowserTreeItem.GetSubList..)rrrP)rrrrrBÚszChildBrowserTreeItem.GetSubListc Cs<yt|jjƒ}| |jj¡Wnttfk r6YnXdS)z2Open module with file_open and position to lineno.N)r*rr:ZgotolineÚlinenoÚOSErrorÚAttributeError)rZeditrrrrFßs  z"ChildBrowserTreeItem.OnDoubleClickN) r6r7r8r9r r;r=rGrBrFrrrrr>»sr>cCsHttjƒdkrtjd}nt}Gdd„dtƒ}dd„}t||dd�dS)Nr&c@seZdZdd„ZdS)z'_module_browser..Nested_in_funccSsdS)NrrrrrÚnested_in_classïóz7_module_browser..Nested_in_func.nested_in_classN)r6r7r8rTrrrrÚNested_in_funcîsrVcSsGdd„dƒ}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r6r7r8rrrrÚNested_in_closureñsrWr)rWrrrÚclosureðsz _module_browser..closureT)r)ÚlenrJÚargvÚ__file__rr)Úparentr:rVrXrrrÚ_module_browserès  r]Ú__main__r&)Úmainzidlelib.idle_test.test_browseréF)Ú verbosityÚexit)Úrun)N)r9r3r+rJZidlelib.configrZidlelibrZ idlelib.treerrrZidlelib.windowrr*rrr5r>r]r6rYrZZunittestr_Zidlelib.idle_test.htestrcrrrrÚ s&    M4-