
    e;%                     p    d Z ddlZddlZddlmZmZ dgZd Zd Zd Z	d	 Z
 G d
 dej                        Zy)a  
WidgetGroup.py -  WidgetGroup class for easily managing lots of Qt widgets
Copyright 2010  Luke Campagnola
Distributed under MIT/X11 license. See license.txt for more information.

This class addresses the problem of having to save and restore the state
of a large group of widgets. 
    N   )QtCore	QtWidgetsWidgetGroupc                 z    | j                         j                         j                         j                         }|S N)	saveStatetoPercentEncodingdatadecode)wss     7/usr/lib/python3/dist-packages/pyqtgraph/WidgetGroup.pysplitterStater      s-    	'')..0779AH    c                    t        |      t        u r| j                  |       nct        |      t        u r=| j	                  t
        j                  j                  |j                                      nt        dt        |             | j                         dkD  r@| j                         D ]	  }|dkD  s	 y  | j                  dg| j                         z         y y )Nz.Can't configure QSplitter using object of typer   2   )typelistsetSizesstrrestoreStater   
QByteArrayfromPercentEncodingencodeprintcountsizes)r   r   is      r   restoreSplitterr       s    Aw$	

1	aC	v((<<QXXZHI>QHwwy1} 	A1u	 	


B4!'')#$	 r   c                     | j                         }| j                  |      }|'	 |j                         sd }n|j                         d   }|t        | j                  |            S |S # t        $ r Y )w xY w)Nr   )currentIndexitemDataisValidtoIntAttributeErrorr   itemText)r   indr   s      r   
comboStater)   "   sv    
..
C::c?D	<<>zz|A |1::c?##  		s   &A) )	A54A5c                     t        |      t        u r(| j                  |      }|dkD  r| j                  |       y | j                  | j	                  t        |                   y )N)r   intfindDatasetCurrentIndexfindTextr   )r   vr(   s      r   setComboStater1   2   sM    Aw#~jjm8c"ajjQ()r   c                      e Zd ZdZej
                  d ej
                  j                  ej
                  j                  fej                  d ej                  j                  ej                  j                  fej                  de
edfej                  d ej                  j                  ej                  j                  fej                  d eefej$                  d ej$                  j                  ej$                  j                  dfej&                  d	 d
 ej&                  j(                  fej*                  d ej*                  j                  ej*                  j                  fej,                  d ej,                  j                  ej,                  j                  fi	Z ej2                  ee      ZddZddZd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)y)r   aF  State manager for groups of widgets.

    WidgetGroup handles common problems that arise when dealing with groups of widgets like a control
    panel:
    - Provide a single place for saving / restoring the state of all widgets in the group
    - Provide a single signal for detecting when any of the widgets have changed
    c                     | j                   S r   valueChangedr   s    r   <lambda>zWidgetGroup.<lambda>M   
    ann r   c                     | j                   S r   r4   r6   s    r   r7   zWidgetGroup.<lambda>R   r8   r   NTc                     | j                   S r   )stateChangedr6   s    r   r7   zWidgetGroup.<lambda>]   r8   r   c                     | j                   S r   )currentIndexChangedr6   s    r   r7   zWidgetGroup.<lambda>b   s    a++ r   c                     | j                   S r   toggledr6   s    r   r7   zWidgetGroup.<lambda>g   
    aii r   c                     | j                   S r   )editingFinishedr6   s    r   r7   zWidgetGroup.<lambda>m   s    a'' r   c                 4    t        | j                               S r   )r   textr6   s    r   r7   zWidgetGroup.<lambda>n   s    c!&&(m r   c                     | j                   S r   r?   r6   s    r   r7   zWidgetGroup.<lambda>r   rA   r   c                     | j                   S r   r4   r6   s    r   r7   zWidgetGroup.<lambda>w   r8   r   c                 4   t         j                  j                  |        t        j                         | _        t        j                         | _        i | _        t        j                         | _        t        |t         j                        r| j                  |       yt        |t              r|D ]  } | j                  |   yt        |t              r+|j                         D ]  \  }}| j                  ||        y|yt        dt!        |      z        )a%  Initialize WidgetGroup, adding specified widgets into this group.
        widgetList can be: 
         - a list of widget specifications (widget, [name], [scale])
         - a dict of name: widget pairs
         - any QObject, and all compatible child widgets will be added recursively.
        
        The 'scale' parameter for each widget allows QSpinBox to display a different value than the value recorded
        in the group state (for example, the program may set a spin box value to 100e-6 and have it displayed as 100 to the user)
        NzWrong argument type %s)r   QObject__init__weakrefWeakKeyDictionary
