
    G@d              	       *   d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lm Z m!Z! dd
l"m#Z# ddl$m%Z% ddl&m'Z' dZ(e#j)        ddde(e(e(e(dZ*e#j)        e(dZ+d Z, G d de          Z- G d de'          Z. G d de          Z/ G d de/          Z0 G d de/          Z1 G d de          Z2 G d d e          Z3d! Z4d" Z5d# Z6d$ Z7d% Z8d)d&Z9d)d'Z:e;d(k    r e:             dS dS )*zSwitcher widget interface.    N)QEventQObjectQSizeQSortFilterProxyModelQtSignalSlotQModelIndex)QStandardItemQStandardItemModelQTextDocument)QAbstractItemViewQApplicationQDialog	QLineEdit	QListViewQListWidgetItemQStyleQVBoxLayout)_)CONF)	is_ubuntu)
TEXT_TYPESto_text_string)ima)get_search_scores)HTMLDelegate
   rgb(153, 153, 153)rgb(70, 179, 239)title_colordescription_colorsection_colorshortcut_colortitle_font_sizedescription_font_sizesection_font_sizeshortcut_font_sizecolor	font_sizec                 <    dD ]}|                      |d          } | S )z,Remove regex special characters from string.)().\?*[]&|^+ )replace)textchs     7lib/python3.11/site-packages/spyder/widgets/switcher.pyclean_stringr?   1   s+    K $ $||B##K    c                   ^     e Zd ZdZ e            Z e            Z e            Z fdZ xZ	S )KeyPressFilterzDUse with `installEventFilter` to get up/down arrow key press signal.c                    |                                 t          j        k    r|                                t          j        k    r| j                                         dS |                                t          j        k    r| j	                                         dS |                                t          j
        k    r| j                                         dS t          t          |                               ||          S )zOverride Qt eventFilter.T)typer   KeyPresskeyr   Key_Upsig_up_key_pressedemitKey_Downsig_down_key_pressed
Key_Returnsig_enter_key_pressedsuperrB   eventFilter)selfsrce	__class__s      r>   rO   zKeyPressFilter.eventFilter?   s    6688v&&uuww")##',,...tBK'')..000t%%''R]***//111t^T**66sA>>>r@   )
__name__
__module____qualname____doc__r   rH   rK   rM   rO   __classcell__rS   s   @r>   rB   rB   8   sb        NN!688"FHH? ? ? ? ? ? ? ? ?r@   rB   c                   "     e Zd ZdZ fdZ xZS )SwitcherDelegatez
    This delegate allows the list view of the switcher to look like it has
    the focus, even when its focus policy is set to Qt.NoFocus.
    c                     |xj         t          j        z  c_         t          t          |                               |||           dS )zX
        Override Qt method to force this delegate to look active at all times.
        N)stater   State_ActiverN   r[   paint)rP   painteroptionindexrS   s       r>   r_   zSwitcherDelegate.paintT   sA     	++%%++GVUCCCCCr@   )rT   rU   rV   rW   r_   rX   rY   s   @r>   r[   r[   N   sK         
D D D D D D D D Dr@   r[   c                   ~     e Zd ZdZdZdZdZdZdef fd	Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Z fdZ xZS )SwitcherBaseItemzBase List Item.   i  Nc                 T   t          t          |                                            | j        | _        | j        | _        |r|ni | _        d| _        d| _	        | 
                                | _        |                     t          dt          | j                                       dS )zCreate basic List Item.Fr   N)rN   rd   __init___WIDTH_width_PADDING_padding_styles_action_item_score_get_height_heightsetSizeHintr   intrP   parentstylesrS   s      r>   rh   zSwitcherBaseItem.__init__d   s    %%..000 k!'/vvR!''))
 	q#dl"3"34455555r@   c                     t           )'Render the html template for this item.NotImplementedErrorrP   s    r>   _render_textzSwitcherBaseItem._render_textu       !!r@   c                 T    |                      |                                            dS )z4Set the rendered html template as text of this item.N)setTextr|   r{   s    r>   _set_rendered_textz#SwitcherBaseItem._set_rendered_texty   s&    T&&(()))))r@   c                     t           )Set the styles for this item.ry   r{   s    r>   _set_styleszSwitcherBaseItem._set_styles}   r}   r@   c                     t           )e
        Return the expected height of this item's text, including
        the text margins.
        ry   r{   s    r>   rp   zSwitcherBaseItem._get_height   s
    
 "!r@   c                 R    || j         dz  z
  | _        |                                  dS )zSet the content width.   N)rl   rj   r   rP   values     r>   	set_widthzSwitcherBaseItem.set_width   s-    t}q01!!!!!r@   c                     | j         S )zReturn the content width.)rj   r{   s    r>   	get_widthzSwitcherBaseItem.get_width   
    {r@   c                     | j         S )zReturn the content height.)rq   r{   s    r>   
get_heightzSwitcherBaseItem.get_height   s
    |r@   c                     | j         S )zReturn the fuzzy matchig score.)ro   r{   s    r>   	get_scorezSwitcherBaseItem.get_score   r   r@   c                 <    || _         |                                  dS )z&Set the search text fuzzy match score.N)ro   r   r   s     r>   	set_scorezSwitcherBaseItem.set_score   !    !!!!!r@   c                 *    t          | j                  S )z*Return whether the item is of action type.)boolrn   r{   s    r>   is_action_itemzSwitcherBaseItem.is_action_item   s    D%&&&r@   c                     t          t          |                                            |                                  |                                  dS )zOverride Qt.N)rN   rd   refreshr   r   rP   rS   s    r>   r   zSwitcherBaseItem.refresh   sJ    %%--///!!!!!r@   )rT   rU   rV   rW   rk   ri   _STYLES	_TEMPLATErh   r|   r   r   rp   r   r   r   r   r   r   r   rX   rY   s   @r>   rd   rd   \   s       HFGI"7 6 6 6 6 6 6"" " "* * *" " "" " "" " "
      " " "
