
    e                     r   d Z ddlZddlmZmZmZ  ej                  d      Zej                  d       ej                         Zej                  j                  d      Zej                  j                  d      Zd	 Zej"                  j%                  e       d
 Zej"                  j%                  e        G d dej(                        Z ed      Zej/                  e        ed      Zej3                  e       ej5                  dd       ej7                  d       edk(  r ej:                          yy)a  
Demonstrates adding a custom context menu to a GraphicsItem
and extending the context menu of a ViewBox.

PyQtGraph implements a system that allows each item in a scene to implement its 
own context menu, and for the menus of its parent items to be automatically 
displayed as well. 

    N)QtCoreQtGui	QtWidgetsT)showzpyqtgraph example: context menuzZoom to box 1zZoom to box 2c                  :    t         j                  t        g       y N)items)view	autoRangebox1     @/usr/lib/python3/dist-packages/pyqtgraph/examples/contextMenu.pyzoomTo1r          NN$N r   c                  :    t         j                  t        g       y r   )r
   r   box2r   r   r   zoomTo2r      r   r   c                   H    e Zd ZdZd Zd Zd Zd Zd ZddZ	d	 Z
d
 Zd Zy)MenuBoxz
    This class draws a rectangular area. Right-clicking inside the area will
    raise a custom context menu which also includes the context menus of
    its parents.    
    c                     || _         t        j                  d      | _        d | _        t        j
                  j                  |        y )Nr)namepgmkPenpenmenuGraphicsObject__init__)selfr   s     r   r   zMenuBox.__init__,   s7    	88C= 	 	""4(r   c                 2    t        j                  dddd      S )Nr   
   )r   QRectFr    s    r   boundingRectzMenuBox.boundingRect:   s    }}Q2r**r   c                 x    |j                  | j                         |j                  | j                                y N)setPenr   drawRectr%   )r    pargss      r   paintzMenuBox.paint=   s'    		

4$$&'r   c                     |j                         t        j                  j                  j                  k(  r#| j                  |      r|j                          y y y r'   )buttonr   QtMouseButtonRightButtonraiseContextMenuaccept)r    evs     r   mouseClickEventzMenuBox.mouseClickEventC   sA    99;&))//;;;$$R(		 ) <r   c           	      ,   | j                         }| j                         j                  | ||      }|j                         }|j	                  t        j                  t        |j                               t        |j                                            y)NT)
getContextMenussceneaddParentContextMenus	screenPospopupr   QPointintxy)r    r4   r   poss       r   r2   zMenuBox.raiseContextMenuH   se    ##% zz|11$bAlln

6==SUUWs3557|<=r   Nc                 p   | j                   t        j                         | _         | j                   j                  | j                  dz          t        j                  d| j                         }|j                  j                  | j                         | j                   j                  |       || j                   _        t        j                  d| j                         }|j                  j                  | j                         | j                   j                  |       || j                   _        t        j                  | j                         }t        j                         }|j                  t         j"                  j$                  j&                         |j)                  d       |j+                  d       |j,                  j                  | j.                         |j1                  |       | j                   j                  |       || j                   _        || j                   _        | j                   S )Nz
 options..z
Turn greenz	Turn blue   )r   r   QMenusetTitler   r   QAction	triggeredconnectsetGreen	addActiongreensetBlueQWidgetActionQSlidersetOrientationr   r/   Orientation
Horizontal
setMaximumsetValuevalueChangedsetAlphasetDefaultWidgetalphaalphaSlider)r    eventrJ   bluerV   rW   s         r   r7   zMenuBox.getContextMenusU   sx   99!)DIIItyy,67MM,		:EOO##DMM2II&#DIIO==dii8DNN""4<<0II%"DIIO++DII6E#++-K&&vyy'<'<'G'GH""3'  %$$,,T]];"";/II&#DIIO$/DII!yyr   c                 X    t        j                  d      | _        | j                          y )Ngr   r   r   updater$   s    r   rH   zMenuBox.setGreenq   s    88C=r   c                 X    t        j                  d      | _        | j                          y )Nbr\   r$   s    r   rK   zMenuBox.setBluev   s    88C=r   c                 ,    | j                  |dz         y )Ng     o@)
setOpacity)r    as     r   rT   zMenuBox.setAlphaz   s    $r   r'   )__name__
__module____qualname____doc__r   r%   r,   r5   r2   r7   rH   rK   rT   r   r   r   r   r   &   s4    

)+(
	8
 r   r   zMenu Box #1zMenu Box #2   g?__main__)rf   	pyqtgraphr   pyqtgraph.Qtr   r   r   GraphicsLayoutWidgetwinsetWindowTitle
addViewBoxr
   r   rI   zoom1zoom2r   rF   rG   r   r   r   r   addItemr   setParentItemsetPossetScalerc   execr   r   r   <module>rv      s    1 1b4(   4 5 ~~ 			O,		O,!     !     U b U r } T  }   4  Aq  c zBGGI r   