
    e>                     T    d dl Z d dlmZ ddlmZ dgZ G d dej                        Zy)    N)OrderedDict   )	QtWidgetsComboBoxc                       e Zd ZdZddZd Zd Zd Zd Zd Z	ee	d	               Z
d
 Zd Zd Zd Zd Zed        Zed        Zed        Zd Zee	d               Zed        Zd Zd Zd Zy)r   a  Extends QComboBox to add extra functionality.

      * Handles dict mappings -- user selects a text key, and the ComboBox indicates
        the selected value.
      * Requires item strings to be unique
      * Remembers selected value if list is cleared and subsequently repopulated
      * setItems() replaces the items in the ComboBox and blocks signals if the
        value ultimately does not change.
    Nc                    t         j                  j                  | |       | j                  j	                  | j
                         d| _        dt        j                  v r3| j                  t         j                  j                  j                         d | _        t               | _        |&| j                  |       || j!                  |       y y y )NFdarwin)r   	QComboBox__init__currentIndexChangedconnectindexChanged_ignoreIndexChangesysplatformsetSizeAdjustPolicySizeAdjustPolicyAdjustToContents_chosenTextr   _itemssetItemssetValue)selfparentitemsdefaults       </usr/lib/python3/dist-packages/pyqtgraph/widgets/ComboBox.pyr   zComboBox.__init__   s    $$T62  (():):;"' s||#$$Y%8%8%I%I%Z%Z[!mMM% "g& #     c                     d}| j                   j                         D ]  \  }}||k(  s|} n |t        |      | j                  |       y)z>Set the selected item to the first one having the given value.N)r   r   
ValueErrorsetText)r   valuetextkvs        r   r   zComboBox.setValue%   sT    ;;$$& 	CAaEz	 <U##Tr   c                 h    | j                  |      }|dk(  rt        |      | j                  |       y)z=Set the selected item to the first one having the given text.N)findTextr    setCurrentIndex)r   r#   inds      r   r!   zComboBox.setText1   s0    mmD!"9T""S!r   c                 h    | j                         dk(  ry| j                         }| j                  |   S )a  
        If items were given as a list of strings, then return the currently 
        selected text. If items were given as a dict, then return the value
        corresponding to the currently selected key. If the combo list is empty,
        return None.
        r   N)countcurrentTextr   )r   r#   s     r   r"   zComboBox.value9   s2     ::<1!{{4  r   c                       fd}|S )Nc                 n    | j                   }d| _         	  | g|i |}|| _         |S # || _         w xY wNT)r   )r   argskwdsprevretfuncs        r   fnz&ComboBox.ignoreIndexChange.<locals>.fnG   sH    **D&*D#/4/$/$/*.'J +/'s   + 	4 r5   r6   s   ` r   ignoreIndexChangezComboBox.ignoreIndexChangeE   s    	 	r   c                       fd}|S )Nc                 J   | j                         }| j                         }| j                  d       	  | g|i |}| j                  |       | j                         |k7  r)| j                  j	                  | j                                |S # | j                  |       w xY wr0   )r"   signalsBlockedblockSignalsr   emitcurrentIndex)r   r1   r2   prevValblockedr4   r5   s         r   r6   z%ComboBox.blockIfUnchanged.<locals>.fnU   s    jjlG))+Gd#+4/$/$/!!'* zz|w&((--d.?.?.ABJ !!'*s   B B"r7   r8   s   ` r   blockIfUnchangedzComboBox.blockIfUnchangedQ   s    	 	r   c                 F    | j                          | j                  |       y)z
        *items* may be a list, a tuple, or a dict. 
        If a dict is given, then the keys are used to populate the combo box
        and the values will be used for both value() and setValue().
        N)clearaddItemsr   r   s     r   r   zComboBox.setItemse   s     	