widgetListscalescacheuncachedWidgets
isinstanceautoAddr   	addWidgetdictitems	Exceptionr   )selfrM   r   names       r   rJ   zWidgetGroup.__init__   s     	%!335//1
&88:j&..1LL$
D) #"#
D)%++- (aq$'(4tJ7GGHHr   c                 z   | j                  |      st        dt        |      z        |t        |j	                               }|dk(  rt        dt        |      z        || j
                  |<   || j                  |<   | j                  |       t        |      t        j                  v r t        j                  t        |         d   }n|j                         d   }|Nt        j                  |      st        j                  |      r ||      }|j                  | j                         y d | j                   |<   y )Nz+Widget type %s not supported by WidgetGroup z&Cannot add widget '%s' without a name.r   )acceptsTyperV   r   r   
objectNamerM   rN   
readWidgetr   classeswidgetGroupInterfaceinspect
isfunctionismethodconnectwidgetChangedrP   )rW   r   rX   scalesignals        r   rS   zWidgetGroup.addWidget   s   "IDQRGSTT<q||~&D2:Ds1vMNN!A7k))) ((a1!4F++-a0F!!&)W-=-=f-ENN4--.&*D  #r   c                 R    | j                   D ]  }| j                   |   |k(  s|c S  y r   )rM   )rW   rX   r   s      r   
findWidgetzWidgetGroup.findWidget   s0     	Aq!T)	 r   c                     t        |      }|t        j                  v rt        j                  |   S |j                         S r   )r   r   r^   r_   )rW   objts      r   	interfacezWidgetGroup.interface   s9    I###&&q))++--r   c                 N    | j                  |      }t        |      dkD  xr |d   S )zSReturn true if we should automatically search the children of this object for more.   )rl   len)rW   rj   ifaces      r   checkForChildrenzWidgetGroup.checkForChildren   s'    s#E
Q+58,r   c                     | j                  |      }|r| j                  |       |r| j                  |      r'|j                         D ]  }| j	                  |        y y r   )r[   rS   rq   childrenrR   )rW   rj   acceptedcs       r   rR   zWidgetGroup.autoAdd   sV    ##C(NN34005\\^  Q  6r   c                 d    t         j                  D ]  }t        ||      s y t        |d      ryy)NTr_   F)r   r^   rQ   hasattr)rW   rj   ru   s      r   r[   zWidgetGroup.acceptsType   s7    $$ 	A#q!	 3./r   c                 h    | j                  |      }|| j                  |<   | j                  ||       y r   )r]   rN   	setWidget)rW   widgetre   vals       r   setScalezWidgetGroup.setScale   s,    oof%#Fvs#r   c                     | j                         }| j                  |   }| j                  |   }| j                  |      }||k7  r*| j                  j                  | j                  |   |       y y r   )senderrM   rO   r]   
sigChangedemit)rW   argsr   nv1v2s         r   rd   zWidgetGroup.widgetChanged   s_    KKMOOAZZ]__Q8OO  !3R8 r   c                 z    | j                   D ]  }| j                  |        | j                  j                         S r   )rP   r]   rO   copy)rW   r   s     r   statezWidgetGroup.state   s4    %% 	AOOA	zz  r   c                 x    | j                   D ]+  }| j                   |   }||vr| j                  |||          - y r   )rM   ry   )rW   r   r   r   s       r   setStatezWidgetGroup.setState   s?     	$A"AzNN1ad#		$r   c                    t        |      t        j                  v r t        j                  t        |         d   }n|j                         d   }|y t	        j
                  |      r|j                   |       }n ||      }| j                  |   || j                  |   z  }| j                  |   }|| j                  |<   |S )Nr   )
r   r   r^   r_   r`   rb   __self__rN   rM   rO   )rW   r   getFuncr{   r   s        r   r]   zWidgetGroup.readWidget   s    7k)))!))$q'215G,,.q1G?
 G$)9)9)E)C!*C;;q>%4;;q>!COOA

1
r   c                 H   | j                   |   || j                   |   z  }t        |      t        j                  v r t        j                  t        |         d   }n|j	                         d   }t        j                  |      r|j                  	 ||       y  |||       y )N   )rN   r   r   r^   r_   r`   rb   r   )rW   r   r0   setFuncs       r   ry   zWidgetGroup.setWidget  s    ;;q>%QA7k)))!))$q'215G,,.q1G
 G$)9)9)EAJAqMr   r   )NN)*__name__
__module____qualname____doc__r   QSpinBoxvaluesetValueQDoubleSpinBox	QSplitterr   r    	QCheckBox	isChecked
setChecked	QComboBoxr)   r1   	QGroupBox	QLineEditsetTextQRadioButtonQSliderr^   r   Signalr   objectr   rJ   rS   rh   rl   rq   rR   r[   r|   rd   r   r   r]   ry    r   r   r   r   ;   s     	$$$''

 	  $$$**$$--#

 		
 	$))**

 	+

 	))**	
 	'#''

 	"",,""--!

 	$##&&
W0Gd sF+JI8+..-
 $
9!
$.r   )r   r`   rK   Qtr   r   __all__r   r    r)   r1   rI   r   r   r   r   <module>r      sB      !/% *[&.. [r   