3
8ßL]
+  ã               @   st   d Z ddlmZmZ ddlZddlmZ ddlZejdƒZ	ej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.
é    )Úabsolute_importÚprint_functionN)Ú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kr|}|| _t|ddƒ| _i | _|jdƒ| _d| _|r^tj	ƒ  | _
}| j|dƒ n$tjƒ  | _
}| j|dƒ |j|ƒ dS )z! Initializes the object.
        NZ	call_menuÚ
r   é   éÿÿÿÿr   )ÚownerÚwindowÚgetattrÚindirectÚnamesÚsplitÚdescÚindexr   ÚQMenuÚmenuÚparseZQMenuBarZ
setMenuBar)Úselfr   r	   Zpopupr
   r   © r   ú7/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/menu.pyÚ__init__K   s    zMakeMenu.__init__c             C   sà  �xØ| j t| jƒkrdS | j| j  }|jƒ }t|ƒt|ƒ }||krHdS |  j d7  _ |dks|dd… dkrpq|dd… dkrŠ|jƒ  qd}tj|ƒ}|rÂd|jdƒjƒ  }|jdƒ|jd	ƒ }|j	d
ƒ}|dk�rª||d d… jƒ }	|	dk�rL| j
�r| j
t|	ƒ | j
}	n:y(t| d�}
td|	 tƒ |
ƒ |
d }	W n   t}	Y nX nBy0t| d�}
td| j|ƒf tƒ |
ƒ |
d }	W n   t}	Y nX d } }}d }}|d|… }tj|ƒ}|�rî|jdƒ|jd	ƒ }td|jdƒjƒ ƒ\}}}}|jƒ }|j	dƒ}|dk�r.||d d… jƒ }|d|… jƒ }|j||	ƒ}|j|�pF|ƒ |j|ƒ |�rd|j|ƒ |�rt|jdƒ |�r„|jdƒ |�rØ|| j|< t| j|t| |ƒƒ qtj|jƒ ƒ}| j||ƒ |j |ƒ}|j|ƒ qW dS )z= Recursively parses menu items from the description.
        Nr   Ú 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   Zcur_idÚ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   b   s’    















zMakeMenu.parsec             C   sv   g }xR| j t| jƒk rV| j| j  }t|ƒt|jƒ ƒ |kr<P |j|ƒ |  j d7  _ qW dj|ƒjƒ }|dkrr|S dS )z/ Returns the body of an inline method.
        r   r   r   z  pass)r   r!   r   r"   ÚappendÚjoinÚrstrip)r   r3   Úresultr4   r   r   r   r,   Ô   s    
zMakeMenu.get_bodyc             C   s   t |tjƒr| j| S |S )z? Returns the QAction associated with a specified name.
        )Ú
isinstanceÚsixÚstring_typesr   )r   r:   r   r   r   Ú
get_actionç   s    
zMakeMenu.get_actionc             C   s(   | j |ƒ}|dkr|jƒ S |j|ƒ dS )z= Checks (or unchecks) a menu item specified by name.
        N)rE   Z	isCheckedr/   )r   r:   Úcheckr=   r   r   r   r8   ó   s    
zMakeMenu.checkedc             C   s(   | j |ƒ}|dkr|jƒ S |j|ƒ dS )z> Enables (or disables) a menu item specified by name.
        N)rE   Z	isEnabledr0   )r   r:   Úenabler=   r   r   r   Úenabled  s    
zMakeMenu.enabledc             C   s.   | j |ƒ}|dkr tj|jƒ ƒS |j|ƒ dS )z1 Gets or sets the label for a menu item.
        N)rE   rC   Ú	text_typeÚtextZsetText)r   r:   r<   r=   r   r   r   r<     s    
zMakeMenu.label)FN)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r,   rE   r8   rH   r<   r   r   r   r   r   D   s   
r

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 )r2   z1 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| j|ƒS )N)r   r8   r=   )r   rF   r   r   r   r8   &  s    zMakeMenuItem.checkedc             C   s   | j ƒ  }| j |ƒ |S )N)r8   )r   r8   r   r   r   Útoggle)  s    

zMakeMenuItem.togglec             C   s   | j j| j|ƒS )N)r   rH   r=   )r   rG   r   r   r   rH   .  s    zMakeMenuItem.enabledc             C   s   | j j| j|ƒS )N)r   r<   r=   )r   r<   r   r   r   r<   1  s    zMakeMenuItem.label)N)N)N)	rK   rL   rM   rN   r   r8   rO   rH   r<   r   r   r   r   r2     s   

r2   c             C   s\   g }xH| D ]@}|j |ƒ}|j|dkƒ |dkr
|d|… ||d d…  }q
W ||jƒ g S )zl Determines whether a string contains any specified option characters,
    and removes them if it does.
    r   Nr   )r'   r>   r&   )ÚtestÚstringrA   Úcharr7   r   r   r   r.   :  s    

 r.   c             C   s   t dƒ d S )Nznull_handler invoked)Úprint)Úeventr   r   r   r+   K  s    r+   )rN   Ú
__future__r   r   ÚreZ	pyface.qtr   rC   Úcompiler#   r-   r   r2   r.   r+   r   r   r   r   Ú<module>+   s   

 [