er   c                 6    | j                   j                         S N)r   copyr   s    r   r   zComboBox.itemsp   s    zz  r   c                 $    | j                  |      S rH   )r   rF   s     r   
updateListzComboBox.updateLists   s    }}U##r   c                 H    | j                   ry | j                         | _        y rH   )r   r-   r   r   indexs     r   r   zComboBox.indexChangedw   s    ""++-r   c                 D    t         j                  j                  | |       y rH   )r   r
   r)   rN   s     r   r)   zComboBox.setCurrentIndex}   s    ++D%8r   c                 t    | j                   	 | j                  | j                          y y # t        $ r Y y w xY wrH   )r   r!   r    rJ   s    r   itemsChangedzComboBox.itemsChanged   s>    'T--. (  s   + 	77c                     t               rH   NotImplementedErrorr   r1   s     r   
insertItemzComboBox.insertItem       !##r   c                     t               rH   rT   rV   s     r   insertItemszComboBox.insertItems   rX   r   c                    	 t        |d   t              r,|d   }t        |      dk(  r|d   }n>|j                  d|      }n+|d   }t        |      dk(  r|d   }n|j                  d|      }|| j                  v rt        d|z        || j                  |<   t        j                  j                  | g|  | j                          y # t        $ r t        d      w xY w)Nr   r      r"      z5First or second argument of addItem must be a string.%ComboBox already has item named "%s".)
isinstancestrlenget
IndexError	TypeErrorr   	Exceptionr   r
   addItemrR   )r   r1   r2   r#   r"   s        r   rf   zComboBox.addItem   s    	U$q'3'Awt9> GE HHWd3EAwt9> GE HHWd3E
 4;;CdJKK!D##D040  	USTT	Us   A*C Cc                 d    || j                   vr| j                  ||       y || j                   |<   y rH   )r   rf   )r   namer"   s      r   setItemValuezComboBox.setItemValue   s*    t{{"LLu% %DKKr   c                    t        |t              st        |t              r|}t        |D cg c]  }||f c}      }nAt        |t              rt        |j	                               }nt        dt        |      z        |D ]  }|| j                  v st        d|z         |j                         D ]  \  }}|| j                  |<    t        j                  j                  | t        |             | j                          y c c}w )Nz6items argument must be list or dict or tuple (got %s).r^   )r_   listtupledictkeysrd   typer   re   r   r   r
   rE   rR   )r   r   textsxtr$   r%   s          r   rE   zComboBox.addItems   s     eT"j&>E%0Q1a&01Et$&ETW[\aWbbcc 	MADKK G! KLL	M
 ;;= 	CAaDKKN	$$T4;7 1s   Dc                     t               | _        t        j                  j	                  |        | j                          y rH   )r   r   r   r
   rD   rR   rJ   s    r   rD   zComboBox.clear   s+    !m!!$'r   c                     | j                         }| j                  |      }|'	 |j                         sd }n|j                         d   }|| j                  |      S |S # t        $ r Y  w xY w)Nr   )r?   itemDataisValidtoIntAttributeErroritemText)r   r*   datas      r   	saveStatezComboBox.saveState   su    !}}S!||~D::<?D <==%%K " s   &A   	A,+A,c                     t        |      t        u r(| j                  |      }|dkD  r| j                  |       y | j                  | j	                  t        |                   y )Nr'   )ro   intfindDatar)   r(   r`   )r   r%   r*   s      r   restoreStatezComboBox.restoreState   sN    7c>--"CRx$$S)T]]3q623r   c                 H    | j                   | j                  | j                  fS rH   )r   r{   r   rJ   s    r   widgetGroupInterfacezComboBox.widgetGroupInterface   s    (($..$:K:KLLr   )NNN)__name__
__module____qualname____doc__r   r   r!   r"   r9   rB   r   r   rL   r   r)   rR   rW   rZ   rf   ri   rE   rD   r{   r   r   r7   r   r   r   r      s    '"
"
!
(   !$.9 $ $
 $ $
  4&   (  
"4Mr   )r   collectionsr   Qtr   __all__r
   r   r7   r   r   <module>r      s+    
 # ,cMy"" cMr   