' ' '
" " " " " " " " "r@   rd   c                        e Zd ZdZdZddgZ ej                                                    	                                
                                ddZdZdef fd		Zd
 Zd Zd Z xZS )SwitcherSeparatorItemz
    Separator Item represented as <hr>.

    Based on HTML delegate.

    See: https://doc.qt.io/qt-5/richtext-html-subset.html
    r   r+   r,   r   r*   z<table cellpadding="{padding}" cellspacing="0" width="{width}"
                  height="{height}" border="0">
  <tr><td valign="top" align="center"><hr></td></tr>
</table>Nc                     t          t          |                               ||           |                     t          j                   |                                  dS )z#Separator Item represented as <hr>.ru   rv   N)rN   r   rh   setFlagsr   NoItemFlagsr   rt   s      r>   rh   zSwitcherSeparatorItem.__init__   s_    #T**336;A 	4 	C 	C 	Cbn%%%!!!!!r@   c                    | j         D ] }|| j        vr| j        |         | j        |<   !| j        d         }t          j        dk    r|}n,t
          j        dk    r|}nt                      r|dz
  }n|dz
  }|| j        d<   dS )r   r,   darwinnt   N_STYLE_ATTRIBUTESrm   r   sysplatformosnamer   )rP   attr	rich_fontr,   s       r>   r   z!SwitcherSeparatorItem._set_styles   s    * 	8 	8D4<''%)\$%7T"L-	<8##!IIW__!II[[ 	&!AII!AI$-[!!!r@   c                     | j         }| j        }|                                 } | j        j        d|||d| j        }|S )rx   )widthheightpadding )rl   rj   r   r   formatrm   )rP   r   r   r   r<   s        r>   r|   z"SwitcherSeparatorItem._render_text   sZ    -""$t~$ F5-4F F8<F Fr@   c                     t                      }|                    d           |                    | j                   |                                                                S )r   z<hr>)r   setHtmlsetDocumentMarginrk   sizer   rP   docs     r>   rp   z!SwitcherSeparatorItem._get_height   sO    
 ooFdm,,,xxzz  """r@   )rT   rU   rV   rW   
_SEPARATORr   r   paletter<   r+   r   r   r   rh   r   r|   rp   rX   rY   s   @r>   r   r      s          J +.%%'',,..4466;;== G
	  #7 " " " " " ". . .&  # # # # # # #r@   r   c            
       b    e Zd ZdZdZg dZ ej                                                    	                                
                                dddeeeedZdZdddddddddef
 f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d Z fdZd Zd Zd Zd Zd Z d Z! xZ"S )SwitcherItemz
    Switcher item with title, description, shortcut and section.

    SwitcherItem: [title description    <shortcut> section]

    Based on HTML delegate.
    See: https://doc.qt.io/qt-5/richtext-html-subset.html
    r   r!   r   r    a  
<table width="{width}" max_width="{width}" height="{height}"
                          cellpadding="{padding}">
  <tr>
    <td valign="middle">
      <span style="color:{title_color};font-size:{title_font_size}pt">
        {title}
      </span>&nbsp;
      <small
       style="color:{description_color};font-size:{description_font_size}pt">
        <span>{description}</span>
      </small>
    </td>
    <td valign="middle" align="right" float="right">
      <span style="color:{shortcut_color};font-size:{shortcut_font_size}pt">
         <small><code><i>{shortcut}</i></code></small>
      </span>&nbsp;
      <span style="color:{section_color};font-size:{section_font_size}pt">
         <small>{section}</small>
      </span>
    </td>
  </tr>
</table>NFc                    t          t          |                               ||
           |r|nd| _        d| _        |r|nd| _        |r|nd| _        |r|nd| _        || _        || _	        d| _
        |	| _        d| _        |                     t          j        t          j        z             |r|                     |           d| _        nd| _        |                                  |                                  dS )z<Switcher item with title, description, shortcut and section.r   r:   rg   T   r   N)rN   r   rh   _title_rich_title	_shortcut_description_section_icon_dataro   rn   _section_visibler   r   ItemIsEnabledItemIsSelectablesetIcon_icon_widthr   r   )rP   ru   icontitledescriptionshortcutsectiondatatool_tipaction_itemrv   rS   s              r>   rh   zSwitcherItem.__init__   s    	lD!!**&*HHH$,ee"%-52+6>KKB#*2

' $ 	b&)<<=== 	!LL!D D!!!!!r@   c                 :   | j         r| j         }n|r|n| j        }|r|n| j        }| j        r|r|n| j        }nd}| j        }t          | j        | j        z
            }t          | 	                                          }| 
                    t          ||                     | j        rd| j        z   dz   nd}t          |d          }t          |d          }t          |d          }t          |d          } | j        j        d|||||||d| j        }|S )rx   r:   z&lt;z&gt;zutf-8)encoding)r   r   r   r   r   r   r   r   )r   r   r   r   r   rk   rs   rj   r   r   rr   r   r   r   r   r   rm   )	rP   r   r   r   r   r   r   r   r<   s	            r>   r|   zSwitcherItem._render_text@  sW    	4$EE"3EEE &1Gkkd6G  	!(;ggdmGGG-DK$"2233T__&&''uf--...7;~M6DN*V332uw777 7;;;$[7CCC!(W===$t~$ 55u-4+-4x5 5 (,|5 5 r@   c                 >   | j         D ] }|| j        vr| j        |         | j        |<   !| j        d         }t          j        dk    r|}|dz   }n;t
          j        dk    r|}|dz   }n#t                      r|dz
  }|dz   }n
|dz
  }|dz   }|| j        d<   || j        d<   dS )	r   r&   r   r   r      r'   r(   Nr   )rP   r   r   r&   r'   s        r>   r   zSwitcherItem._set_stylesa  s    * 	8 	8D4<''%)\$%7T"L!23	<8##'O$3a$7!!W__'O$3a$7!![[ 	8'!mO$3a$7!!'!mO$3a$7!0E,-,A()))r@   c                 R   t                      }	 |                    d                    | j        d                              n%# t          $ r |                    d           Y nw xY w|                    | j                   |                                                                S )r   z)<span style="font-size:{}pt">Title</span>r&   z<span>Title</span>)	r   r   r   rm   KeyErrorr   rk   r   r   r   s     r>   rp   zSwitcherItem._get_heighty  s    
 oo	.KKC-> ?@@B B B B 	. 	. 	.KK,-----	.dm,,,xxzz  """s   3A A&%A&c                 >    || _         |                     |           dS )z Set the QIcon for the list item.N)r   r   )rP   r   s     r>   set_iconzSwitcherItem.set_icon  s!    
