3
6ßL]i%  ã               @   sØ   d Z ddlmZmZmZmZmZmZmZ ddl	m
Z
mZmZmZ ddl	mZmZmZ ddlmZ ddlmZ ddlmZ eeegd	d
dd	d	d	d	dd�	gd	ddd	d�ZG dd„ deƒZG dd„ de
ƒZG dd„ deƒZdS )z The preferences manager. é    )Ú	HasTraitsÚInstanceÚListÚPropertyÚAnyÚBoolÚDict)ÚHandlerÚHSplitÚItemÚ
TreeEditor)ÚTreeNodeÚViewÚ
HTMLEditor)ÚActioné   )ÚPreferencesNode)ÚPreferencesPageFÚchildrenÚnameN)	Únode_forÚ	auto_openr   ÚlabelÚrenameÚcopyÚdeleteÚinsertÚmenuTÚselected_node)ÚnodesÚeditableÚ	hide_rootÚselectedÚ
show_iconsc               @   s   e Zd ZdZdd„ ZdS )ÚPreferencesHelpWindowz5 Container class to present a view with string info. c             C   s†   g }ddgdddddœ}i }x6t | jƒ jƒ ƒD ]"\}}|dkr.|dkr.|j||< q.W x"|D ]}|jt|d	tƒ d
�ƒ qZW t||Ž}|S )z& Default view to show for this class. zPreferences Page HelpÚOKi   Tz0apptools.preferences.ui.preferences_manager.help)ÚtitleÚbuttonsÚwidthÚheightÚ	resizableÚidZtrait_addedZtrait_modifiedÚreadonly)ÚstyleÚeditor)ÚlistÚtraitsÚitemsÚhelpÚappendr   r   r   )ÚselfÚargsZkw_argsÚto_showr   Ú	trait_objÚview© r9   úQ/tmp/pip-install-5sebvq2j/apptools/apptools/preferences/ui/preferences_manager.pyÚtraits_view.   s"    

z!PreferencesHelpWindow.traits_viewN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r;   r9   r9   r9   r:   r$   +   s   r$   c                   sL   e Zd ZdZeeƒZdd„ Z‡ fdd„Z‡ fdd„Z	dd	„ Z
d
d„ Z‡  ZS )ÚPreferencesManagerHandlerz4 The traits UI handler for the preferences manager. c             C   s   |j jƒ  dS )z, Handle the **Apply** button being clicked. N)ÚobjectÚapply)r4   Úinfor9   r9   r:   rB   O   s    
zPreferencesManagerHandler.applyc                s   | j |ƒ tt| ƒj|ƒS )z. Initialize the controls of a user interface. )Ú_select_first_nodeÚsuperr@   Úinit)r4   rC   )Ú	__class__r9   r:   rF   U   s    
zPreferencesManagerHandler.initc                s    |r|j jƒ  tt| ƒj||ƒS )z& Close a dialog-based user interface. )rA   rB   rE   r@   Úclose)r4   rC   Zis_ok)rG   r9   r:   rH   ^   s    
zPreferencesManagerHandler.closec             C   s^   | j j}i }x6t|jƒ jƒ ƒD ]"\}}t|dƒr|jr|j||< qW tf |Ž}|j	dd� dS )z= Custom preferences help panel. The Traits help doesn't work.Ú	show_helpZ	livemodal)ÚkindN)
ÚmodelÚselected_pager/   r0   r1   ÚhasattrrI   r2   r$   Zedit_traits)r4   rC   Zcurrent_pager6   Z
trait_namer7   Zhelp_objr9   r9   r:   Úpreferences_helpg   s    
z*PreferencesManagerHandler.preferences_helpc             C   s.   |j j}t|jƒdkr*|jd }|j|j _dS )z6 Select the first node in the tree (if there is one). r   N)rA   ÚrootÚlenr   ÚpagerL   )r4   rC   rO   Únoder9   r9   r:   rD   x   s
    

z,PreferencesManagerHandler._select_first_node)r<   r=   r>   r?   r   r   rK   rB   rF   rH   rN   rD   Ú__classcell__r9   r9   )rG   r:   r@   F   s   		r@   c               @   st   e Zd ZdZeeƒZeee	ƒƒZ
ee	ƒZeeƒZedƒZedƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ ZdS )ÚPreferencesManagerz The preferences manager. Fc             C   s°   t ddd�}ddg}| jr$dg| }| jr4|g| }tttgddd	ddddd
d�	g| jddddd�}ttt	d|ddd�t	ddddd�ƒ|t
| d�dddddd�}| jd | _|S )z% Default traits view for this class. ZInforN   )r   Úactionr%   ZCancelZApplyFr   r   N)	r   r   r   r   r   r   r   r   r   Tr   )r   Z	on_selectr    r!   r"   r#   rO   éú   )r   r.   Ú
show_labelr(   rL   iÂ  Zcustom)r   rW   r(   r-   )rK   ZPreferencesg333333Ó?Úmodal)r'   Úhandlerr*   r&   r(   r)   rJ   r   )r   Ú
show_applyrI   r   r   r   Ú_selection_changedr   r
   r   r@   ÚpagesrL   )r4   Zhelp_actionr'   Útree_editorr8   r9   r9   r:   r;   ž   sV    

zPreferencesManager.traits_viewc             C   s\   dd„ }| j j|d� tddd�}t|d�}x*| j D ] }| j||ƒ}|jt|d�ƒ q4W |S )z Property getter. c             S   s(   t | jƒdkrd}nt | jjdƒƒ}|S )Nr   ú/)rP   ÚcategoryÚsplit)ÚaZlen_ar9   r9   r:   Úsort_keyê   s    z.PreferencesManager._get_root.<locals>.sort_key)ÚkeyZRootrO   )r   Zpreferences_path)rQ   )r\   Úsortr   r   Ú_get_parentr3   )r4   rb   Z	root_pagerO   rQ   Úparentr9   r9   r:   Ú	_get_rootä   s    
zPreferencesManager._get_rootc             C   s
   || _ d S )N)r   )r4   Znew_selectionr9   r9   r:   r[     s    z%PreferencesManager._selection_changedc             C   s   | j r| j j| _dS )z Static trait change handler. N)r   rQ   rL   )r4   Únewr9   r9   r:   Ú_selected_node_changed  s    
z)PreferencesManager._selected_node_changedc             C   s   x| j D ]}|jƒ  qW dS )z( Apply all changes made in the manager. N)r\   rB   )r4   rQ   r9   r9   r:   rB     s    zPreferencesManager.applyc             C   s:   |}t |jƒdkr6|jjdƒ}x|D ]}|j|ƒ}q$W |S )z+ Return the page's parent preference node. r   r^   )rP   r_   r`   Úlookup)r4   rO   rQ   rf   Ú
componentsÚ	componentr9   r9   r:   re   $  s    
zPreferencesManager._get_parentN)r<   r=   r>   r?   r   r   r\   r   r   r   rO   r   rL   r   rI   rZ   r;   rg   r[   ri   rB   re   r9   r9   r9   r:   rT   „   s   F'	rT   )r?   Z
traits.apir   r   r   r   r   r   r   Ztraitsui.apir	   r
   r   r   r   r   r   Ztraitsui.menur   Zpreferences_noder   Zpreferences_pager   r]   r$   r@   rT   r9   r9   r9   r:   Ú<module>   s0   $>