
    G@d<                         d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ  G d d          Z G d d          Z G d de          ZdS )z
Layout container.
    )OrderedDictN)QtSlot)QMessageBox)SpyderAPIError)_)PluginMainContainer)BaseGridLayoutType)DefaultLayouts)LayoutSaveDialogLayoutSettingsDialogc                   F    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdS )LayoutContainerActionsdefault_layout_actionmatlab_layout_actionrstudio_layout_actionhorizontal_split_layout_actionvertical_split_layout_actionsave_layout_actionshow_layout_preferences_actionreset_layout_actionzMaximize paneFullscreen modeUse next layoutUse previous layoutz
Close panezLock unlock panesN)__name__
__module____qualname__DefaultLayoutMatlabLayoutRStudioHorizontalSplitVerticalSplitSaveLayoutActionShowLayoutPreferencesActionResetLayoutMaximizeCurrentDockwidget
Fullscreen
NextLayoutPreviousLayoutCloseCurrentDockwidgetLockDockwidgetsAndToolbars     ?lib/python3.11/site-packages/spyder/plugins/layout/container.pyr   r      sg        +M)L%G6O2M+"B'K !0 #J #J +N * "5r-   r   c                       e Zd ZdZdZdS )LayoutPluginMenusplugins_menulayouts_menuN)r   r   r   PluginsMenuLayoutsMenur,   r-   r.   r0   r0   :   s         K KKKr-   r0   c                      e Zd ZdZd Zd Zd Zd Zd Zd Z	 e
            d             Z e
            d	             Z e
            d
             Z e
            d             Z e
            d             ZddZd ZdS )LayoutContainerzU
    Plugin container class that handles the Spyder quick layouts functionality.
    c           	          t                       _        d  _        d  _        d  _        d  _                             t          j        t          d           
                    d           j        j        t          j        dd           _                             t          j        t          d           
                    d           fdt          j        dd	           _                             t          j        t          d
           j        j        t          j        dd           _        t*          j        dk    rA j                            d            j                            t          d                                          t          j        d fdt          j        dd           _                             t          j        t          d           j        t          j        d           _                             t          j        t          d           j        t          j        d           _                              t          j!        t          d           j"        d           _#                             t          j$        t          d           j%        t          j        dd           _&                             t          j'        t          d           j(        t          j        dd           _)         *                    tV          j,        t          d                     _         *                    tV          j-        t          d                     _.         j.        /                    d           d S )NzClose current pane
close_paneTr   )texticon	triggeredcontextregister_shortcutshortcut_contextzMaximize current panemaximizec                 6    j                                         S N)_pluginmaximize_dockwidget)stateselfs    r.   <lambda>z'LayoutContainer.setup.<locals>.<lambda>\   s    $,"B"B"D"D r-   )r9   r:   toggledr<   r=   r>   r   )r9   r;   r<   r=   r>   darwinFz2For fullscreen mode use the macOS built-in feature c                 6    j                                         S rA   )rB   toggle_lock)checkedrE   s    r.   rF   z'LayoutContainer.setup.<locals>.<lambda>r   s    ((** r-   zSave current layout)r;   r<   r=   zLayout preferences)r9   r;   r<   r=   zReset to Spyder default)r9   r;   r=   r   )r;   r<   r=   r>   r   zWindow layoutsPaneszcheckbox-padding)0r   _spyder_layouts_save_dialog_settings_dialog_layouts_menu_current_quick_layoutcreate_actionr   r*   r   create_iconrB   close_current_dockwidgetr   ApplicationShortcut_close_dockwidget_actionr&   _maximize_dockwidget_actionr'   toggle_fullscreen_fullscreen_actionsysplatform
setEnabled
setToolTipr+   _lock_interface_actionr#   show_save_layout_save_layout_actionr$   show_layout_settings_show_preferences_actionr%   reset_window_layout_reset_actionr(   toggle_next_layout_toggle_next_layout_actionr)   toggle_previous_layout_toggle_previous_layout_actioncreate_menur0   r4   r3   _plugins_menusetObjectNamerE   s   `r.   setupzLayoutContainer.setupD   sx   *}}  $!%)" )-(:(:"9'((!!,//l;*"  ); )
 )