Tr@   c                     | j         S )z#Return the QIcon for the list item.)r   r{   s    r>   get_iconzSwitcherItem.get_icon  
    zr@   c                 <    || _         |                                  dS )z&Set the main text (title) of the item.N)r   r   r   s     r>   	set_titlezSwitcherItem.set_title  r   r@   c                     | j         S )z-Return the the main text (title) of the item.)r   r{   s    r>   	get_titlezSwitcherItem.get_title  r   r@   c                 <    || _         |                                  dS )z:Set the rich title version (filter highlight) of the item.N)r   r   r   s     r>   set_rich_titlezSwitcherItem.set_rich_title  s"     !!!!!r@   c                     | j         S )z=Return the rich title version (filter highlight) of the item.)r   r{   s    r>   get_rich_titlezSwitcherItem.get_rich_title  s    r@   c                 <    || _         |                                  dS )zSet the item description text.N)r   r   r   s     r>   set_descriptionzSwitcherItem.set_description  "    !!!!!!r@   c                     | j         S )z!Return the item description text.)r   r{   s    r>   get_descriptionzSwitcherItem.get_description  s      r@   c                 <    || _         |                                  dS )z%Set the shortcut for the item action.N)r   r   r   s     r>   set_shortcutzSwitcherItem.set_shortcut  s!    !!!!!r@   c                     | j         S )z(Return the shortcut for the item action.)r   r   s     r>   get_shortcutzSwitcherItem.get_shortcut  s
    ~r@   c                 X    t          t          |                               |           dS )z"Set the tooltip text for the item.N)rN   r   
