
,]c           @   s  d  Z  d d l m Z d d l m Z d d l j Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d l m Z m Z m Z m Z 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  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& d d	 l' m( Z( d d
 l) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 d d l9 m: Z: d d l; m< Z< m= Z= m> Z> d d l? m@ Z@ mA ZA d d lB mC ZC mD ZD mE ZE d d lF mG ZG d d lH mI ZJ d d lH mK ZL d d lH mM ZM mN ZN d d lO mP ZP d d lQ mR ZR mS ZS mT ZT d d lU mV ZV mW ZW d d lX mY ZY d d lZ m[ Z[ d d l\ m] Z] y  d d l^ Z^ d d l_ m` Za Wn eb Z^ n Xe< d  Zc e> d k Zd eP e d d  Ze d   Zf d e+ f d      YZg d! e8 f d"     YZh d# e8 f d$     YZi d% e8 f d&     YZj d' e! f d(     YZk d)   Zl eb d*  Zm d+ e[ f d,     YZn d- e( f d.     YZo d/ e4 f d0     YZp d1   Zq er d2 k res e
 jt  d3 k re
 jt d3 Zu n ev Zu eq eu  n  d S(4   s-   
Editor widget based on QtGui.QPlainTextEdit
i(   t   division(   t   categoryN(   t
   QT_VERSION(   t   to_qvariant(   t   QRectt   QRegExpt   QSizet   Qtt   QTimert   Signalt   Slot(   t   QBrusht   QColort   QCursort   QFontt   QIntValidatort   QKeySequencet   QPaintEventt   QPaintert   QTextBlockUserDatat   QTextCharFormatt   QTextCursort   QTextDocumentt   QTextFormatt   QTextOption(   t   QPrinter(   t   QApplicationt   QDialogt   QDialogButtonBoxt   QGridLayoutt   QHBoxLayoutt   QInputDialogt   QLabelt	   QLineEditt   QMenut   QMessageBoxt	   QSplittert	   QTextEditt   QToolTipt   QVBoxLayoutt   QWidget(   t   getobj(   t   get_conf_patht   _t   DEBUG(   t   config_shortcutt   get_shortcut(   t   CONFt   RUN_CELL_SHORTCUTt   RUN_CELL_AND_ADVANCE_SHORTCUT(   t   to_text_string(   t   icon_manager(   t   syntaxhighlighters(   t   encodingt
   sourcecode(   t   check_version(   t   add_actionst   create_actiont   mimedata2url(   t   ALL_LANGUAGESt   CELL_LANGUAGES(   t	   PythonCFM(   t   TextEditBaseWidget(   t
   QtKillRing(   t   PythonExporters   codeeditor.logi   s   5.5s   >=c         C   s(   t  |   } | j d  p' | j d  S(   sN    Returns whether the specified unicode character is a letter or a number.
    t   Lt   N(   R   t
   startswith(   t   chart   cat(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_letter_or_numberK   s    t   GoToLineDialogc           B   s#   e  Z d    Z d   Z d   Z RS(   c            s  t  j |  | t j t j B |  j t j  d  |  _ | |  _	 |  j
 t d   |  j t  t t d   } t   |  _ t |  j  } | j d | j    |  j j |  |  j j j |  j  t t d   } t d | j    } t t d   } t d | j    } t   } | j | d d t j t j B | j |  j d d t j  | j | d d t j t j B | j | d d t j  | j | d	 d t j t j B | j | d	 d t j  t t j t j Bt j  |   }	 |	 j! j |  j"  |	 j# j |  j$  t%   }
 |
 j |	  |
 j& d  |	 j' t j      j( t)  |  j j j   f d
    t*   } | j+ |  | j+ |
  |  j, |  |  j j-   d  S(   Nt   Editors   Go to line:i   s   Current line:s	   <b>%d</b>s   Line count:s   %di    i   c            s     j  t |   d k  S(   Ni    (   t
   setEnabledt   len(   t   text(   t	   ok_button(    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   <lambda>   t    (.   R   t   __init__R   t   WindowTitleHintt   WindowCloseButtonHintt   setAttributet   WA_DeleteOnCloset   Nonet   linenot   editort   setWindowTitleR+   t   setModalt   TrueR    R!   t   lineeditR   t   setRanget   get_line_countt   setValidatort   textChangedt   connectt   text_has_changedt   get_cursor_line_numberR   t	   addWidgett   AlignVCentert
   AlignRightR   t   Okt   Cancelt   Verticalt   acceptedt   acceptt   rejectedt   rejectR'   t
   addStretcht   buttonRI   t   FalseR   t	   addLayoutt	   setLayoutt   setFocus(   t   selfRV   t   labelt	   validatort   cl_labelt
   cl_label_vt
   last_labelt   last_label_vt   glayoutt   bboxt	   btnlayoutt   layout(    (   RL   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO   U   sP    			   		c         C   s1   t  |  } | r$ t |  |  _ n	 d |  _ d S(   s   Line edit's text has changedN(   R2   t   intRU   RT   (   Rr   RK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR`      s    c         C   s   |  j  S(   s   Return line number(   RU   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_line_number   s    (   t   __name__t
   __module__RO   R`   R~   (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRG   T   s   	7	t   LineNumberAreac           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s=   Line number area (on the left side of the text editor widget)c         C   s*   t  j |  |  | |  _ |  j t  d  S(   N(   R(   RO   t   code_editort   setMouseTrackingRY   (   Rr   RV   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO      s    	c         C   s   t  |  j j   d  S(   s   Override Qt methodi    (   R   R   t   compute_linenumberarea_width(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   sizeHint   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t   linenumberarea_paint_event(   Rr   t   event(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt
   paintEvent   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t   linenumberarea_mousemove_event(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   mouseMoveEvent   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t%   linenumberarea_mousedoubleclick_event(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   mouseDoubleClickEvent   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t   linenumberarea_mousepress_event(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   mousePressEvent   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t!   linenumberarea_mouserelease_event(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   mouseReleaseEvent   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t
   wheelEvent(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    (   R   R   t   __doc__RO   R   R   R   R   R   R   R   (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s   							t   ScrollFlagAreac           B   s   e  Z d  Z d Z d Z d Z d   Z d   Z d   Z d   Z	 e
 d  Z e
 d	  Z e
 d
  Z d   Z d   Z d   Z RS(   s%   Source code editor's scroll flag areai   i   i   c            sL   t  j   |    j t j  |   _ | j   j j   f d    d  S(   Nc            s
     j    S(   N(   t   repaint(   t   value(   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM      RN   (	   R(   RO   RR   R   t   WA_OpaquePaintEventR   t   verticalScrollBart   valueChangedR_   (   Rr   RV   (    (   Rr   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO      s
    	c         C   s   t  |  j d  S(   s   Override Qt methodi    (   R   t   WIDTH(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   t   scrollflagarea_paint_event(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    c         C   sM   |  j  j   } |  j | j   j   d  } | j | d | j    d S(   s   Override Qt methodi   g      ?N(   R   R   t   position_to_valuet   post   yt   setValuet   pageStep(   Rr   R   t   vsbR   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    c         C   sc   | r d n d } |  j  j   } | j   | d } | j   | j   | j   } t |  | S(   s^   Return scrollbar's scale factor:
        ratio between pixel span height and value span heighti    i   i   (   R   R   t   heightt   maximumt   minimumR   t   float(   Rr   t   slidert   deltaR   t   position_heightt   value_height(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_scale_factor   s
     c         C   s@   | r d n d } |  j  j   } | | j   |  j |  | S(   s   Convert value to positioni    i   (   R   R   R   R   (   Rr   R   R   t   offsetR   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   value_to_position   s    c         C   sL   | r d n d } |  j  j   } | j   t d | | |  j |  g  S(   s   Convert position to valuei    i   (   R   R   R   t   maxR   (   Rr   R   R   R   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    c         C   s2   t  |  j d | |  j d |  j |  j |  j  S(   s   Make flag QRecti   (   R   t   FLAGS_DXt   FLAGS_DYR   (   Rr   t   position(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   make_flag_qrect   s    c         C   se   |  j  j   } |  j | d t } |  j | | j   d t } t d | |  j d | | d  S(   s   Make slider range QRectR   i   i   (   R   R   R   RY   R   R   R   (   Rr   R   R   t   pos1t   pos2(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   make_slider_range   s    c         C   s   |  j  j |  d S(   s   Override Qt methodN(   R   R   (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s    (   R   R   R   R   R   R   RO   R   R   R   Rn   R   R   R   R   R   R   (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR      s   							t   EdgeLinec           B   s    e  Z d  Z d   Z d   Z RS(   s:   Source code editor's edge line (default: 79 columns, PEP8)c         C   s6   t  j |  |  | |  _ d |  _ |  j t j  d  S(   NiO   (   R(   RO   R   t   columnRR   R   t   WA_TransparentForMouseEvents(   Rr   RV   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO     s    		c         C   sB   t  |   } t t j  } | j d  | j | j   |  d S(   s   Override Qt methodg      ?N(   R   R   R   t   darkGrayt	   setAlphaFt   fillRectt   rect(   Rr   R   t   paintert   color(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    (   R   R   R   RO   R   (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s   	t   BlockUserDatac           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   sQ   t  j |   | |  _ t |  _ d  |  _ g  |  _ d |  _ |  j j	 j
 |   d  S(   NRN   (   R   RO   RV   Rn   t
   breakpointRT   t   breakpoint_conditiont   code_analysist   todot   blockuserdata_listt   append(   Rr   RV   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO     s    					c         C   s   |  j  o |  j o |  j S(   N(   R   R   R   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_empty   s    c         C   s&   |  j  j } | j | j |    d  S(   N(   RV   R   t   popt   index(   Rr   t   bud_list(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __del__#  s    (   R   R   RO   R   R   (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s   			c         C   s9   |  j  t |  j d   |  j t t |    d S(   s1   Set scroll flag area painter pen and brush colorsix   N(   t   setPenR   t   darkert   setBrushR   (   R   t   light_color(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   set_scrollflagarea_painter(  s    c         C   s   t  j |   d } | j d  r/ | d } n  | } | s | d k r_ t j |   \ } } n  x[ | j   D]J } | j   s ql n  | j d  r | d } d | k r d } q ql Pql Wn  | S(   s   Get file language from filenamei   t   .s   #!i   t   pythonN(   t   ospt   splitextRC   RT   R5   t   readt
   splitlinest   strip(   t   filenameRK   t   extt   languaget   _enct   linet   shebang(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_file_language.  s     
t
   CodeEditorc           B   s  e  Z d  Z i e j d e f d 6e j d e f d 6e j d d f d 6e j	 d d f d 6e j
 d d f d	 6e j d
 d f d 6e j d d f d 6e j d d f d 6e j d
 d f d 6e j d d f d 6e j d d f d 6e j d d f d 6e j d e f d 6e j d d f d 6Z d Z e e  Z d Z d Z e   Z e e  Z e e  Z e e  Z  e   Z! e   Z" e   Z# e   Z$ e e  Z% e e e  Z& e   Z' e e(  Z) d d  Z* d   Z+ d   Z, d   Z- d   Z. d    Z/ d!   Z0 e1 d e2 d d e2 e1 e1 e1 e1 e1 e1 e1 d" e2 e1 e2 e2 d e2 e1 e2 e1 e1 d d$ d d d% d&  Z3 d'   Z4 d(   Z5 d)   Z6 d*   Z7 d+   Z8 d,   Z9 d-   Z: d.   Z; d/   Z< d0   Z= d1   Z> d d2  Z? d3   Z@ d4   ZA d5   ZB d6   ZC d7   ZD d8   ZE d9   ZF d:   ZG d;   ZH d<   ZI e1 e1 d=  ZJ d>   ZK d?   ZL d@   ZM eN   dA    ZO dB   ZP dC   ZQ dD   ZR dE   ZS d d d eT jU e2 dF  ZV dG   ZW e2 e2 dH  ZX dI   ZY dJ   ZZ dK   Z[ dL   Z\ dM   Z] dN   Z^ d dO  Z_ dP   Z` dQ   Za dR   Zb dS   Zc dT   Zd dU   Ze dV   Zf dW   Zg d d e2 dX  Zh dY   Zi dZ   Zj d[   Zk d\   Zl e2 d]  Zm d^   Zn d_   Zo d`   Zp da   Zq db   Zr dc   Zs dd   Zt de   Zu df   Zv dg   Zw dh   Zx di   Zy d dj  Zz dk   Z{ d dl  Z| dm   Z} dn   Z~ d do  Z dp   Z eN   dq    Z dr   Z ds   Z eN   dt    Z d
 du  Z dv   Z dw   Z dx   Z dy   Z dz   Z d{   Z d|   Z d}   Z d~   Z d   Z d   Z d   Z d   Z e1 d  Z e1 e2 d  Z eN   d    Z eN   d    Z e2 d  Z d   Z e2 d  Z eN   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 d   Z d d  Z d d  Z d   Z 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 d   Z eN   d d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d    Z d   Z RS(   s1   Source Code Editor Widget based exclusively on Qtt   #t   Pythont   Cythont   ct	   Fortran77t   !t   Fortrant   ;t   IdlRN   t   Difft   GetTextt   Nsist   Htmlt   Yamls   //t   Cppt   OpenCLt   Enamlt   Markdownt   pyt   pywR   t   cppt   clt   hc            s`  t  j   |    j t j  t j d k r t |  } d | j   k r]   j	 d  q d | j   k r   j	 d  q d | j   k r   j	 d  q d | j   k r   j	 d  q n    j
 t j d d   t   _ t      _ t   _ t   _ d   _ t j d	  j t d
 d
     _ t j d  j t d
 d
     _ t j d  j t d
 d
     _ t j d  j t d
 d
     _ t j d  j t d
 d
     _ t   _ d    _  t!      _"   j# j$   j%    j& j$   j'  d   _( d   _) d    _* d    _+ d    _, d    _- d    _. d    _/ d    _0 t1 t j2    _3 t4 j5   _6 d    _7 d } | t4 j8 k rt4 j8 d } n  |   _9 t   _: d    _; t<      _=   j= j>   d   _? d   _@ d   _A d   _B   j%   tC      _D   jE j$   jF  d    _G d    _H t   _I t   _J d    _K d    _L tM      _N g    _O   j# j$   jP  tQ      _R   jR jS t    jR jT d    jR jU j$   jV  d    _W tQ      _X   jX jS t    jX jT d    jX jU j$   jY  g    _Z t1 t j[  j\ d    _*   j] j$   j^  g    __ t1 t j`  j\ d    _a d    _b   jc   d    _d t   _e t   _f t   _g t   _h t   _i t   _j t   _k   jl t  t   _m t1 t jn    _+   jo     _p   jq     _r g    _s   jt j$   ju    jv   jw j$   f d    d  S(   Nt   darwinRV   t   helpt
   historylogt   configdialogt   mains   cursor/widthi   t   errori   t   warningR   t   breakpoint_bigt   breakpoint_cond_bigit   Spyderi    s   #FFAD07s   #EA2B0Es   #B4D4F3s   #30E62Ei,  i  i   i   c            s
     j    S(   N(   t   rehighlight_cells(   R   (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   (x   R>   RO   t   setFocusPolicyR   t   StrongFocust   syst   platformt   reprt   lowert   setObjectNamet   setCursorWidthR/   t   getRY   t   edge_line_enabledR   t	   edge_lineRn   t   blanks_enabledt   markers_margint   markers_margin_widtht   imat   icont   pixmapR   t   error_pixmapt   warning_pixmapt   todo_pixmapt	   bp_pixmapt
   bpc_pixmapt   linenumbers_marginRT   t   linenumberarea_enabledR   t   linenumberareat   blockCountChangedR_   t   update_linenumberarea_widtht   updateRequestt   update_linenumberareat   linenumberarea_pressedt   linenumberarea_releasedt   occurrence_colort   ctrl_click_colort   sideareas_colort   matched_p_colort   unmatched_p_colort   normal_colort   comment_colorR   R   t   linenumbers_colort   sht   TextSHt   highlighter_classt   highlightert   COLOR_SCHEME_NAMESt   color_schemet   highlight_current_line_enabledt   scrollflagarea_enabledR   t   scrollflagareat   hidet   warning_colort   error_colort
   todo_colort   breakpoint_colort   idt   document_idt   cursorPositionChangedt$   _CodeEditor__cursor_position_changedt   _CodeEditor__find_first_post   _CodeEditor__find_flagst   supported_languaget   supported_cell_languaget   classfunc_matcht   comment_stringR?   t
   _kill_ringR   t   update_breakpointsR   t   timer_syntax_highlightt   setSingleShott   setIntervalt   timeoutt   run_pygments_highlightert   occurrence_highlightingt   occurrence_timert   _CodeEditor__mark_occurrencest   occurrencest   yellowt   lighterR^   t   _CodeEditor__text_has_changedt   found_resultst   magentat   found_results_colort   gotodef_actiont   setup_context_menut   tab_indentst   tab_modet   intelligent_backspacet   go_to_definition_enabledt   close_parentheses_enabledt   close_quotes_enabledt   add_colons_enabledt   auto_unindent_enabledR   t   _CodeEditor__cursor_changedt   bluet   get_breakpointst   breakpointst   create_shortcutst	   shortcutst   _CodeEditor__visible_blockst   paintedt   _draw_editor_cell_dividerR   R   (   Rr   t   parentt   plugin_namet   ccs(    (   Rr   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO   l  s    				$$$$$																			
							
				
										c   *   (      s  t    j d d d d d   } t    j d d d d d   } t    j d d d d d   } t    j d d d d d   } t    j d d d d	 d   } t    j d d d d
 d   } t    j d d d d d   } t    j d d d d d   } t    j	 d d d d d   }	 t    j
 d d d d d   }
 t    j d d d d d   } t    j d d d d d   } t    j d d d d d   } t    f d   d d d d d   } t    f d   d d d d d   }   f d   } t  | d  d d d d d   } t  | d  d d d d d   } t  | d  d d d d d   } t  | d  d d d d d   } t  | d  d d d d  d   } t  | d!  d d d d" d   } t  | d#  d d d d$ d   } t  | d%  d d d d& d   } t    j d d d d' d   } t    j d d d d( d   } t    j j d d d d) d   } t    j j d d d d* d   } t    j d d d d+ d   } t    j d d d d, d   } t  | d-  d d d d. d   } t  | d/  d d d d0 d   }  t    j d d d d1 d   }! t    j d d d d2 d   }" t    j d d d d3 d   }# t    j d d d d4 d   }$ t    j d d d d5 d   }% t    j d d d d6 d   }& t    j d d d d7 d   }' t    f d8   d d9 d d: d   }( t    f d;   d d9 d d< d   }) | | | | | | | | |	 |
 | | | | | | | | | | | | | | | | | | |  |! |" |# |$ |% |& |' |( |) | | g( S(=   Nt   contextRH   t   names   Code CompletionRb  s   Duplicate lines	   Copy lines   Delete lines   Move line ups   Move line downs   Go to new lines   Go to definitions   Toggle commentt   Blockcommentt   Unblockcomments   Transform to uppercases   Transform to lowercasec              s     j  d t  S(   Nt   force(   t   indentRY   (    (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM   8  RN   t   Indentc              s     j  d t  S(   NRi  (   t   unindentRY   (    (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM   :  RN   t   Unindentc            s      f d   } | S(   sG   Make a callback for cursor move event type, (e.g. "Start")
            c             s9    j    }  t t    } |  j |   j |   d  S(   N(   t
   textCursort   getattrR   t   movePositiont   setTextCursor(   t   cursort	   move_type(   t   attrRr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   cursor_move_eventA  s    (    (   Rt  Ru  (   Rr   (   Rt  sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   cb_maker>  s    t   StartOfLines   Start of linet	   EndOfLines   End of linet   Ups   Previous linet   Downs	   Next linet   Lefts   Previous chart   Rights	   Next chart   PreviousWords   Previous wordt   NextWords	   Next words   Kill to line ends   Kill to line startt   Yanks   Rotate kill rings   Kill previous words   Kill next wordt   Starts   Start of Documentt   Ends   End of documentt   undot   redot   cutt   copyt   pastet   deletes
   Select Allc              s
     j    S(   N(   t   enter_array_inline(    (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   t   array_builders   enter array inlinec              s
     j    S(   N(   t   enter_array_table(    (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   s   enter array table(   R-   t   do_completiont   duplicate_linet	   copy_linet   delete_linet   move_line_upt   move_line_downt   go_to_new_linet   do_go_to_definitiont   toggle_commentt   blockcommentt   unblockcommentt   transform_to_uppercaset   transform_to_lowercaset   kill_line_endt   kill_line_startR>  t   yankt   rotatet   kill_prev_wordt   kill_next_wordR  R  R  R  R  R  t	   selectAll(*   Rr   t   codecompR  t   copylinet
   deletelinet
   movelineupt   movelinedownt   gotonewlinet   gotodefR  R  R  t   transform_uppercaset   transform_lowercaseRj  Rl  Rv  t
   line_startt   line_endt	   prev_linet	   next_linet	   prev_chart	   next_chart	   prev_wordt	   next_wordR  R  R  t   kill_ring_rotateR  R  t	   start_doct   end_docR  R  R  R  R  R  t
   select_allt   array_inlinet   array_table(    (   Rr   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR]    s    			
				c         C   s   g  |  j  D] } | j ^ q
 S(   s   
        Returns shortcut data, a list of tuples (shortcut, text, default)
        shortcut (QShortcut or QAction instance)
        text (string): action/shortcut description
        default (string): default key sequence
        (   R^  t   data(   Rr   t   sc(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_shortcut_data  s    c         C   s   t  j |  |  d  S(   N(   R>   t
   closeEvent(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   |  j  S(   N(   R5  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_document_id  s    c         C   sH   |  j  | j    | j   |  _ | j |  _ | j |  _ |  j   d S(   s   Set as clone editorN(   t   setDocumentt   documentR  R5  R)  t	   eol_charst   _apply_highlighter_color_scheme(   Rr   RV   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   set_as_clone  s
    c         C   s   |  j  | r d n d  d S(   s   Enable/disable wrap modet   wordN(   t   set_wrap_modeRT   (   Rr   t   enable(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   toggle_wrap_mode  s    iO   t    i   i  c         C   s  |  j  |  |  j |  |  j |  |  j |  |  j |  |  j |  |  j |  |  j |  |  j |  |  j	 |  |  j
 |  |  j |  |  j |  |  j |  | r |  j |  n  |  j | |  |  j | |  |  j |
  |  j |	  |  j |  |  j |  |  j |  |  j |  | d  k	 r`|  j |  |  j   n; | d  k	 r|  j | |  n | d  k	 r|  j |  n  |  j |  |  j |  d  S(   N(   t   set_codecompletion_autot   set_codecompletion_caset   set_codecompletion_entert   set_calltipst   set_go_to_definition_enabledt   set_close_parentheses_enabledt   set_close_quotes_enabledt   set_add_colons_enabledt   set_auto_unindent_enabledt   set_indent_charst   set_scrollflagarea_enabledt   set_edge_line_enabledt   set_edge_line_columnt   set_blanks_enabledt   setFontt   setup_marginst   set_languaget   set_highlight_current_cellt   set_highlight_current_linet   set_occurrence_highlightingt   set_occurrence_timeoutt   set_tab_modet   toggle_intelligent_backspaceRT   R  R  t   set_fontt   set_color_schemet   set_tab_stop_width_spacesR  (   Rr   t   linenumbersR   t   markerst   fontR+  t   wrapRR  RS  t   highlight_current_linet   highlight_current_cellRE  R.  R	  t   edge_line_columnt   codecompletion_autot   codecompletion_caset   codecompletion_entert   show_blankst   calltipst   go_to_definitiont   close_parenthesest   close_quotest
   add_colonst   auto_unindentt   indent_charst   tab_stop_width_spacest   cloned_fromR   t   occurrence_timeout(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   setup_editor  sB    c         C   s   | |  _  d S(   s|   
        enabled = tab always indent
        (otherwise tab indents only when cursor is at the beginning of a line)
        N(   RR  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d  S(   N(   RS  (   Rr   t   state(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d S(   se   Enable/Disable go-to-definition feature, which is implemented in
        child class -> Editor widgetN(   RT  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d S(   s6   Enable/disable automatic parentheses insertion featureN(   RU  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d S(   s0   Enable/disable automatic quote insertion featureN(   RV  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d S(   s1   Enable/disable automatic colons insertion featureN(   RW  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   | |  _  d S(   s@   Enable/disable automatic unindent after else/elif/finally/exceptN(   RX  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s    | |  _  | s |  j   n  d S(   s&   Enable/disable occurrence highlightingN(   RE  t   _CodeEditor__clear_occurrences(   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    	c         C   s   |  j  j |  d S(   s(   Set occurrence highlighting timeout (ms)N(   RF  RB  (   Rr   RC  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s-   | |  _  |  j  r |  j   n
 |  j   d S(   s(   Enable/disable current line highlightingN(   R,  R  t   unhighlight_current_line(   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  !  s    		c         C   s<   | o |  j  } | |  _ |  j r. |  j   n
 |  j   d S(   s(   Enable/disable current line highlightingN(   R;  t   highlight_current_cell_enabledR  t   unhighlight_current_cell(   Rr   R  t   hl_cell_enable(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  )  s
    		c         C   s"  | |  j  k |  _ d |  _ t j } | d  k	 r x t j   D] \ } } | j   | k r= t	 |  _
 |  j | \ } } } | |  _ | t k r t	 |  _ t | |  _ n  | d  k r d  |  _ n |   |  _ Pq= q= Wn  | d  k	 r|  j
 rt j |  } | t j k	 |  _ n  |  j |  d  S(   NRN   (   t   TAB_ALWAYS_INDENTSRQ  R=  R&  R'  RT   R;   t   itemsR  RY   R:  t	   LANGUAGESR<   R;  t   cell_separatorsR<  t   guess_pygments_highlightert   support_languaget   _set_highlighter(   Rr   R   R   t   sh_classt   keyR   R=  t   CFMatch(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  2  s(    					c         C   sp   | |  _  |  j d  k	 r; |  j j d   |  j j d   n  |  j  |  j   |  j   |  j  |  _ |  j   d  S(   N(	   R(  R)  RT   t	   setParentR  R  R  R+  R  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  I  s    		c         C   s(   t  |  j t j  o' |  j j j d k S(   Nt   JSON(   t
   isinstanceR)  R&  t
   PygmentsSHt   _lexerRf  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_jsonU  s    c         C   s   |  j  t j k S(   N(   R(  R&  t   PythonSH(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt	   is_pythonY  s    c         C   s   |  j  t j k S(   N(   R(  R&  t   CythonSH(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt	   is_cython\  s    c         C   s   |  j  t j k S(   N(   R(  R&  t   EnamlSH(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_enaml_  s    c         C   s"   |  j    p! |  j   p! |  j   S(   N(   R  R  R  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_python_likeb  s    c         C   s:  |  j  d d  } | j   s. | j d  r; |  j   n |  j   rd | j d  rd |  j   n | j d  s | d d k r |  j   n | j   d d k r d | k r |  j   nw | d d k s | j d  r |  j   nK | j d  r|  j   n/ t j d | t j	  r,|  j   n
 |  j   d S(   s.   Provide intelligent behavoir for Tab key presst   solRr  R   R  s   import iR   i    t   fromt   importR   s   (,s   , s   [^\d\W]\w*\ZN(   R  R  (
   t   get_textR   t   endswitht   indent_or_replacet   in_comment_or_stringR  t   splitt   ret   searcht   UNICODE(   Rr   t   leading_text(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   intelligent_tabe  s"    c         C   s   |  j  d d  } | j   s+ |  j   na |  j   rD |  j   nH | d d k sc | j d  r |  j d  } |  j |  n
 |  j   d S(   s4   Provide intelligent behavoir for Shift+Tab key pressR  Rr  is   (,s   , N(   R  R   Rl  R  R  t   get_positiont   show_object_info(   Rr   R  R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   intelligent_backtab  s    c         C   sc   |  j  d k	 r |  j  j   n  |  j r5 |  j   n
 |  j   |  j rU |  j   n
 |  j   d S(   s   
        Rehighlight the whole document to rebuild outline explorer data
        and import statements data from scratch
        N(	   R)  RT   t   rehighlightR  R  R  R,  R  R  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR"    s    	
	c         C   s   |  j  r |  j   n  d S(   s+   Rehighlight cells when moving the scrollbarN(   R  R  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    	c         C   s)   | |  _  | |  _ |  j | p! |  d S(   sW   
        Setup margin settings
        (except font, now set in self.set_font)
        N(   R  R  t   set_linenumberarea_enabled(   Rr   R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    		c         C   s   |  j    } | j   | j t j  x t r | j t j  t | j   j	    } t
 |  t
 | j    } | d k r | j t j t j |  | j   n  | j   r Pn  | j t j  q) W| j   d S(   s   Remove trailing spacesi    N(   Rn  t   beginEditBlockRp  R   R  RY   t
   EndOfBlockR2   t   blockRK   RJ   t   rstripR{  t
   KeepAnchort   removeSelectedTextt   atEndt	   NextBlockt   endEditBlock(   Rr   Rr  RK   t   length(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   remove_trailing_spaces  s    
	c         C   sT   t  |  j    } t j |  } | | k rP |  j |  |  j   j t  n  d S(   s   Replace tabs by spacesN(   R2   t   toPlainTextR6   t   fix_indentationt   setPlainTextR  t   setModifiedRY   (   Rr   t   text_beforet
   text_after(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR0    s
    c         C   s1   t  |  j    } |  j d  } t j | |  S(   s   Return current object (string) Rr  (   R2   R/  R  R6   t   get_primary_at(   Rr   t   source_codeR   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_current_object  s    c         C   sh   |  j    sZ |  j   } | j   } | j   sJ | j | d t j  n  |  j |  n  |  j   d S(   s'   Remove selected text or next character.i   N(	   t   has_selected_textRn  R   R*  t   setPositionR   R(  Rq  t   remove_selected_text(   Rr   Rr  R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   sy   t  j t  j B} |  j   } | j t j  t d t j |  t	 j
  } |  j   j | | |  } | j   |  _ | S(   s*   Find first occurrence: scan whole documents   \b%s\b(   R   t   FindCaseSensitivelyt   FindWholeWordsRn  Rp  R   R  R   t   escapeR   t   CaseSensitiveR  t   findR   R8  (   Rr   RK   t   flagsRr  t   regexp(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __find_first  s    c         C   sg   t  j t  j B} t d t j |  t j  } |  j   j | | |  } | j	   |  j
 k rc | Sd S(   s   Find next occurrences   \b%s\bN(   R   R;  R<  R   R=  R   R>  R  R?  R   R8  (   Rr   RK   Rr  R@  RA  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __find_next  s
    c         C   s   |  j    \ } } |  j j | |  |  j r; |  j   n
 |  j   |  j r[ |  j   n
 |  j   |  j	 r |  j
 j   |  j
 j   n  d S(   s   Cursor position has changedN(   t   get_cursor_line_columnt   sig_cursor_position_changedt   emitR  R  R  R,  R  R  RE  RF  t   stopt   start(   Rr   R   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __cursor_position_changed  s    	
	
	c         C   s'   g  |  _  |  j d  |  j j   d S(   s   Clear occurrence markersRH  N(   RH  t   clear_extra_selectionsR.  t   update(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __clear_occurrences  s    	c   
      C   s   |  j  |  } t j   }	 | d  k	 r: |	 j j |  n  | d  k	 rY |	 j j |  n  | d  k	 r |	 j j t j	 t
 |   |	 j j t j t
 |   n  |	 j j t j t
 t   | |	 _ | j |	  |  j | |  | r |  j   n  d  S(   N(   t   get_extra_selectionsR%   t   ExtraSelectionRT   t   formatt   setForegroundt   setBackgroundt   setPropertyR   t   TextUnderlineStyleR   t   TextUnderlineColort   FullWidthSelectionRY   Rr  R   t   set_extra_selectionst   update_extra_selections(
   Rr   R  Rr  t   foreground_colort   background_colort   underline_colort   underline_styleRK  t   extra_selectionst	   selection(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __highlight_selection  s$    	c         C   sH  |  j    |  j s d S|  j   } | d k r3 d S|  j   rU |  j   | k rU d S|  j   r t j t	 |   s t	 |  d k r d S|  j
 |  } g  |  _ xK | r |  j j | j    |  j d | d |  j |  j | |  } q W|  j   t |  j  d k r7|  j d d k r7|  j j d  n  |  j j   d S(   s2   Marking occurrences of the currently selected wordNRr   RH  RY  i   ii    (   R  R:  t   get_current_wordRT   R8  t   get_selected_textR  R6   t
   is_keywordR2   t   _CodeEditor__find_firstRH  R   t   blockNumbert    _CodeEditor__highlight_selectionR  t   _CodeEditor__find_nextRW  RJ   R   R.  RK  (   Rr   RK   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __mark_occurrences  s.    
			

(c         C   sZ  t  |  } | s d S| s4 t j t  |   } n  | rD d | n | } t  |  j    } y t j |  } Wn t j k
 r d SXg  } g  |  _ x | j |  D] } | j	   \ } }	 t
 j   }
 |
 j j |  j  |  j   |
 _ |
 j j |  |  j j |
 j j    |
 j j |	 t j  | j |
  q W|  j d |  |  j   d S(   s   Highlight all found patternsNs   \b%s\bR?  (   R2   R  R=  R/  t   compilet   sre_constantsR   RL  t   finditert   spanR%   RN  RO  RQ  RN  Rn  Rr  R9  R   Rc  R   R(  RV  RW  (   Rr   t   patternt   wordsRA  RK   t   regobjR\  t   matchR   R   R]  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   highlight_found_results=  s0    	c         C   s'   g  |  _  |  j d  |  j j   d S(   s    Clear found results highlightingR?  N(   RL  RJ  R.  RK  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   clear_found_resultsX  s    	c         C   s   |  j  r |  j   n  d S(   s=   Text has changed, eventually clear found results highlightingN(   RL  Rp  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __text_has_changed^  s    	c         C   s   |  j  r |  j Sd Sd  S(   Ni    (   R  R  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_markers_margind  s    	c         C   s'   | |  _  |  j j |  |  j   d  S(   N(   R  R  t
   setVisibleR  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR#  k  s    	c         C   s   |  j  j   j   S(   s%   Return current line number area width(   R  t   contentsRectt   width(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_linenumberarea_widthp  s    c         C   s   |  j  s d Sd } t d |  j    } x$ | d k rN | d } | d 7} q+ W|  j rx d |  j   j d |  } n d } | |  j   S(   s)   Compute and return line number area widthi    i   i
   i   t   9(   R  R   t
   blockCountR  t   fontMetricsRu  Rr  (   Rr   t   digitst   maxbR  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR   t  s    	
	 c         C   s&   |  j  |  j   d |  j   d  d S(   s{   
        Update line number area width.

        new_block_count is needed to handle blockCountChanged(int) signal
        i    N(   t   setViewportMarginsR   t   get_scrollflagarea_width(   Rr   t   new_block_count(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   sv   | r |  j  j d |  n. |  j  j d | j   |  j  j   | j    | j |  j   j    rr |  j	   n  d S(   s   Update line number areai    N(
   R  t   scrollRK  R   Ru  R   t   containst   viewportR   R  (   Rr   t   qrectt   dy(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c      	      s  t  |  j    j | j   |  j  |  j   } |  j   j     |  j   j	   } | j
   d }    f d   } x|  j D]\ } } } |  j r=| | k r | j | j   j |   j |  j  n- | j | j   j |   j |  j   j d | |  j j     t j t j Bt |   n  | j   }	 |  j r |	 r |	 j rx! |	 j D] \ }
 } | rkPqkqkW| r| | |  j  q| | |  j  n  |	 j r| | |  j   n  |	 j! r|	 j" d k r| | |  j$  q| | |  j%  qq q Wd S(   s   Painting line number areai   c            sN   t  s | j   } n | j   | j   }  j d |    | d |  d  S(   Ni    i   (   t   QT55_VERSIONR   t   devicePixelRatiot
   drawPixmap(   t   ytopR  t   pixmap_height(   t   font_heightR   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   draw_pixmap  s
    i    N(&   R   R  R   R   R   R  Ry  R   Rn  R&  Rc  t   visible_blocksR  t	   setWeightt   BoldR  R   R#  t   NormalR%  t   drawTextRu  R   Rd   t   AlignBottomR2   t   userDataR  R   R  R  R   R  R   R   RT   R  R  (   Rr   R   R  t   active_blockt   active_line_numberR  t   topt   line_numberR&  R  t   _messageR   (    (   R  R   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     sF    					c         C   s   |  j    } | j   } |  j |  j |  j    j   } | |  j |  j   } x] | j   r | | j	   j
   k  r | j   } | } | |  j |  j   } | d 7} qX W| S(   s#   Return line number from mouse eventi   (   t   firstVisibleBlockRc  t   blockBoundingGeometryt
   translatedt   contentOffsetR  t   blockBoundingRectR   t   isValidR   R   t   next(   Rr   R   R&  R  R  t   bottom(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt!   __get_linenumber_from_mouse_event  s    'c         C   s   |  j  |  } |  j   j | d  } | j   } |  j d k } | rn | j rn | rn |  j | | j  n  | j   t j	 k r | |  _ |  j
 |  j |  j  n  d S(   s*   Handling line number area mouse move eventi   iN(   t,   _CodeEditor__get_linenumber_from_mouse_eventR  t   findBlockByNumberR  R  R   t'   _CodeEditor__show_code_analysis_resultst   buttonsR   t
   LeftButtont   linenumberarea_select_linesR  (   Rr   R   R  R&  R  t   check(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    	c         C   s9   |  j  |  } | j   t j @} |  j | d | d S(   s2   Handling line number area mouse double-click eventt   edit_conditionN(   R  t	   modifiersR   t   ShiftModifiert   add_remove_breakpoint(   Rr   R   R  t   shift(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    c         C   s;   |  j  |  } | |  _ | |  _ |  j |  j |  j  d S(   s2   Handling line number area mouse double press eventN(   R  R  R  R  (   Rr   R   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s
    		c         C   s   d |  _  d |  _ d S(   s-   Handling line number area mouse release eventiN(   R  R  (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    	c   	      C   s-  |  j    j } | | } | } | | d  } |  j   } | j | j    | d k r x~ t t |  d  D] } | j | j | j	  qq WnG | j | j  x4 t t |  d  D] } | j | j
 | j	  q W| |  j   k r| j | j | j	  n | j | j | j	  |  j |  d S(   s9   Select line(s) after a mouse press/mouse press drag eventi   i    N(   R  t   findBlockByLineNumberRn  R9  R   t   ranget   absRp  R+  R(  t   PreviousBlockRx  R%  t   StartOfBlockRq  (	   Rr   t   linenumber_pressedt   linenumber_releasedt   find_block_by_line_numbert   move_n_blockst
   start_linet   start_blockRr  t   n(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s     
c         C   s  |  j    s d S| d k r1 |  j   j   } n |  j   j | d  } | j   } | st t |   } t | _	 n | s | j	 | _	 d | _
 n  | d k	 r | | _
 n  | r| j
 } t j |  t d  t d  t j |  \ } } | s d St | _	 | rt |  n d | _
 n  | j	 rlt | j    j   } t |  d k s]| j d	  rlt | _	 qln  | j |  |  j j   |  j j   |  j j   d S(
   s   Add/remove breakpointNi   t
   Breakpoints
   Condition:i    R   t   "t   '(   R   R  R  (   R  RT   Rn  R&  R  R  R  R   RY   R   R   R   t   getTextR+   R!   R  t   strR2   RK   R   RJ   RC   Rn   t   setUserDataR  RK  R.  t   breakpoints_changedRF  (   Rr   R  t	   conditionR  R&  R  t   validRK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  !  s@    						!c         C   s   g  } |  j    j   } xg t d |  j    j   d  D]F } | j   } | rr | j rr | j | | j f  n  | j   } q8 W| S(   s   Get breakpointsi   (	   R  t
   firstBlockR  Rx  R  R   R   R   R  (   Rr   R\  R&  R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR[  F  s    &c         C   s=   g  |  _  x- |  j D]! } t | _ | j   r ~ q q Wd S(   s   Clear breakpointsN(   R\  R   Rn   R   R   (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   clear_breakpointsQ  s
    		c         C   s5   |  j    x$ | D] \ } } |  j | |  q Wd S(   s   Set breakpointsN(   R  R  (   Rr   R\  R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   set_breakpoints]  s    
c         C   s   |  j  j   d S(   s   Update breakpointsN(   R  RF  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR?  c  s    c         C   s#   |  j    s |  j j |  n  d S(   s   Trigger completionN(   t   is_completion_widget_visiblet   get_completionsRF  (   Rr   t	   automatic(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  h  s    c         C   s/   |  j    s+ |  j j |  j   j    n  d S(   s   Trigger go-to-definitionN(   R  R  RF  Rn  R   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  m  s    c         C   s   |  j  j |  d S(   s   Trigger a calltipN(   t   sig_show_object_infoRF  (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR   r  s    c         C   s   | |  _  |  j j |  d S(   s   Toggle edge line visibilityN(   R  R	  Rs  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  w  s    	c         C   s   | |  j  _ |  j  j   d S(   s   Set edge line column valueN(   R	  R   RK  (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  |  s    c         C   s   | |  _  |  j   j   } | j | j   t j B |  j  r[ | j | j   t j B n | j | j   t j @ |  j   j |  |  j	   d S(   s   Toggle blanks visibilityN(
   R
  R  t   defaultTextOptiont   setFlagsR@  R   t%   AddSpaceForLineAndParagraphSeparatorst   ShowTabsAndSpacest   setDefaultTextOptionR"  (   Rr   R  t   option(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    		c         C   s'   | |  _  |  j j |  |  j   d S(   s"   Toggle scroll flag area visibilityN(   R-  R.  Rs  R  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    	c         C   s   |  j  r t j Sd Sd S(   s   Return scroll flag area widthi    N(   R-  R   R   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR}    s    	c         C   s  |  j  j } |  j  j } t |  j   } | j | j   |  j  |  j   j   } xt	 d |  j   j
   d  D] } | j   } | r_|  j  j |  } | j r |  j }	 x* | j D] \ }
 } | r |  j }	 Pq q Wt | |	  | j | |   n  | j r-t | |  j  | j | |   n  | j r_t | |  j  | j | |   q_n  | j   } qr W|  j rt | |  j  x9 |  j D]+ } |  j  j |  } | j | |   qWn  |  j rt | |  j  x9 |  j D]+ } |  j  j |  } | j | |   qWn  t t j  } | j d  | j |  t t j  } | j d  | j  t! |   | j | |  j"   j#     d S(   s   Painting the scroll flag areai   g?g      ?N($   R.  R   R   R   R   R   R   R  R  R  Rx  R  R   R   R0  R1  R   t   drawRectR   R2  R   R3  R  RH  R  RL  RN  R   R   t   whiteR   R   R   R   R  Rc  (   Rr   R   t	   make_flagt   make_sliderR   R&  R  R  R   R   R  R   t	   pen_colort   brush_color(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     sR    &							c         C   sd   t  j |  |  |  j   } |  j j t | j   | j   |  j   | j	     |  j
 |  d S(   s;   Reimplemented Qt method to handle line number area resizingN(   R>   t   resizeEventRt  R  t   setGeometryR   t   leftR  R   R   t(   _CodeEditor__set_scrollflagarea_geometry(   Rr   R   t   cr(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    	c         C   s   | } |  j    j   r3 |  j    j   j   } n d } |  j   \ } } } } | | k rf d } n  |  j j t | j   t	 j
 | | j   |  j j
 | j     d S(   s   Set scroll flag area geometryi    N(   R   t	   isVisibleRt  Ru  t   getContentsMarginsR.  R  R   t   rightR   R   R  R   (   Rr   t   contentrectR  t   vsbwt   _leftt   _topR  t   _bottom(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __set_scrollflagarea_geometry  s    		 c         C   s   |  j    } |  j |  j    j | j   | j    j   |  j   |  j   j	 d |  j
 j  d } |  j   } |  j
 j t | | j   d | j     |  j |  t j |  |  S(   s   Override Qt methodRw  i   i   (   R  R  R  R  t   xR   R  Rv  Ry  Ru  R	  R   Rt  R  R   R  R  R  R>   t   viewportEvent(   Rr   R   R   R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    ^+c         C   s   |  j  } | d k	 r |  j d | j   d | j    | j   |  _ | j   |  _ | j	   |  _
 | j   |  _ | j   |  _ | j   |  _ | j   |  _ | j   |  _ | j   |  _ n  d S(   s8   Apply color scheme from syntax highlighter to the editort
   backgroundt
   foregroundN(   R)  RT   t   set_palettet   get_background_colort   get_foreground_colort   get_currentline_colort   currentline_colort   get_currentcell_colort   currentcell_colort   get_occurrence_colorR  t   get_ctrlclick_colorR  t   get_sideareas_colorR   t   get_comment_colorR$  R#  t   get_matched_p_colorR!  t   get_unmatched_p_colorR"  (   Rr   t   hl(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    	c         C   sU   |  j  d k	 rQ |  j  j |  j    | d k	 rA |  j |  qQ |  j  j   n  d S(   s!   Apply syntax highlighter settingsN(   R)  RT   t   setup_formatsR  R  R"  (   Rr   R+  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   apply_highlighter_settings  s
    c         C   s   |  j  j   S(   s)   Get data provided by the Outline Explorer(   R)  t   get_outlineexplorer_data(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s@   | d k	 r | |  _ n  |  j |  |  j   |  j |  d S(   s   Set fontN(   RT   R+  R  R  R  (   Rr   R  R+  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s
    
c         C   sy   | |  _  |  j d k	 r5 |  j j |  |  j   n  |  j rK |  j   n
 |  j   |  j rk |  j	   n
 |  j
   d S(   s(   Set color scheme for syntax highlightingN(   R+  R)  RT   R  R  R  R  R  R,  R  R  (   Rr   R+  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  )  s    		
	c         C   s   |  j  |  |  j |  d S(   s   Set the text of the editorN(   R1  t   set_eol_chars(   Rr   RK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   set_text9  s    c         C   sT   t  j |  \ } } | d k r3 t | |  } n  |  j | |  |  j |  d S(   s,   Set the text of the editor from file *fname*N(   R5   R   RT   R   R  R  (   Rr   R   R   RK   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   set_text_from_file@  s
    c         C   s-   |  j    } | j t j  | j |  d S(   s)   Append text to the end of the text widgetN(   Rn  Rp  R   R  t
   insertText(   Rr   RK   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR   H  s    c         C   sv   t  j   } t | j    } t | j    d k re |  j   } | j | j | | j     n  t	 j
 |   d S(   s   
        Reimplement QPlainTextEdit's method to fix the following issue:
        on Windows, pasted text has only 'LF' EOL chars even if the original
        text has 'CRLF' EOL chars
        i   N(   R   t	   clipboardR2   RK   RJ   R   t   get_line_separatort   setTextt   joinR>   R  (   Rr   R  RK   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  N  s    #c         C   s   |  j  j j |  S(   s+   Return block data (from syntax highlighter)(   R)  t
   block_dataR  (   Rr   R&  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_block_data]  s    c         C   s%   |  j    j |  } |  j |  j S(   sV   Is it a fold header line?
        If so, return fold level
        If not, return None(   R  R  R   t
   fold_level(   Rr   t   block_nbR&  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   get_fold_levela  s    c         C   s!   |  j    |  j j |  j  d S(   sA   QPlainTextEdit's "centerCursor" requires the widget to be visibleN(   t   centerCursort   focus_int
   disconnectt   center_cursor_on_next_focus(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  l  s    
c         C   s   t  | |  j    } |  j   j | d  } |  j t |   |  j   rZ |  j   n |  j j	 |  j
  |  j   j d  | r t |  t | j    k r |  j | t j  n  d S(   s4   Go to line number *line* and eventually highlight iti   i    N(   t   minR\   R  R  Rq  R   R  R  R  R_   R  t   horizontalScrollBarR   R2   RK   R?  R   R;  (   Rr   R   R  R&  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt
   go_to_liner  s    $c         C   s2   t  |   } | j   r. |  j | j    n  d S(   s%   Execute the GoToLineDialog dialog boxN(   RG   t   exec_R
  R~   (   Rr   t   dlg(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   exec_gotolinedialog  s    c         C   su   |  j  t  |  j d  x- |  j D]! } g  | _ | j   r% ~ q% q% W|  j  t  |  j j   |  j	 j   d S(   s    Remove all code analysis markersR   N(
   t   setUpdatesEnabledRn   RJ  R   R   R   RY   R.  RK  R  (   Rr   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   cleanup_code_analysis  s    	
c            sc  |  j    | d k r d S|  j t  |  j   } |  j     t j t j B} x| D]\ } } d | k } |  j   j	 | d  } | j
   } | s t |   } n  | j j | | f  | j |  t j d |  }	 xW|	 D]O}
 |
 d d !}   f d   } | d } x0 | |  j   d k  rB| |  rB| d 7} qW| j | j    | j t j  t d t j |  t j  } | r|  j n |  j }   j | | |  } | r xx | r/| j   | k r/| j   | d k r/| j   d k r/|  j d	 | d
 t  |    j | | |  } qWq q WqV W|  j!   |  j t"  |  j# j$   d S(   s#   Analyze filename code with pyflakesNt   syntaxi   s   \'[a-zA-Z0-9_]*\'ic            sU   t    j |   j    } | j   } | j d  pT | j d  pT t |  d k S(   Ns   \t   ,i    (   R2   R  RK   R   R  RJ   (   t   line_noRK   t   stripped(   R  (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   is_line_splitted  s
    s   \b%s\bi    R   RZ  (%   R  RT   R  Rn   Rn  R  R   R;  R<  R  R  R   R   R   R  R  t   findallRx  R9  R   Rp  R   R  R   R=  R   R>  R1  R0  R?  Rc  Rd  R   RW  RY   R  RK  (   Rr   t   check_resultsRr  R@  t   messageR  R   R&  R  t   refst   refRK   R  t   line2RA  R   (    (   R  sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   process_code_analysis  sL    

%$
c         C   sE   g  | D] \ } } | ^ q } |  j  t d  | d d d | d S(   s   Show warning/error messagess   Code analysisR   s   #129625t   at_lineN(   t   show_calltipR+   (   Rr   R  R   t   msgt   _errort   msglist(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __show_code_analysis_results  s    c         C   s   |  j    j   } |  j   j   } x` t r | j   d | k  rR | j   } n |  j   j   } | j   } | r' | j	 r' Pq' q' W| j   d } |  j
 |  |  j | | j	  |  j d  S(   sO   Go to next code analysis warning message
        and return new cursor positioni   Rr  (   Rn  R&  R  Rx  RY   Rc  R  R  R  R   R
  R  R  (   Rr   R&  t
   line_countR  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   go_to_next_warning  s    	c         C   s   |  j    j   } x\ t rp | j   d k r< | j   } n |  j   j   } | j   } | r | j r Pq q W| j   d } |  j	 |  |  j
 | | j  |  j d  S(   sS   Go to previous code analysis warning message
        and return new cursor positioni    i   Rr  (   Rn  R&  RY   Rc  t   previousR  t	   lastBlockR  R   R
  R  R  (   Rr   R&  R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   go_to_previous_warning  s    	c         C   s   |  j    j   } |  j   j   } x` t r | j   d | k  rR | j   } n |  j   j   } | j   } | r' | j	 r' Pq' q' W| j   d } |  j
 |  |  j t d  | j	 d d d | |  j d  S(   s.   Go to next todo and return new cursor positioni   s   To doR   s   #3096FCR  Rr  (   Rn  R&  R  Rx  RY   Rc  R  R  R  R   R
  R  R+   R  (   Rr   R&  R"  R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   go_to_next_todo  s    	c         C   s   x- |  j  D]! } d | _ | j   r ~ q q Wxd | D]\ \ } } |  j   j | d  } | j   } | s} t |   } n  | | _ | j |  q7 W|  j j	   d S(   s   Process todo finder resultsRN   i   N(
   R   R   R   R  R  R  R   R  R.  RK  (   Rr   t   todo_resultsR  R  R  R&  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   process_todo  s    	
	c         C   s	  |  j    } |  j   r| j   | j   } } t | | g  } |  j    } | j |  | j   } | j   | j |  | j   r | j t	 j
  | j   | k  r | j |  q n  xu | j   | k r7| j t	 j  | j |  | d k r| j   d k rPn  | j t	 j
  | j t	 j  q W| j   | r|  j    } | j   } | j   } | | k  r| t |  8} n | t |  8} | j | t	 j  | j | t	 j  |  j |  qn1 | j   | j t	 j  | j |  | j   d S(   s.   Add prefix to current line or selected line(s)i    N(   Rn  R8  t   selectionStartt   selectionEndR  R9  t   atBlockStartR$  Rp  R   R  R   R  R  Rc  R%  R,  RJ   t
   MoveAnchorR(  Rq  (   Rr   t   prefixRr  t	   start_post   end_post	   first_post   first_cursort   begins_at_block_start(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt
   add_prefix  sF    


c         C   s   | j  t j  d  S(   N(   Rp  R   R  (   Rr   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __is_cursor_at_start_of_blockI  s    c         C   sX   |  j    } | j | j   t |  t j  t | j    | k rT | j   n  d S(   sU   
        Remove suffix from current line (there should not be any selection)
        N(	   Rn  R9  R   RJ   R   R(  R2   t   selectedTextR)  (   Rr   t   suffixRr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   remove_suffixL  s
    
c         C   sz  |  j    } |  j   rt | j   | j   g  \ } } | j |  | j   st | j t j	  | j
   } n  | j   | j |  | j   r | j t j  | j
   | k  r | j |  q n  | j t j	  d } x | j
   | k r| j
   } | | k rPn | } t | j   j    } | j   rR| j   j |  sa| j |  r| j t j t j | j |   | j t j t j t |   | j   n  | j t j  q W| j   n | j t j	  t | j   j    } | j   r| j   j |  s(| j |  rv| j t j t j | j |   | j t j t j t |   | j   n  d S(   s3   Remove prefix from current line or selected line(s)N(   Rn  R8  t   sortedR*  R+  R9  R,  Rp  R   R  R   R$  R  RT   R2   R&  RK   R   t   lstripRC   R|  R-  R?  R(  RJ   R)  R,  (   Rr   R.  Rr  R/  R0  t   old_post   new_post	   line_text(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   remove_prefixV  sT    
!!c         O   s0   |  j    r |  j | |   S|  j | |   Sd S(   s(   Indent line according to the preferencesN(   R  t   fix_indent_smartt   simple_indentation(   Rr   t   argst   kwargs(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt
   fix_indent  s    c         K   s   |  j    } | j   } |  j   j | d  } t | j    } t j d |  j   } | sw | t	 |  j
  } n  | j |  t S(   sM   
        Simply preserve the indentation-level of the previous line.
        i   s   \s*(   Rn  Rc  R  R  R2   RK   R  Rn  t   groupRJ   R  R  Rn   (   Rr   t   forwardRB  Rr  R  t
   prev_blockt   prevlinet   indentation(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR@    s    c         C   s  |  j    } | j   } d } d } d } t } d }	 d }
 x|t | d d d  D]d}	 | j t j  t | j	   j
    j   }
 |
 j d  } | d k r |
 |  }
 n  |  j   r |
 j   j d  r |
 s |
 rS d |
 j   j   d  k rA|
 j   j d  s8|
 j   j d  s8|
 j   j d	  rAt } n0 |
 j   j d
  rq|  j   rqt } t } n  |
 j d  |
 j d  k r|
 j d  |
 j d  } q|
 j d  |
 j d  k r|
 j d  |
 j d  } q|
 j d	  |
 j d  k r(|
 j d	  |
 j d  } q| s:| s:| r| |
 j d  |
 j d  7} | |
 j d  |
 j d  7} | |
 j d	  |
 j d  7} | p| p| sPqqPqS qS W|	 r|  j |	  } n d } |  j |  } | r#|  j d k r| |  j 7} q#| t |  j  7} n  | s|
 j d
  ry|  j   ry|  j d k rc| |  j 7} q| t |  j  7} q|  j   r3|
 j d  s|
 j d  s|
 j d  sd |
 j   j   d  k r3t t j d |
   t t j d |
   k r3|  j d k r| |  j 8} q| t |  j  8} qt t j d |
   d k rd g } d } x |
 D] } | d k	 r| | k r=d } q=qg| d k r| } qg| d k r| j |  qg| d k r| d d k r| j   qg| d k r| d d k r| j   qg| d	 k rg| d d k rg| j   qgqgWt |  d k rVqt j d |
  d k	 r|  j d k r|  j d t |
  k  s|  j j d  rt |  j  d t |
  k  r|  j d k r| |  j d 7} q| t |  j  d 7} qi d d 6d d 6d d	 6} x | D] } |
 j |  } | d k r&|
 |  }
 xS t t |
 j |    D]3 } |
 j | |  } | d k r|
 |  }
 qmPqmWq&q&W|
 j   rt t j d |
   d k rt j d |
  d } t |
  t |  } qt |
  } qqn  | p(| p(| r|
 j d
  r|	 r|  j | d  } |  j | d  j   } |  j |	  } |  j |  j   } | | k  r| s| r| t |  j  d k r| } q| t |  j  | t |  j  } qn  | r	| | k s| r | | k r t S| d k r|  j    } | j t j  |  j d k rg| |  j } n  | j | j    | t j!  | j"   |  j d k rd | |  j d | |  j } n
 d | } | j# |  t Sd S(   s_  
        Fix indentation (Python only, no text selection)
        forward=True: fix indent only if text is not enough indented
                      (otherwise force indent)
        forward=False: fix indent only if text is too much indented
                       (otherwise force unindent)

        Returns True if indent needed to be fixed
        i    RN   i   iR   t   returnt   )t   ]t   }t   :t   (t   [t   {s   	t   continuet   breakt   passs   \(|\{|\[s   \)|\}|\]t   dummyR  R  s   [\(|\{|\[]\s*$i   R  N(   R  R  (   RN  RO  RP  ($   Rn  Rc  Rn   RT   R  Rp  R   R  R2   R&  RK   R'  R?  R  R   RC   R  R  RY   t   countt   get_block_indentationR  R  RJ   R  R   R   R  t   rfindt   get_text_lineR  R9  R   R(  R)  R  (   Rr   RE  t   comment_or_stringRr  R  t
   diff_parent
   diff_brackt
   diff_curlyt
   add_indentRG  t   prevtextt   inline_commentt   correct_indentRj  t   stackt
   deactivateR   t   rlmapt   part   i_rightt   _it   i_leftt   prevexprt
   cur_indentt   is_blankt   prevline_indentt   trailing_textt   indent_text(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR?    s   
	!	   		
"	

c         C   s   y t  j |  j   d d } | j rp xF | j D]8 } d | k rP g  | d <n  d | k r1 d | d <q1 q1 Wn  |  j   |  j t  j |   Wn= t k
 r } t	 j
 |  t d  t d  t |   d SXd S(   s1   Removes all ouput in the ipynb format (Json only)t
   as_versioni   t   outputst   prompt_numbers   Removal errorsI   It was not possible to remove outputs from this notebook. The error is:

N(   t   nbformatt   readsR/  t   cellsRT   R  t   insertPlainTextt   writest	   ExceptionR#   t   criticalR+   R2   (   Rr   t   nbt   cellt   e(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   clear_all_outputZ  s    	
	c         C   s   y5 t  j |  j   d d } t   j |  d } Wn= t k
 rt } t j |  t d  t d  t	 |   d SX|  j
 j |  d S(   s8   Convert an IPython notebook to a Python script in editorRn  i   i    s   Conversion errors=   It was not possible to convert this notebook. The error is:

N(   Rq  Rr  R/  t
   nbexportert   from_notebook_nodeRv  R#   Rw  R+   R2   t   sig_new_fileRF  (   Rr   Rx  t   scriptRz  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   convert_notebookp  s    	c         C   s   |  j  d d  } |  j   r1 |  j |  j  n | sV | j   sV |  j r |  j r |  j   r |  j d t	  s |  j |  j  q q |  j |  j  nV t
 |  j  d k r t
 |  j  } |  j d | t
 |  |  n |  j |  j  d S(   s   
        Indent current line or selection

        force=True: indent even if cursor is not a the beginning of the line
        R  Rr  RE  i   R  N(   R  R8  R4  R  R   RQ  RR  R  RC  RY   RJ   t   insert_text(   Rr   Ri  R  R-  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRj  ~  s    "c         C   s   |  j  r |  j s |  j   r, |  j   n |  j   } |  j   t | j   j    k ri |  j   ns |  j   } | j	 | j
    |  j   } | j	 | j    | j   | j   k r |  j   n |  j |  j  d S(   sA   Indent or replace by 4 spaces depending on selection and tab modeN(   RQ  RR  R8  Rj  Rn  R`  R2   R&  RK   R9  R*  R+  Rc  t   replaceR  (   Rr   Rr  t   cursor1t   cursor2(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    	c         C   s   |  j    r |  j |  j  n |  j d d  } | sV | j   sV |  j r |  j r |  j   r |  j d t	  s |  j |  j  q q | j
 d  r |  j d  q |  j |  j  n  d S(   s   
        Unindent current line or selection

        force=True: unindent even if cursor is not a the beginning of the line
        R  Rr  RE  s   	N(   R8  R>  R  R  R   RQ  RR  R  RC  Rn   R  (   Rr   Ri  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRl    s    c         C   sO  |  j    } t | j   | j   g  \ } } | j |  | j   j   } | j   rt | | k rt | d 8} n  | j |  | j   j   } t } t	 } x t
 | | d  D]q } t | j   j    j   }	 |	 j |  j  }
 |	 d k } | |
 p| 9} |
 rt } n  | j t j  q W| rA| rA|  j   n
 |  j   d S(   s+   Toggle comment on current line or selectioni   RN   N(   Rn  R9  R*  R+  R9  R&  Rc  R,  RY   Rn   R  R2   RK   R:  RC   R=  Rp  R   R+  t	   uncommentt   comment(   Rr   Rr  R/  R0  t	   last_linet
   first_linet   is_comment_or_whitespacet   at_least_one_commentt   _line_nbRK   t
   is_commentt   is_whitespace(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s,    	c         C   s   |  j  |  j  d S(   s"   Comment current line or selection.N(   R4  R=  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   |  j  |  j  d S(   s$   Uncomment current line or selection.N(   R>  R=  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s    |  j  d d d t |  j   S(   NR  t   =iN   (   R=  RJ   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __blockcomment_bar  s    c         C   s   |  j    } | j   } t | j    } t |  d k rm | j   } | j t j  t | j    } n  | j   } | j	 |  |  j
 |  d S(   s.   Change to uppercase current line or selection.i    N(   Rn  R   R2   R6  RJ   t   selectR   t   WordUnderCursort   upperR  t   set_cursor_position(   Rr   Rr  t   prev_post   selected_textt   s(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s   |  j    } | j   } t | j    } t |  d k rm | j   } | j t j  t | j    } n  | j   } | j	 |  |  j
 |  d S(   s.   Change to lowercase current line or selection.i    N(   Rn  R   R2   R6  RJ   R  R   R  R  R  R  (   Rr   Rr  R  R  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    c         C   s  |  j    |  j   } |  j   } |  j   rT |  j   | j   | j   } } n | j   } } | j   | j	 |  | j
 t j  xq | j   | k r | j |  j d  | j
 t j  | j   r Pn  | j
 t j  | t |  j d  7} q W| j	 |  | j
 t j  | j   r>| j |  j    n | j
 t j  | j |  | j	 |  | j
 t j  | j |  | j   d S(   s(   Block comment current line or selection.R  N(   t   _CodeEditor__blockcomment_barR  Rn  R8  t"   extend_selection_to_complete_linesR*  R+  R   R$  R9  Rp  R   R  R  R=  R%  R*  R+  RJ   R,  (   Rr   t   comlineRr  R/  R0  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  	  s4    

c            s    f d   }   j    } | |  r+ d Sx0 | |  s] | j t j  | j   r. Pq. q. W| |  sn d S  f d   } t |  } | j t j  xO | |  r | |  r | j t j  | j     j   j   k r Pq q W| |  s d S  j    } | j	   | j
 | j    | j t j  xq | j   | j   k  r| j t j t j  | j   s| j t j t j  n  | j   | j t j  q7WxA | | f D]3 } | j
 | j    | j t j  | j   qW| j   d S(   s*   Un-block comment current line or selectionc            s%   t  |  j   j    j   j    S(   N(   R2   R&  RK   RC   R  (   Rr  (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __is_comment_bar#	  s    Nc            s(     j  } t |  j   j    j |  S(   N(   R=  R2   R&  RK   RC   (   Rr  t   cs(   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __in_block_comment0	  s    	(   Rn  Rp  R   R  t   atStartR+  R&  R  R%  R$  R9  R   t   NextCharacterR(  t
   atBlockEndR)  R  t   BlockUnderCursorR,  (   Rr   t   _CodeEditor__is_comment_barR  t   _CodeEditor__in_block_commentR  t   cursor3Rr  (    (   Rr   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  !	  sH    


c         C   sr   |  j    } | j   | j t j t j  | j   sQ | j t j t j  n  |  j j	 |  |  j
 |  d S(   s9   Kill the text on the current line from the cursor forwardN(   Rn  t   clearSelectionRp  R   Rx  R(  t   hasSelectionR+  R>  t   kill_cursorRq  (   Rr   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  U	  s    
c         C   sM   |  j    } | j   | j t j t j  |  j j |  |  j |  d S(   s:   Kill the text on the current line from the cursor backwardN(	   Rn  R  Rp  R   R  R(  R>  R  Rq  (   Rr   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  a	  s    

c         C   s   |  j    } | d 8} x* | rB t | j |   rB | d 8} q Wx) | rn t | j |   rn | d 8} qF W|  j   } | j | d  | S(   s   Find the start of the word to the left of the given position. If a
           sequence of non-word characters precedes the first word, skip over
           them. (This emulates the behavior of bash, emacs, etc.)
        i   (   R  RF   t   characterAtRn  R9  (   Rr   R   R  Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   _get_word_start_cursorj	  s    
	c         C   s   |  j    } |  j   } | j   } | j t j  | j   } x0 | | k  rr t | j |   rr | d 7} qC Wx/ | | k  r t | j |   r | d 7} qv W| j |  | S(   s   Find the end of the word to the right of the given position. If a
           sequence of non-word characters precedes the first word, skip over
           them. (This emulates the behavior of bash, emacs, etc.)
        i   (	   R  Rn  R   Rp  R   R  RF   R  R9  (   Rr   R   R  Rr  t   end(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   _get_word_end_cursorz	  s    c         C   sU   |  j    j   } |  j |  } | j | t j  |  j j |  |  j |  d S(   s   Kill the previous wordN(	   Rn  R   R  R9  R   R(  R>  R  Rq  (   Rr   R   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  	  s
    c         C   sU   |  j    j   } |  j |  } | j | t j  |  j j |  |  j |  d S(   s   Kill the next wordN(	   Rn  R   R  R9  R   R(  R>  R  Rq  (   Rr   R   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  	  s
    c   	      C   s   | d k r |  j   } n  | j   } | j   | j   } | j   } | j   } | r | j   rw | d j } nX d } x? | D]7 } | | j k r | | j | j	 k  r | j } q q W| d k r d S| j
   j   j   } | Sd Sd S(   sA   Get the syntax highlighting color for the current cursor positioniN(   RT   Rn  R&  R   R|   t   additionalFormatsR  RO  RH  R-  R  R   Rf  (	   Rr   Rr  R&  R   R|   t   block_formatst   current_formatt   fmtR   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __get_current_color	  s$    %c         C   s   |  j  r} | d k r$ |  j   } n |  j d |  } |  j  j d  } |  j  j d  } | | k sr | | k rv t St Sn t Sd S(   s4   Is the cursor inside or next to a comment or string?Rr  R  t   stringN(   R)  RT   t   _CodeEditor__get_current_colort   get_color_nameRY   Rn   (   Rr   Rr  t   current_colorR$  t   string_color(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  	  s    	c         C   s   d d d d d d d d g } d	 d
 d d g } | j    } | j   } t g  | D] } | | k ^ qR  rq t St |  d k  r t St g  | D] } | d | k ^ q  r t St Sd  S(   Nt   deft   fort   ift   whilet   witht   classt   elift   exceptt   elset   tryt   finallyi   i    (   R:  R  t   anyRY   RJ   Rn   (   Rr   RK   t   stmt_kwst	   whole_kwsRl  t   wkt   sk(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __colon_keyword	  s    	%)c         C   sX   d d d d d d g } | j    } t g  | D] } | j |  ^ q.  rP t St Sd  S(   NRM  s   \RO  RP  RN  R  (   R'  R  R  RY   Rn   (   Rr   RK   t	   end_charsR   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __forbidden_colon_end_char	  s
    (c   
      C   s/  | d k r- d d d g } d d d g } n+ | g } i d d 6d d 6d d 6| g } |  j   j   } | j   } x t |  D] \ } } | | k r |  j | | | d t }	 |	 d k s |	 | t |  k r t Sn  | | k r |  j | | | d t }	 |	 d k s |	 | k  r't Sq q Wt S(	   s   
        Checks if there is an unmatched brace in the 'text'.
        The brace type can be general or specified by closing_braces_type
        (')', ']', or '}')
        RN  RO  RP  RJ  RK  RL  RE  N(	   RT   Rn  R&  R   t	   enumeratet   find_brace_matchRY   RJ   Rn   (
   Rr   RK   t   closing_braces_typet   opening_bracest   closing_bracesR&  t   line_posR   RD   Rn  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __unmatched_braces_in_line	  s$    	"c         C   sE   x> t  |  D]0 \ } } | d k r |  j | |   r t Sq Wt S(   s"  
        Return whether a string has a colon which is not between brackets.
        This function returns True if the given string has a colon which is
        not between a pair of (round, square or curly) brackets. It assumes
        that the brackets in the string are balanced.
        RM  (   R  t%   _CodeEditor__unmatched_braces_in_lineRY   Rn   (   Rr   RK   R   RD   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __has_colon_not_in_brackets	  s     c         C   s   |  j  d d  } |  j   j   s( t S|  j   r8 t S|  j |  sK t S|  j |  r^ t S|  j |  rq t S|  j |  r t St	 Sd S(   s&   Decide if we want to autoinsert colonsR  Rr  N(
   R  Rn  R  Rn   R  t   _CodeEditor__colon_keywordt%   _CodeEditor__forbidden_colon_end_charR  t&   _CodeEditor__has_colon_not_in_bracketsRY   (   Rr   R=  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   autoinsert_colons
  s    c         C   sZ   | j  d d  } | j  d d  } | j d  d r; d S| j d  d rR d Sd Sd S(   s6  Return whether a string has open quotes.
        This simply counts whether the number of quote characters of either
        type in the string is odd.

        Take from the IPython project (in IPython/core/completer.py in v0.13)
        Spyder team: Add some changes to deal with escaped quotes

        - Copyright (C) 2008-2011 IPython Development Team
        - Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
        - Copyright (C) 2001 Python Software Foundation, www.python.org

        Distributed under the terms of the BSD License.
        s   \'RN   s   \"R  i   R  N(   R  RU  (   Rr   RK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __unmatched_quotes_in_line
  s    c         C   s8   |  j    } | j t j t j  t | j    } | S(   N(   Rn  Rp  R   R  R(  R2   R6  (   Rr   Rr  R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __next_char1
  s
    
c         C   sF   |  j  r> |  j   } |  j  j d  } | | k r7 t St Sn t Sd  S(   NR  (   R)  R  R  RY   Rn   (   Rr   R  R$  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   __in_comment8
  s    	c   
      C   sS  i d t  j 6d t  j 6| } |  j d d  } |  j d d  } |  j   } |  j d d  d } |  j d d  d } |  j d d  j   } |  j   r d j | |  j   | g  }	 |  j	 |	  n|  j
   r |  j	 |  ngt |  d	 k r |  j |  | k r |  j	 |  n/|  j |  rP| d
 | k rP|  j	 |  n |  j   | k r| j t j t j d  | j   |  j |  n | d
 | k r|  j	 d
 |  |  j   } | j t j t j d
  | j   |  j |  nZ | d | k r|  j	 |  n: |  j	 d |  |  j   } | j t j  |  j |  d S(   s@   Control how to automatically insert quotes in various situationsR  s   'R  t   eolRr  iiRN   i    i   i   i   N(   R   t   Key_QuoteDblt   Key_ApostropheR  Rn  R   R8  R  R`  R  t   _CodeEditor__in_commentRJ   t%   _CodeEditor__unmatched_quotes_in_linet   _CodeEditor__next_charRp  R   R  R(  R  Rq  t   PreviousCharacter(
   Rr   R  RD   R=  t   line_to_cursorRr  t
   last_threet   last_twoRl  RK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   autoinsert_quotesC
  sH    

c   
      C   s  t  |  t d  d t j d  d t d d  d |  j |  _ t  |  t d  d t j d  d t d d  d |  j |  _ t  |  t d	  d t j d
  d t d d  d |  j	 |  _
 t  |  t d  d t j d  d t d d  d |  j |  _ t  |  t d  d t j d  d t d d  d |  j |  _ t  |  t d  d t j d  d t d d  d |  j } t  |  t d  d t d  d t j d  d t d d  d |  j } t  |  t d  d t j d  d |  j |  _ t  |  t d  d t j d  d |  j |  _ t  |  t d  d t d d  d |  j |  _ t  |  t d   d t j d!  d t t  d |  j j |  _ t  |  t d"  d t j d!  d t t  d |  j j |  _ t  |  t d#  d t j d!  d t d d$  d |  j j |  _  t  |  t d%  d t j d&  d t d d'  d |  j! j |  _" t  |  t d(  d t j d)  d t t j#  d |  j$ j } t  |  t d*  d t j d+  d t t j%  d |  j& j } t  |  t d,  d t d-  d |  j' j } t( |   |  _) |  j |  j |  j  |  j" |  j d. |  j |  j d. |  j
 |  j |  j | g } d. | | | d. | g } t+ d. k	 r|  j |  j d. g } | | | }	 t, |  j) |	  n | | }	 t, |  j) |	  t( |   |  _- t, |  j- |  j d. | |  j f  d. S(/   s   Setup context menut   UndoR  R  t   shortcutRV   t	   triggeredt   RedoR  t   Cutt   editcutR  t   Copyt   editcopyR  t   Pastet	   editpasteR  s
   Select Allt	   selectalls
   select allt   Commentt   /t	   UncommentR  s   toggle comments   Clear all ouputt   ipython_consoles   Convert to Python scriptR   s   Go to definitions   go to definitions   Run cellt   run_cells   Run cell and advances   Re-run last cells   re-run last cells   Run &selection or current linet   run_selections   run selections   Zoom int   zoom_ins   Zoom outt   zoom_outs
   Zoom resets   Ctrl+0N(.   R9   R+   R  R  R.   R  t   undo_actionR  t   redo_actionR  t
   cut_actionR  t   copy_actionR  t   paste_actionR  R  R{  t   clear_all_output_actionR  t   ipynb_convert_actiont   go_to_definition_from_cursorRO  R   R0   R  RF  t   run_cell_actionR1   t   run_cell_and_advancet   run_cell_and_advance_actiont   re_run_last_cellt   re_run_last_cell_actionR  t   run_selection_actiont   ZoomInR  t   ZoomOutR  t
   zoom_resetR"   t   menuRT   Rq  R8   t   readonly_menu(
   Rr   t   selectall_actiont   toggle_comment_actiont   zoom_in_actiont   zoom_out_actiont   zoom_reset_actiont	   actions_1t	   actions_2t
   nb_actionst   actions(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRP  u
  s    ,
	c         C   s1   |  j  j   t t |   j |  | j   d S(   s   Override Qt method.N(   R@  RH  t   superR   t   keyReleaseEventt   ignore(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  
  s    c         C   s	  | j    } | j   t j @} | j   t j @} t | j    } |  j   } | rc |  j   n  t	 j
   r |  j |  n  d$ d% d& d' g } x | D] \ } }	 t t |  }
 t d |	  } t |
  j   } | |
 k r | | k r xJ |  j D]? } | j \ } }	 } | | k r | j j   | j   d Sq W| j   d Sq W| t j t j f k r| r| r|  j r|  j   r|  j   r|  j   j   |  j d |  j    |  j   |  j   j   q|  j    r|  j! r|  j"   q|  j#   } |  j   } | j$ | j%   j&   t' j(  |  j# d	 |  } | oJ| } |  j   j   t) j* |  |  |  j d
 |  |  j   j   q	| r|  j+ j   q	| r	|  j, j   q	n| r| t j- k r| r|  j.   q	|  j/   n| r| t j0 k r|  j1   n| t j0 k rJ| rJ| rJ|  j2 |  j3    n| t j4 k r| r| r|  j5 d d	  } t6 |  } | t6 | j7    } | s|  j8 rt) j* |  |  q	|  j5 d	 d  } | j9   r+| t6 |  j:  k r+| t6 |  j:  d k r|  j;   qt) j* |  |  q	| rS| j9   rS|  j< | |  q	| r| r| d | d d( k r|  j   } | j= t' j>  | j= t' j? t' j( d  | j@   q	t) j* |  |  |  j    r	|  jA d  |  _A q	n| t jB k rm|  j |  |  j   r	|  j#   r	|  jC r	tD |  j5 d d	   } | rj| jE   rj|  jF d tG  qjq	nc| t jH k r|  jI | |  nA| t jJ k r|  jK | |  n| d k r| r|  jL   |  jM |  n| d) k r| r|  jN r|  j5 d	 d  j9   } t6 |  d k s4| d d* k r|  j i d d 6d d 6|  |  j   } | j= t' j>  |  jO |  q	t) j* |  |  n>| t jP t jQ f k r|  jR r|  jS |  n| t jT t jU t jV f k r| r|  jN r|  j   jW   r|  j   } | j= t' j? t' j(  t | jX    } | i d t jT 6d t jU 6d t jV 6| k } | r|  jY | j%   j   |  r| jZ   |  jO |  q	t) j* |  |  n| t j[ k ri| ri|  j\ ri|  j5 d d	  } | j]   d+ k rVd   } t |  j   j%   j^   j    } | |  | |  k rV|  j; d  tG  qVn  t) j* |  |  ng| t j_ k r(	| r(	| r(	| r(	|  j\ r(	|  j5 d d	  } | j]   d, k r	d#   } t |  j   j%   j^   j    } | |  | |  k r	|  j; d  tG  q	n  t) j* |  |  n | t j` k rb	| rU	|  ja rU	|  jb   q	|  jc   nn | t jd k r	| r	|  ja r	|  je   q	|  j;   n4 t) j* |  |  |  j    r	| r	|  jA | 7_A n  d S(-   s   Reimplement Qt methodt	   SelectAlls
   Select AllR  R  R  RV   NRM  Rr  RY  R  R  i    is   ()s   []s   {}s   ''s   ""i   R  RN  RO  RP  R  RJ  RK  RL  R  R  c         S   s   t  |   t  |  j    S(   N(   RJ   R:  (   t   txt(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   Ri  R  R  c         S   s   t  |   t  |  j    S(   N(   RJ   R:  (   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   (   R  s
   Select All(   R  R  (   R  R  (   R  R  (   s   ()s   []s   {}s   ''s   ""(   RO  RP  (   R  RJ  RK  RL  (   R  R  (   R  R  (f   R  R  R   t   ControlModifierR  R2   RK   R8  R  R&   R  t   hide_tooltip_if_necessaryRo  R   R.   t   toStringR^  R  t	   activatedRF  R  t	   Key_Entert
   Key_ReturnRW  R  R  Rn  R$  R  R  RC  R,  R  R  t   select_completion_listR  R9  R&  R   R   R(  R>   t   keyPressEventR  R  t
   Key_DeleteR  R  t
   Key_InsertR  t   setOverwriteModet   overwriteModet   Key_BackspaceR  RJ   R'  RS  R   R  Rl  R8  Rp  R  R  R)  t   completion_textt
   Key_PeriodR  R)   t   isdigitR  RY   t   Key_Homet   stdkey_homet   Key_Endt
   stdkey_endt   hide_completion_widgett   handle_parenthesesRU  Rq  R  R  RV  R  t   Key_ParenRightt   Key_BraceRightt   Key_BracketRightR  R6  R  R  t	   Key_ColonRX  R:  R$  t	   Key_Spacet   Key_TabRR  R  R  t   Key_BacktabR!  (   Rr   R   R  t   ctrlR  RK   t   has_selectiont   checkst   qnameRf  t   seqR  t   defaultR  t   qsct   keystrt   cmt_or_str_cursorRr  t   cmt_or_str_line_begint
   cmt_or_strR  t   leading_lengtht   trailing_spacesRl  t   last_objt   s_trailing_textt   key_matches_next_chart   indt   prevtxt(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  
  s8   	


	
			
		

		$	$c         C   s)   t  |  j t j  r% |  j j   n  d S(   s   Run pygments highlighter.N(   R  R)  R&  R  t   make_charlist(   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRD    s    c         C   s   |  j  d  } |  j d d  j   } | p; | d d k } |  j r | r |  j d  |  j   } | j t j  |  j	 |  n |  j |  |  j
   r |  j d	 d  r |  j r |  j j |  n  d
 S(   s=   Handle left and right parenthesis depending on editor config.Rr  R  i    R  RJ  RK  RL  s   ()R  N(   R  RJ  RK  RL  (   R  R  R'  RU  R  Rn  Rp  R   R  Rq  R  R  R  RF  (   Rr   RK   R   t   restR  Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR,    s    	c         C   sX  |  j    r  t j |  |  d S|  j r| j   t j @r|  j | j    } | r|  j	   rt
 j t |   r|  j s t j t t j   t |  _ n  |  j | j    } | j t j  |  j d  |  j d | d t d |  j d |  j d t j | j   d Sn  |  j rDt j   t |  _ |  j d  n  t j |  |  d S(   s'   Underline words when pressing <CONTROL>Nt
   ctrl_clickRK  RX  RZ  R[  (   R8  R>   R   RT  R  R   R  t   get_word_atR   R  R6   Ra  R2   RY  R   t   setOverrideCursorR   t   PointingHandCursorRY   t   cursorForPositionR  R   R  RJ  Rd  R  R   t   SingleUnderlineRi   t   restoreOverrideCursorRn   (   Rr   R   RK   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s4    				

	
	c         C   s@   |  j  r, t j   t |  _  |  j d  n  t j |  |  d S(   s.   If cursor has not been restored yet, do it nowRH  N(   RY  R   RN  Rn   RJ  R>   t
   leaveEvent(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO    s
    	
	c         C   s   |  j  s d S| d k r( |  j   } n  |  j   r8 d S| j   } t | j    } t |  d k r | j t	 j
  t | j    } n  | d k	 r |  j j |  n  d S(   s3   Go to definition from cursor instance (QTextCursor)Ni    (   RT  RT   Rn  R  R   R2   R6  RJ   R  R   R  R  RF  (   Rr   Rr  R   RK   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s    	c         C   sq   | j    t j k r] | j   t j @r] t j |  |  |  j | j    } |  j	 |  n t j |  |  d S(   s   Reimplement Qt methodN(
   Rm   R   R  R  R  R>   R   RL  R   R  (   Rr   R   Rr  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR     s    c         C   s  |  j    } |  j j |  |  j j |  |  j j |  j   oJ t d k	  |  j	 j |  j   ol t d k	  |  j
 j |  j    |  j j |  j    |  j j |  j    |  j j |  j    |  j j |  j o |  j    |  j   } t | j    } t |  d k r<| j t j  t | j    } n  |  j j |  j   j    |  j j |  j   j    |  j } |  j   r|  j  } n  | j! | j"    | j#   d S(   s   Reimplement Qt methodi    N($   R8  R  RI   R  R  Rs  R
  Rq  RT   R  R  R  R   R  R  RO  RT  R  Rn  R2   R6  RJ   R  R   R  R  R  t   isUndoAvailableR  t   isRedoAvailableR  t
   isReadOnlyR  t   popupt	   globalPosRi   (   Rr   R   t   nonempty_selectionRr  RK   R  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   contextMenuEvent  s2    	c         C   s3   t  | j    r | j   n t j |  |  d S(   sW   Reimplement Qt method
        Inform Qt about the types of data that the widget acceptsN(   R:   t   mimeDataR  R>   t   dragEnterEvent(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRX    s    c         C   s3   t  | j    r | j   n t j |  |  d S(   s?   Reimplement Qt method
        Unpack dropped data and handle itN(   R:   RW  R  R>   t	   dropEvent(   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRY  &  s    c         C   s1   |  j  |  t j |  |  |  j j |  d S(   s:   Overrides paint event to update the list of visible blocksN(   t   update_visible_blocksR>   R   R`  RF  (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR   0  s    c   	      C   s  g  |  j  (|  j   } | j   } t |  j |  j |  j    j    } | t |  j |  j	    } d } |  j	   } x | j
   r| | k } | s Pn  | j   r |  j  j | | d | f  n  | j   } | } | t |  j |  j	    } | j   } q Wd S(   s0   Update the list of visible blocks/lines positioni    i   N(   R_  R  Rc  R}   R  R  R  R  R  R   R  R  R   R  (	   Rr   R   R&  Rc  R  R  t   ebottom_topt   ebottom_bottomt   visible(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRZ  6  s$    
 c         C   s   |  j  r |  j } t |  j    } | j   } | j t j  | j |  | j	 |  xK |  j
 D]= \ } } } |  j |  rd | j d | |  j   |  qd qd Wn  d S(   s#   Draw a line on top of a define celli   N(   R;  R$  R   R  t   pent   setStyleR   t	   SolidLineR   R   R  t   is_cell_separatort   drawLineRu  (   Rr   t   cell_line_colorR   R^  R  R  R&  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRa  L  s    		c         C   s   |  j  S(   sH  
        Returns the list of visible blocks.

        Each element in the list is a tuple made up of the line top position,
        the line number (already 1 based), and the QTextBlock itself.

        :return: A list of tuple(top position, line number, block)
        :rtype: List of tuple(int, int, QtGui.QTextBlock)
        (   R_  (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR  Z  s    c         C   s   t  S(   N(   RY   (   Rr   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt	   is_editorg  s    N(   R   R   R   R   R   R   R   s       (   R   R   R   R&  R  R=   R  t   Fortran77SHRT   t	   FortranSHt   IdlSHt   DiffSHt	   GetTextSHt   NsisSHt   HtmlSHt   YamlSHt   CppSHt   OpenCLSHR  t
   MarkdownSHR  R  R	   R   R`  R	  R  R  t   boolR  R}   R  R  R  R  R  R  t   go_to_definition_regexRE  t   focus_changedR  R~  RO   R]  R  R  R  R  R  RY   Rn   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R
  R  R  R  R  R  R!  R"  R   R  R.  R0  R7  R
   R  Rb  Re  R7  R  R   t   SpellCheckUnderlineRd  RG  Ro  Rp  RK  Rr  R#  Rv  R   R  R  R   R  R   R   R   R   R  R  R[  R  R  R?  R  R  R   R  R  R  R  R}  R   R  R  R  R  R  R  R  R  R  R  R   R  R   R  R  R
  R  R  R  R  R#  R&  R'  R)  R4  t(   _CodeEditor__is_cursor_at_start_of_blockR8  R>  RC  R@  R?  R{  R  Rj  R  Rl  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  RP  R  R  RD  R,  R   RO  R  R   RV  RX  RY  R   RZ  Ra  t   propertyR  Rd  (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR   C  s  							|											=																															#									8						$												9					
									5						2		
	5									4																2	\							
	 			
			t   Printerc           B   s#   e  Z e j d d   Z d   Z RS(   c         C   s[   t  j |  |  |  j t  j  |  j t  j  t j   |  _ | d  k	 rW | |  _
 n  d  S(   N(   R   RO   t   setColorModet   Colort   setPageOrdert   FirstPageFirstt   timet   ctimet   dateRT   t   header_font(   Rr   t   modeR~  (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO   q  s    c         C   s   d |  j    |  j | f } | j   | j |  j  | j t t j   | r | j	 | j
   | j   j |  | j   | j   j   |  n  | j | j   | j   j   d  | j   d  S(   Ns   %s - %s - Page %si   (   t   docNameR}  t   saveR  R~  R   R   R   t   blackR  R  Ry  Ru  R  t   ascentt   setTopR   t   restore(   Rr   R   t   drawingt   areat   pagenrt   header(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt
   formatPage{  s    
"#'N(   R   R   R   t   ScreenResolutionRT   RO   R  (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRv  p  s   
t
   TestWidgetc           B   s   e  Z d    Z d   Z RS(   c            s   t  j   |  t      _   j j d t d t d t d t d d  d t d d	    j   j  d
 d l	 m
 } |      _   j   j    j j j   f d      j d d    j d d    j t j d   d  S(   NR  R  RR  R  s   Courier Newi
   R  R+  t   Zenburni(   t   OutlineExplorerWidgetc            s     j  j | |  S(   N(   RV   R
  (   t   _fnR   R  (   Rr   (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRM     RN   i    i   i   t   spyder(   R$   RO   R   RV   R  RY   Rn   R   Rb   t   spyder.widgets.editortoolsR  t	   classtreet	   edit_gotoR_   t   setStretchFactort   setWindowIconR  R  (   Rr   Rb  R  (    (   Rr   sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyRO     s    c         C   sb   |  j  j |  |  j d t d  t j |  t j |  f  |  j j |  j  | t	 t	  d  S(   Ns   %s - %s (%s)RH   (
   RV   R  RW   R+   R   t   basenamet   dirnameR  t   set_current_editorRn   (   Rr   R   (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   load  s
    (   R   R   RO   R  (    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyR    s   	c         C   s   d d l  m } | d d  } t d   } | j   | j |   | j d d  d d l m } m	 } t
 | j j    } | | |   | | |   } | j j |  t j | j    d  S(   Ni(   t   qapplicationt	   test_timei   i  i  (   t   check_with_pyflakest   check_with_pep8(   t   spyder.utils.qthelpersR  R  RT   t   showR  t   resizet   spyder.utils.codeanalysisR  R  R2   RV   R/  R  R  t   exitR  (   t   fnameR  t   appt   winR  R  R6  t   results(    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   test  s    
t   __main__i   (w   R   t
   __future__R    t   unicodedataR   t   os.patht   pathR   R  Rh  R  R{  t   qtpyR   t   qtpy.compatR   t   qtpy.QtCoreR   R   R   R   R   R	   R
   t
   qtpy.QtGuiR   R   R   R   R   R   R   R   R   R   R   R   R   R   t   qtpy.QtPrintSupportR   t   qtpy.QtWidgetsR   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   t   spyder_kernels.utils.dochelpersR)   t   spyder.config.baseR*   R+   R,   t   spyder.config.guiR-   R.   t   spyder.config.mainR/   R0   R1   t   spyder.py3compatR2   t   spyder.utilsR3   R  R4   R&  R5   R6   t   spyder.utils.programsR7   R  R8   R9   R:   t   spyder.utils.sourcecodeR;   R<   R  R=   t   spyder.widgets.sourcecode.baseR>   t#   spyder.widgets.sourcecode.kill_ringR?   Rq  t	   nbconvertR@   R|  RT   t   LOG_FILENAMEt   DEBUG_EDITORR  RF   RG   R   R   R   R   R   R   R   Rv  R  R  R   RJ   t   argvR  t   __file__(    (    (    sC   lib/python2.7/site-packages/spyder/widgets/sourcecode/codeeditor.pyt   <module>	   s~   4^d
		J$A	           8	