a
    §ˆcî#  ã                   @   s\   d Z ddlZddlmZ e d¡Ze d¡ZG dd„ dƒZG dd	„ d	ƒZd
d„ Z	dd„ Z
dS )ax  
Dynamically construct PyQt 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.
é    N)ÚQtGuiz(.*){(.*)}(.*)z(.*)\[(.*)\](.*)c                   @   sP   e 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.FNc                 C   s†   || _ |du r|}|| _t|ddƒ| _i | _| d¡| _d| _|r^t 	¡  | _
}|  |d¡ n$t ¡  | _
}|  |d¡ | |¡ dS )zInitializes the object.NZ	call_menuÚ
r   éÿÿÿÿ)ÚownerÚwindowÚgetattrÚindirectÚnamesÚsplitÚdescÚindexr   ÚQMenuÚmenuÚparseZQMenuBarZ
setMenuBar)Úselfr   r   Zpopupr   r   © r   úT/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/menu.pyÚ__init__D   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 d}t |¡}|r¾d| d¡ ¡  }| d¡| d	¡ }| 	d
¡}|dk�r¦||d d…  ¡ }	|	dk�rH| j
�r|  
d|	¡ | j
}	n:z(t| d�}
td|	 tƒ |
ƒ |
d }	W n   t}	Y n0 nBz0t| d�}
td|  |¡f tƒ |
ƒ |
d }	W n   t}	Y n0 d } }}d }}|d|… }t |¡}|�rê| d¡| d	¡ }td| d¡ ¡ ƒ\}}}}| ¡ }| 	d¡}|dk�r*||d d…  ¡ }|d|…  ¡ }| ||	¡}| |�pB|¡ | |¡ |�r`| |¡ |�rp| d¡ |�r€| d¡ |�rÔ|| j|< t| j|t| |ƒƒ q t | ¡ ¡}|  ||¡ | |¡}| |¡ q dS )z3Recursively parses menu items from the description.Né   Ú r   ú#ú-ú é   é   ú:)r   z"def handler(self=self.owner):
 %s
Úhandlerz!def handler(self=self.owner):
%s
Fz~/-ú|T) r   Úlenr   ÚlstripZaddSeparatorÚhelp_patÚsearchÚgroupÚstripÚfindr	   ÚdictÚexecÚglobalsÚnull_handlerÚget_bodyÚoptions_patÚoption_checkZ	addActionZsetCheckableZsetStatusTipZsetShortcutÚ
setCheckedÚ
setEnabledr
   Úsetattrr   ÚMakeMenuItemr   r   r   ZaddMenu)r   r   ÚindentZdlineÚlineZindentedÚhelpÚmatchÚcolr   Z_loclZnot_checkedÚcheckedÚdisabledÚnameÚkeyÚlabelÚactZsubmenur   r   r   r   V   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    ÚappendÚjoinÚrstrip)r   r1   Úresultr2   r   r   r   r*   Æ   s    
zMakeMenu.get_bodyc                 C   s   t |tƒr| j| S |S )z5Returns the QAction associated with a specified name.)Ú
isinstanceÚstrr
   )r   r8   r   r   r   Ú
get_actionÔ   s    

zMakeMenu.get_actionc                 C   s(   |   |¡}|du r| ¡ S | |¡ dS )z3Checks (or unchecks) a menu item specified by name.N)rB   Z	isCheckedr-   )r   r8   Úcheckr;   r   r   r   r6   Û   s    
zMakeMenu.checkedc                 C   s(   |   |¡}|du r| ¡ S | |¡ dS )z4Enables (or disables) a menu item specified by name.N)rB   Z	isEnabledr.   )r   r8   Úenabler;   r   r   r   Úenabledä   s    
zMakeMenu.enabledc                 C   s,   |   |¡}|du rt| ¡ ƒS | |¡ dS )z'Gets or sets the label for a menu item.N)rB   rA   ÚtextZsetText)r   r8   r:   r;   r   r   r   r:   í   s    
zMakeMenu.label)FN)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r*   rB   r6   rE   r:   r   r   r   r   r   A   s   
p
	
	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 )r0   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 rK   )r   r6   r;   )r   rC   r   r   r   r6   þ   s    zMakeMenuItem.checkedc                 C   s   |   ¡  }|   |¡ |S rK   )r6   )r   r6   r   r   r   Útoggle  s    

zMakeMenuItem.togglec                 C   s   | j  | j|¡S rK   )r   rE   r;   )r   rD   r   r   r   rE     s    zMakeMenuItem.enabledc                 C   s   | j  | j|¡S rK   )r   r:   r;   )r   r:   r   r   r   r:   	  s    zMakeMenuItem.label)N)N)N)	rG   rH   rI   rJ   r   r6   rL   rE   r:   r   r   r   r   r0   ÷   s   

r0   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Ústringr?   Úcharr5   r   r   r   r,     s    
r,   c                 C   s   t dƒ d S )Nznull_handler invoked)Úprint)Úeventr   r   r   r)   %  s    r)   )rJ   ÚreZ	pyface.qtr   Úcompiler!   r+   r   r0   r,   r)   r   r   r   r   Ú<module>   s   !

 7