setTooltip)rP   r   rS   s     r>   set_tooltipzSwitcherItem.set_tooltip  s'    lD!!,,U33333r@   c                     || _         dS )z/Set the additional data associated to the item.Nr   r   s     r>   set_datazSwitcherItem.set_data  s    


r@   c                     | j         S )z2Return the additional data associated to the item.r   r{   s    r>   get_datazSwitcherItem.get_data  r   r@   c                 <    || _         |                                  dS )zSet the item section name.N)r   r   r   s     r>   set_sectionzSwitcherItem.set_section  s!    !!!!!r@   c                     | j         S )zReturn the item section name.)r   r{   s    r>   get_sectionzSwitcherItem.get_section  
    }r@   c                 <    || _         |                                  dS )z#Set visibility of the item section.N)r   r   r   s     r>   set_section_visiblez SwitcherItem.set_section_visible  s"     %!!!!!r@   c                 <    || _         |                                  dS )z,Enable/disable the action type for the item.N)rn   r   r   s     r>   set_action_itemzSwitcherItem.set_action_item  r   r@   )NNN)#rT   rU   rV   rW   
_FONT_SIZEr   r   r   r<   r+   r   r   r   rh   r|   r   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rX   rY   s   @r>   r   r      s         J/ / /
 ,|+--2244::<<AACC1,.%!+'(	 	GI0 #Tt4$"7" " " " " "@   BB B B0# # #  
  " " "
  " " "
     " " "
! ! !" " "
  4 4 4 4 4    " " "
  " " "
" " " " " " "r@   r   c                   <     e Zd ZdZd fd	Zd Zd Zd Zd Z xZ	S )	SwitcherProxyModelz5A proxy model to perform sorting on the scored items.Nc                    t          t          |                               |           |                     t          j                   |                     t          j                   |                     d           d| _        dS )z3Proxy model to perform sorting on the scored items.TFN)	rN   r  rh   setFilterCaseSensitivityr   CaseInsensitivesetSortCaseSensitivitysetDynamicSortFilter$_SwitcherProxyModel__filter_by_score)rP   ru   rS   s     r>   rh   zSwitcherProxyModel.__init__  sr     $''00888%%b&8999##B$6777!!$'''!&r@   c                 <    || _         |                                  dS )z
        Set whether the items should be filtered by their score result.

        Parameters
        ----------
        value : bool
           Indicates whether the items should be filtered by their
           score result.
        N)r
  invalidateFilterr   s     r>   set_filter_by_scorez&SwitcherProxyModel.set_filter_by_score  s$     "'r@   c                     |                                                      |          }| j        du s|                                rdS |                                dk     S )z9Override Qt method to filter items by their score result.FTrg   )sourceModelitemr
  r   r   )rP   
