
    ce                        d dl mZ dZd dlmZ d dlmZmZ d dlmZ  G d dej	                  Z
 G d d	e          Zd
S )    )annotations )QtCore)
QTableViewQHeaderView)QtGuic                  ,     e Zd ZdZ fdZ fdZ xZS )SelectableChannelsItemz4
    Standard table item object representation.
    c                d     t                      j        |i | |                     d           d S )NF)super__init__setEditable)selfargskwargs	__class__s      Klib/python3.11/site-packages/anaconda_navigator/widgets/manager/channels.pyr   zSelectableChannelsItem.__init__   s9    $)&)))    c                    |                                  r9|                                 |                                t          j        j        fvS t                                          |          S )N)isCheckable
checkStater   QtCheckedr   __lt__)r   otherr   s     r   r   zSelectableChannelsItem.__lt__   sY     	T((U-=-=-?-?AR,SSSww~~e$$$r   )__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   r
   r
      s[                  
% % % % % % % % %r   r
   c                  h     e Zd ZdZdZdZdZdZdZdZ	g dZ
d fd
	Zd Zedd            Zd Z xZS )SelectableChannelsListTablezk
    Table object representation for selecting channels while doing login to Anaconda Server instance.
    r                  )NameMirrorPrivacyOwnerszAdd to default_channelszAdd to channelsNc                `   t                                                       |sg }|sg }|| _        |                     |||           t	          t          | j                            D ]4}|                                                     |t          j
                   5|                                                     d           |                                                     d           |                     d           |                                                     | j        d           d S )NTFx   )r   r   parentapply_data_modelrangelenTABLE_HEADERShorizontalHeadersetSectionResizeModer   ResizeToContentssetStretchLastSectionverticalHeader
setVisiblesetSortingEnabledresizeSectionCHANNELS_INDEX)r   r/   
table_datachannelsdefault_channelsindexr   s         r   r   z$SelectableChannelsListTable.__init__)   s    	H 	"!j(4DEEE3t12233 	^ 	^E!!##88@\]]]]55d;;;((///t$$$--d.A3GGGGGr   c                8   t          j                    }|                    | j                   t	          |          D ]\  }}d                    t          t          |                    dd          |d         f                    }|	                    || j
        t          |                     |	                    || j        |                     t          |d                   d                     |	                    || j        t          |d                              |	                    || j        t          d                    t          t          |d	                                                  |	                    || j        |                     ||v                      |	                    || j        |                     ||v                      |                     |           |                     | j        t(          j        j                   dS )
a  
        Creates the model data for the table depending on passed data in 'table_data' attribute.

        :param dict[str, str/int] table_data: The data which will be hold in model.
        :param list[str] channels: List of 'channels' names which must be checked by default.
        :param list[str] default_channels: List of 'default_channels' which must be checked by default.
        /r/   Nnamemirror_countFprivacyz, owners)r   QStandardItemModelsetHorizontalHeaderLabelsr3   	enumeratejoinfilterboolgetsetItem
NAME_INDEXr
   MIRROR_INDEXgenerate_checkable_itemPRIVACY_INDEXOWNERS_INDEXDEFAULT_CHANNELS_INDEXr<   setModelsortByColumnr   r   DescendingOrder)r   r=   r>   r?   modelrowchannelrC   s           r   r0   z,SelectableChannelsListTable.apply_data_model=   s    (**''(:;;;%j11 	d 	dLCw{{8T/J/JGTZO.\!]!]^^DMM#t0Ft0L0LMMMMM#t0$2N2NtT[\jTkOlOlns2t2tuuuMM#t13I'R[J\3]3]^^^MM#t02HSYZ^`ghp`qSrSrIsIs2t2tuuuMM#t:D<X<XY]aqYq<r<rsssMM#t2D4P4PQUYaQa4b4bcccce$+VY-FGGGGGr   FTc                
   t                      }|                    d           |                    |           |                    t          j        j                   | r$|                    t          j        j                   |S )a#  
        Creates a table item with a checkbox and empty string.

        :param bool is_checked: Defines if the checkbox must be checked.
        :param bool is_enabled: Defines if the checkbox must be enabled.

        :return SelectableChannelsItem: The created table item object.
        T)	r
   setCheckable
setEnabledsetTextAlignmentr   r   AlignCentersetCheckStater   )
is_checked
is_enabledcheckable_items      r   rQ   z3SelectableChannelsListTable.generate_checkable_itemU   sw     011##D)))!!*---''	(=>>> 	<(():;;;r   c                   g }g }t          |                                                                           D ]H}|                                                     || j                  }|                                                     || j                                                  t          j	        j
        k    r:|                    |                                                     |                     |                                                     || j                                                  t          j	        j
        k    r:|                    |                                                     |                     J||fS )z
        Returns the lists with 'default_channels' and 'channels' names fetched from the model,
        where on row 4 and 5 (default_channels and channels) checkboxes are in the checked state.

        :return tuple[list[str], list[str]]
        )r1   rX   rowCountr@   rO   itemrT   r   r   r   r   appenddatar<   )r   r?   r>   rY   
data_indexs        r   get_selected_channelsz1SelectableChannelsListTable.get_selected_channelsi   s'    ..0011 	? 	?C++CAAJzz||  d&ABBMMOOSYS\Sddd ''

(9(9*(E(EFFFzz||  d&9::EEGG69K\\\

 1 1* = =>>>))r   )NN)FT)r   r   r   r   rO   rP   rR   rS   rT   r<   r3   r   r0   staticmethodrQ   rj   r    r!   s   @r   r#   r#      s          JLMLNiiiMH H H H H H(H H H0    \&* * * * * * *r   r#   N)
__future__r   __all__qtpyr   qtpy.QtWidgetsr   r   r   QStandardItemr
   r#   r   r   r   <module>rq      s    # " " " " "
       2 2 2 2 2 2 2 2      % % % % %U0 % % %`* `* `* `* `** `* `* `* `* `*r   