
    e                     h    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gZ	 G d	 de      Z
y
)   )	functions)	QtWidgets   )GraphicsWidget)	LabelItem)PlotItem)ViewBoxGraphicsLayoutc                       e Zd ZdZddZd Zd Zd Zd ZddZ	dd	Z
dd
ZddZddZd Zd Zd Zd Zd Zd Zd Zd Zy)r
   z
    Used for laying out GraphicsWidgets in a grid.
    This is usually created automatically as part of a :class:`GraphicsLayoutWidget <pyqtgraph.GraphicsLayoutWidget>`.
    Nc                    t        j                  | |       |du rd}n|du rd }|| _        t        j                         | _        | j                  | j
                         i | _        i | _        i | _	        d| _
        d| _        | j                  t        j                  t        j                  j                  j                  t        j                  j                  j                               y )NT)d   r   r   F    )r   __init__borderr   QGraphicsGridLayoutlayout	setLayoutitemsrowsitemBorders
currentRow
currentColsetSizePolicyQSizePolicyPolicy	Expanding)selfparentr   s      H/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/GraphicsLayout.pyr   zGraphicsLayout.__init__   s    f-T>"Fu_F335t{{#
	9001F1F1M1M1W1WYbYnYnYuYuYY  A  	B    c                     t        j                  |i || _        | j                  j	                         D ]  }|j                  | j                          y)z
        Set the pen used to draw border between cells.
        
        See :func:`mkPen <pyqtgraph.mkPen>` for arguments.        
        N)fnmkPenr   r   valuessetPen)r   argskwds
borderRects       r   	setBorderzGraphicsLayout.setBorder&   sI     hh--**113 	+Jdkk*	+r    c                 \    | xj                   dz  c_         d| _        | j                          y)z0Advance to next row for automatic item placementr   N)r   r   
nextColumnr   s    r   nextRowzGraphicsLayout.nextRow1   s!    1r    c                     | xj                   dz  c_         | j                  | j                  | j                         =| xj                   dz  c_         | j                  | j                  | j                         <yy)z]Advance to next available column
        (generally only for internal use--called by addItem)r   N)r   getItemr   r-   s    r   r,   zGraphicsLayout.nextColumn7   sT     	1ll4??DOO<HOOq O ll4??DOO<Hr    c                 &     | j                   |i |S )zAlias of nextColumn)r,   )r   r&   kargss      r   nextColzGraphicsLayout.nextCol>   s    t...r    c                 F    t        di |}| j                  |||||       |S )z
        Create a PlotItem and place it in the next available cell (or in the cell specified)
        All extra keyword arguments are passed to :func:`PlotItem.__init__ <pyqtgraph.PlotItem.__init__>`
        Returns the created item.
         )r   addItem)r   rowcolrowspancolspanr2   plots          r   addPlotzGraphicsLayout.addPlotB   s*      % T3Wg6r    c                 F    t        di |}| j                  |||||       |S )z
        Create a ViewBox and place it in the next available cell (or in the cell specified)
        All extra keyword arguments are passed to :func:`ViewBox.__init__ <pyqtgraph.ViewBox.__init__>`
        Returns the created item.
        r5   )r	   r6   )r   r7   r8   r9   r:   r2   vbs          r   
