
    e6                         d dl Z ddlmZ ddlmZmZmZmZ ddlmZ ddlmZ  G d d	eej                        Z
 G d
 dej                        Zy)    N   )	QtWidgets   )	Container
HContainer
TContainer
VContainer)Dock)DockDropc                       e Zd ZddZd ZddZd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zd Zd Zd Z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#dZd$dZy)%DockAreaNc                 @   t        j                  | |        t        j                  j                  | |       t	        |       | _        | j
                  j                  d       t        j                         | _        | j                  j                  dddd       | j                  j                  d       | j                  | j                         t        j                         | _        d | _        | j
                  j!                          || _        g | _        || _        y )N)parentcenterr   )r   __init__r   QWidgetr   dockdropremoveAllowedAreaQVBoxLayoutlayoutsetContentsMargins
setSpacing	setLayoutweakrefWeakValueDictionarydockstopContainerraiseOverlay	temporary	tempAreashome)selfr   r   r!   s       =/usr/lib/python3/dist-packages/pyqtgraph/dockarea/DockArea.pyr   zDockArea.__init__
   s    4&""4"7 ''1++-&&q1Q/q!t{{#002
 ""$"	    c                      y)Ntop r"   s    r#   typezDockArea.type   s    r$   c                    |t        d	i |}| j                  s| |_        ||| u r | j                  | }d}nQ| j                  }d}nBt	        |t
              r| j                  |   }| j                  |      }|t        d|z        |}ddddddd|   }||j                         k7  r%|j                         dk(  r|}|j                         }||j                         k7  r1|| j                  || j                        }n| j                  ||      }ddddddd|   }|j                         }	|j                  |||       || j                  |j                         <   |	|	j                          |S )
a^  Adds a dock to this area.
        
        ============== =================================================================
        **Arguments:**
        dock           The new Dock object to add. If None, then a new Dock will be 
                       created.
        position       'bottom', 'top', 'left', 'right', 'above', or 'below'
        relativeTo     If relativeTo is None, then the new Dock is added to fill an 
                       entire edge of the window. If relativeTo is another Dock, then 
                       the new Dock is placed adjacent to it (or in a tabbed 
                       configuration for 'above' and 'below'). 
        ============== =================================================================
        
        All extra keyword arguments are passed to Dock.__init__() if *dock* is
        None.        
        NzODock %s is not contained in a DockArea; cannot add another dock relative to it.vertical
horizontaltab)bottomr&   leftrightabovebelowafterbeforer'   )r
   r   	orig_arear   
isinstancestrr   getContainer	TypeErrorr)   	containeraddContainerinsertnameapoptose)
r"   dockposition
relativeTokwdsr:   neighborneededContainer	insertPosolds
             r#   addDockzDockArea.addDock   s   " <<$<D ~~!DN
 t!3  ( 	 --	*c*!ZZ
3
))*5I  qt~ ~!H ! !
  inn..9>>3Cu3L H!++-I inn.. --ot?P?PQ	 --oxH	 
 	 nny(3"&

499;?LLNr$   c                     |dv rC|A|j                         1|j                         j                         dk(  r|j                         }| j                  |||       y)z;
        Move an existing Dock to a new location. 
        )r/   r0   r&   r.   Nr-   )r:   r)   rG   )r"   r?   r@   rC   s       r#   moveDockzDockArea.moveDockp   s~    
 99h>RW_WiWiWkWw  }E  }O  }O  }Q  }V  }V  }X  \a  }a))+HT8X.r$   c                 *    || S |j                         S N)r:   )r"   objs     r#   r8   zDockArea.getContainery   s    ;K}}r$   c                     |dk(  rt        |       }|S |dk(  rt        |       }|S |dk(  rt        |       }|S t        d      )Nr+   r,   r-   z5typ must be one of 'vertical', 'horizontal', or 'tab')r	   r   r   
ValueError)r"   typnews      r#   makeContainerzDockArea.makeContainer~   s^    *T"C 
 L T"C
 
	 E\T"C 
 TUUr$   c                     | j                  |      }| j                  |      }|j                  |d|       ||j                  |       | j                  j	                          |S )zAdd a new container around objr4   )rQ   r8   r<   r   r   )r"   rO   rL   rP   r:   s        r#   r;   zDockArea.addContainer   sY      %%%c*	h,?JJsO""$
