
,]c           @  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" d d	 l# m$ Z$ m% Z% d d
 l& m' Z' m( Z( m) Z) m* Z* d d l+ m, Z, d d l- m. Z/ d d l0 m1 Z1 d d l2 m3 Z3 m4 Z4 d d l5 m6 Z6 d d l5 m7 Z7 i e j8 e j9 6e j: e j; 6e j< e j= 6e j> e j? 6Z@ g  eA d d  D] ZB d jC eB  ^ qd d g ZD d d d d d d d d d d d  d! d" d# d$ d% g d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 g g  eA d6  D] ZB eE eB  ^ q}d7 d8 d9 d: d; d< d= g g  eA d> d?  D] ZB eF eB  ^ qd@ dA dB dC dD dE dF dG g ZG g  eD D] ZH eI e dH jC eH   ^ qZJ g  eG eD D] ZH eI e dH jC eH   ^ q'ZK dI ZL dJ jC eL  ZM i e$ dK  dL 6e$ dM  dN 6ZN e jO dO k re$ dP  eN dQ <n  e$ dR  eN dF <dS e f dT     YZP dU e f dV     YZQ dW d dX dY dZ d[ g \ ZR ZS ZT ZU ZV ZW d\ e f d]     YZX d^ eY f d_     YZZ dW d dX dY g \ Z[ Z\ Z] Z^ d` e f da     YZ_ db e f dc     YZ` dd e! f de     YZa df e, f dg     YZb dh   Zc ed di k rec   n  d S(j   s   Shortcut managementi(   t   print_functionN(   t   PYQT5(   t   from_qvariantt   to_qvariant(   t   QAbstractTableModelt   QModelIndext   QRegExpt   QSortFilterProxyModelt   Qtt   Slot(   t   QKeySequencet   QRegExpValidator(   t   QAbstractItemViewt   QApplicationt   QDialogt   QDialogButtonBoxt   QGridLayoutt   QHBoxLayoutt   QLabelt	   QLineEditt   QMessageBoxt   QPushButtont   QSpacerItemt
   QTableViewt   QVBoxLayout(   t   _t   debug_print(   t   get_shortcutt   iter_shortcutst   reset_shortcutst   set_shortcut(   t   GeneralConfigPage(   t   icon_manager(   t   get_std_icon(   t   get_search_scorest   get_search_regex(   t   HTMLDelegate(   t   HelperToolButtoni   i$   s   F{}t   Deletet   Escapet   Tabt   Backtabt	   Backspacet   Returnt   Entert   Pauset   Printt   Cleart   Homet   Endt   Leftt   Upt   Rightt   Downt   PageUpt   PageDownt   Spacet   Exclamt   QuoteDblt
   NumberSignt   Dollart   Percentt	   Ampersandt
   Apostrophet	   ParenLeftt
   ParenRightt   Asteriskt   Plust   Commat   Minust   Periodt   Slashi
   t   Colont	   Semicolont   Lesst   Equalt   Greatert   Questiont   AtiA   i[   t   BracketLeftt	   Backslasht   BracketRightt
   Underscoret   Controlt   Altt   Shiftt   Metas   Key_{0}sS   ÁÉÍOÚáéíúóàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜñÑs   [A-Za-z\s{0}]s3   Currently used to delete lines on editor/Cut a words	   Shift+Dels   Currently used to paste a words	   Shift+Inst   nts*   We cannot support this shortcut on Windowss   Alt+Backspaces8   Shortcuts that use Shift and another key are unsupportedt   CustomLineEditc           B  s)   e  Z d  Z d   Z d   Z d   Z RS(   s8   QLineEdit that filters its key press and release events.c         C  s7   t  t |   j |  |  j t  |  j t j  d  S(   N(   t   superRX   t   __init__t   setReadOnlyt   Truet   setFocusPolicyR   t   NoFocus(   t   selft   parent(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ   O   s    c         C  s   |  j    j |  d S(   s   Qt OverrideN(   R`   t   keyPressEvent(   R_   t   e(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRa   T   s    c         C  s   |  j    j |  d S(   s   Qt OverrideN(   R`   t   keyReleaseEvent(   R_   Rb   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRc   X   s    (   t   __name__t
   __module__t   __doc__RZ   Ra   Rc   (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRX   M   s   		t   ShortcutFinderc           B  s,   e  Z d  Z d d  Z d   Z d   Z RS(   s4   Textbox for filtering listed shortcuts in the table.c         C  s_   t  t |   j |  | |  _ t t d  } |  j t |   | r[ |  j j	 |  n  d  S(   Ns   {100}(
   RY   Rg   RZ   t   _parentR   t   VALID_FINDER_CHARSt   setValidatorR   t   textChangedt   connect(   R_   R`   t   callbackt   regex(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ   _   s    	c         C  s-   | j    } |  j   | } |  j |  d S(   s   Set the filter text.N(   t   stript   textt   setText(   R_   Rp   t   new_text(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   set_textk   s    c         C  s   | j    } | t j g k r. |  j j   n` | t j g k rP |  j j   n> | t j t j g k rx |  j j	   n t
 t |   j |  d S(   s   Qt Override.N(   t   keyR   t   Key_UpRh   t   previous_rowt   Key_Downt   next_rowt	   Key_Entert
   Key_Returnt   show_editorRY   Rg   Ra   (   R_   t   eventRt   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRa   q   s    N(   Rd   Re   Rf   t   NoneRZ   Rs   Ra   (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRg   ]   s   	i    i   i   i   i   t   ShortcutEditorc           B  s   e  Z d  Z d   Z e   d    Z e   d    Z d   Z d   Z d   Z	 d   Z
 d   Z e g  d	  Z d
   Z d   Z RS(   s$   A dialog for entering key sequences.c         C  s`  t  t |   j |  | |  _ | |  _ d |  _ t   |  _ t   |  _ t	   |  _
 t	   |  _ | |  _ d  |  _ t |  _ | |  _ t   |  _ |  j j t d   t t d   |  _ t |  |  _ t t d   |  _ t |   |  _ |  j j |  t   |  _ |  j j   t   |  _ |  j j   t  t  j! t  j" B } | j# t  j!  |  _$ | j# t  j"  |  _% |  j& t d  j' |   |  j$ j( t) j*  |  j$ j+ t,  |  j% j( t) j*  |  j j- d  |  j j( t) j*  d } |  j j. |  |  j j( t) j*  |  j j( t) j*  d } t/   }	 |	 j0 |  j d d d	 d
  |	 j1 t2 | |  d	 d d	 d  |	 j0 |  j d d  |	 j0 |  j d d  |	 j0 |  j d
 d  |	 j0 |  j d
 d	  |	 j0 |  j d
 d  |	 j0 |  j d d d	 d  t3   }
 |
 j4 |	  |
 j5 |  |
 j0 |  |  j6 |
  | j7 j8 |  j9  | j: j8 |  j;  d  S(   Ni    s   Press the new shortcut and select 'Ok': 
(Press 'Tab' once to switch focus between the shortcut entry 
and the buttons below it)s   Current shortcut:s   New shortcut:s   Shortcut: {0}t    s   
            QToolButton {
              margin:1px;
              border: 0px solid grey;
              padding:0px;
              border-radius: 0px;
            }i   i   i   i   i   (<   RY   R~   RZ   Rh   t   contextt   npressedt   sett   keyst   key_modifierst   listt   key_non_modifierst   key_textt   sequenceR}   t   new_sequenceR\   t
   edit_statet	   shortcutsR   t
   label_infoRq   R   t   label_current_sequencet   text_current_sequencet   label_new_sequenceRX   t   text_new_sequencet   setPlaceholderTextR%   t   helper_buttont   hidet   label_warningR   t   Okt   Cancelt   buttont	   button_okt   button_cancelt   setWindowTitlet   formatR]   R   R^   t
   setEnabledt   Falset
   setToolTipt   setStyleSheetR   t	   addWidgett   addItemR   R   t	   addLayoutt
   addSpacingt	   setLayoutt   acceptedRl   t   acceptt   rejectedt   reject(   R_   R`   R   t   nameR   R   t   bboxt   stylet   spacingt   layout_sequencet   layout(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ      sj    								"	c         C  s$   |  j  j   t t |   j   d S(   s   Slot for rejected signal.N(   R   t   setFocusRY   R~   R   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR      s    c         C  s$   |  j  j   t t |   j   d S(   s   Slot for accepted signal.N(   R   R   RY   R~   R   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR      s    c         C  s  | j    } | t k r% t |  _ d S|  j d 7_ |  j j |  |  j j |  |  j	 j | j
    t |  _ t d j | |  j   | t j k r d S| t j k s | t j k s | t j k s | t j k r d S| j   } | t j @r| t j 7} n  | t j @rP| t j 7} t j d k rC|  j d 8_ n  t d  n  | t j @rm| t j 7} n  | t j @r| t j 7} n  |  j j |  d S(   s   Qt override.Ni   s   key {0}, npressed: {1}t   darwint   decrementing(    Rt   t
   VALID_KEYSR\   t   invalid_key_flagR   R   t   appendR   t   addR   Rp   R   R   R   R   t   Key_unknownt   Key_Controlt	   Key_Shiftt   Key_Altt   Key_Metat	   modifierst   ShiftModifiert   SHIFTt   ControlModifiert   CTRLt   syst   platformt   AltModifiert   ALTt   MetaModifiert   METAR   (   R_   Rb   Rt   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRa      s<    		c         C  sv   |  j  |  _  |  j  sU |  j j t  |  j j   rE |  j j   qr |  j j   n |  j j t  |  j j   d S(   s>   Switch between shortcut entry and Accept/Cancel shortcut mode.N(	   R   R   R   R   R   t	   isEnabledR   R   R\   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   toggle_state  s    	c         C  s   | j    } | t j g k r, |  j   d S| t j t j t j t j g k r |  j j	   ro |  j
 j   q |  j j   n  d S(   s%   Key release event for non-edit state.N(   Rt   R   t
   Key_Escapet   closet   Key_Leftt	   Key_RightRu   Rw   R   t   hasFocusR   R   (   R_   Rb   Rt   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   nonedit_keyrelease  s    
c         C  su  |  j  d 8_  |  j  d k rq| j   } t |  j  d k r\ | t j k r\ |  j   d St |  j  d k r | t j k r |  j d  |  j	 j
 t d   n  t |  j  d k r | t j t j g k r |  j   d S|  j s |  j |  qqt d j |  j   |  j r5| t j k r5|  j   n  t   |  _ t   |  _ t   |  _ t   |  _ d |  _  n  d S(   s   Qt override.i   i    NR   s%   Please introduce a different shortcuts   keys: {}(   R   Rt   t   lenR   R   t   Key_TabR   R   t   set_sequenceR   Rq   R   Rz   Ry   R   R   R   R   t   validate_sequenceR   R   R   R   R   (   R_   Rb   Rt   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRc   '  s,    $
$-
	c         C  s   g  } x{ t  |  j  D]j \ } } t | j  } | |  j k r | j |  j k sp | j d k sp |  j d k r | j |  q q W| S(   s   Check shortcuts for conflicts.R   (   t	   enumerateR   t   strRt   R   R   R   (   R_   t	   conflictst   indext   shortcutR   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   check_conflictsF  s    !c   
      C  s1  | t  k r t } d } n| t k r d } t d  d } d } x* | D]" } | d j | j | j  7} qJ W| d  } | j | |  } t } n)| t k r d } t d  d } d } t	 |  j
 }	 |	 d k	 r |	 } n  | j | |  } t } n | t k r\d } t d  d } d } t	 d	 }	 |	 d k	 rA|	 } n  | j | |  } t } nb | t k rd
 } t d  j i d d 6  } t } n+ | t k rd
 } t d  d } t } n  |  j j   | r|  j j   |  j j t d   |  j j t  n |  j j t d   |  j j |  d S(   s?   Update warning label to reflect conflict status of new shortcuts   This shortcut is correct!s   <i>{0}<b>{1}</b></i>s    The new shortcut conflicts with:s   <br>R   s    - {0}: {1}<br>is   Forbidden key sequence!RU   s
   <i>{0}</i>sH   A compound sequence can have {break} a maximum of 4 subsequences.{break}t   breaks   Invalid key enteredt   MessageBoxWarningt   DialogApplyButtonN(   t
   NO_WARNINGR   t   SEQUENCE_CONFLICTR   R   R   R   R\   t   IN_BLACKLISTt	   BLACKLISTR   R}   t   SHIFT_BLACKLISTt   SEQUENCE_LENGTHt   INVALID_KEYR   t   showR   t   setIconR!   R   R   Rq   (
   R_   t   warning_typeR   t   warnt   tipt   templatet	   tip_titlet   tip_bodyt   st   use(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   update_warningQ  s\    	 
			
				c         C  s  | s |  j  | k r/ |  j j t  t } n |  j j t  t } t j d k r d | k ru | j d d  } q d | k r | j d d  } q d | k r | j d d  } q d | k r | j d d  } q | } n | } |  j j	 |  | |  _
 |  j   } |  j
 t k } |  j
 j d	  } | rB| rBt } n@ | rQt } n1 t |  d
 k r|| d d k r|t } n t } |  j d | d |  d S(   s(   Set the new shortcut and update buttons.R   s	   Meta+Ctrls   Ctrl+Cmds	   Ctrl+Metas   Cmd+Ctrlt   Ctrlt   CmdRV   t   +i   i    RU   R   R   N(   R   R   R   R   R\   R   R   t   replaceR   Rq   R   R   R   t   splitR   R   R   R   R   R   (   R_   R   t   different_sequencet   shown_sequenceR   t	   blacklistt   individual_keysR   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR     s:    					"	c   
      C  s  |  j  r |  j d t  d SxL t D]D } t |  j  } | j |  | |  j k r$ |  j j |  q$ q$ W|  j | |  _ x# d |  j	 k r |  j	 j d  q Wg  |  j	 D] } | j
   ^ q |  _	 t j |  j k r|  j j t j  } t j |  j | <n  t |  j  d k rI|  j d t k r-d St |  j  d k rId Sn  t |  j  d k rr|  j d t  d Sg  } xc t t |  j   D]L } d } x |  j D] } | t | 7} qW| |  j | 7} | j |  qWt |   }	 |  j |	 j    d S(   s?   Provide additional checks for accepting or rejecting shortcuts.R   Nu    i    i   i   (   R   R   R   t	   MODIFIERSR   R   t   discardt   removeR   R   t   upperR   t   Key_BacktabR   R   R   t   VALID_SINGLE_KEYSR   R   t   rangeR   R
   R   t   toString(
   R_   t   modt   non_modt   kt   idxR   t   it   key_seqt   mR   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR     s@    	%(   Rd   Re   Rf   RZ   R	   R   R   Ra   R   R   Rc   R   R   R   R   R   (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR~      s   	J			*				6	't   Shortcutc           B  s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s   Shortcut convenience class for holding shortcut context, name,
    original ordering index, key sequence for the shortcut and localized text.
    c         C  s(   d |  _  | |  _ | |  _ | |  _ d  S(   Ni    (   R   R   R   Rt   (   R_   R   R   Rt   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ     s    			c         C  s   d j  |  j |  j |  j  S(   Ns   {0}/{1}: {2}(   R   R   R   Rt   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   __str__  s    c         C  s   t  |  j |  j  |  _ d  S(   N(   R   R   R   Rt   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   load  s    c         C  s   t  |  j |  j |  j  d  S(   N(   R   R   R   Rt   (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   save  s    N(   Rd   Re   Rf   R}   RZ   R  R  R  (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR    s
   		t   ShortcutsModelc           B  s   e  Z d    Z d   Z d   Z d   Z e j d  Z e j d  Z	 e
   d  Z e
   d  Z e j d  Z d	   Z d
   Z d   Z d   Z RS(   c         C  s   t  j |   | |  _ g  |  _ g  |  _ g  |  _ g  |  _ d |  _ t   |  _	 g  |  _
 | j   } | j   j   j   |  _ | j   j   j   |  _ d  S(   NR   (   R   RZ   Rh   R   t   scorest	   rich_textt   normal_textt   lettersR   t   labelt   widthst   paletteRp   t   colorR   t
   text_colort   highlightedTextt   text_color_highlight(   R_   R`   R  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ     s    							c         C  s"   |  j  j j |  j  j    } | S(   s:   Get the currently selected index in the parent table view.(   Rh   t   proxy_modelt   mapToSourcet   currentIndex(   R_   R  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   current_index
  s    c         C  s)   t  |  j d d   |  _ |  j   d S(   s   Qt Override.Rt   c         S  s   |  j  d |  j S(   Nt   /(   R   R   (   t   x(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   <lambda>  R   N(   t   sortedR   t   reset(   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt
   sortByName  s    c         C  s,   | j    s t j St j t j |  |   S(   s   Qt Override.(   t   isValidR   t   ItemIsEnabledt	   ItemFlagsR   t   flags(   R_   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR"    s    c   	      C  s  | j    } | j   s? d | k o9 t |  j  k  n rF t   S|  j | } | j } | j   } | t j k ra| t	 k r t | j
  S| t k r|  j } |  j t j   k r |  j   j    | k r |  j } q |  j } n  |  j | } d j | |  } t |  S| t k rAt |  j t j  } t |  S| t k rt |  j |  Sn) | t j k rt t t j t j B  St   S(   s   Qt Override.i    s   <p style="color:{0}">{1}</p>(   t   rowR  R   R   R   Rt   t   columnR   t   DisplayRolet   CONTEXTR   t   NAMER  Rh   R   t   focusWidgetR  R  R  R   t   SEQUENCER
   R   t
   NativeTextt   SEARCH_SCORER
  t   TextAlignmentRolet   intt   AlignHCentert   AlignVCenter(	   R_   R   t   roleR#  R   Rt   R$  R  Rp   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   data  s4    3		

c         C  s   | t  j k rR | t  j k r8 t t t  j t  j B  St t t  j t  j B  S| t  j k rh t   S| t  j k r | t	 k r t t
 d   S| t k r t t
 d   S| t k r t t
 d   S| t k r t t
 d   Sn  t   S(   s   Qt Override.t   Contextt   NameR  t   Score(   R   R,  t
   HorizontalR   R-  R.  R/  t
   AlignRightR%  R&  R   R'  R)  R+  (   R_   t   sectiont   orientationR0  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt
   headerData?  s     c         C  s   t  |  j  S(   s   Qt Override.(   R   R   (   R_   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   rowCountR  s    c         C  s   d S(   s   Qt Override.i   (    (   R_   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   columnCountV  s    c         C  s   | j    r d | j   k o2 t |  j  k  n r |  j | j   } | j   } t | t  } | t k r} | | _ n  |  j	 j
 | |  t St S(   s   Qt Override.i    (   R  R#  R   R   R$  R   R   R)  Rt   t   dataChangedt   emitR\   R   (   R_   R   t   valueR0  R   R$  Rp   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   setDataZ  s    7c         C  si   | |  _  g  |  j D] } | j ^ q } t | | d d } t |   \ |  _ |  _ |  _ |  j   d S(   s4   Update search letters with text input in search box.R   s
   <b>{0}</b>N(	   R  R   R   R"   t   zipR  R  R
  R  (   R_   Rp   R   t   namest   results(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   update_search_lettersf  s
    	c         C  s   |  j  |  j    d S(   s3   Update active row to update color in selected text.N(   R1  R  (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   update_active_rown  s    c         C  s   |  j  | S(   s@   Get row based on model index. Needed for the custom proxy model.(   R   (   R_   t   row_num(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR#  r  s    c         C  s   |  j    |  j   d S(   s5   "Reset model to take into account new search letters.N(   t   beginResetModelt   endResetModel(   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR  v  s    
(   Rd   Re   RZ   R  R  R"  R   R%  R1  R9  R   R:  R;  t   EditRoleR?  RC  RD  R#  R  (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR	    s   				$			t   CustomSortFilterProxyc           B  s,   e  Z d  Z d d  Z d   Z d   Z RS(   s$   Custom column filter based on regex.c         C  s5   t  t |   j |  | |  _ t j d  |  _ d  S(   NR   (   RY   RI  RZ   Rh   t   ret   compilet   pattern(   R_   R`   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ   ~  s    	c         C  sI   t  |  |  _ |  j r+ |  j j t  n |  j j t  |  j   d S(   s"   Set regular expression for filter.N(   R#   RL  Rh   t   setSortingEnabledR   R\   t   invalidateFilter(   R_   Rp   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt
   set_filter  s
    	c         C  sK   |  j    } | j |  j } t j |  j |  } | d k rC t St Sd S(   sb   Qt override.

        Reimplemented from base class to allow the use of custom filtering.
        N(	   t   sourceModelR#  R   RJ  t   searchRL  R}   R   R\   (   R_   RE  R`   t   modelR   t   r(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   filterAcceptsRow  s    N(   Rd   Re   Rf   R}   RZ   RO  RT  (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRI  |  s   		t   ShortcutsTablec           B  s   e  Z d d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d e d	  Z d
   Z d   Z d   Z d   Z RS(   c         C  s<  t  j |  |  | |  _ d  |  _ t |   |  _ t |   |  _ d |  _	 |  j j
 |  j  |  j j t  |  j j t  |  j j t j  |  j |  j  |  j t  |  j t t |  d d  |  j t j  |  j t j  |  j t  |  j t j  |  j   j  j! |  j"  |  j#   j$   |  j%   d  S(   NR   t   margini	   (&   R   RZ   Rh   R}   t   finderR	  t   source_modelRI  R  t
   last_regext   setSourceModelt   setDynamicSortFilterR\   t   setFilterKeyColumnR'  t   setFilterCaseSensitivityR   t   CaseInsensitivet   setModelt
   hideColumnR+  t   setItemDelegateForColumnR$   t   setSelectionBehaviorR   t
   SelectRowst   setSelectionModet   SingleSelectionRM  t   setEditTriggerst   AllEditTriggerst   selectionModelt   selectionChangedRl   t	   selectiont   verticalHeaderR   t   load_shortcuts(   R_   R`   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRZ     s(    			c         C  s'   |  j  j   t t |   j |  d S(   s   Qt Override.N(   RX  RD  RY   RU  t   focusOutEvent(   R_   Rb   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRm    s    c         C  s3   t  t |   j |  |  j |  j   j    d S(   s   Qt Override.N(   RY   RU  t   focusInEventt	   selectRowR  R#  (   R_   Rb   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRn    s    c         C  s   |  j    |  j   d S(   s   Update selected row.N(   t   updatet   isActiveWindow(   R_   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRj    s    
c         C  s   |  j    |  j   |  j   j   } g  |  j j D] } | j | j d  ^ q3 } |  j t	 t
 |   |  j   j t  d S(   s%   Adjust column size based on contents.t    i	   Ns	            (   t   resizeRowsToContentst   resizeColumnsToContentst   horizontalHeadert   fontMetricsRX  R   t   widthR   t   setColumnWidthR'  t   maxt   setStretchLastSectionR\   (   R_   t   fmR   RA  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   adjust_cells  s    

/c         C  s   g  } x9 t    D]. \ } } } t | | |  } | j |  q Wt | d d   } x# t |  D] \ } } | | _ qd W| |  j _ d g t |  |  j _	 g  | D] } | j
 ^ q |  j _ |  j j   |  j   |  j t t j  d S(   s)   Load shortcuts and assign to table model.Rt   c         S  s   |  j  |  j S(   N(   R   R   (   R  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR    R   i    N(   R   R  R   R  R   R   RX  R   R   R
  R   R  R  R|  t   sortByColumnR&  R   t   AscendingOrder(   R_   R   R   R   t   keystrR   R  R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRl    s    "
c         C  s]  g  } x t  |  j j  D] \ } } | t |  j j  d k rE Pn  x |  j j | d D]| } | | k rr qZ n  t | j  t | j  k rZ | j | j k s | j d k s | j d k rZ | j | | f  qZ qZ Wq W| rY|  j   j	 j
   d j g  | D] \ } } d | | f ^ q } t j |  t d  t d  d | t j  n  d S(   s   Check shortcuts for conflicts.i   R   s   
s   %s <---> %st	   Conflictss+   The following conflicts have been detected:N(   R   RX  R   R   R   Rt   R   R   R`   t   show_this_pageR=  t   joinR   t   warningR   R   (   R_   R   R   t   sh1t   sh2t   cstr(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   check_shortcuts  s"    !	)c         C  s/   |  j    x |  j j D] } | j   q Wd S(   s    Save shortcuts from table model.N(   R  RX  R   R  (   R_   R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   save_shortcuts  s    
c         C  s   |  j  j |  j    } | j   | j   } } |  j j } | | j } | | j } |  j j	 | t
  } | j   } t |  | | | |  }	 |	 j   r |	 j }
 |  j j | |
  n  d S(   s5   Create, setup and display the shortcut editor dialog.N(   R  R  R  R#  R$  RX  R   R   R   R   R)  R1  R~   t   exec_R   R?  (   R_   R   R#  R$  R   R   R   t   sequence_indexR   t   dialogR   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR{     s    	c         C  s   | r d } n! |  j  j   j d d  j   } |  j j |  |  j j |  |  j t	 t
 j  |  j | k r |  j d  n  | |  _ d S(   s.   Update the regex text for the shortcut finder.R   Rr  i    N(   RW  Rp   R   t   lowerR  RO  RX  RC  R}  R+  R   R~  RY  Ro  (   R_   Rn   R  Rp   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt	   set_regex  s    	!c         C  sO   |  j    j   } |  j j   } | d | k r: d } n  |  j | d  d S(   s-   Move to next row from currently selected row.i   iN(   R  R#  R  R:  Ro  (   R_   R#  t   rows(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRx     s
    	c         C  sK   |  j    j   } |  j j   } | d k r6 | } n  |  j | d  d S(   s1   Move to previous row from currently selected row.i    i   N(   R  R#  R  R:  Ro  (   R_   R#  R  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRv   "  s
    	c         C  sI  | j    } | t j t j g k r1 |  j   n| t j g k rS |  j j   n | t j g k r{ |  j	   j
 j   n | t j t j t j t j g k r t t |   j |  n | t j t j g k r | j   } | rEt j t |  d k	 r|  j j   |  j j |  qqEn% | t j g k rE|  j j |  n  d S(   s   Qt Override.N(   Rt   R   Ry   Rz   R{   R   RW  R   R   R`   t	   reset_btnRu   Rw   R   R   RY   RU  Ra   R   t	   Key_SpaceRp   RJ  RQ  Ri   R}   Rs   (   R_   R|   Rt   Rp   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRa   *  s"    $c         C  s   |  j    d S(   s   Qt Override.N(   R{   (   R_   R|   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   mouseDoubleClickEvent>  s    N(   Rd   Re   R}   RZ   Rm  Rn  Rj  R|  Rl  R  R  R{   R   R  Rx   Rv   Ra   R  (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyRU    s   												t   ShortcutsConfigPagec           B  sM   e  Z d  Z e d  Z e j d  Z d   Z d   Z	 d   Z
 d   Z RS(   R   s   Keyboard shortcutst   keyboardc           sb  t       _ t   j   j j    _   j   j _ t t d     _ t t d     _	 t
   } t   } | j   j  | j   j  | j   j  | j |  | j   j	    j |    j   j   j    j   j   j	  t r&  j j j j d   f d   n"   j j j j d   f d     j	 j j   j  d  S(   Ns   Search: s   Reset to default valuesR   c           s     j  |  S(   N(   t   has_been_modified(   t   i1t   i2t   rolest   opt(   R_   (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR  b  R   c           s     j  |  S(   N(   R  (   R  R  R  (   R_   (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR  e  R   (   RU  t   tableRg   R  RW  R   R   t   label_finderR   R  R   R   R   R   R   t   setTabOrderR   R  R<  Rl   t   clickedt   reset_to_default(   R_   t   hlayoutt   vlayout(    (   R_   s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt
   setup_pageI  s*    		c         C  s   |  j  j   d  S(   N(   R  R  (   R_   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   check_settingsh  s    c         C  s}   t  j |  t d  t d  t  j t  j B } | t  j k rA d St   |  j j   |  j j	   |  j
   |  j t  d S(   s?   Reset to default values of the shortcuts making a confirmation.s   Shortcuts resets'   Do you want to reset to default values?N(   R   R  R   t   Yest   NoR   t   maint   apply_shortcutsR  Rl  t   load_from_conft   set_modifiedR   (   R_   R  (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR  k  s    	
c         C  s   |  j  j   |  j j   d  S(   N(   R  R  R  R  (   R_   t   options(    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   apply_settingsy  s    (   Rd   Re   t   CONF_SECTIONR   R'  t   imat   icont   ICONR  R  R  R  (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyR  C  s   			c          C  sm   d d l  m }  |    } t   } | j   | j   t g  | j j D] } t |  ^ qF  | j	   d  S(   Ni(   t   qapplication(
   t   spyder.utils.qthelpersR  RU  R   R  t   printRX  R   R   R  (   R  t   appR  R   (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   test~  s    		

)t   __main__(e   Rf   t
   __future__R    t   osRJ  R   t   qtpyR   t   qtpy.compatR   R   t   qtpy.QtCoreR   R   R   R   R   R	   t
   qtpy.QtGuiR
   R   t   qtpy.QtWidgetsR   R   R   R   R   R   R   R   R   R   R   R   R   t   spyder.config.baseR   R   t   spyder.config.guiR   R   R   R   t   spyder.plugins.configdialogR   t   spyder.utilsR    R  R  R!   t   spyder.utils.stringmatchingR"   R#   t   spyder.widgets.helperwidgetsR$   R%   R   R   R   R   R   R   R   R   R   R   t   _iR   t   SINGLE_KEYSR   t   chrt
   KEYSTRINGSR   t   getattrR   R   t   VALID_ACCENT_CHARSRi   R   R   RX   Rg   R   R   R   R   R   R   R~   t   objectR  R&  R'  R)  R+  R	  RI  RU  R  R  Rd   (    (    (    s7   lib/python2.7/site-packages/spyder/plugins/shortcuts.pyt   <module>   sb   .X"5
+/#* _;		