
    d!                     V   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ dadZd	 Zdd
Z G d d          Z G d de
          Z G d de
          Zd Zedk    r; eej                  dk    rddlmZ  eddd           ddlmZ  ee           dS dS )zModule 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
    N)idleConf)pyshell)TreeNodeTreeItemScrolledCanvas)py_extensions)ListedToplevel)z.pyic                     t           j                            |           \  }}t           j                            |          }|t          v o|t
          vS N)ospathsplitextnormcaser   browseable_extension_blocklist)r   _exts      !  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/browser.pyis_browseable_extensionr      sF    Wd##FAs
'

3

C-MC/M$MM    c                    g }|                                  D ]\  }}||j        |k    rt          |d          r|j        r|j        |k    rg }|j        D ]R}t          |t                    r|}n#|j        }|j        |j        k    r|j         d| }|                    |           S|xj        d                    d	                    |                    z  c_        |                    |           |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.
    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
isinstancestrappendformatjoin)
child_dictmodnameobskeyobjsuperssupsnames           r   transform_childrenr*   #   s
    C$$&&  S?cjG33sG$$ = =sx39 ) )C!#s++ < # #:33'*z$;$;E$;$;EMM%((((FMM$))F*;*;<<<JJsOOOJr   c                   :    e Zd ZdZddddZd
dZd Zd Zd	 ZdS )ModuleBrowserz1Browse module classes and functions in IDLE.
    F)_htest_utestc                f    || _         || _        || _        || _        |                                  dS )a  Create 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 supported extension.
                Used in creating ModuleBrowserTreeItem as the rootnode for
                the tree and subsequently in the children.
        N)masterr   r-   r.   init)selfr0   r   r-   r.   s        r   __init__zModuleBrowser.__init__J   s1    $ 			r   Nc                 j    | j                                          | j                                         dS )z&Dismiss the window and the tree nodes.N)topdestroynode)r2   events     r   closezModuleBrowser.closeb   s0    	r   c                    | j         }| j        s| j        st          j        nt          j        |          }|j        at          j	        
                                 t          |          x| _        }|                    d| j                   |                    d| j                   | j        rA|                    d|                                |                                dz   fz             |                                  |                                 t+          j                    }t+          j        |d          d         }t1          ||dd	          }|j                            dd
           |                                 }t9          |j        d|          x| _        }| j        s*|                                 |                                  dS dS )z3Create browser tkinter widgets, including the tree.WM_DELETE_WINDOWz<Escape>z+%d+%d   normal
backgroundr      )bghighlightthickness	takefocusboth)expandfillN)!r0   r-   r.   r   flistPyShellFileListopen	file_openpyclbr_modulesclearr	   r5   protocolr9   bindgeometrywinfo_rootxwinfo_rootysettitle	focus_setr   CurrentThemeGetHighlightr   framepackrootnoder   canvasr7   updaterD   )	r2   rootrF   r5   themer>   scitemr7   s	            r   r1   zModuleBrowser.initg   s    {'+{ 4dk 4-d33 	J	 (---3'444TZ(((; 	@LL!!##T%5%5%7%7#%=>? @ @ @ %''*5(;;LI
CJ1&') ) )
QV,,,}}#BItT:::	D{ 	KKMMMKKMMMMM	 	r   c                     | j                             dt          j                            | j                  z              | j                             d           dS )zSet the window title.zModule Browser - zModule BrowserN)r5   wm_titler   r   basenamewm_iconnamer2   s    r   rR   zModuleBrowser.settitle   sM    -0@0@0K0KKLLL-.....r   c                 *    t          | j                  S )z7Return a ModuleBrowserTreeItem as the root of the tree.)ModuleBrowserTreeItemr   rc   s    r   rX   zModuleBrowser.rootnode   s    $TY///r   r   )	__name__
__module____qualname____doc__r3   r9   r1   rR   rX    r   r   r,   r,   C   s          05U     0   
  >/ / /
0 0 0 0 0r   r,   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
re   z~Browser tree for Python module.

    Uses TreeItem as the basis for the structure of the tree.
    Used by both browsers.
    c                     || _         dS )zdCreate a TreeItem for the file.

        Args:
            file: Full path and module name.
        N)file)r2   rm   s     r   r3   zModuleBrowserTreeItem.__init__   s     			r   c                 J    t           j                            | j                  S )z5Return the module name as the text string to display.)r   r   ra   rm   rc   s    r   GetTextzModuleBrowserTreeItem.GetText   s    w	***r   c                     dS )'Return the name of the icon to display.pythonrj   rc   s    r   GetIconNamez!ModuleBrowserTreeItem.GetIconName   s    xr   c                 >    d |                                  D             S )*Return ChildBrowserTreeItems for children.c                 ,    g | ]}t          |          S rj   ChildBrowserTreeItem.0r&   s     r   
