a
    §ˆc  ã                   @   s˜   d Z ddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZmZ ddlmZ ededd	�Zd
d„ Zdd„ ZG dd„ dejƒZG dd„ deƒZdS )zÉ Creates a wizard-based wxPython user interface for a specified UI object.

    A wizard is a dialog box that displays a series of pages, which the user
    can navigate with forward and back buttons.
é    N)ÚStrÚUnioné   )ÚDefaultTitle)Úrestore_windowÚsave_windowÚGroupEditor)Úfill_panel_for_groupÚ )Údefault_valuec                 C   s¤  | j  | _}dd„ | ¡ D ƒ}|| _ | j ¡  | jj}|dkrBt}t 	|d|¡ | _
}g }g }| j}| jj | ¡}	d }
}i }|	 ¡ D ]à}|j|jf||< d\|_|_t||ƒ}| |¡ t||| ƒ | ¡ }| |¡ | ¡ }t|
| ¡ ƒ}
t|| ¡ ƒ}|| \|_|_|j�s|jr†t|d� |_}|j�rR|j|_| |¡ | |j|¡ |jr†|  |j|¡ q†| t |
|¡¡ |  tj!t"¡ |d }| #|¡ |dd	… D ]}| $|¡ | %|¡ |}�q¦z|  &¡  W n,   | j
 '¡  d	| j
_(d	| _
d
| _)‚ Y n0 | j* +| j¡ t,| ƒ | -|d ¡�rl| j}| j  ¡ D ],\}}|d	u�rX||  .|¡ nd	||< �q6d| _)nd
| _)|j/tj!t"d� t0| ƒ |  1¡  | j| _ i | _d	S )zRCreates a wizard-based wxPython user interface for a specified UI
    object.
    c                 S   s&   i | ]\}}||d u rd n|  ¡ “qS ©N)Zclone_traits)Ú.0ÚnameÚvalue© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/ui_wizard.pyÚ
<dictcomp>)   s   ÿzui_wizard.<locals>.<dictcomp>r
   éÿÿÿÿr   )r
   r
   )Úcontrolr   NFT)Úhandler)2ÚcontextÚ_contextÚitemsÚinfoZbind_contextÚviewÚtitler   ÚwzZWizardr   ÚcontentZ
get_shadowÚget_contentÚidZenabled_whenÚUIWizardPageÚappendr	   ZGetSizerZFitZCalcMinÚmaxZGetWidthZ	GetHeightÚPageGroupEditorÚeditorÚbindZadd_enabledZSetPageSizeÚwxÚSizeZBindZEVT_WIZARD_PAGE_CHANGINGÚpage_changingZ	FitToPageÚSetPrevÚSetNextZ
prepare_uiZDestroyÚuiÚresultr   Úpositionr   Z	RunWizardZcopy_traitsZUnbindr   Úfinish)r+   Úparentr   Znew_contextr   ÚwizardÚpagesZeditor_pagesr   Zshadow_groupZmin_dxZmin_dyZgroup_fields_mappingÚgroupÚpageZsizerÚsizer$   Z	prev_pageÚoriginalr   r   r   r   r   Ú	ui_wizard#   s†    þ









r6   c                 C   sb   |   ¡ }|  ¡ r| ¡ }n| ¡ }|dur^|jdur^|jjs^|  ¡  |jj}|dkr^t 	|¡ dS )z>Handles the user attempting to change the current wizard page.Nr
   )
ZGetPageZGetDirectionÚGetNextÚGetPrevr$   ZenabledZVetoÚmsgr&   Z
MessageBox)Úeventr3   Znew_pager9   r   r   r   r(   ›   s    
ÿþýr(   c                       s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )r    z!A page within a wizard interface.c                    s(   t ƒ  |¡ d  | _ | _| _|| _d S r   )ÚsuperÚ__init__ÚnextÚpreviousr$   r1   )Úselfr0   r1   ©Ú	__class__r   r   r<   µ   s    zUIWizardPage.__init__c                 C   s
   || _ dS )z"Sets the next page after this one.N)r=   ©r?   r3   r   r   r   r*   º   s    zUIWizardPage.SetNextc                 C   s
   || _ dS )z#Sets the previous page to this one.N)r>   rB   r   r   r   r)   ¾   s    zUIWizardPage.SetPrevc                 C   sN   | j }|durH|jdkrH|j}|du r*dS | jD ]}|j|kr0|  S q0| jS )z%Returns the next page after this one.Nr
   )r$   r=   r1   r   )r?   r$   Znext_r3   r   r   r   r7   Â   s    


zUIWizardPage.GetNextc                 C   sN   | j }|durH|jdkrH|j}|du r*dS | jD ]}|j|kr0|  S q0| jS )z&Returns the previous page to this one.Nr
   )r$   r>   r1   r   )r?   r$   r>   r3   r   r   r   r8   Î   s    


zUIWizardPage.GetPrev)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   r*   r)   r7   r8   Ú__classcell__r   r   r@   r   r    ²   s   r    c                   @   s   e Zd ZdZeZeZeƒ ZdS )r#   z*Editor for a group, which displays a page.N)	rC   rD   rE   rF   Únone_str_traitr=   r>   r   r9   r   r   r   r   r#   Û   s   r#   )rF   r&   Zwx.advZadvr   Z
traits.apir   r   Ú	constantsr   Úhelperr   r   r   Zui_panelr	   rH   r6   r(   Z
WizardPager    r#   r   r   r   r   Ú<module>   s   x)