
    Je              	          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#jR                  ddde(e(e(e(dZ*e#jR                  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:        yy)*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                 8    dD ]  }| j                  |d      }  | S )z,Remove regex special characters from string.)().\?*[]&|^+ )replace)textchs     9/usr/lib/python3/dist-packages/spyder/widgets/switcher.pyclean_stringr?   1   s&    K $||B#$K    c                   L     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                    |j                         t        j                  k(  r|j                         t        j
                  k(  r| j                  j                          y|j                         t        j                  k(  r| j                  j                          y|j                         t        j                  k(  r| j                  j                          y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    668v&uuw"))#'',,.BKK'))..0%%'R]]***//1^T6sA>>r@   )
__name__
__module____qualname____doc__r   rH   rK   rM   rO   __classcell__rS   s   @r>   rB   rB   8   s(    N!8"H? ?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                 v    |xj                   t        j                  z  c_         t        t        |   |||       y)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   s-     	++++GVUCr@   )rT   rU   rV   rW   r_   rX   rY   s   @r>   r[   r[   N   s    
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        |           | j                  | _        | j
                  | _        |r|ni | _        d| _        d| _	        | j                         | _        | j                  t        dt        | j                                     y)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   ss    .0 kk!'vR!'')
 	q#dll"345r@   c                     t         )'Render the html template for this item.NotImplementedErrorrP   s    r>   _render_textzSwitcherBaseItem._render_textu       !!r@   c                 B    | j                  | j                                y)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
  | _        | j                          y)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                 2    || _         | j                          y)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                 j    t         t        |           | j                          | j	                          y)zOverride Qt.N)rN   rd   refreshr   r   rP   rS   s    r>   r   zSwitcherBaseItem.refresh   s)    -/!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""*"""
"
'
" "r@   rd   c                        e Zd ZdZdZddgZ ej                         j                         j                         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        |   ||       | j                  t        j
                         | j                          y)z#Separator Item represented as <hr>.ru   rv   N)rN   r   rh   setFlagsr   NoItemFlagsr   rt   s      r>   rh   zSwitcherSeparatorItem.__init__   s:    #T36;A 	4 	Cbnn%!r@   c                 :   | j                   D ]-  }|| j                  vs| 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<   y)r   r,   darwinnt   N_STYLE_ATTRIBUTESrm   r   sysplatformosnamer   )rP   attr	rich_fontr,   s       r>   r   z!SwitcherSeparatorItem._set_styles   s    ** 	8D4<<'%)\\$%7T"	8 LL-	<<8#!IWW_!I[!AI!AI$-[!r@   c                     | j                   }| 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   sV    --"$t~~$$ F5-4F8<Fr@   c                     t               }|j                  d       |j                  | j                         |j	                         j                         S )r   z<hr>)r   setHtmlsetDocumentMarginrk   sizer   rP   docs     r>   rp   z!SwitcherSeparatorItem._get_height   s>    
 oFdmm,xxz  ""r@   )rT   rU   rV   rW   
_SEPARATORr   r   paletter<   r+   r   r   r   rh   r   r|   rp   rX   rY   s   @r>   r   r      sr     J +.%%%',,.446;;=G
	  #7 ".&#r@   r   c            
       N    e Zd ZdZdZg dZ ej                         j                         j                         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| _        | j                  t        j                  t        j                   z         |r| j#                  |       d| _        nd| _        | j'                          | j)                          y)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$e"%-2+6KB#*

' $ 	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        | j                               }| j                  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@  s"   $$E"EE &1kd6G6G  !(gdmmGG--DKK$"2"223T__&'uf-.7;~~6DNN*V32uw7 7;$[7C!(W=$t~~$$ 55u-4+-4x5 (,||5 r@   c                    | j                   D ]-  }|| j                  vs| 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<   y)	r   r&   r   r   r      r'   r(   Nr   )rP   r   r   r&   r'   s        r>   r   zSwitcherItem._set_stylesa  s    ** 	8D4<<'%)\\$%7T"	8 LL!23	<<8#'O$3a$7!WW_'O$3a$7!['!mO$3a$7!'!mO$3a$7!0E,-,A()r@   c                 $   t               }	 |j                  dj                  | j                  d                |j                  | j                         |j                         j                         S # t        $ r |j                  d       Y Uw xY w)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{    
 o	.KKC-> ?@B 	dmm,xxz  ""  	.KK,-	.s   -A2 2BBc                 4    || _         | j                  |       y)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      zzr@   c                 2    || _         | j                          y)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                 2    || _         | j                          y)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                 2    || _         | j                          y)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                 2    || _         | j                          y)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                 ,    t         t        |   |       y)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3r@   c                     || _         y)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                 2    || _         | j                          y)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                 2    || _         | j                          y)z#Set visibility of the item section.N)r   r   r   s     r>   set_section_visiblez SwitcherItem.set_section_visible  s     %!r@   c                 2    || _         | j                          y)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::<AAC1,.%!+'(	GI0 #Tt4$"7"@BB0#
"
"
 "
!"
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.c                     t         t        |   |       | j                  t        j
                         | j                  t        j
                         | j                  d       d| _        y)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__  sQ     $08%%b&8&89##B$6$67!!$'!&r@   c                 2    || _         | j                          y)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                         j                  |      }| j                  du s|j                         ry|j	                         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  sL    !&&z2!!U*d.A.A.C~~'2---r@   c                 r    || _         | j                          | j                  dt        j                         yOverride Qt method.r   N)_SwitcherProxyModel__sort_by
invalidatesortr   AscendingOrder)rP   r   s     r>   sortByzSwitcherProxyModel.sortBy  s'    		!R&&'r@   c                    | j                         j                  |      }| j                         j                  |      }t        || j                        r1t	        || j                        }t	        || j                        }||k  S yr  N)r  itemFromIndexhasattrr  getattr)rP   leftright	left_item
right_item	left_data
right_datas          r>   lessThanzSwitcherProxyModel.lessThan  st    $$&44T:	%%'55e<
 9dnn-	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                 D	   t         t        |   |       i | _        d| _        || _        || _        t        |       | _        t        |       | _
        t        | j                        | _        t        | j                        | _        t               | _        | j#                  t$        j&                  t$        j(                  z         | j+                  d       | j-                  | j.                         | j                  j1                  | j                          | j                  j3                  |r|nd       | j                  j5                  | j6                         | j                  j9                  t;        |              | j                  j=                  t$        j>                         | j                  jA                  | j                  jB                         | j                  jE                  | j                  jF                         | j                  jI                  tJ        jL                         | j                  jO                  | j                         | j                  jQ                  | j                         tS               }|jU                  | j                         |jU                  | j                         | jW                  |       | j                   jX                  j[                  | j\                         | j                   j^                  j[                  | j`                         | j                   jb                  j[                  | jd                         | j                  jf                  j[                  | jh                         | j                  jf                  j[                  | jj                         | j                  jl                  j[                  | jd                         | j                  jn                  j[                  | jd                         | j                  jn                  j[                  | j                  jp                         | j                  js                         jt                  j[                  | jv                         | j                  jq                          y)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__&  s    	h&v.'&;# dO	dO	'		2
'		2
$& 	BHHr'='==>d#d../		$$T[[1		$$)YD		!!$//2		!!"24"89		  ,		&&tyy'<'<=		""499#<#<=		''(9(G(GH

!!$**-		4::& ##v 	&&..t/@/@A((00?))11$**=		%%djj1		%%d&;&;<		''

3		!!$**-		!!$))"4"45		  "1199%%	'		r@   c                     |j                  | j                         | j                  j                  |       |r!| j	                  d       | j                          | j                          y)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  sO    t''(

T"   #OOr@   c                     | j                  d       | j                  j                          | j                  j                          | j                  j	                          | j                  | j                         y)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  sT    !!"%

""$



  "d../r@   c                 :    | j                   j                  |       y)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    t        |      dk(  r|| j                  |<   y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  s'    u:?!,DKK8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                 X    || j                   v r| j                   j                  |       yy)zRemove mode by token key.N)r.  pop)rP   rr  s     r>   remove_modezSwitcher.remove_mode~  s#    DKKKKOOE"  r@   c                     | ` i | _         y)z%Delete all modes spreviously defined.N)r.  r{   s    r>   clear_modeszSwitcher.clear_modes  s    Kr@   c
                 |    t        | j                  ||||||||| j                  
      }
| j                  |
|	       y)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  sH     99##$$
 	ty1r@   c                 h    t        | j                  | j                        }| j                  |       y)zAdd separator item.r   N)r   r3  r1  rf  rP   r  s     r>   add_separatorzSwitcher.add_separator  s(    $DII,0,G,GItr@   c                    | j                   }|r| j                         t        |      d }n| j                         }| j                         dk(  rXd| _         | j                          | j                  j                  d       | j                  j                  | j                          y| j                  D ]H  }| j                         j                  |      s#|r&|| _         | j                  j                  |        y g }t        | j                  j                               D ]Q  }| j                  j                  |      }t        |t              r|j!                         }nd}|j#                  |       S t%        |      }t'        t)        |      |d      }t+        |      D ]y  \  }	\  }}
}| j                  j                  |	      }| j-                  |      s3|j/                         s#|
j1                  dd      }
|j3                  |
       |j5                  |       { | j                  j                  d       | j7                          | j9                         r| j;                  d	       n| j;                  d
       | j=                          y)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YZ8K**,K #DMJJLJJ**51""''6 ;; 	C!,,S1$ #&&++C0		 ,,./ 	!C::??3'D$-(MM% 	! #;/">+#>#)MC 6?v5F 	(1C1%[::??3'D%%d+D4G4G4I'//X>
##J/NN;'	( 	

&&t,::<  #  $r@   c                    | j                   }|r| j                         t        |      d }n| j                         }|rft        | j                  j                               D ]?  }| j                  j                  |      }t        |t              s/|j                  d       A ng }t        | j                  j                               D ]  }| j                  j                  |      }t        |t              r:|j                  |j                                |j                  t        |             n|j                  d       |dk7  r2||   ||dz
     k7  }| j                  |      r|j                  |       |j                  d        | j                  j                  d       | j                   j#                  | j%                                y)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  st   }}**,SYZ8K**,KTZZ0023 4zzs+dL1,,U34
 HTZZ0023 3zzs+dL1OOD$4$4$67,,T+->?OOB'!8&smxa/@@G--d3009,,T23 	

(#""4#4#4#67r@   c                 
   | j                         | j                  k\  r| j                  }n| j                         dk7  r| j                         r| j                         }|j	                         }|| j                         dz   z  }| j
                  j                         }| j                         j                         dz  }||z   |z   }t        || j                        }n| j                  }| j                  t        |             y)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..."..OZZ\Q4#4#4#6,,.L&113K%)9:K))**,K![[]224q8N)K7.HO!/43C3CDO"..OC01r@   c                    | j                         }||j                         }| j                  j                         }|j                         j                         dz  |dz  z
  }|rI|j                         }||j	                         z  }||j                         z  }|j                         }|rI| j                  t        |      |       yy)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IIOO%E??$**,Q.q8Doo'swwy 
"	  IIeDk3' r@   c                 V    | j                   j                  | j                                y)zHandle item selection.N)r  rI   r  )rP   currentpreviouss      r>   rZ  zSwitcher.current_item_changed  s!     	""4#4#4#67r@   c                 l   | j                         }| j                  j                  | j                  j                  |d            }| j                  j                  |j                               }|rD| j                  }| j                  j                  ||| j                         t        |      d        yy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      jj,,TZZ-=-=c1-EFzz{01==D""''d(,(8(8(:3t9:(FH r@   c                 *    t         t        |           yr  )rN   r*  acceptr   s    r>   r  zSwitcher.accept)  s    h$&r@   c                     | j                  d       | j                  j                          t        t        |           y)r  r:   N)set_search_textsig_rejectedrI   rN   r*  rejectr   s    r>   r  zSwitcher.reject-  s0    R  h$&r@   c                 ,    t         t        |   |       yr  )rN   r*  resizeEvent)rP   eventrS   s     r>   r  zSwitcher.resizeEvent3  s    h)%0r@   c                 d    t        | j                  j                               j                         S )z9Get the normalized (lowecase) content of the search text.)r   r2  r<   lowerr{   s    r>   r  zSwitcher.search_text8  s!    diinn./5577r@   c                 :    | j                   j                  |       y)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6r@   c                     | j                         |z   }d|cxk  r| j                         k  rn y| j                  |       yy)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  s=    
  5("djjl"  % #r@   c                 6    | j                   j                         S )z&Get the item count in the list widget.)r5  r  r{   s    r>   r  zSwitcher.countN  s    zz""$$r@   c                 R    | j                   j                         j                         S )z3Return the current selected row in the list widget.)r3  currentIndexr  r{   s    r>   r  zSwitcher.current_rowR  s    yy%%'++--r@   c                     | j                         }| j                  j                  | j                  j                  |d            }| j                  j                  |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  sS     jj,,TZZ-=-=c1-EFzz{01r@   c                     | j                   j                  |d      }| j                  j                         }|j	                  ||j
                         | j                  j                  |t        j                         y)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]  sb    jj&&sA.))224 	''77	9 			;(9(G(GHr@   c                    d}| j                         |z
  }|dk(  r#| j                  | j                         dz
         y|dk\  rw| j                  j	                  |d      }| j                  j                  |      }| j                  j                  |j                         d      }| j                  |      r|dz  }| j                  |        y)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1}!ZZ--h:
"jj44Z@zz{'8!<%%d+QJEeV$r@   c                    d}| j                         |z   }| j                  j                  |d      }| j                  j                  |      }| j                  j                  |j                         d      }|| j                         k\  r| j                  d       y|r| j                  |      r|dz  }| j                  |       y)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    ##%- ZZ%%h2
jj,,Z8zz{0!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*  	  sM   
 8Ljn-f~vz"~z"~Hz"~.NJKKr/K)-;'<1h
0+:#

 JNEJ2$3j8B2 (  
+{#8 $8 
V	/H  H''1
8"
7&%.
I%"$r@   r*  c                 L   | j                          | j                  d       | j                  ddt        j                  d             | j                  dd       | j                  d	d
       | j                  dd       | j                          | j                  dd       y)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    HHJ67KK)tXX56  8KKhHK5KKiZK8KKk{K;KKg>K:r@   c                    | j                          | j                  d       t        d      }| j                  t        d      d|d       | j                  t        d      d|       | j                  t        d	      |
       | j	                          t        d      }| j                  t        d      d|       | j                  t        d      |
       | j                  t        d      |
       y)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    s    HHJO,GKKa-.F(  4KKa+,&  !KKa9:GKLGKKa78f  !KKa56KHKKa23WKEr@   c                    | j                          | j                  t        d      d       | j                          | j                  t        d      d       | j                          | j                  t        d      d       y)	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_    HHJKKa
mSK1KKaosK3KKaosK3r@   c                 \    | j                          | j                  t        d      d       y)zAdd current line example.zCurrent line, type somethingT)r   r   Nrj  r|  r   r  s    r>   create_line_example_switcherr    s!    HHJKKa67TKJr@   c                     | j                          | j                  t        d             | j                  t        d             y)zAdd symbol data example.zSome symbol)r   zanother symbolNr  r  s    r>   create_symbol_example_switcherr    s2    HHJKKa&K'KKa()K*r@   c                    | 
t               } t        |       j                  dt        d             j                  dt        d             j                  dt        d             j                  dt        d	             fd
}d }j                  j                  |       j                  j                  |       t               j                          y)zCreate example switcher.N>Commandsr2   Help:z
Go to Line@zGo to Symbol in Filec                     | dk(  rt               y | dk(  rt               y | dk(  rt               y | dk(  rt               y | dk(  rt	               y y )Nr  r2   r  r  r:   )r  r  r  r  r  )r  r  s    r>   handle_modesz-create_example_switcher.<locals>.handle_modes  sS    3;+B/S[(,S[(,S[*2.RZ'+ r@   c                 X    t        | ||g       t        | j                         ||g       y r(  )printr   )r  r  r  s      r>   item_selectedz.create_example_switcher.<locals>.item_selected  s'    tT;'(t~~{34r@   )	r   r*  rs  r   r  rN  r  r  show)mainr  r  r  s      @r>   create_example_switcherr    s     |{	$BKKQz]#KKQvYKKQ|_%KKQ-./
,5   .  /#GGIr@   c                 V    ddl m}  |       }t        |        |j                          y)z*Launch the switcher with some test values.r   )qapplication)r  N)spyder.utils.qthelpersr   r  exec_)r  r   apps      r>   testr    s    3
.C&IIKr@   __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     s4   ! 
 
4 4 4 G G) ) )
 ! & ) 7 ) 9 5 	((1,.$!*&'	 "" ?W ?,D| DL"} L"^A#, A#Hc"# c"L/*. /*hA$w A$H
;F$4K+D zF r@   