% ,0+=+="<*++!!*--DDDD*"  ,> ," ,"( #'"4"4"-$%%l4*"  #5 #" #" <8###..u555#..q 2J 0K 0K L L L '+&8&8"=+ + + +*"  '9 '
 '
# $(#5#5"3#$$+*# $6 $
 $
  )-(:(:">'((/*# ); )
 )
% "//".,--.#	 0 
 
 +/*<*<"-  -*"  += +" +"' /3.@.@"1#$$1*"  /A /" /"+ "--)1-=+>+>@ @ "--)1W::7 7(();<<<<<r-   c                     d S rA   r,   rm   s    r.   update_actionszLayoutContainer.update_actions   s    r-   c                    | j         }|                                 |                     d          }|                     d          }|                     d          }|                     d          }g }|D ]}||v r|| j        v r"|}| j        |                                         }n|                    |          }||         }|| fd}	|                     || |	            dd          }
|                    |
           |D ]}|                     ||d	
           | j	        | j
        | j        fD ]}|                     ||d
           | j
                            t          |          dk               dS )zB
        Update layouts menu and layouts related actions.
        namesui_namesorderactivec                       fdS )Nc                  .                                    S rA   )quick_layout_switchirE   s   r.   rF   zMLayoutContainer.update_layout_menu_actions.<locals>.trigger.<locals>.<lambda>   s    4#;#;A#>#> r-   r,   ry   s   ``r.   triggerz;LayoutContainer.update_layout_menu_actions.<locals>.trigger   s    >>>>>>r-   FT)r9   r;   r=   	overwritelayouts_sectionsectionlayouts_section_2r   N)rQ   clear_actionsget_confrN   get_nameindexrS   appendadd_item_to_menura   rc   re   r]   len)rE   menurr   rs   rt   ru   actionsnamer   r{   layout_switch_actionitems               r.   update_layout_menu_actionsz*LayoutContainer.update_layout_menu_actions   s    !g&&==,,g&&x(( 	5 	5Dv~~4/// E/6??AADD!KK--E#E?D $$ ? ? ? ? (,'9'9%gii&+" (: ( ($ 3444 	I 	ID!!$6G!HHHH-t/L') 	K 	KD!!$6I!JJJJ%00UqAAAAAr-   c                 2    t          j        | ||           dS )z@Expose a QMessageBox.critical dialog to be used from the plugin.N)r   critical)rE   titlemessages      r.   critical_messagez LayoutContainer.critical_message   s    T5'22222r-   c                 4   t          |t                    st          d          |j        }|| j        v r"t          d                    |                     ||          }|                                 || j        |<   |                     d          }|                     d          }|                     d          }|                     d          }||vr|                    |           |                    |	                                           |                    |           |                    |           | 
                    d|           | 
                    d|           | 
                    d|           | 
                    d|           dS dS )a  
        Register a new layout type.

        Parameters
        ----------
        parent_plugin: spyder.api.plugins.SpyderPluginV2
            Plugin registering the layout type.
        layout_type: spyder.plugins.layout.api.BaseGridLayoutType
            Layout to register.
        z4A layout must be a subclass is `BaseGridLayoutType`!z'Layout with id `{}` already registered!rr   rs   rt   ru   N)
issubclassr
   r   IDrN   format_check_layout_validityr   r   r   set_conf)	rE   parent_pluginlayout_type	layout_idlayoutrr   rs   rt   ru   s	            r.   register_layoutzLayoutContainer.register_layout   s    +'9:: 	H FH H H  N	,,, 9@@KKM M M ]++%%'''*0Y'g&&==,,g&&x((E!!LL###OOFOO--...LL###MM)$$$MM'5)))MM*h///MM'5)))MM(F+++++ "!r-   c                 r    || j         vr"t          d                    |                    | j         |         S )a  
        Get a registered layout by its ID.

        Parameters
        ----------
        layout_id : string
            The ID of the layout.

        Raises
        ------
        SpyderAPIError
            If the given id is not found in the registered layouts.

        Returns
        -------
        Instance of a spyder.plugins.layout.api.BaseGridLayoutType subclass
            Layout.
        z&Layout with id `{}` is not registered!)rN   r   r   )rE   r   s     r.   
get_layoutzLayoutContainer.get_layout  sH    & D000 8??	JJL L L #I..r-   c                 2                          d          }                      d          }                      d          }                      d          } fd|D             }t           |          x} _        |                                r|j                                        }| j        v rEt          j         t          d          t          d          
                    |                     dS ||v rqt          j         t          d	          t          d
          
                    |          t          j        t          j        z            }|                    |          }	nZd}d|v r|                    d          }	|||	<   n$t          |          }	|                    |           |                    |           ||vr|                    |           ||vr|                    |           |r j                            d
                    |	          d                                d|                                d|                                d|                                d|                                             dS dS )zShow the save layout dialog.rr   rs   rt   ru   c                 J    g | ]}|j                                         v| S r,   )rN   keys).0r   rE   s     r.   
<listcomp>z4LayoutContainer.show_save_layout.<locals>.<listcomp>!  s?     D D Dt';'@'@'B'BBB BBBr-   ErrorzrLayout <b>{0}</b> was defined programatically. It is not possible to overwrite programatically registered layouts.NWarningz?Layout <b>{0}</b> will be overwritten. Do you want to continue?Tz
layout_{}/quick_layoutsr~   )r   r   rO   exec_	combo_boxcurrentTextrN   r   r   r   r   warningYesNor   r   r   rB   save_current_window_settingsr   r   )
rE   rr   rs   rt   ru   dialog_namesdlgr   answerr   s
   `         r.   r`   z LayoutContainer.show_save_layout  s    g&&==,,g&&x((D D D D D D D"24"F"FFd99;; /	.=,,..Dt+++$gJJ , - --3VD\\   u}}$,iLL 1 2 228&,,Okn4  D))5==!KK--E#'E%LLJJELL&&&T""" 6!!d###8##%%% 099 ''.. : I I Igu---j(333gu---h///++-----_/	. /	.r-   c                 \   |                      d          }|                      d          }|                      d          }|                      d          }t          | j                                                  }t	          | |||||          x}| _        |                                r|                     d|j                   |                     d|j	                   |                     d|j
                   |                     d|j                   |                                  dS dS )zLayout settings dialog.rr   rs   rt   ru   N)r   listrN   r   r   rP   r   r   rr   rs   rt   ru   r   )rE   rr   rs   rt   ru   	read_onlyr   s          r.   rb   z$LayoutContainer.show_layout_settingsV  s    g&&==,,g&&x((-224455	&:%5&)'= '= 	=d#99;; 	.MM'39---MM*cl333MM'39---MM(CJ///++-----	. 	.r-   c                     t          j        | t          d          t          d          t           j        t           j        z            }|t           j        k    r| j                            d           dS dS )zReset window layout to default.r   z}Window layout will be reset to default settings: this affects window position, size and dockwidgets.
Do you want to continue?T)defaultN)r   r   r   r   r   rB   setup_layout)rE   r   s     r.   rd   z#LayoutContainer.reset_window_layouti  sx     $iLL ) * * Okn,
 
 [_$$L%%d%33333 %$r-   c                 0    |                      d           dS )zAUse the previous layout from the layouts list (default + custom).previousNtoggle_layoutrm   s    r.   rh   z&LayoutContainer.toggle_previous_layoutx  s     	:&&&&&r-   c                 0    |                      d           dS )z=Use the next layout from the layouts list (default + custom).nextNr   rm   s    r.   rf   z"LayoutContainer.toggle_next_layout}  s     	6"""""r-   r   c                 T   |                      d          }|                      d          }|                      d          }t          |          dk    rdS g }|D ].}||v r(|                    |                    |                     /| j        }ddd}||                    t
          j                  }||v r|                    |          }	nd}	|	||         z   t          |          z  }
||
         }||         | j        v }|r|||
                  }|                     |           dS )	zChange current layout.rr   rt   ru   r   N   )r   r   )	r   r   r   r   rR   r   SpyderLayoutrN   rx   )rE   	directionrr   rt   ru   layout_indexr   current_layoutdiccurrent_index	new_indexindex_or_layout_idis_layout_ids                r.   r   zLayoutContainer.toggle_layout  sO   g&&g&&x((v;;!F 	7 	7Dv~~##EKK$5$56663b))!"[[)DEEN\))(..~>>MMM"S^3s<7H7HH	))4$%)== 	  	@!&|I'>!?  !344444r-   c                     | j                             |          }|Ot          |t                    r	|| _        dS |                     d          }|                    |          | _        dS dS )z
        Switch to quick layout number *index* or *layout id*.

        Parameters
        ----------
        index: int or str
        Nrr   )rB   rx   
isinstanceintrR   r   r   )rE   r   possible_current_layoutrr   s       r.   rx   z#LayoutContainer.quick_layout_switch  s     #',"B"B#  #  #.1377 --D***g..-2[[+.- .-*** /.r-   N)r   )r   r   r   __doc__rn   rp   r   r   r   r   r   r`   rb   rd   rh   rf   r   rx   r,   r-   r.   r6   r6   ?   sK        `= `= `=D  *B *B *B\3 3 3$, $, $,L/ / /2 
TVV9. 9. V9.v 
TVV. . V.$ 
TVV4 4 V4 
TVV' ' V' 
TVV# # V#"5 "5 "5 "5H- - - - -r-   r6   )r   collectionsr   r[   qtpy.QtCorer   r   qtpy.QtWidgetsr   spyder.api.exceptionsr   spyder.api.translationsr   !spyder.api.widgets.main_containerr	   spyder.plugins.layout.apir
   spyder.plugins.layout.layoutsr   $spyder.plugins.layout.widgets.dialogr   r   r   r0   r6   r,   r-   r.   <module>r      sk   
 $ # # # # # 



 !               & & & & & & 1 0 0 0 0 0 % % % % % % A A A A A A 8 8 8 8 8 8 8 8 8 8 8 8, , , , , , , ,5 5 5 5 5 5 5 5:! ! ! ! ! ! ! !
x- x- x- x- x-) x- x- x- x- x-r-   