
    ee                         d dl Z d dlZd dlZd dlmZ ddlmZ ddlm	Z	 ddl
m
Z
 i ai ai addZdd	Zd
 Z G d de	j"                        Z G d de      Zy)    N)OrderedDict   )	functions)QtCore   ParameterItemc                 v    | t         v r|st        d|  d      |xs t        }|t         | <   t        | ||       y)az  
    Similar to :func:`registerParameterType`, but works on ParameterItems. This is useful for Parameters where the
    `itemClass` does all the heavy lifting, and a redundant Parameter class must be defined just to house `itemClass`.
    Instead, use `registerParameterItemType`. If this should belong to a subclass of `Parameter`, specify which one
    in `parameterCls`.
    zParameter item type '/' already exists (use override=True to replace)N)_PARAM_ITEM_TYPES
ValueError	ParameterregisterParameterType)nameitemClsparameterClsoverrides       C/usr/lib/python3/dist-packages/pyqtgraph/parametertree/Parameter.pyregisterParameterItemTyper      sL       #D6)XY
 	
  ,9L%d$h7    c                 Z    | t         v r|st        d|  d      |t         | <   | t        |<   y)zRegister a parameter type in the parametertree system.

    This enables construction of custom Parameter classes by name in
    :meth:`~pyqtgraph.parametertree.Parameter.create`.
    zParameter type 'r   N)PARAM_TYPESr   PARAM_NAMES)r   clsr   s      r   r   r   "   s8     {8+D61`abbKKr   c                     t         j                  | j                  di              t        j                  | j                  di              y )Nr   r   )r   updategetr   )olds    r   
