3  fY @sdZddlZddlmZddlZddlmZddlmZddl m Z m Z m Z ddl mZdaddd ZGd d d ZGd d d e ZGddde 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)_pyclbr)idleConf)pyshell)TreeNodeTreeItemScrolledCanvas)ListedToplevelcCsg}x|jD]\}}|dks(|j|krt|dr|jr|j|krg}xP|jD]F}t|tdkrh|}n"|j}|j|jkr|jd|}|j|qNW|jdjdj|7_|j|qWt |ddd 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. 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. Nsuper.z({})z, cSs|jS)N)lineno)or4/opt/alt/python36/lib64/python3.6/idlelib/browser.py6sz$transform_children..)key) itemsmodulehasattrr nametypeappendformatjoinsorted)Z child_dictmodnameZobsrobjZsupersZsupZsnamerrrtransform_childrens   rc@sBeZdZdZdddddZdddZd d Zd d Zd dZdS) ModuleBrowserz1Browse module classes and functions in IDLE. F)_htest_utestcCs$||_||_||_||_|jdS)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)masterpathrr init)selfr!r"rr rrr__init__@s zModuleBrowser.__init__NcCs|jj|jjdS)z&Dismiss the window and the tree nodes.N)topZdestroynode)r$ZeventrrrcloseXs zModuleBrowser.closec Cs|j}|jp|jstjntj|}|jatj j t ||_ }|j d|j|jd|j|jr|jd|j|jdf|j|jtj}tj|dd}t||ddd }|jjdd d |j}t|jd ||_}|js|j|j d S) z3Create browser tkinter widgets, including the tree.ZWM_DELETE_WINDOWzz+%d+%dZnormal backgroundr)ZbgZhighlightthicknessZ takefocusZboth)expandZfillN)!r!rr rflistZPyShellFileListopen file_openpyclbrZ_modulesclearrr&Zprotocolr(ZbindZgeometryZ winfo_rootxZ winfo_rootysettitleZ focus_setrZ CurrentThemeZ GetHighlightrframeZpackrootnoderZcanvasr'updater,) r$rootr-r&Zthemer*Zscitemr'rrrr#]s.  zModuleBrowser.initcCs*|jjdtjj|j|jjddS)zSet the window title.zModule Browser - zModule BrowserN)r&Zwm_titleosr"basenameZ wm_iconname)r$rrrr2|szModuleBrowser.settitlecCs t|jS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemr")r$rrrr4szModuleBrowser.rootnode)N) __name__ __module__ __qualname____doc__r%r(r#r2r4rrrrr9s  rc@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$r?rrrr%szModuleBrowserTreeItem.__init__cCstjj|jS)z5Return the module name as the text string to display.)r8r"r9r?)r$rrrGetTextszModuleBrowserTreeItem.GetTextcCsdS)z'Return the name of the icon to display.pythonr)r$rrr GetIconNamesz!ModuleBrowserTreeItem.GetIconNamecCsdd|jDS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|qSr)ChildBrowserTreeItem).0rrrr sz4ModuleBrowserTreeItem.GetSubList..) listchildren)r$rrr GetSubListsz ModuleBrowserTreeItem.GetSubListcCs>tjj|jdddkrdStjj|js0dSt|jdS)z6Open a module in an editor window when double clicked.Nz.py)r8r"normcaser?existsr/)r$rrr OnDoubleClicks z#ModuleBrowserTreeItem.OnDoubleClickcCstjj|jdddkS)z!Return True if Python (.py) file.rHNz.pyrI)r8r"rJr?)r$rrr IsExpandablesz"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_exsys ImportErrorr)r$dirbaserZextZtreerrrrFsz"ModuleBrowserTreeItem.listchildrenN) r;r<r=r>r%r@rBrGrLrMrFrrrrr:sr:c@s@eZdZdZddZddZddZdd 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$rrrrBsz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)rchildren)r$rrrrMsz!ChildBrowserTreeItem.IsExpandablecCsddt|jjDS)z*Return ChildBrowserTreeItems for children.cSsg|] }t|qSr)rC)rDrrrrrEsz3ChildBrowserTreeItem.GetSubList..)rrrV)r$rrrrGszChildBrowserTreeItem.GetSubListc Cs<yt|jj}|j|jjWnttfk r6YnXdS)z2Open module with file_open and position to lineno.N)r/rr?Zgotoliner OSErrorAttributeError)r$ZeditrrrrLs  z"ChildBrowserTreeItem.OnDoubleClickN) r;r<r=r>r%r@rBrMrGrLrrrrrCsrCcCsHttjdkrtjd}nt}Gdddt}dd}t||dddS)Nr+c@seZdZddZdS)z'_module_browser..Nested_in_funccSsdS)Nrrrrrnested_in_classsz7_module_browser..Nested_in_func.nested_in_classN)r;r<r=rYrrrrNested_in_funcsrZcSsGddd}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r;r<r=rrrrNested_in_closuresr[r)r[rrrclosuresz _module_browser..closureT)r)lenrPargv__file__rr)parentr?rZr\rrr_module_browsers  ra__main__r+)mainzidlelib.idle_test.test_browserF) verbosityexit)run)N)r>r8Zidlelibrr0rPZidlelib.configrrZ idlelib.treerrrZidlelib.windowrr/rrr:rCrar;r]r^ZunittestrcZidlelib.idle_test.htestrgrrrr s&     M4-