r$   c                     | j                   | j                   j                  d        | j                  j                  |       |j                  |        || _         | j                  j                          y rK   )r   containerChangedr   	addWidgetr   r   )r"   rP   posrC   s       r#   r<   zDockArea.insert   s\    ( ..t4c"T"""$r$   c                     | j                   yy)Nr   r   )r   r(   s    r#   countzDockArea.count   s    $r$   c                 V    | j                   j                  | j                                y rK   )r   resizeOverlaysize)r"   evs     r#   resizeEventzDockArea.resizeEvent   s    ##DIIK0r$   c                     | j                   Lt        d|       }| j                  j                  |       t	        |      }||_        |j                          |S | j                   j                         }|S )NT)r   r!   )r!   r   r    appendTempAreaWindowwinshowaddTempArea)r"   areara   s      r#   rc   zDockArea.addTempArea   sd    99d6DNN!!$' &CDHHHJ  99((*Dr$   c                     | j                         }|j                  j                  |j                                |j	                  |dd       y)z@Removes *dock* from this DockArea and places it in a new window.r&   N)rc   ra   resizer[   rI   )r"   r?   rd   s      r#   	floatDockzDockArea.floatDock   s6    !		$dE4(r$   c                 v    | j                   j                  |       |j                         j                          y rK   )r    removewindowclose)r"   rd   s     r#   removeTempAreazDockArea.removeTempArea   s&    d#r$   c                 ~   | j                   d}n| j                  | j                         }|g d}| j                  D ]~  }|j                  j	                         }|j                         |j                         |j                         |j                         f}|d   j                  |j                         |f        |S )zj
        Return a serialized (storable) representation of the state of
        all Docks in this DockArea.N)mainfloatro   )r   
childStater    ra   geometryxywidthheightr_   	saveState)r"   rn   stateageos        r#   rv   zDockArea.saveState   s    
 $D??4#4#45D+ 	8A%%.."C557CEEGSYY[#**,?C'N!!1;;=#"67	8 r$   c                 (   t        |t              rd|j                         i fS g }t        |j	                               D ]1  }|j                  | j                  |j                  |                   3 |j                         ||j                         fS )Nr?   )
r6   r
   r=   rangerX   r_   rp   widgetr)   rv   )r"   rL   childsis       r#   rp   zDockArea.childState   st    c4 CHHJ++F399;' >doocjjm<=>HHJ88r$   c                 @   | j                         \  }}| j                  dd }|d   | j                  |d   || |       |d   D ]Y  }| j                         }|j                  |d   d   |||        |j                  j
                  |d     |j                          [ |j                         D ]=  }	|dk(  r#| j                         }|j                  |	d       +| j                  |	|d       ? |D ]  }
|
j                           |D ]  }|j                           y)a}  
        Restore Dock configuration as generated by saveState.
        
        This function does not create any Docks--it will only 
        restore the arrangement of an existing set of Docks.
        
        By default, docks that are described in *state* but do not exist
        in the dock area will cause an exception to be raised. This behavior
        can be changed by setting *missing* to 'ignore' or 'create'.
        
        Extra docks that are in the dockarea but that are not mentioned in
        *state* will be added to the bottom of the dockarea, unless otherwise
        specified by the *extra* argument.
        Nrn   missingro   r   r   r2   )findAllr    buildFromStaterc   ra   setGeometryr>   valuesrG   rI   rk   )r"   rw   r   extra
containersr   oldTempssrx   dcs              r#   restoreStatezDockArea.restoreState   s)   " !LLN
E>>!$ =$fudGL w 	A  "AQqT&\5!WEAEEqt$JJL		  	.A$$&		!W%a-	.  	AGGI	 	AJJL	r$   c                    |\  }}}|dk(  r
	 ||   }||= n| j	                  |      }|j                  |d       |dk7  rD|D ]  }	| j                  |	|||d	z   |
        |j                  d       |j                  |       y y # t         $ r: |dk(  rt        d|z        |dk(  rt        |      }n|dk(  rY y t        d      Y w xY w)Nr?   errorz1Cannot restore dock state; no dock with name "%s"creater=   ignorezA"missing" argument must be one of "error", "create", or "ignore".r3   r   r   F)	propagate)	KeyError	Exceptionr
   rN   rQ   r<   r   r>   r   )
r"   rw   r   rootdepthr   rO   contentsrL   os
             r#   r   zDockArea.buildFromState  s    $Xu&=jHo(O $$S)CC!&= M##Auc57G#LM LL5L)U#   jg%#$WZb$bcc(H-C($%hii	 	js   B 3C8CCc                    || j                   }|Jg }i }| j                  D ]7  }|j                         \  }}|j                  |       |j	                  |       9 t        |t              r|||j                         <   ||fS |v|j                  |       t        |j                               D ]I  }|j                  |      }| j                  |      \  }	}
|j                  |	       |j	                  |
       K ||fS rK   )r   r    r   extendupdater6   r
   r=   r_   r{   rX   r|   )r"   rL   r   r   rx   c1d1r~   o2c2d2s              r#   r   zDockArea.findAll$  s    ;##C 9AA^^ B
 c4 AchhjM 1v _HHSM399;' ZZ]b)B	
 1vr$   c                     | j                   | j                   j                         dk(  r=d | _         | j                  r)| j                  | j                  j	                  |        y y y y Nr   )r   rX   r   r!   rl   )r"   r   s     r#   r>   zDockArea.apoptose<  s]     $(9(9(?(?(AQ(F $D~~$))"7		((. #8~ )Gr$   c                 t    | j                         d   }|j                         D ]  }|j                           y )Nr   )r   r   rk   )r"   r   r?   s      r#   clearzDockArea.clearE  s0    q!LLN 	DJJL	r$   c                 6     | j                   j                  |  y rK   )r   dragEnterEventr"   argss     r#   r   zDockArea.dragEnterEventJ      $$$d+r$   c                 6     | j                   j                  |  y rK   )r   dragMoveEventr   s     r#   r   zDockArea.dragMoveEventM  s    ###T*r$   c                 6     | j                   j                  |  y rK   )r   dragLeaveEventr   s     r#   r   zDockArea.dragLeaveEventP  r   r$   c                 6     | j                   j                  |  y rK   )r   	dropEventr   s     r#   r   zDockArea.dropEventS  s    &r$   c                     || j                         }t        d|z         |d   t        d       n| j                  |d          t        |d         D ]  \  }}| j	                  |d   d|z           y )Nz=== %s dock area ===rn   z
   (empty)ro   r   zfloat %dr   )rv   print_printAreaState	enumerate
printState)r"   rw   r=   r~   ro   s        r#   r   zDockArea.printStateV  sy    =NN$E$t+,= ,  v/!%.1 	;HAuOOE!H:>O:	;r$   c                     |d   dk(  r't        d|z  |d   z   dz   t        |dd        z          y t        d|z  |d   z          |d   D ]  }| j                  ||dz           y )Nr   r?   z   r   )r   r7   r   )r"   rd   indentchs       r#   r   zDockArea._printAreaStateb  sv    7f$-$q')C/#d12h-?@$-$q')*1g 3$$R23r$   )NFN)Nr.   N)NN)r   r.   )r   r   )NNN)T)NMain)r   )__name__
__module____qualname__r   r)   rG   rI   r8   rQ   r;   r<   rX   r]   rc   rg   rl   rv   rp   r   r   r   r>   r   r   r   r   r   r   r   r'   r$   r#   r   r   	   s     Qf/
	
%
1
)
"9-^$:0/
,+,'
;3r$   r   c                   $     e Zd Zd Z fdZ xZS )r`   c                 ,   t        j                  j                  | fi | t        j                         | _        | j                  | j                         | j                  j                  dddd       || _        | j                  j                  |       y r   )	r   r   r   QGridLayoutr   r   r   dockarearU   )r"   rd   kwargss      r#   r   zTempAreaWindow.__init__n  sl    ""4262++-t{{#&&q!Q2d#r$   c                    | j                   j                         d   }|j                         D ]*  }t        |d      s|j                  j                  |       , | j                   j                          t        |    |  y )Nr   r5   )	r   r   r   hasattrr5   rG   r   super
closeEvent)r"   r   r   r?   	__class__s       r#   r   zTempAreaWindow.closeEventv  sj    %%'*LLN 	/Dt[)&&t.	/ 	D!r$   )r   r   r   r   r   __classcell__)r   s   @r#   r`   r`   m  s    $" "r$   r`   )r   Qtr   r   r   r   r	   r
   r   r   r   r`   r'   r$   r#   <module>r      s@      D D  `3y)++ `3H"Y&& "r$   