__reload__r   /   s4    sww}b12sww}b12r   c                      e Zd ZdZ ej
                  ee      Z ej
                  ee      Z ej
                  eee      Z	 ej
                  ee      Z
 ej
                  e      Z ej
                  ee      Z ej
                  ee      Z ej
                  ee      Z ej
                  ee      Z ej
                  ee      Z ej
                  eee      Z ej
                  ee      Z ej
                  ee      Zed        Zd Zed        Zd Zd Zd Zd Zd	 Zd
 Zd ZdFdZ d Z!d Z"d Z#d Z$dFdZ%dGdZ&d Z'd Z(dHdZ)d Z*d Z+d Z,d Z-d Z.dIdZ/d Z0dIdZ1d Z2d  Z3d! Z4d" Z5d# Z6d$ Z7d% Z8d& Z9d' Z:d( Z;d) Z<d* Z=dJd+Z>d, Z?dJd-Z@d. ZAd/ ZBd0 ZCd1 ZDd2 ZEd3 ZFd4 ZGd5 ZHd6 ZId7 ZJd8 ZKd9 ZLd: ZMd; ZNd< ZOd= ZPd> ZQd? ZRdId@ZSdA ZTdB ZUdC ZVdD ZWdE ZXy)Kr   a
  
    A Parameter is the basic unit of data in a parameter tree. Each parameter has
    a name, a type, a value, and several other properties that modify the behavior of the 
    Parameter. Parameters may have parent / child / sibling relationships to construct
    organized hierarchies. Parameters generally do not have any inherent GUI or visual
    interpretation; instead they manage ParameterItem instances which take care of
    display and user interaction.
    
    Note: It is fairly uncommon to use the Parameter class directly; mostly you 
    will use subclasses which provide specialized type and data handling. The static
    method Parameter.create(...) is an easy way to generate instances of these subclasses.
       
    For more Parameter types, see ParameterTree.parameterTypes module.
    
    ===================================  =========================================================
    **Signals:**
    sigStateChanged(self, change, info)  Emitted when anything changes about this parameter at 
                                         all.
                                         The second argument is a string indicating what changed 
                                         ('value', 'childAdded', etc..)
                                         The third argument can be any extra information about 
                                         the change
    sigTreeStateChanged(self, changes)   Emitted when any child in the tree changes state
                                         (but only if monitorChildren() is called)
                                         the format of *changes* is [(param, change, info), ...]
    sigValueChanged(self, value)         Emitted when value is finished changing
    sigValueChanging(self, value)        Emitted immediately for all value changes, 
                                         including during editing.
    sigChildAdded(self, child, index)    Emitted when a child is added
    sigChildRemoved(self, child)         Emitted when a child is removed
    sigRemoved(self)                     Emitted when this parameter is removed
    sigParentChanged(self, parent)       Emitted when this parameter's parent has changed
    sigLimitsChanged(self, limits)       Emitted when this parameter's limits have changed
    sigDefaultChanged(self, default)     Emitted when this parameter's default value has changed
    sigNameChanged(self, name)           Emitted when this parameter's name has changed
    sigOptionsChanged(self, opts)        Emitted when any of this parameter's options have changed
    sigContextMenu(self, name)           Emitted when a context menu was clicked
    ===================================  =========================================================
    c                  `    | j                  dd      }|t        }nt        | d      } |di | S )a%  
        Static method that creates a new Parameter (or subclass) instance using 
        opts['type'] to select the appropriate class.
        
        All options are passed directly to the new Parameter's __init__ method.
        Use registerParameterType() to add new class types.
        typeN )r   r   r   )optstypr   s      r   createzParameter.create~   s8     hhvt$;Cd6l+C{T{r   c                    t         j                  j                  |        ddddddddddd
| _        |j	                  dd      }t        |t              st        d      | j                  j                  |       d| j                  d<   g | _	        i | _
        t        j                         | _        d| _        g | _        d| _        | j#                  |       | j%                  | j                  j'                  dg              d	| j                  v rFd
| j                  vr8t)        j*                  dt,        d       | j                  d	   | j                  d
<   | j                  j	                  d	| j                  j	                  d
d            }d	| j                  v }|| j/                  |       || _        | j2                  j5                  | j6                         | j8                  j5                  | j:                         | j<                  j5                  | j>                         | j@                  j5                  | jB                         | jD                  j5                  | jF                         | jH                  j5                  | jJ                         | jL                  j5                  | jN                         | jP                  j5                  | jR                         | jT                  j5                  | jV                         y)a  
        Initialize a Parameter object. Although it is rare to directly create a
        Parameter instance, the options available to this method are also allowed
        by most Parameter subclasses.
        
        =======================      =========================================================
        **Keyword Arguments:**
        name                         The name to give this Parameter. This is the name that
                                     will appear in the left-most column of a ParameterTree
                                     for this Parameter.
        value                        The value to initially assign to this Parameter.
        default                      The default value for this Parameter (most Parameters
                                     provide an option to 'reset to default').
        children                     A list of children for this Parameter. Children
                                     may be given either as a Parameter instance or as a
                                     dictionary to pass to Parameter.create(). In this way,
                                     it is possible to specify complex hierarchies of
                                     Parameters from a single nested data structure.
        readonly                     If True, the user will not be allowed to edit this
                                     Parameter. (default=False)
        enabled                      If False, any widget(s) for this parameter will appear
                                     disabled. (default=True)
        visible                      If False, the Parameter will not appear when displayed
                                     in a ParameterTree. (default=True)
        renamable                    If True, the user may rename this Parameter.
                                     (default=False)
        removable                    If True, the user may remove this Parameter.
                                     (default=False)
        expanded                     If True, the Parameter will initially be expanded in
                                     ParameterTrees: Its children will be visible.
                                     (default=True)
        syncExpanded                 If True, the `expanded` state of this Parameter is
                                     synchronized with all ParameterTrees it is displayed in.
                                     (default=False)
        title                        (str or None) If specified, then the parameter will be 
                                     displayed to the user using this string as its name. 
                                     However, the parameter will still be referred to 
                                     internally using the *name* specified above. Note that
                                     this option is not compatible with renamable=True.
                                     (default=None; added in version 0.9.9)
        =======================      =========================================================
        NFT)
r"   readonlyvisibleenabled	renamable	removablestrictNamingexpandedsyncExpandedtitler   z4Parameter must have a string name specified in opts.r   childrenvaluedefaultzParameter has no default value. Pass a default, or use setDefault(). This will no longer set an implicit default after January 2025.r   
stacklevel),r   QObject__init__r$   r   
isinstancestr	TypeErrorr   childsnamesweakrefWeakKeyDictionaryitems_parenttreeStateChangesblockTreeChangeEmitsetNameaddChildrenpopwarningswarnDeprecationWarningsetValue_modifiedSinceResetsigValueChangedconnect_emitValueChangedsigChildAdded_emitChildAddedChangedsigChildRemoved_emitChildRemovedChangedsigParentChanged_emitParentChangedsigLimitsChanged_emitLimitsChangedsigDefaultChanged_emitDefaultChangedsigNameChanged_emitNameChangedsigOptionsChanged_emitOptionsChangedsigContextMenu_emitContextMenuChanged)selfr$   r   r2   modifieds        r   r7   zParameter.__init__   sd   V 	% !!
	 xx%$$RSS		 		&
..0
 "#$ Tz267diiITYY$>MM:"	 $(99W#5DIIi 		gtyy}}Y'EFdii'MM% #+  	$$T%;%;<""4#>#>?$$T%B%BC%%d&=&=>%%d&=&=>&&t'?'?@##D$9$9:&&t'?'?@##D$@$@Ar   c                     t         S )zf
        The class of ParameterItem to use when displaying this parameter in a ParameterTree.
        r   r^   s    r   	itemClasszParameter.itemClass   s
    
 r   c                      | j                   d   S )z"Return the name of this Parameter.r   r$   ra   s    r   r   zParameter.name       yy  r   c                 b    | j                   j                  dd      }|| j                         }|S )zReturn the title of this Parameter.
        
        By default, the title is the same as the name unless it has been explicitly specified
        otherwise.r0   N)r$   r   r   )r^   r0   s     r   r0   zParameter.title   s-    
 		gt,=IIKEr   c                 <    | j                   j                  | |       y)z!"A context menu entry was clickedN)r\   emit)r^   r   s     r   contextMenuzParameter.contextMenu  s      t,r   c                 ~   | j                   d   rLt        |      dk  s/t        j                  d|      st        j                  d|d         rt        d| d      | j                         }||j                  | |      }| j                   d   |k7  r+|| j                   d<   | j                  j                  | |       |S )	zAttempt to change the name of this parameter; return the actual name. 
        (The parameter may reject the name change or automatically pick a different name)r-   r   z\Wz\dr   zParameter name 'zh' is invalid. (Must contain only alphanumeric and underscore characters and may not start with a number)r   )
r$   lenresearchmatchr   parent_renameChildrX   rh   )r^   r   ro   s      r   rC   zParameter.setName
  s     99^$#d)a-299UD;QUWU]U]^ceijkelUm"4& )/ 01 1 &&tT2D99V$ $DIIf$$T40r   c                      | j                   d   S )z*Return the type string for this Parameter.r"   rd   ra   s    r   r"   zParameter.type  re   r   c                     | j                         |k(  ryt        j                  |d      }|t        d| d      | j                  |u S )z
        Return True if this parameter type matches the name *typ*.
        This can occur either of two ways:
        
          - If self.type() == *typ*
          - If this parameter's class is registered with the name *typ*
        TNzType name 'z' is not registered.)r"   r   r   r   	__class__)r^   r%   r   s      r   isTypezParameter.isType  sN     99;#ooc4(;{3%/CDEE~~$$r   c                     g }|| ur8|j                  d|j                                |j                         }|y|| ur8|S )z
        Return the path of parameter names from self to child.
        If child is not a (grand)child of self, return None.
        r   N)insertr   ro   )r^   childpaths      r   	childPathzParameter.childPath-  sI    
 4KK5::<(LLNE}	 4
 r   Nc                    	 || j                   j                  |       | j                  |      }t        j                  | j
                  j                  dd      |      r ||| j                   j                  |       S S d| _        || j
                  d<   | j                   j                  | |       || j                   j                  |       	 | j
                  d   S # || j                   j                  |       w w xY w)z
        Set the value of this Parameter; return the actual value that was set.
        (this may be different from the value that was requested)
        Nr2   T)
rK   
disconnect_interpretValuefneqr$   r   rL   rJ   rh   )r^   r2   blockSignals      r   rI   zParameter.setValue:  s    
	:&$$//<((/EuuTYY]]7D159
 &$$,,[9 '	 (,D$!&DIIg  %%dE2&$$,,[9yy!! &$$,,[9 's   AC  2C  C?c                     |S Nr#   )r^   vs     r   r|   zParameter._interpretValueN  s    r   c                     d| j                   v S )z.Return True if this Parameter has a value set.r2   rd   ra   s    r   hasValuezParameter.hasValueQ  s    $))##r   c                     d| j                   vrt        j                  dt        d       | j                   j	                  d      S )za
        Return the value of this Parameter. Raises ValueError if no value has been set.
        r2   zParameter has no value set. Pass an initial value or default, or use setValue() or setDefault(). This will be an error after January 2025.r   r4   r$   rF   rG   rH   r   ra   s    r   r2   zParameter.valueU  s<     $))#MM<"	 yy}}W%%r   c                     t               }| D ]3  }|j                         |j                         f||j                         <   5 |S )z
        Return a tree of all values that are children of this parameter. Raises ValueError if any child has no value.
        )r   r2   	getValuesr   )r^   valschs      r   r   zParameter.getValuesb  s?     } 	;B!xxz2<<>:DO	;r   c           	         |B| j                   j                         }|d   ]t        j                  t	        |       d      |d<   n:|dk(  r&| j                         rd| j                         i}ni }nt        d| d      t        | D cg c]$  }|j                         |j                  |      f& c}      }t        |      dkD  r||d	<   |S c c}w )
a  
        Return a structure representing the entire state of the parameter tree.
        The tree state may be restored from this structure using restoreState().

        If *filter* is set to 'user', then only user-settable data will be included in the
        returned state.
        Nr"   userr2   zUnrecognized filter argument: '')filterr   r1   )r$   copyr   r   r"   r   r2   r   r   r   	saveStaterk   )r^   r   stater   s       r   r   zParameter.saveStatek  s     >IINN$EV}$ +T
D Afv}} $**,/>vhaHIITRr2779bll&l&ABRSr7Q; "E* Ss   )Cc                    |j                         }|j                  dg       }t        |t              rPg }|j	                         D ]9  \  }}	|j                  |	j                                |d   j                  d|       ; |}|r| j                          	  | j                  d
i | |s	 |r| j                          yyd}
t               }|D ]  }|d   }d}t        | j                  |
d       D ]Y  \  }}|j                         |k7  rd}|dk7  r| j                  |
|       |j                  ||||       |j!                  |        n |s;|st#        j$                  d
i |}| j                  |
|       |j!                  |       |
d	z  }
 |r*| j                  dd D ]  }||vs| j'                  |        |r| j                          yy# |r| j                          w w xY w)a  
        Restore the state of this parameter and its children from a structure generated using saveState()
        If recursive is True, then attempt to restore the state of child parameters as well.
        If addChildren is True, then any children which are referenced in the state object will be
        created if they do not already exist.
        If removeChildren is True, then any children which are not referenced in the state object will 
        be removed.
        If blockSignals is True, no signals will be emitted until the tree has been completely restored. 
        This prevents signal handlers from responding to a partially-rebuilt network.
        r1   r   Nr   FT)	recursiverD   removeChildrenr   r#   )r   rE   r8   dictr?   append
setdefaultblockTreeChangeSignalsetOptsunblockTreeChangeSignalset	enumerater;   r   insertChildrestoreStateaddr   r&   removeChild)r^   r   r   rD   r   blockSignals
childStatecskr   ptrfoundChildsr   r   gotChildich2s                    r   r   zParameter.restoreState  s    

YYz2.
 j$'B!'') -!		!&&(#2!!&!,- J&&(2	/DLL!5!Z ,,. W C%K ! &z
 !'CD(9: FAsxxzT) #HAv((c2$$R9+ft$uOOC(  & #**0R0C$$S#.OOC(q?B ++a. -B,((,-
 ,,. |,,. s   G ?C(G (G G$c                     | j                   S )zuReturn True if this parameter's value has been changed since the last time
        it was reset to its default value.)rJ   ra   s    r    valueModifiedSinceResetToDefaultz*Parameter.valueModifiedSinceResetToDefault  s     '''r   c                     d| j                   vrt        j                  dt        d       | j                   j	                  d      S )zMReturn the default value for this parameter. Raises ValueError if no default.r3   zMParameter has no default value. This will be a ValueError after January 2025.r   r4   r   ra   s    r   defaultValuezParameter.defaultValue  s8    DII%MMi,%&( yy}}Y''r   c                 (   | j                   j                  dd      |k(  ry|| j                   d<   d| j                   vs|r | j                         s| j                          | j	                         sd| _        | j                  j                  | |       y)zSet the default value for this parameter. If updatePristineValues is True, then
        any values that haven't been modified since the last time they were reset to default
        will be updated to the new default value (default: False).r3   Nr2   T)r$   r   r   setToDefaultvalueIsDefaultrJ   rV   rh   )r^   valupdatePristineValuess      r   
setDefaultzParameter.setDefault  s|     99==D)S0"		)$))#(<TEjEjEl""$'+D$##D#.r   c                     | j                         5  | j                  | j                                d| _        ddd       y# 1 sw Y   yxY w)zRSet this parameter's value to the default. Raises ValueError if no default is set.FN)treeChangeBlockerrI   r   rJ   ra   s    r   r   zParameter.setToDefault  s@    ##% 	-MM$++-.',D$	- 	- 	-s   'AA
c                 >    | j                   j                  dd      duS )z3Returns True if this parameter has a default value.r3   Nr$   r   ra   s    r   
hasDefaultzParameter.hasDefault  s    yy}}Y-T99r   c                     | j                         r| j                         syt        j                  | j	                         | j                               S )zEReturns True if this parameter's value is equal to the default value.F)r   r   r}   r~   r2   r   ra   s    r   r   zParameter.valueIsDefault  s7    }}doo&7uuTZZ\4#4#4#677r   c                     d| j                   v r$t        j                  | j                   d   |      ry|| j                   d<   | j                  j	                  | |       |S )zSet limits on the acceptable values for this parameter. 
        The format of limits depends on the type of the parameter and
        some parameters do not make use of limits at all.limitsN)r$   r}   r~   rT   rh   )r^   r   s     r   	setLimitszParameter.setLimits  sR     tyy RUU499X+>%G$		(""40r   c                 $    | j                          S )z
        Returns True if this parameter's value can be changed by the user.
        Note that the value of the parameter can *always* be changed by
        calling setValue().
        r(   ra   s    r   writablezParameter.writable  s     ==?""r   c                 *    | j                  |        y)zrSet whether this Parameter should be editable by the user. (This is 
        exactly the opposite of setReadonly).r   Nr   )r^   r   s     r   setWritablezParameter.setWritable  s     	(l+r   c                 :    | j                   j                  dd      S )zb
        Return True if this parameter is read-only. (this is the opposite of writable())
        r(   Fr   ra   s    r   r(   zParameter.readonly  s     yy}}Z//r   c                 (    | j                  |       y)zmSet whether this Parameter's value may be edited by the user
        (this is the opposite of setWritable()).r   Nr   )r^   r(   s     r   setReadonlyzParameter.setReadonly  s     	h'r   c                    t               }|D ]  }|dk(  r| j                  ||          |dk(  r| j                  ||          7|dk(  r| j                  ||          Q|dk(  r| j	                  ||          k|| j
                  vs't        j                  | j
                  |   ||         r||   | j
                  |<   ||   ||<    t        |      dkD  r| j                  j                  | |       yy)a  
        Set any arbitrary options on this parameter.
        The exact behavior of this function will depend on the parameter type, but
        most parameters will accept a common set of options: value, name, limits,
        default, readonly, removable, renamable, visible, enabled, expanded and
        syncExpanded.
        
        See :func:`Parameter.__init__ <pyqtgraph.parametertree.Parameter.__init__>`
        for more information on default options.
        r2   r   r   r3   r   N)r   rI   rC   r   r   r$   r}   r~   rk   rZ   rh   )r^   r$   changedr   s       r   r   zParameter.setOpts  s     - 	%AG|d1g&fT!W%htAw'iQ($))#2551tAw+G#Aw		!!!W
	% w<!""''g6 r   c                     | j                   j                  | ||       | j                  j                  | ||f       | j	                          y r   )sigStateChangedrh   rA   r   emitTreeChanges)r^   
changeDescdatas      r   emitStateChangedzParameter.emitStateChanged:  sC     	!!$
D9$$dJ%=>r   c                 (    | j                  d|       y )Nr2   r   r^   paramr   s      r   rM   zParameter._emitValueChangedB  s    gt,r   c                 (    | j                  d|       y )N
childAddedr   r   s      r   rO   z Parameter._emitChildAddedChangedE  s    lD1r   c                 (    | j                  d|       y )NchildRemovedr   r   s      r   rQ   z"Parameter._emitChildRemovedChangedH  s    nd3r   c                 (    | j                  d|       y )Nro   r   r   s      r   rS   zParameter._emitParentChangedK      h-r   c                 (    | j                  d|       y )Nr   r   r   s      r   rU   zParameter._emitLimitsChangedN  r   r   c                 (    | j                  d|       y )Nr3   r   r   s      r   rW   zParameter._emitDefaultChangedQ      i.r   c                 (    | j                  d|       y )Nr   r   r   s      r   rY   zParameter._emitNameChangedT  s    fd+r   c                 (    | j                  d|       y )Noptionsr   r   s      r   r[   zParameter._emitOptionsChangedW  r   r   c                 (    | j                  d|       y )Nri   r   r   s      r   r]   z!Parameter._emitContextMenuChangedZ  s    mT2r   c                 ~    | j                   xs' t        j                  | j                  d   t              } || |      S )a  
        Return a TreeWidgetItem suitable for displaying/controlling the content of 
        this parameter. This is called automatically when a ParameterTree attempts
        to display this Parameter.
        Most subclasses will want to override this function.
        r"   )rb   r   r   r$   r	   )r^   depthrb   s      r   makeTreeItemzParameter.makeTreeItem]  s6     NN]&7&;&;DIIf<M}&]	u%%r   c                 R    | j                  t        | j                        |||      S )z
        Add another parameter to the end of this parameter's child list.
        
        See insertChild() for a description of the *autoIncrementName* and *existOk*
        arguments.
        )autoIncrementNameexistOk)r   rk   r;   )r^   rw   r   r   s       r   addChildzParameter.addChildi  s)     DKK 0%K\fmnnr   c                     t        |t              rVg }|j                         D ]?  \  }}t        |t              rd|vr|j                         }||d<   |j	                  |       A |}|D ]  }| j                  |        y)z
        Add a list or dict of children to this parameter. This method calls
        addChild once for each value in *children*.
        r   N)r8   r   r?   r   r   r   )r^   r1   r   r   r$   chOptss         r   rD   zParameter.addChildrenr  s     h%C&nn. !
ddD)fD.@99;D#'DL

4 	!
 H 	"FMM&!	"r   c                 f   t        |t              rt        j                  di |}|j	                         }|| j
                  v r~|| j
                  |   urm|du s|?|j                  j                  dd      r#| j                  |      }|j                  |       n(|r| j
                  |   S t        dt        |      z        t        |t              r| j                  j                  |      }| j                         5  |j                         |j!                          || j
                  |<   | j                  j#                  ||       |j%                  |        |j&                  j)                  | j*                         | j,                  j/                  | ||       ddd       |S # 1 sw Y   |S xY w)a  
        Insert a new child at pos.
        If pos is a Parameter, then insert at the position of that Parameter.
        If child is a dict, then a parameter is constructed using
        :func:`Parameter.create <pyqtgraph.parametertree.Parameter.create>`.
        
        By default, the child's 'autoIncrementName' option determines whether
        the name will be adjusted to avoid prior name collisions. This 
        behavior may be overridden by specifying the *autoIncrementName* 
        argument. This argument was added in version 0.9.9.

        If 'autoIncrementName' is *False*, an error is raised when the inserted child already exists. However, if
        'existOk' is *True*, the existing child will be returned instead, and this child will *not* be inserted.
        TNr   FzAlready have child named %sr#   )r8   r   r   r&   r   r<   r$   r   incrementNamerC   r   r9   r;   indexr   ro   removerv   parentChangedsigTreeStateChangedrL   treeStateChangedrN   rh   )r^   posrw   r   r   r   s         r   r   zParameter.insertChild  sk    eT"$$-u-Ezz|4::%tzz$/?"? D(->-F5::>>ZmotKu))$/d#zz$'' !>T!JKKc9%++##C(C##% 		6||~)$DJJtKKsE*%%%--d.C.CD##D%5		6 		6 s   =BF&&F0c                    |j                         }|| j                  vs| j                  |   |urt        dt        |      z        | j                  |= | j                  j                  | j                  j                  |             |j                  d       	 |j                  j                  | j                         | j                  j                  | |       y# t        t        f$ r Y .w xY w)zRemove a child parameter.z+Parameter %s is not my child; can't remove.N)r   r<   	Exceptionr9   r;   rE   r   r   r   r{   r   r:   RuntimeErrorrP   rh   r^   rw   r   s      r   r   zParameter.removeChild  s    zz|tzz!TZZ%5U%BICPUJVWWJJt))%01D!	%%001F1FG 	!!$. <( 		s   %C C.-C.c                 N    | j                   dd D ]  }| j                  |        y)zRemove all child parameters.N)r;   r   )r^   r   s     r   clearChildrenzParameter.clearChildren  s'    ++a. 	!BR 	!r   c                      | j                   dd S )zeReturn a list of this parameter's children.
        Warning: this overrides QObject.children
        Nr;   ra   s    r   r1   zParameter.children  s     {{1~r   c                 2    t        | j                        dkD  S )z+Return True if this Parameter has children.r   )rk   r;   ra   s    r   hasChildrenzParameter.hasChildren  s    4;;!##r   c                 J    || _         | j                  j                  | |       y)z|This method is called when the parameter's parent has changed.
        It may be useful to extend this method in subclasses.N)r@   rR   rh   r^   ro   s     r   r   zParameter.parentChanged  s!     ""40r   c                     | j                   S )z$Return the parent of this parameter.)r@   ra   s    r   ro   zParameter.parent  s    ||r   c                     | j                         }|t        d      |j                  |        | j                  j	                  |        y)z2Remove this parameter from its parent's child listNzCannot remove; no parent.)ro   r   r   
sigRemovedrh   r   s     r   r   zParameter.remove  s>    >7884 T"r   c                     t        j                  d|      j                         \  }}t        |      }|dk(  rd}d}nt	        |      }	 |d|z  |z  z   }|| j
                  vr|S |dz  }!)Nz([^\d]*)(\d*)r   r   r   z%%0%dd)rl   rn   groupsrk   intr<   )r^   r   basenumnumLennewNames         r   r   zParameter.incrementName  sx    HH-t4;;=	cSQ;CFc(Chvo44Gdjj(1HC	 r   c              #   8   K   | j                   E d {    y 7 wr   r   ra   s    r   __iter__zParameter.__iter__  s     ;;s   c                 b    t        |t              s|f} | j                  | j                         S )zGet the value of a child parameter. The name may also be a tuple giving
        the path to a sub-parameter::
        
            value = param[('child', 'grandchild')]

        Raises ValueError if the child value is not set.
        )r8   tupler   r2   r^   r<   s     r   __getitem__zParameter.__getitem__  s/     %'HEtzz5!''))r   c                 d    t        |t              r|f} | j                  | j                  |      S )zSet the value of a child parameter. The name may also be a tuple giving
        the path to a sub-parameter::
        
            param[('child', 'grandchild')] = value
        )r8   r9   r   rI   )r^   r<   r2   s      r   __setitem__zParameter.__setitem__  s1     eS!HEtzz5!**511r   c                     | j                   S r   )r<   ra   s    r   keyszParameter.keys  s    zzr   c                     	 | j                   |d      }t        |      dkD  r |j                  |dd  S |S # t        $ r(}t        d| j                          d|d          |d}~ww xY w)zReturn a child parameter. 
        Accepts the name of the child or a tuple (path, to, child)

        Added in version 0.9.9. Earlier versions used the 'param' method, which is still
        implemented for backward compatibility.
        r   z
Parameter z has no child named Nr   )r<   KeyErrorr   rk   rw   )r^   r<   r   es       r   rw   zParameter.child	  s}    	\JJuQx(E u:>5;;ab	**L  	\Z		}4Hq
STZ[[	\s   6 	A'#A""A'c                       | j                   | S r   )rw   r  s     r   r   zParameter.param  s    tzz5!!r   c                 h    d| j                   j                  | j                         t        |       fz  S )Nz<%s '%s' at 0x%x>)rs   __name__r   idra   s    r   __repr__zParameter.__repr__  s(    "dnn&=&=tyy{BtH%UUUr   c                     || j                   v r|j                         S || j                   |<   | j                   |j                         = |S r   )r<   r   r   s      r   rp   zParameter._renameChild!  s?    4::::< 

4JJuzz|$r   c                 "    d | j                   |<   y r   )r?   )r^   items     r   registerItemzParameter.registerItem)  s    

4r   c                 &    | j                  d       y)z{Hide this parameter. It and its children will no longer be visible in any ParameterTree
        widgets it is connected to.FN)showra   s    r   hidezParameter.hide,  s     			%r   c                 ^    || j                   d<   | j                  j                  | d|i       y)zShow this parameter. r)   N)r$   rZ   rh   )r^   ss     r   r  zParameter.show1  s*     		)##D9a.9r   c                 B    t        | j                  | j                        S )a  
        Return an object that can be used to temporarily block and accumulate
        sigTreeStateChanged signals. This is meant to be used when numerous changes are 
        about to be made to the tree and only one change signal should be
        emitted at the end.
        
        Example::

            with param.treeChangeBlocker():
                param.addChild(...)
                param.removeChild(...)
                param.setValue(...)
        )SignalBlockerr   r   ra   s    r   r   zParameter.treeChangeBlocker7  s     T779U9UVVr   c                 .    | xj                   dz  c_         y)z
        Used to temporarily block and accumulate tree change signals.
        *You must remember to unblock*, so it is advisable to use treeChangeBlocker() instead.
        r   N)rB   ra   s    r   r   zParameter.blockTreeChangeSignalG  s    
 	  A% r   c                 N    | xj                   dz  c_         | j                          y)z]Unblocks enission of sigTreeStateChanged and flushes the changes out through a single signal.r   N)rB   r   ra   s    r   r   z!Parameter.unblockTreeChangeSignalN  s      A% r   c                 Z    | j                   j                  |       | j                          y)a  
        Called when the state of any sub-parameter has changed. 
        
        ==============  ================================================================
        **Arguments:**
        param           The immediate child whose tree state has changed.
                        note that the change may have originated from a grandchild.
        changes         List of tuples describing all changes that have been made
                        in this event: (param, changeDescr, data)
        ==============  ================================================================
                     
        This function can be extended to react to tree state changes.
        N)rA   extendr   )r^   r   changess      r   r   zParameter.treeStateChangedT  s$     	$$W-r   c                     | j                   dk(  r?| j                  }g | _        t        |      dkD  r| j                  j	                  | |       y y y )Nr   )rB   rA   rk   r   rh   )r^   r(  s     r   r   zParameter.emitTreeChangese  sO    ##q(++G$&D!7|a((--dG<   )r   r   )TTTTF)TNF)Yr  
__module____qualname____doc__r   SignalobjectrK   sigValueChangingrN   rP   r   rR   rT   rV   rX   rZ   r   r   r\   staticmethodr&   r7   propertyrb   r   r0   ri   rC   r"   rt   ry   rI   r|   r   r2   r   r   r   r   r   r   r   r   r   r   r   r   r(   r   r   r   rM   rO   rQ   rS   rU   rW   rY   r[   r]   r   r   rD   r   r   r   r1   r   r   ro   r   r   r  r  r  r  rw   r   r  rp   r  r  r  r   r   r   r   r   r#   r   r   r   r   4   sv   &T $fmmFF3O$v}}VV4!FMM&&&9M#fmmFF3Ov&J$v}}VV4$v}}VV4%ff5"V]]662N%ff5
 $fmmFFF;O (&--7"V]]662N  aBF  !-!% "($&4K/Z(
(/-:8#,
0(
78-24../,/3
&o"&(T/!
$1#
*2""V 
:W &"=r   r   c                       e Zd Zd Zd Zd Zy)r#  c                      || _         || _        y r   )enterFnexitFn)r^   r6  r7  s      r   r7   zSignalBlocker.__init__n  s    r   c                 $    | j                          y r   )r6  ra   s    r   	__enter__zSignalBlocker.__enter__r  s    r   c                 $    | j                          y r   )r7  )r^   exc_type	exc_valuetbs       r   __exit__zSignalBlocker.__exit__u  s    r   N)r  r,  r-  r7   r9  r>  r#   r   r   r#  r#  m  s    r   r#  r+  r*  )rl   rF   r=   collectionsr    r   r}   Qtr   r	   r   r   r   r   r   r   r6   r   r0  r#  r#   r   r   <module>rB     sX    	   #   ( 8$
3
v= v=r	F 	r   