
    G@dH                     t    d Z ddlZddl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  G d d	          ZdS )
z
Layout Plugin API.
    N)QRectFQt)QGridLayoutQPlainTextEditQWidget)SpyderAPIError)PLUGIN_REGISTRY)_c                   \    e Zd ZdZdZ	 d Zd Zd Zd Zdddd	g fd
Z	d Z
d ZddZd ZdS )BaseGridLayoutTypea  
    A base layout type to create custom layouts for Spyder panes.

    The API for this plugin is a subset of a QGridLayout, so the same
    concepts, like row, column, spans and stretches apply.

    Notes
    -----
    See: https://doc.qt.io/qt-5/qgridlayout.html
    Nc                     || _         g | _        g | _        i | _        i | _        d| _        d | _        g | _        d| _        d| _	        g | _
        d S )NFr   )plugin_areas_area_rects_column_stretchs_row_stretchs_default_added_default_area_visible_areas_rows_cols_plugin_ids)selfparent_plugins     9lib/python3.11/site-packages/spyder/plugins/layout/api.py__init__zBaseGridLayoutType.__init__'   s\    # "#! 

    c           	         g | _         | j        t          d          |                                  | j        st          d          g }d}| j        D ]}|                    |d                    |d         r|| _        | j                             |d                    |r'|d         dk    r|d	         dk    rt          d
          |d         dk    r|d	         dk    rd}t          |d                   t          |d                   k    sBt          d                    |                                 |d         |d                             t          | j                   st          d          t          |          st          d          |
                    d          dk    rt          d          |st          d          |                                  dS )z:
        Check the current layout is a valid one.
        Nz-A Layout must define an `ID` class attribute!z(A Layout must define add least one area!Fdefaultvisiblerowr   columnz1Multiple areas defined their row and column as 0!Thidden_plugin_ids
plugin_idszAt least 1 hidden plugin id is not being specified in the area plugin ids list!
 SpyderLayout: {}
 hidden_plugin_ids: {}
plugin_ids: {}z!At least 1 area must be `visible`zNo area is the `default`!   z!Only 1 area can be the `default`!z51 area needs to be specified with row 0 and column 0!)r   IDr   get_namer   appendr   setformatanycount_check_area)r   default_areasarea_zero_zeroareas       r   _check_layout_validityz)BaseGridLayoutType._check_layout_validity6   s;    !7?  ". / / / 	 { 	M !KLLLK 	A 	AD  i111I *%)"&&tI777 I$u+"2"2tH~7J7J$GI I I E{aDNa$7$7!%t/011Sl9K5L5LLL$% &,VDMMOO,01D,E,0,>&@ &@	A A A M 4&'' 	F !DEEE =!! 	> !<=== t$$)) !DEEE  	I GI I I 	r   c                    g | _         | j        dz   }g }d}t          | j                  D ]\  }}t	                      }|                    |d         |z              |                    |d         |d         z   |z
             |                    ||d         z
  |z
             |                    ||d         z
  |d         z
  |z              ||_	        |d         |_
        |                    |           t	                      }|                    |d                    |                    |d         |d         z              |                    ||d         z
             |                    ||d         z
  |d         z
             ||_	        |d         |_
        | j                             |           |D ]Y}|D ]T}	|j	        |	j	        k    rB|                    |	          r-t          d                    |j
        |	j
                            UZd	}
g }g }t          | j                   D ]\  }}|                    |                                           |                    |                                           t#          |                                |                                z            }|
|z  }
|| j        |         d
<   |
t)          |          t)          |          z  k    rt          d          dS )z
        Check if the current layout added areas cover the entire rectangle.

        Rectangle given by the extreme points for the added areas.
        r%   g-C6?r"   col_spanr!   row_spanr$   z:Area with plugins {0} is overlapping area with plugins {1}r   r0   zpAreas are not covering the entire section!