source_rowsource_parentr  s       r>   filterAcceptsRowz#SwitcherProxyModel.filterAcceptsRow  s]    !!&&z22!U**d.A.A.C.C*4~~''2---r@   c                 |    || _         |                                  |                     dt          j                   dS Override Qt method.r   N)_SwitcherProxyModel__sort_by
invalidatesortr   AscendingOrder)rP   r   s     r>   sortByzSwitcherProxyModel.sortBy  s6    		!R&'''''r@   c                 ,   |                                                      |          }|                                                      |          }t          || j                  r0t	          || j                  }t	          || j                  }||k     S dS r  N)r  itemFromIndexhasattrr  getattr)rP   leftright	left_item
right_item	left_data
right_datas          r>   lessThanzSwitcherProxyModel.lessThan  s    $$&&44T::	%%''55e<<
 9dn-- 	*	4>::I T^<<Jz))	* 	*r@   N)
rT   rU   rV   rW   rh   r  r  r  r'  rX   rY   s   @r>   r  r    s        ??' ' ' ' ' '     . . .( ( (	* 	* 	* 	* 	* 	* 	*r@   r  c                   
    e Zd ZdZ e            Z eed                   Z ee          Z	 eeed         ed                   Z
 eed                   ZdZdZdZdZedz
  Zdeef fd		Zd(dZd Zd Zd Zd Zd Zd Z	 	 	 d)dZd Zd Zd Zd Zd Z  e!e"e"          d             Z# e!             e!e$          d*d                        Z% fdZ& fdZ' fdZ(d Z)d Z*d  Z+d! Z,d" Z-d# Z.d$ Z/d% Z0d& Z1d' Z2 xZ3S )+Switchera  
    A multi purpose switcher.

    Example
    -------
      SwitcherItem:      [title description    <shortcut> section]
      SwitcherItem:      [title description    <shortcut> section]
      SwitcherSeparator: [---------------------------------------]
      SwitcherItem:      [title description    <shortcut> section]
      SwitcherItem:      [title description    <shortcut> section]
    rg      iD     i  r   Nc                 X   t          t          |                               |           i | _        d| _        || _        || _        t          |           | _        t          |           | _
        t          | j
                  | _        t          | j
                  | _        t                      | _        |                     t$          j        t$          j        z             |                     d           |                     | j                   | j                            | j                   | j                            |r|nd           | j
                            | j                   | j
                            t;          |                      | j
                            t$          j                   | j
                             | j
        j!                   | j
        "                    | j
        j#                   | j
        $                    tJ          j&                   | j        '                    | j                   | j
        (                    | j                   tS                      }|*                    | j                   |*                    | j
                   | +                    |           | j        j,        -                    | j.                   | j        j/        -                    | j0                   | j        j1        -                    | j2                   | j        j3        -                    | j4                   | j        j3        -                    | j5                   | j        j6        -                    | j2                   | j
        j7        -                    | j2                   | j
        j7        -                    | j        j8                   | j
        9                                j:        -                    | j;                   | j        8                                 dS )zMulti purpose switcher.r:   gffffff?N)<rN   r*  rh   _modes_mode_on_item_styles_item_separator_stylesr   editr   listr   modelr  proxyrB   filtersetWindowFlagsr   PopupFramelessWindowHintsetWindowOpacitysetMaximumHeight_MAX_HEIGHTinstallEventFiltersetPlaceholderTextsetMinimumWidth
_MIN_WIDTHsetItemDelegater[   setFocusPolicyNoFocussetSelectionBehaviorSelectItemssetSelectionModeSingleSelectionsetVerticalScrollModer   ScrollPerItemsetSourceModelsetModelr   	addWidget	setLayoutrH   connectprevious_rowrK   next_rowrM   entertextChangedsetupsig_text_changedreturnPressedclickedsetFocusselectionModelcurrentChangedcurrent_item_changed)rP   ru   	help_textitem_stylesitem_separator_styleslayoutrS   s         r>   rh   zSwitcher.__init__&  sN    	h&&v...'&;# dOO	dOO	'	22
'	22
$&& 	BHr'==>>>d###d.///	$$T[111	$$)%CYYDDD	!!$/222	!!"24"8"8999	  ,,,	&&ty'<===	""49#<===	''(9(GHHH
!!$*---	4:&&& ######v 	&..t/@AAA(00???)11$*===	%%dj111	%%d&;<<<	''
333	!!$*---	!!$)"4555	  ""199%	' 	' 	'	r@   Tc                     |                     | j                   | j                            |           |r)|                     d           |                                  |                                  dS )z)Perform common actions when adding items.r   N)r   _ITEM_WIDTHr4  	appendRowset_current_row
set_heightsetup_sections)rP   r  	last_items      r>   	_add_itemzSwitcher._add_itemZ  ss    t'(((
T""" 	   ###OOr@   c                     |                      d           | j                                         | j                                         | j                                         |                     | j                   dS )z9Remove all items from the list and clear the search text.r:   N)set_placeholder_textr4  beginResetModelclearendResetModelsetMinimumHeight_MIN_HEIGHTr{   s    r>   rj  zSwitcher.clearg  so    !!"%%%
""$$$

  """d./////r@   c                 :    | j                             |           dS )z.Set the text appearing on the empty line edit.N)r2  r>  )rP   r<   s     r>   rh  zSwitcher.set_placeholder_texto  s    	$$T*****r@   c                 ^    t          |          dk    r|| j        |<   dS t          d          )z&Add mode by token key and description.r   zToken must be of length 1!N)lenr.  	Exception)rP   tokenr   s      r>   add_modezSwitcher.add_modes  s2    u::??!,DK8999r@   c                     | j         S )z(Get the current mode the switcher is in.)r/  r{   s    r>   get_modezSwitcher.get_modez  r   r@   c                 P    || j         v r| j                             |           dS dS )zRemove mode by token key.N)r.  pop)rP   rr  s     r>   remove_modezSwitcher.remove_mode~  s1    DKKOOE"""""  r@   c                     | ` i | _         dS )z%Delete all modes spreviously defined.N)r.  r{   s    r>   clear_modeszSwitcher.clear_modes  s    Kr@   Fc
                 z    t          | j        ||||||||| j        
  
        }
|                     |
|	           dS )zAdd switcher list item.)
ru   r   r   r   r   r   r   r   r   rv   )re  N)r   r3  r0  rf  )rP   r   r   r   r   r   r   r   r   re  r  s              r>   add_itemzSwitcher.add_item  sY     9##$
 
 
 	ty11111r@   c                 f    t          | j        | j                  }|                     |           dS )zAdd separator item.r   N)r   r3  r1  rf  rP   r  s     r>   add_separatorzSwitcher.add_separator  s;    $DI,0,GI I Itr@   c                    | j         }|r*|                                 t          |          d         }n|                                 }|                                 dk    rVd| _         |                                  | j                            d           | j                            | j                    dS | j        D ]O}|                                 	                    |          r&|s$|| _         | j                            |            dS Pg }t          | j                                                  D ]]}| j                            |          }t          |t                    r|                                }nd}|                    |           ^t%          |          }t'          t)          |          |d          }t+          |          D ]\  }	\  }}
}| j                            |	          }|                     |          s?|                                s+|
                    dd          }
|                    |
           |                    |           | j                            d           |                                  |                                 r|                     d	           n|                     d
           |                                  dS )z2Set-up list widget content based on the filtering.Nr:   Fz
<b>{0}</b>)template z&nbsp;Tr   rg   )r/  search_textrp  rj  r5  r  sig_mode_selectedrI   r.  
startswithranger4  rowCountr  
isinstancer   r   appendr?   r   r   	enumerate_is_separatorr   r;   r   r   rd  countrb  rc  )rP   moder  rF   titlesrowr  r   scoresidx
rich_titlescore_values               r>   rS  zSwitcher.setup  s    } 	-**,,SYYZZ8KK**,,K ##DMJJLLLJ**5111"''666F ; 	 	C!!,,S11 $  #&++C000 ,,..// 	! 	!C:??3''D$-- ((MM%    ";//">+#>#>#)MC C C 6?v5F5F 	( 	(1C1%[:??3''D%%d++ 0D4G4G4I4I 0'//X>>
##J///NN;''''
&&t,,,::<< 	%  ####  $$$r@   c                 *   | j         }|r*|                                 t          |          d         }n|                                 }|rot          | j                                                  D ]F}| j                            |          }t          |t                    r|	                    d           Gng }t          | j                                                  D ]}| j                            |          }t          |t                    rJ|
                    |                                           |	                    t          |                     n|
                    d           |dk    r@||         ||dz
           k    }|                     |          s|	                    |           |	                    d           | j                            d           | j                            |                                            dS )z.Set-up which sections appear on the item list.NFr:   r   r   Tro   )r/  r  rp  r  r4  r  r  r  r   r   r  r   r   r  r5  r  sig_item_changedrI   current_item)rP   r  r  r  r  sectionsvisibles          r>   rd  zSwitcher.setup_sections  s   } 	-**,,SYYZZ8KK**,,K 	3TZ002233 4 4zs++dL11 4,,U3334
 HTZ002233 3 3zs++dL11 (OOD$4$4$6$6777,,T+->->????OOB'''!88&smxa/@@G--d33 :00999,,T2222
(###""4#4#4#6#677777r@   c                 >   |                                  | j        k    r| j        }n|                                  dk    r|                                 r|                                 }|                                }||                                  dz   z  }| j                                        }|                                                                 dz  }||z   |z   }t          || j
                  }n| j
        }|                     t          |                     dS )z3Set height taking into account the number of items.r   r      N)r  _MAX_NUM_ITEMSr<  r  r   r2  r   r^  spacingmaxrm  setFixedHeightrs   )rP   switcher_heightr  item_heightlist_heightedit_heightspacing_heights          r>   rc  zSwitcher.set_height  s    ::<<4...".OOZZ\\Q4#4#4#6#6,,..L&1133K%)9:K)**,,K![[]]2244q8N)K7.HO!/43CDDOO".OC0011111r@   c                    |                                  }||                                }| j                                        }|                                                                dz  |dz  z
  }|rX|                                }||                                z  }||                                z  }|                                 }|X|                     t          |          |           dS dS )zSet the position of the dialog.Nr   )ru   geometryr3  r   topr!  moveround)rP   r  ru   geor   r!  s         r>   set_positionzSwitcher.set_position  s    //##CIOO%%E??$$**,,Q.q8D )oo''swwyy 

"	  ) IIeDkk3''''' r@   c                 ^    | j                             |                                            dS )zHandle item selection.N)r  rI   r  )rP   currentpreviouss      r>   rZ  zSwitcher.current_item_changed  s-     	""4#4#4#6#677777r@   c                    |                                  }| j                            | j                            |d                    }| j                            |                                          }|rL| j        }| j        	                    ||| 
                                t          |          d                    dS dS r  )current_rowr5  mapToSourcerb   r4  r  r  r/  sig_item_selectedrI   r  rp  )rP   itemClickedr  model_indexr  r  s         r>   rQ  zSwitcher.enter  s       j,,TZ-=-=c1-E-EFFz{0011 	H=D"''d(,(8(8(:(:3t99::(FH H H H H	H 	Hr@   c                 V    t          t          |                                            dS r  )rN   r*  acceptr   s    r>   r  zSwitcher.accept)  s%    h$$&&&&&r@   c                     |                      d           | j                                         t          t          |                                            dS )r  r:   N)set_search_textsig_rejectedrI   rN   r*  rejectr   s    r>   r  zSwitcher.reject-  sN    R      h$$&&&&&r@   c                 X    t          t          |                               |           dS r  )rN   r*  resizeEvent)rP   eventrS   s     r>   r  zSwitcher.resizeEvent3  s'    h))%00000r@   c                 r    t          | j                                                                                  S )z9Get the normalized (lowecase) content of the search text.)r   r2  r<   lowerr{   s    r>   r  zSwitcher.search_text8  s(    dinn..//55777r@   c                 :    | j                             |           dS )z#Set the content of the search text.N)r2  r   )rP   strings     r>   r  zSwitcher.set_search_text<  s    	&!!!!!r@   c                 ,    t          |t                    S )z;Check if item is an separator item (SwitcherSeparatorItem).)r  r   r~  s     r>   r  zSwitcher._is_separatorA  s    $ 5666r@   c                     |                                  |z   }d|cxk    r|                                 k     rn dS |                     |           dS dS )zSelect row in list widget based on a number of steps with direction.

        Steps can be positive (next rows) or negative (previous rows).
        r   N)r  r  rb  )rP   stepsr  s      r>   _select_rowzSwitcher._select_rowE  si    
   5(""""djjll""""""  %%%%% #"r@   c                 4    | j                                         S )z&Get the item count in the list widget.)r5  r  r{   s    r>   r  zSwitcher.countN  s    z""$$$r@   c                 X    | j                                                                         S )z3Return the current selected row in the list widget.)r3  currentIndexr  r{   s    r>   r  zSwitcher.current_rowR  s"    y%%''++---r@   c                     |                                  }| j                            | j                            |d                    }| j                            |                                          }|S )z4Return the current selected item in the list widget.r   )r  r5  r  rb   r4  r  r  )rP   r  r  r  s       r>   r  zSwitcher.current_itemV  s\      j,,TZ-=-=c1-E-EFFz{0011r@   c                     | j                             |d          }| j                                        }|                    ||j                   | j                            |t          j                   dS )z0Set the current selected row in the list widget.r   N)	r5  rb   r3  rX  setCurrentIndexClearAndSelectscrollTor   EnsureVisible)rP   r  proxy_indexselection_models       r>   rb  zSwitcher.set_current_row]  sr    j&&sA..)2244 	''7	9 	9 	9 		;(9(GHHHHHr@   c                    d}|                                  |z
  }|dk    r,|                     |                                 dz
             dS |dk    r|| j                            |d          }| j                            |          }| j                            |                                d          }| 	                    |          r|dz  }| 
                    |            dS )z#Select previous row in list widget.r   rg   r   N)r  rb  r  r5  rb   r  r4  r  r  r  r  )rP   r  prev_row
list_indexr  r  s         r>   rO  zSwitcher.previous_rowi  s    ##%%-r>>  !1222221}}!Z--h::
"j44Z@@z{'8'8!<<%%d++ QJEeV$$$$$r@   c                    d}|                                  |z   }| j                            |d          }| j                            |          }| j                            |                                d          }||                                 k    r|                     d           dS |r| 	                    |          r|dz  }| 
                    |           dS )zSelect next row in list widget.r   r   N)r  r5  rb   r  r4  r  r  r  rb  r  r  )rP   r  rP  r  r  r  s         r>   rP  zSwitcher.next_rowz  s    ##%%- Z%%h22
j,,Z88z{00!44tzz||##  ##### %%d++ QJEU#####r@   )T)	NNNNNNNFTr(  )4rT   rU   rV   rW   r   r  r   rT  objectr  r  r  r  r@  rm  r<  r`  ITEM_STYLESITEM_SEPARATOR_STYLESrh   rf  rj  rh  rs  ru  rx  rz  r|  r  rS  rd  rc  r  r	   r
   rZ  r   rQ  r  r  r  r  r  r  r  r  r  r  rb  rO  rP  rX   rY   s   @r>   r*  r*  	  s       
 
 688Lvjn--vf~~vz"~z"~HHz"~..NJKKr/K)-;'<1 1 1 1 1 1h
 
 
 
0 0 0+ + +: : :  # # #
  
 JNEJ2 2 2 2$  3 3 3j8 8 8B2 2 2 ( ( (  
T+{##8 8 $#8 
TVV	T/H H H  VH' ' ' ' '' ' ' ' '1 1 1 1 1
8 8 8" " "
7 7 7& & &% % %. . .  
I 
I 
I% % %"$ $ $ $ $ $ $r@   r*  c                    |                                   |                     d           |                     ddt          j        d                     |                     dd           |                     d	d
           |                     dd           |                                  |                     dd           dS )zAdd example data for vcs.zSelect a ref to CheckoutzCreate New BranchTMessageBoxInformation)r   r   r   master123123)r   r   develop1231232au   test-试	1231232abotherq2211231232aN)rj  rh  r|  r   r   r  sws    r>   create_vcs_example_switcherr    s    HHJJJ6777KK)tX566  8 8 8KKhHK555KKiZK888KKk{K;;;KKg>K:::::r@   c                 t   |                                   |                     d           t          d          }|                     t          d          d|d           |                     t          d          d|           |                     t          d	          |
           |                                  t          d          }|                     t          d          d|           |                     t          d          |
           |                     t          d          |
           dS )zAdd example actions.zSelect Actionzchange viewzIndent Using SpacesTestzCtrl+I)r   r   r   r   zIndent Using Tabs)r   r   r   zDetect Indentation from Contentr   r   zconvert filezConvert Indentation to SpaceszConvert Indentation to TabszTrim Trailing WhitespaceN)rj  rh  r   r|  r  )r  r   s     r>   create_options_example_switcherr    s5   HHJJJO,,,GKKa-..F(  4 4 4KKa+,,&  ! ! !KKa9::GKLLLGKKa788f  ! ! !KKa566KHHHKKa233WKEEEEEr@   c                 V   |                                   |                     t          d          d           |                                  |                     t          d          d           |                                  |                     t          d          d           dS )	zAdd help data.zHelp me!1r  z
Help me 2!2z
Help me 3!3N)rj  r|  r   r  r  s    r>   create_help_example_switcherr    s    HHJJJKKa
mmSK111KKaoosK333KKaoosK33333r@   c                 v    |                                   |                     t          d          d           dS )zAdd current line example.zCurrent line, type somethingT)r   r   Nrj  r|  r   r  s    r>   create_line_example_switcherr    s4    HHJJJKKa677TKJJJJJr@   c                     |                                   |                     t          d                     |                     t          d                     dS )zAdd symbol data example.zSome symbol)r   zanother symbolNr  r  s    r>   create_symbol_example_switcherr    sN    HHJJJKKa&&K'''KKa())K*****r@   c                    | t                      } t          |                               dt          d                                         dt          d                                         dt          d                                         dt          d	                     fd
}d }j                            |           j                            |           t                                                      dS )zCreate example switcher.N>Commandsr2   Help:z
Go to Line@zGo to Symbol in Filec                     | dk    rt                     d S | dk    rt                     d S | dk    rt                     d S | dk    rt                     d S | dk    rt	                     d S d S )Nr  r2   r  r  r:   )r  r  r  r  r  )r  r  s    r>   handle_modesz-create_example_switcher.<locals>.handle_modes  s    3;;+B/////S[[(,,,,,S[[(,,,,,S[[*2.....RZZ'+++++ Zr@   c                 r    t          | ||g           t          |                                 ||g           d S r(  )printr   )r  r  r  s      r>   item_selectedz.create_example_switcher.<locals>.item_selected  s<    tT;'(((t~~{344444r@   )	r   r*  rs  r   r  rN  r  r  show)mainr  r  r  s      @r>   create_example_switcherr    s     |{{	$BKKQz]]###KKQvYYKKQ|__%%%KKQ-..///
, 
, 
, 
, 
,5 5 5   ...  ///###GGIIIIIr@   c                 n    ddl m}  |            }t          |            |                                 dS )z*Launch the switcher with some test values.r   )qapplication)r  N)spyder.utils.qthelpersr   r  exec_)r  r   apps      r>   testr    sA    333333
,..C&&&&IIKKKKKr@   __main__r(  )<rW   r   r   qtpy.QtCorer   r   r   r   r   r   r	   r
   
qtpy.QtGuir   r   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   spyder.config.baser   spyder.config.managerr   spyder.config.utilsr   spyder.py3compatr   r   spyder.utils.icon_managerr   spyder.utils.stringmatchingr   spyder.widgets.helperwidgetsr   	FONT_SIZEMAIN_FG_COLORr  r  r?   rB   r[   rd   r   r   r  r*  r  r  r  r  r  r  r  rT   r   r@   r>   <module>r     s   !   
			 



4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 G G G G G G G G G G) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
 !           & & & & & & ) ) ) ) ) ) 7 7 7 7 7 7 7 7 ) ) ) ) ) ) 9 9 9 9 9 9 5 5 5 5 5 5 	(1,.$!*&'	 	 "    ? ? ? ? ?W ? ? ?,D D D D D| D D DL" L" L" L" L"} L" L" L"^A# A# A# A# A#, A# A# A#Hc" c" c" c" c"# c" c" c"L/* /* /* /* /*. /* /* /*hA$ A$ A$ A$ A$w A$ A$ A$H
; 
; 
;F F F$4 4 4K K K+ + +   D    zDFFFFF r@   