a
    §ˆcû*  ã                   @   s    d Z ddlZddlZddlZe e¡Ze d¡Ze d¡Z	ej
ejejejejejejejejejejejdœZG dd„ dƒZG dd	„ d	ƒZd
d„ Zdd„ ZdS )a€   Dynamically construct wxPython Menus or MenuBars from a supplied string
    description of the menu.

Menu Description Syntax::

    submenu_label {help_string}
        menuitem_label | accelerator {help_string} [~/-name]: code

*submenu_label*
    Label of a sub menu
*menuitem_label*
    Label of a menu item
{*help_string*}
    Help string to display on the status line (optional)
*accelerator*
    Accelerator key (e.g., Ctrl-C) (The '|' and keyname are optional, but must
    be used together.)
[~]
    The menu item is checkable, but is not checked initially (optional)
[/]
    The menu item is checkable, and is checked initially (optional)
[-]
    The menu item disabled initially (optional)
[*name*]
    Symbolic name used to refer to menu item (optional)
*code*
    Python code invoked when menu item is selected

A line beginning with a hyphen (-) is interpreted as a menu separator.
é    Nz(.*){(.*)}(.*)z(.*)\[(.*)\](.*))ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12c                   @   sT   e Zd ZdZdZddd„Zdd„ Zd	d
„ Zdd„ Zddd„Z	ddd„Z
ddd„ZdS )ÚMakeMenuzManages creation of menus.iè  FNc                 C   s¬   || _ |du r|}|| _t|ddƒ| _i | _| d¡| _d| _g | _|rdt	 
¡  | _}|  |d¡ nDt	 ¡  | _}|  |d¡ | |¡ t| jƒdkr¨| t	 | j¡¡ dS )zInitializes the object.NZ	call_menuÚ
r   éÿÿÿÿ)ÚownerÚwindowÚgetattrÚindirectÚnamesÚsplitÚdescÚindexÚkeysÚwxÚMenuÚmenuÚparseZMenuBarZ
SetMenuBarÚlenZSetAcceleratorTableZAcceleratorTable)Úselfr   r   Zpopupr   r   © r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/menu.pyÚ__init__W   s"    
zMakeMenu.__init__c                 C   sÚ  | j t| jƒkrdS | j| j  }| ¡ }t|ƒt|ƒ }||krDdS |  j d7  _ |dks |dd… dkrlq |dd… dkr†| ¡  q t jd7  _tj}d}t |¡}|rÒd| 	d¡ 
¡  }| 	d¡| 	d	¡ }| d
¡}	|	dk�rŠ||	d d…  
¡ }
|
dk�rt| j�r |  ||
¡ | j}
nRz(t| d�}td|
 tƒ |ƒ |d }
W n( t�yp   t d |
¡¡ t}
Y n0 nZz0t| d�}td|  |¡f tƒ |ƒ |d }
W n( t�yÌ   t d |
¡¡ t}
Y n0 | jjtj|
|d� d } }}|d|	… }t |¡}|�rb| 	d¡| 	d	¡ }td| 	d¡ 
¡ ƒ\}}}}|dk�rb|| j|< t| j|t| |ƒƒ | 
¡ }| d¡}	|	dk�rP||	d d…  
¡ }d|d|	…  
¡ d|f }|  ¡ }tj!}| d¡}	|	dk�r
tj"tj#tj$dœ %|d|	…  
¡ tj"¡}||	d d…  
¡ }t& %|d¡}z,|du �r*t'|ƒ}| j( )t *|||¡¡ W n   Y n0 | +||||�pb|¡ |�rx| ,|d¡ |r | -|d¡ q t .¡ }| 
¡ }|  /||¡ z| 0||||¡ W q    | +||¡ Y q 0 q dS )z3Recursively parses menu items from the description.Né   Ú r   ú#ú-ú é   é   ú:)r   z)def handler(event, self=self.owner):
 %s