Either an area is missing or col_span/row_span are not correctly set!N)r   r   	enumerater   r   setLeftsetRightsetTop	setBottomindexr$   r(   
intersectsr   r*   toprightabswidthheightmax)r   r@   area_float_rectsdeltar:   r0   rectfrectrect_1rect_2
total_areatopsrightss                r   r-   zBaseGridLayoutType._check_areau   s    a$T[11 	* 	*KE4 HHEMM$x.50111NN4>D,<<uDEEELL$u+-5666OOFT%[04
3CCeKLLLEK#L1E##E*** 88DLLh(((MM$x.4
+;;<<<KKe,---NN6DK/$z2BBCCCDJ"<0DO##D)))) ' 	J 	JF* J J<6<//((00 J,//5vf6G6<6G0I 0IJ J JJ 
$T%566 	. 	.KE4KK

###MM$**,,'''tzz||dkkmm344D$J)-DKv&&VSYY... %   /.r   c                      t          d          )z
        Return the layout localized name.

        Returns
        -------
        str
            Localized name of the layout.

        Notes
        -----
        This is a method to be able to update localization without a restart.
        z)A layout must define a `get_name` method!)NotImplementedError)r   s    r   r'   zBaseGridLayoutType.get_name   s     ""MNNNr   r%   FTc	                 R   | j         r|rt          d          | xj        |z  c_        t          || j                  | _        t          || j                  | _        || _         d| j        |<   d| j        |<   | j        	                    t          ||||||||                     dS )a	  
        Add a new area and `plugin_ids` that will populate it to the layout.

        The area will start at row, column spanning row_pan rows and
        column_span columns.

        Parameters
        ----------
        plugin_ids: list
            List of plugin ids that will be in the area
        row: int
            Initial row where the area starts
        column: int
            Initial column where the area starts
        row_span: int, optional
            Number of rows that the area covers
        col_span: int, optional
            Number of columns the area covers
        default: bool, optiona
            Defines an area as the default one, i.e all other plugins that where
            not passed in the `plugins_ids` will be added to the default area.
            By default is False.
        visible: bool, optional
            Defines if the area is visible when setting up the layout.
            Default is True.

        Notes
        -----
        See: https://doc.qt.io/qt-5/qgridlayout.html
        z,A default location has already been defined!r%   )r$   r!   r"   r4   r3   r   r    r#   N)r   r   r   rA   r   r   r   r   r   r(   dict)	r   r$   r!   r"   r4   r3   r   r    r#   s	            r   add_areazBaseGridLayoutType.add_area   s    N  	-7 	-  ", - - - 	J&dj))
,,
%()f%"#3%!!"3	 	 		
 	
 	
 	
 	
r   c                     || j         |<   dS )a  
        Set the factor of column to stretch.

        The stretch factor is relative to the other columns in this grid.
        Columns with a higher stretch factor take more of the available space.

        Parameters
        ----------
        column: int
            The column number. The first column is number 0.
        stretch: int
            Column stretch factor.

        Notes
        -----
        See: https://doc.qt.io/qt-5/qgridlayout.html
        N)r   )r   r"   stretchs      r   set_column_stretchz%BaseGridLayoutType.set_column_stretch  s    $ )0f%%%r   c                     || j         |<   dS )a  
        Set the factor of row to stretch.

        The stretch factor is relative to the other rows in this grid.
        Rows with a higher stretch factor take more of the available space.

        Parameters
        ----------
        row: int
            The row number. The first row is number 0.
        stretch: int
            Row stretch factor.

        Notes
        -----
        See: https://doc.qt.io/qt-5/qgridlayout.html
        N)r   )r   r!   rQ   s      r   set_row_stretchz"BaseGridLayoutType.set_row_stretch  s    $ #*3r   c           	      L   ddl m}  |            }t                      }t                      }| j        D ]}t                      }|                    d           |                    d                    |d                              |d         s|r1|	                    ||d         |d         |d	         |d
                    |d         r|
                    d           |d         s|
                    d           | j                                        D ]\  }}	|                    ||	           | j                                        D ]\  }
}	|                    |
|	           |                    |           |                                 |                                 dS )zI
        Show the layout with placeholder texts using a QWidget.
        r   )qapplicationT
r$   r    r!   r"   r4   r3   r   z+QPlainTextEdit {background-color: #ff0000;}z+QPlainTextEdit {background-color: #eeeeee;}N)spyder.utils.qthelpersrV   r   r   r   r   setReadOnlysetPlainTextjoin	addWidgetsetStyleSheetr   itemssetRowStretchr   setColumnStretch	setLayoutshowMaximizedexec_)r   show_hidden_areasrV   appwidgetlayoutr0   labelr!   rQ   cols              r   preview_layoutz!BaseGridLayoutType.preview_layout+  s    	877777lnnK 	C 	CD"$$Ed###tyyl);<<===I "3   KN$$   I C##AC C C 	? C##AC C C !.4466 	/ 	/LC  g.... 17799 	2 	2LC##C1111   		r   c           	        ! g }g }|D ]w}|                     |j                   |j        t          j        v r3|j                                        r|                     |j                   |                    d           xt          j        | j	                  !t          t          | j                  t          |          z            }!dxx         |z  cc<   !dxx         |z  cc<   !fd| j        D             }i }|D ]}	|	}
|
d         d         }|                    |d          }|r\|j        }|||
d         |
d         f<   |	d	         |_        |	d
         |_        |	d         |_        |                    |	d                    g }t$          j        }t)          d| j        dz             D ]}d}t)          d| j        dz             D ]l}||f}||v rb|	||         }n6|                     d||         j        z  ||||         |f           ||         }|                    t$          j        ||           mt$          j        }t)          d| j        dz             D ]h}d}t)          d| j        dz             D ]K}||f}||v rA|	||         }|                     d||         j        z  ||||         |f           ||         }Lit5          |d           }|D ]\  }	}}}}|                    |||            g }|D ]}	|	d         }|                    |	d         d         d          }|r|	d         dd         }|	d         }|D ]}|                    |d          }|rv||v r(t9          |d          r|                     ||f           G| j                            ||           ||vr|                    |           ||                    d           |	d         r2|j                                         |j                                          |D ]O\  }}| j        !                    |          s| j                            ||           |                    d           Pg }g }|"                                D ]e\  }}| j#        "                                D ]F\  }}|d         |k    r5|j        dk    r*|                     |           |                     |           Gfg }g }|"                                D ]e\  }}| j$        "                                D ]F\  }}|d         |k    r5|j        dk    r*|                     |           |                     |           Gf|%                                 |&                    ||t$          j                   |&                    ||t$          j                   |D ]}|                    |d          }|r|'                    d           |j                                         |j(        )                    d           |'                    d           |j        j*        } | r| +                    d           dS )z
        Set the given mainwindow layout.

        First validate the current layout definition, then clear the mainwindow
        current layout and finally calculate and set the new layout.
        Fr$   r#   c                 (    g | ]}|d          rn|S )r    ).0r0   patched_default_areas     r   
