a  zez @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_dictmodnameZobskeyobjZsuperssupZsnamerC/opt/bitninja-python-dojo/embedded/lib/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)r eventrrrcloseYs 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)bgZhighlightthicknessZ takefocusZboth)expandfillN)!rrrrflistZPyShellFileListopen file_openpyclbrZ_modulesclearrr"protocolr%bindZgeometryZ winfo_rootxZ winfo_rootysettitleZ focus_setrZ CurrentThemeZ GetHighlightrframepackrootnoderZcanvasr#updater*) r rootr,r"Zthemer'Zscitemr#rrrr^s4 zModuleBrowser.initcCs*|jdtj|j|jddS)zSet the window title.zModule Browser - zModule BrowserN)r"Zwm_titleosrbasenameZ wm_iconnamer rrrr3}szModuleBrowser.settitlecCs t|jS)z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemrr<rrrr6szModuleBrowser.rootnode)N) __name__ __module__ __qualname____doc__r!r%rr3r6rrrrr:s  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 rBrrrr!szModuleBrowserTreeItem.__init__cCstj|jS)z5Return the module name as the text string to display.)r:rr;rBr<rrrGetTextszModuleBrowserTreeItem.GetTextcCsdS)'Return the name of the icon to display.pythonrr<rrr GetIconNamesz!ModuleBrowserTreeItem.GetIconNamecCsdd|DS)*Return ChildBrowserTreeItems for children.cSsg|] }t|qSrChildBrowserTreeItem.0rrrr z4ModuleBrowserTreeItem.GetSubList..) listchildrenr<rrr GetSubListsz ModuleBrowserTreeItem.GetSubListcCs>tj|jdddkrdStj|js0dSt|jdS)z6Open a module in an editor window when double clicked.N.py)r:rnormcaserBexistsr.r<rrr OnDoubleClicks z#ModuleBrowserTreeItem.OnDoubleClickcCstj|jdddkS)z!Return True if Python (.py) file.rPNrQ)r:rrRrBr<rrr IsExpandablesz"ModuleBrowserTreeItem.IsExpandablecCsptj|j\}}tj|\}}tj|dkr6gSzt||gtj}Wnt ydgYS0t ||S)z5Return sequenced classes and functions in the module.rQ) r:rsplitrBsplitextrRr/Z readmodule_exsys ImportErrorr)r dirbaserextZtreerrrrNs  z"ModuleBrowserTreeItem.listchildrenN) r>r?r@rAr!rCrFrOrTrUrNrrrrr=sr=c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)rIzsBrowser 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)r rrrrr!szChildBrowserTreeItem.__init__cCs$|j}|jrd|dSd|SdS)z1Return the name of the function/class to display.zdef z(...)zclass N)rr^)r rrrrrCs zChildBrowserTreeItem.GetTextcCs|jr dSdSdS)rDrEZfolderN)r^r<rrrrFsz ChildBrowserTreeItem.GetIconNamecCs |jjikS)z+Return True if self.obj has nested objects.)rchildrenr<rrrrUsz!ChildBrowserTreeItem.IsExpandablecCsddt|jjDS)rGcSsg|] }t|qSrrHrJrrrrLsz3ChildBrowserTreeItem.GetSubList..)rrr_r<rrrrOs zChildBrowserTreeItem.GetSubListc Cs:zt|jj}||jjWnttfy4Yn0dS)z2Open module with file_open and position to lineno.N)r.rrBZgotolinelinenoOSErrorAttributeError)r ZeditrrrrTs  z"ChildBrowserTreeItem.OnDoubleClickN) r>r?r@rAr!rCrFrUrOrTrrrrrIsrIcCsHttjdkrtjd}nt}Gdddt}dd}t||dddS)Nr(c@seZdZddZdS)z'_module_browser..Nested_in_funccSsdS)Nrrrrrnested_in_classrMz7_module_browser..Nested_in_func.nested_in_classN)r>r?r@rcrrrrNested_in_funcsrdcSsGddd}dS)Nc@s eZdZdS)z;_module_browser..closure..Nested_in_closureN)r>r?r@rrrrNested_in_closurerMrer)rerrrclosuresz _module_browser..closureT)r)lenrXargv__file__rr)parentrBrdrfrrr_module_browsers  rk__main__r()mainzidlelib.idle_test.test_browserF) verbosityexit)run)N)rAr:r/rXZidlelib.configrZidlelibrZ idlelib.treerrrZidlelib.windowrr.rrr=rIrkr>rgrhZunittestrmZidlelib.idle_test.htestrqrrrrs&     M4-