addViewBoxzGraphicsLayout.addViewBoxL   s*     uRc7G4	r    c                 H    t        |fi |}| j                  |||||       |S )aA  
        Create a LabelItem with *text* and place it in the next available cell (or in the cell specified)
        All extra keyword arguments are passed to :func:`LabelItem.__init__ <pyqtgraph.LabelItem.__init__>`
        Returns the created item.
        
        To create a vertical label, use *angle* = -90.
        )r   r6   )r   textr7   r8   r9   r:   r2   s          r   addLabelzGraphicsLayout.addLabelV   s,     ''T3Wg6r    c                 F    t        di |}| j                  |||||       |S )a  
        Create an empty GraphicsLayout and place it in the next available cell (or in the cell specified)
        All extra keyword arguments are passed to :func:`GraphicsLayout.__init__ <pyqtgraph.GraphicsLayout.__init__>`
        Returns the created item.
        r5   )r
   r6   )r   r7   r8   r9   r:   r2   r   s          r   	addLayoutzGraphicsLayout.addLayoutb   s*      (%(VS#w8r    c                    || j                   }|| j                  }g | j                  |<   t        |      D ]k  }t        |      D ][  }||z   }||z   }	|| j                  vri | j                  |<   || j                  |   |	<   | j                  |   j                  ||	f       ] m t        j                         }
|
j                  |        |
j                  d       |
j                  t        j                  | j                               |
| j                  |<   |j                  j!                  | j"                         | j$                  j'                  |||||       | j$                  j)                          | j+                          y)z
        Add an item to the layout and place it in the next available cell (or in the cell specified).
        The item must be an instance of a QGraphicsWidget subclass.
        Ng     @@)r   r   r   ranger   appendr   QGraphicsRectItemsetParentItem	setZValuer%   r"   r#   r   r   geometryChangedconnect_updateItemBorderr   r6   activater,   )r   itemr7   r8   r9   r:   ijrow2col2r(   s              r   r6   zGraphicsLayout.addIteml   sS   
 ;//C;//C

4w 	6A7^ 6QwQwtyy(&(DIIdO(,		$%

4 ''t56	6 002
  &S!"((4;;/0!+$$T%;%;<D#sGW= 	r    c                 Z    | j                   j                  |i       j                  |d      S )zEReturn the item in (*row*, *col*). If the cell is empty, return None.N)r   get)r   r7   r8   s      r   r0   zGraphicsLayout.getItem   s$    yy}}S"%))#t44r    c                 "    | j                         S N)rectr-   s    r   boundingRectzGraphicsLayout.boundingRect   s    yy{r    c                     t        | j                  j                               D ]1  }| j                  j                  |      j	                         |u s/|c S  t        d|       )a  Return the numerical index of GraphicsItem object passed in

        Parameters
        ----------
        item : QGraphicsLayoutItem
            Item to query the index position of

        Returns
        -------
        int
            Index of the item within the graphics layout

        Raises
        ------
        ValueError
            Raised if item could not be found inside the GraphicsLayout instance.
        z"Could not determine index of item )rF   r   countitemAtgraphicsItem
ValueError)r   rO   rP   s      r   	itemIndexzGraphicsLayout.itemIndex   s_    $ t{{((*+ 	A{{!!!$113t;	 =dVDEEr    c                    | j                  |      }| j                  j                  |       | j                         j	                  |       | j
                  |   D ]  \  }}| j                  |   |=  | j
                  |= |j                  j                  | j                         | j                  j                  |      }| j                         j	                  |       | j                          y)zRemove *item* from the layout.N)r_   r   removeAtscene
removeItemr   r   rK   
disconnectrM   r   popupdate)r   rO   indrc
itemBorders         r   rc   zGraphicsLayout.removeItem   s    nnT"S!

%JJt$ 	 DAq		!Q	 JJt''(>(>?%%))$/



+r    c                     t        | j                  j                               D ]  }| j                  |        d| _        d| _        y)zQRemove all items from the layout and set the current row and column to 0
        r   N)listr   keysrc   r   r   )r   rP   s     r   clearzGraphicsLayout.clear   s=     djjoo'( 	AOOA	r    c                 6     | j                   j                  |  y rW   )r   setContentsMarginsr   r&   s     r   rp   z!GraphicsLayout.setContentsMargins   s     	'&&-r    c                 6     | j                   j                  |  y rW   )r   
setSpacingrq   s     r   rs   zGraphicsLayout.setSpacing   s    %r    c                     | j                   y | j                         }|y |j                  |j                               }| j                  |   j                  |       y rW   )r   sendermapRectToParentrY   r   setRect)r   rO   rh   s      r   rM   z GraphicsLayout._updateItemBorder   sT    ;;{{}<  !2!2!45&&q)r    )NN)NNr   r   ) NNr   r   )__name__
__module____qualname____doc__r   r)   r.   r,   r3   r<   r?   rB   rD   r6   r0   rY   r_   rc   rn   rp   rs   rM   r5   r    r   r
   r
      sd    
B*	+!/
"H5F. .&	*r    N) r   r"   Qtr   r   r   r   r	   __all__r
   r5   r    r   <module>r      s/      *    
M*^ M*r    