<listcomp>z=BaseGridLayoutType.set_main_window_layout.<locals>.<listcomp>x  s8     % % % %)O=  % % %r   r   )errorr!   r"   r0   r3   r4   r    r%   Nc                 "    | d         | d         fS )Nr   r%   rm   )xs    r   <lambda>z;BaseGridLayoutType.set_main_window_layout.<locals>.<lambda>  s    1qt r   )keyTABIFYT),r(   NAMEr	   external_plugins
dockwidget	isVisibletoggle_viewcopydeepcopyr   listr)   r   r   
get_pluginr0   r3   r4   r   
Horizontalranger   r   addDockWidgetLeftDockWidgetAreaVerticalsortedsplitDockWidgethasattrr   tabify_pluginsshowraise_tabify_pluginr^   r   r   rb   resizeDocksblockSignalstoggle_view_action
setCheckeddock_tabbarsetCurrentIndex)"r   main_windowdockable_pluginsall_plugin_idsexternal_plugins_to_showr   unassgined_plugin_idspatched_areasdocksr0   current_area	plugin_iddocklayout_data	directionr!   ri   ru   sorted_datafirstsecondplugins_to_tabifyarea_visiblebase_pluginr$   r#   current_plugincolumn_dockscolumn_stretchesrQ   	row_docksrow_stretchesr   ro   s"                                    @r   set_main_window_layoutz)BaseGridLayoutType.set_main_window_layoutT  s     $&  ' 
	& 
	&F!!&+... ???%//11 @ )//<<<u%%%%
  $}T-?@@ $ !!C$7$77!9 !9\***.CC***01115JJ111% % % %% % %
 ! 
	4 
	4DL$\215I ++IU+CCF 4(GK|E*L,BCD L	 $Z 0 $Z 0""4	?333  M	DJN++ 	@ 	@CDQ
Q// @ @Cj%<<|$Sz#**uSz. !"3Z&	() ) )  %Sz---tY@ @ @@$ K	DJN++ 	* 	*CDQ
Q// * *Cj%<<|$Sz#**uSz. !"3Z&	() ) )  %Sz*  [.D.DEEE3> 	B 	B/D#ufi''vyAAAA! 	4 	4D	?L%00\"1%U 1 4 4K 4!,/3
$()<$=!!+ B BI%0%;%;! &< &0 &0N% B%)>>> ' A A ?-44!/ =? ? ? ? !K66 +^= = =(0AAA . : :< H H H H . : :5 A A A 	? 4*//111*11333 $5 	. 	.FK;,,V44 @**;???&&u---- 	5 	5IC $ 5 ; ; = = 5 5Wq6S==T]a%7%7 ''---$++G4445
 	 	2 	2IC $ 2 8 8 : : 2 2Wq6S==T]a%7%7$$T***!((1112
 	!!###.>NNN	="+FFF 2 	3 	3I ++IU+CCF 3##D)))!&&((()44T:::##E*** %/; 3//222	3 	3r   )F)__name__
__module____qualname____doc__r&   r   r1   r-   r'   rO   rR   rT   rj   r   rm   r   r   r   r      s        	 	 
B2  = = =~; ; ;~O O O* #%<
 <
 <
 <
|0 0 0(* * *(' ' ' 'Rm3 m3 m3 m3 m3r   r   )r   r|   qtpy.QtCorer   r   qtpy.QtWidgetsr   r   r   spyder.api.exceptionsr   'spyder.api.plugin_registration.registryr	   spyder.api.translationsr
   r   rm   r   r   <module>r      s    
  # " " " " " " " ? ? ? ? ? ? ? ? ? ? 1 0 0 0 0 0 C C C C C C % % % % % %i3 i3 i3 i3 i3 i3 i3 i3 i3 i3r   