3 § fY ã@sädZddlZddlmZddlZddlmZddlmZddl m Z m Z m Z ddl mZdaddd „ZGd d „d ƒZGd d „d e ƒZGdd„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)Ú_pyclbr)ÚidleConf)Úpyshell)ÚTreeNodeÚTreeItemÚScrolledCanvas)ÚListedToplevelcCsÐg}xº|jƒD]®\}}|dks(|j|krt|dƒr²|jr²|j|kr²g}xP|jD]F}t|ƒtdƒkrh|}n"|j}|j|jkrŠ|j›d|›�}|j|ƒqNW|jdjdj|ƒƒ7_|j|ƒqWt |dd„d �S) a¯Transform 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. Sort objects by line number. The current tree only calls this once per child_dic 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, cSs|jS)N)Úlineno)Úo©rú4/opt/alt/python36/lib64/python3.6/idlelib/browser.pyÚ6sz$transform_children..)Úkey) ÚitemsÚmoduleÚhasattrr ÚnameÚtypeÚappendÚformatÚjoinÚsorted)Z child_dictÚmodnameZobsrÚobjZsupersZsupZsnamerrrÚtransform_childrens   rc@sBeZdZdZdddœdd„Zddd„Zd d „Zd d „Zd d„ZdS)Ú ModuleBrowserz1Browse module classes and functions in IDLE. F)Ú_htestÚ_utestcCs$||_||_||_||_|jƒ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)Úselfr!r"rr rrrÚ__init__@s zModuleBrowser.__init__NcCs|jjƒ|jjƒdS)z&Dismiss the window and the tree nodes.N)ÚtopZdestroyÚnode)r$ZeventrrrÚcloseXs zModuleBrowser.closec Csþ|j}|jp|jstjntj|ƒ}|jatj j ƒt |ƒ|_ }|j d|jƒ|jd|jƒ|jr€|jd|jƒ|jƒdfƒ|jƒ|jƒtjƒ}tj|dƒd}t||ddd �}|jjdd d �|jƒ}t|jd |ƒ|_}|jsú|jƒ|j ƒd S) z3Create browser tkinter widgets, including the tree.ZWM_DELETE_WINDOWzz+%d+%déÈZnormalÚ backgroundré)ZbgZhighlightthicknessZ takefocusZboth)ÚexpandZfillN)!r!rr rÚ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*|jjdtjj|jƒƒ|jjdƒdS)zSet the window title.zModule Browser - zModule BrowserN)r&Zwm_titleÚosr"ÚbasenameZ wm_iconname)r$rrrr2|szModuleBrowser.settitlecCs t|jƒS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ÚModuleBrowserTreeItemr")r$rrrr4�szModuleBrowser.rootnode)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__r%r(r#r2r4rrrrr9s  rc@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z 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$r?rrrr%�szModuleBrowserTreeItem.__init__cCstjj|jƒS)z5Return the module name as the text string to display.)r8r"r9r?)r$rrrÚGetText•szModuleBrowserTreeItem.GetTextcCsdS)z'Return the name of the icon to display.Úpythonr)r$rrrÚ GetIconName™sz!ModuleBrowserTreeItem.GetIconNamecCsdd„|jƒDƒS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|ƒ‘qSr)ÚChildBrowserTreeItem)Ú.0rrrrú Ÿsz4ModuleBrowserTreeItem.GetSubList..)Ú listchildren)r$rrrÚ GetSubList�sz ModuleBrowserTreeItem.GetSubListcCs>tjj|jdd…ƒdkrdStjj|jƒs0dSt|jƒdS)z6Open a module in an editor window when double clicked.éNz.pyéýÿÿÿ)r8r"Únormcaser?Úexistsr/)r$rrrÚ OnDoubleClick¡s z#ModuleBrowserTreeItem.OnDoubleClickcCstjj|jdd…ƒdkS)z!Return True if Python (.py) file.rHNz.pyrI)r8r"rJr?)r$rrrÚ IsExpandable©sz"ModuleBrowserTreeItem.IsExpandablec Csntjj|jƒ\}}tjj|ƒ\}}tjj|ƒdkr6gSytj||gtjƒ}Wnt k rbgSXt ||ƒS)z5Return sequenced classes and functions in the module.z.py) r8r"Úsplitr?ÚsplitextrJr0Z readmodule_exÚsysÚ ImportErrorr)r$ÚdirÚbaserZextZtreerrrrF­sz"ModuleBrowserTreeItem.listchildrenN) r;r<r=r>r%r@rBrGrLrMrFrrrrr:†sr:c@s@eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dS)rCzsBrowser 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Ú isinstancer0ZFunctionÚ isfunction)r$rrrrr%ÀszChildBrowserTreeItem.__init__cCs$|j}|jrd|dSd|SdS)z1Return the name of the function/class to display.zdef z(...)zclass N)rrU)r$rrrrr@Æs zChildBrowserTreeItem.GetTextcCs|jr dSdSdS)z'Return the name of the icon to display.rAZfolderN)rU)r$rrrrBÎsz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)rÚchildren)r$rrrrMÕsz!ChildBrowserTreeItem.IsExpandablecCsdd„t|jjƒDƒS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|ƒ‘qSr)rC)rDrrrrrEÛsz3ChildBrowserTreeItem.GetSubList..)rrrV)r$rrrrGÙszChildBrowserTreeItem.GetSubListc Cs<yt|jjƒ}|j|jjƒWnttfk r6YnXdS)z2Open module with file_open and position to lineno.N)r/rr?Zgotoliner ÚOSErrorÚAttributeError)r$ZeditrrrrLÞs  z"ChildBrowserTreeItem.OnDoubleClickN) r;r<r=r>r%r@rBrMrGrLrrrrrCºsrCcCsHttjƒdkrtjd}nt}Gdd„dtƒ}dd„}t||dd�dS)Nr+c@seZdZdd„ZdS)z'_module_browser..Nested_in_funccSsdS)NrrrrrÚnested_in_classîsz7_module_browser..Nested_in_func.nested_in_classN)r;r<r=rYrrrrÚNested_in_funcísrZcSsGdd„dƒ}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r;r<r=rrrrÚNested_in_closureðsr[r)r[rrrÚclosureïsz _module_browser..closureT)r)ÚlenrPÚargvÚ__file__rr)Úparentr?rZr\rrrÚ_module_browserçs  raÚ__main__r+)Úmainzidlelib.idle_test.test_browseréF)Ú verbosityÚexit)Úrun)N)r>r8Zidlelibrr0rPZidlelib.configrrZ idlelib.treerrrZidlelib.windowrr/rrr:rCrar;r]r^ZunittestrcZidlelib.idle_test.htestrgrrrrÚ s&     M4-