ÚhandlerzInvalid menu handler {:r}z(def handler(event, self=self.owner):
%s
)ÚidFz~/-ú|z%s%s%sú	)ZCTRLÚSHIFTZALTT)1r   r   r   ÚlstripZAppendSeparatorr   Úcur_idÚhelp_patÚsearchÚgroupÚstripÚfindr   ÚdictÚexecÚglobalsÚ	ExceptionÚloggerÚ	exceptionÚformatÚnull_handlerÚget_bodyr   ZBindr   ZEVT_MENUÚoptions_patÚoption_checkr	   Úsetattrr   ÚMakeMenuItemÚupperZACCEL_NORMALZ
ACCEL_CTRLZACCEL_SHIFTZ	ACCEL_ALTÚgetÚkey_mapÚordr   ÚappendZAcceleratorEntryZAppendÚCheckÚEnabler   r   Z
AppendMenu)r   r   ÚindentZdlineÚlineZindentedr%   ÚhelpÚmatchÚcolr   Z_loclZnot_checkedÚcheckedÚdisabledÚnameÚlabelÚkeyÚflagÚcodeZsubmenur   r   r   r   l   sÖ    




ÿüÿ

ÿüÿ

ÿ





ýü
ÿzMakeMenu.parsec                 C   sr   g }| j t| jƒk rT| j| j  }t|ƒt| ¡ ƒ |kr:qT| |¡ |  j d7  _ qd |¡ ¡ }|dkrn|S dS )z%Returns the body of an inline method.r   r   r   z  pass)r   r   r   r$   r<   ÚjoinÚrstrip)r   r?   Úresultr@   r   r   r   r3   ô   s    
zMakeMenu.get_bodyc                 C   s   t |tƒr| j| S |S )z0Returns the ID associated with a specified name.)Ú
isinstanceÚstrr	   )r   rF   r   r   r   Úget_id  s    

zMakeMenu.get_idc                 C   s2   |du r| j  |  |¡¡S | j  |  |¡|¡ dS )z3Checks (or unchecks) a menu item specified by name.N)r   Z	IsCheckedrP   r=   )r   rF   Úcheckr   r   r   rD     s    zMakeMenu.checkedc                 C   s2   |du r| j  |  |¡¡S | j  |  |¡|¡ dS )z4Enables (or disables) a menu item specified by name.N)r   Z	IsEnabledrP   r>   )r   rF   Úenabler   r   r   Úenabled  s    zMakeMenu.enabledc                 C   s2   |du r| j  |  |¡¡S | j  |  |¡|¡ dS )z'Gets or sets the label for a menu item.N)r   ZGetLabelrP   ZSetLabel)r   rF   rG   r   r   r   rG     s    zMakeMenu.label)FN)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r   r   r3   rP   rD   rS   rG   r   r   r   r   r   Q   s   
 	

r   c                   @   s>   e Zd ZdZdd„ Zddd„Zdd„ Zdd	d
„Zddd„ZdS )r7   z+A menu item for a menu managed by MakeMenu.c                 C   s   || _ || _d S ©N)r   r    )r   r   r    r   r   r   r     s    zMakeMenuItem.__init__Nc                 C   s   | j  | j|¡S rX   )r   rD   r    )r   rQ   r   r   r   rD   "  s    zMakeMenuItem.checkedc                 C   s   |   ¡  }|   |¡ |S rX   )rD   )r   rD   r   r   r   Útoggle%  s    

zMakeMenuItem.togglec                 C   s   | j  | j|¡S rX   )r   rS   r    )r   rR   r   r   r   rS   *  s    zMakeMenuItem.enabledc                 C   s   | j  | j|¡S rX   )r   rG   r    )r   rG   r   r   r   rG   -  s    zMakeMenuItem.label)N)N)N)	rT   rU   rV   rW   r   rD   rY   rS   rG   r   r   r   r   r7     s   

r7   c                 C   sX   g }| D ]@}|  |¡}| |dk¡ |dkr|d|… ||d d…  }q|| ¡ g S )zkDetermines whether a string contains any specified option characters,
    and removes them if it does.
    r   Nr   )r*   r<   r)   )ÚtestÚstringrM   ÚcharrC   r   r   r   r5   7  s    
r5   c                 C   s   t dƒ d S )Nznull_handler invoked)Úprint)Úeventr   r   r   r2   I  s    r2   )rW   ÚreÚloggingr   Ú	getLoggerrT   r/   Úcompiler&   r4   ZWXK_F1ZWXK_F2ZWXK_F3ZWXK_F4ZWXK_F5ZWXK_F6ZWXK_F7ZWXK_F8ZWXK_F9ZWXK_F10ZWXK_F11ZWXK_F12r:   r   r7   r5   r2   r   r   r   r   Ú<module>   s0   $


ô K