<listcomp>z4ModuleBrowserTreeItem.GetSubList.<locals>.<listcomp>   s!    IIIc$S))IIIr   )listchildrenrc   s    r   
GetSubListz ModuleBrowserTreeItem.GetSubList   s"    IIT5F5F5H5HIIIIr   c                     t          | j                  sdS t          j                            | j                  sdS t          | j                   dS )z6Open a module in an editor window when double clicked.N)r   rm   r   r   existsrI   rc   s    r   OnDoubleClickz#ModuleBrowserTreeItem.OnDoubleClick   sL    &ty11 	Fw~~di(( 	F$)r   c                 *    t          | j                  S )zReturn True if Python file.)r   rm   rc   s    r   IsExpandablez"ModuleBrowserTreeItem.IsExpandable   s    &ty111r   c                 N   t          | j                  sg S t          j                            | j                  \  }}t          j                            |          \  }}	 t          j        ||gt          j        z             }n# t          $ r g cY S w xY wt          ||          S )z5Return sequenced classes and functions in the module.)r   rm   r   r   splitr   rJ   readmodule_exsysImportErrorr*   )r2   dirbaser   r   trees         r   r|   z"ModuleBrowserTreeItem.listchildren   s    &ty11 	IGMM$),,	T'""4((a	'sech.>??DD 	 	 	III	!$---s   !#B BBN)rf   rg   rh   ri   r3   ro   rs   r}   r   r   r|   rj   r   r   re   re      s           + + +  J J J  2 2 2
. 
. 
. 
. 
.r   re   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	rx   zsBrowser tree for child nodes within the module.

    Uses TreeItem as the basis for the structure of the tree.
    c                 j    || _         |j        | _        t          |t          j                  | _        dS )z5Create a TreeItem for a pyclbr class/function object.N)r&   r   r   rJ   Function
isfunction)r2   r&   s     r   r3   zChildBrowserTreeItem.__init__   s)    H	$S&/::r   c                 8    | j         }| j        rd|z   dz   S d|z   S )z1Return the name of the function/class to display.zdef z(...)zclass )r   r   )r2   r   s     r   ro   zChildBrowserTreeItem.GetText   s,    y? 	#D=7**d?"r   c                     | j         rdS dS )rq   rr   folder)r   rc   s    r   rs   z ChildBrowserTreeItem.GetIconName   s    ? 	88r   c                 "    | j         j        i k    S )z+Return True if self.obj has nested objects.)r&   childrenrc   s    r   r   z!ChildBrowserTreeItem.IsExpandable   s    x B&&r   c                 H    d t          | j        j                  D             S )ru   c                 ,    g | ]}t          |          S rj   rw   ry   s     r   r{   z3ChildBrowserTreeItem.GetSubList.<locals>.<listcomp>   s6     B B B %S)) B B Br   )r*   r&   r   rc   s    r   r}   zChildBrowserTreeItem.GetSubList   s6    B B-dh.?@@B B B 	Br   c                     	 t          | j        j                  }|                    | j        j                   dS # t
          t          f$ r Y dS w xY w)z2Open module with file_open and position to lineno.N)rI   r&   rm   gotolinelinenoOSErrorAttributeError)r2   edits     r   r   z"ChildBrowserTreeItem.OnDoubleClick   s[    	TX]++DMM$(/*****( 	 	 	DD	s   8< AAN)
rf   rg   rh   ri   r3   ro   rs   r   r}   r   rj   r   r   rx   rx      s{         
; ; ;# # #  ' ' 'B B B
    r   rx   c                     t          t          j                  dk    rt          j        d         }nt          } G d dt                    }d }t          | |d           d S )Nr?   c                       e Zd Zd ZdS )'_module_browser.<locals>.Nested_in_funcc                      d S r   rj   rj   r   r   nested_in_classz7_module_browser.<locals>.Nested_in_func.nested_in_class   s      r   N)rf   rg   rh   r   rj   r   r   Nested_in_funcr      s        '''''r   r   c                        G d d          } d S )Nc                       e Zd ZdS );_module_browser.<locals>.closure.<locals>.Nested_in_closureN)rf   rg   rh   rj   r   r   Nested_in_closurer      s          r   r   rj   )r   s    r   closurez _module_browser.<locals>.closure   s     ))))))))))r   T)r-   )lenr   argv__file__r   r,   )parentrm   r   r   s       r   _module_browserr      s{    
38}}qx{	( 	( 	( 	( 	(X 	( 	( 	(	* 	* 	*&$t,,,,,,r   __main__r?   )mainzidlelib.idle_test.test_browser   F)	verbosityexit)runr   )ri   r   rJ   r   idlelib.configr   idlelibr   idlelib.treer   r   r   idlelib.utilr   idlelib.windowr	   rI   r   r   r*   r,   re   rx   r   rf   r   r   unittestr   idlelib.idle_test.htestr   rj   r   r   <module>r      s    
			  



 # # # # # #       ; ; ; ; ; ; ; ; ; ; & & & & & & ) ) ) ) ) ) 	 "+ N N N   @J0 J0 J0 J0 J0 J0 J0 J0Z1. 1. 1. 1. 1.H 1. 1. 1.h* * * * *8 * * *Z
- 
- 
- z
s38}}!!!!!!-GGGG++++++C r   