ó
‹²,]c           @   sz  d  Z  d d l j 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 d d l m Z m Z m Z m Z m Z d d l m Z d d l m Z d d	 l m Z m Z y e d
 d ƒ Z Wn( e k
 rþ Z d d l Z e j Z n Xd e
 f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d „  Z# e$ d k rve# ƒ  n  d S(   s   Breakpoint widgetiÿÿÿÿN(   t   API(   t   to_qvariant(   t   QAbstractTableModelt   QModelIndext   Qtt   Signal(   t   QItemDelegatet   QMenut
   QTableViewt   QVBoxLayoutt   QWidget(   t   get_translation(   t   CONF(   t   add_actionst   create_actiont   breakpointst   spyder_breakpointst   BreakpointTableModelc           B   s}   e  Z d  Z d „  Z d „  Z e ƒ  d „ Z e ƒ  d „ Z e j	 d „ Z
 e j d „ Z d „  Z e j d „ Z d	 „  Z RS(
   s5   
    Table model for breakpoints dictionary
    
    c         C   sH   t  j |  | ƒ | d  k r% i  } n  d  |  _ d  |  _ |  j | ƒ d  S(   N(   R   t   __init__t   Nonet   _dataR   t   set_data(   t   selft   parentt   data(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   ,   s    			c         C   s   | |  _  t | j ƒ  ƒ } g  |  _ xZ | D]R } | | } | r+ x9 | | D]* } |  j j | | d | d d f ƒ qL Wq+ q+ W|  j ƒ  d S(   s   Set model datai    i   t    N(   R   t   listt   keysR   t   appendt   reset(   R   R   R   t   keyt   bp_listt   item(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   4   s    		
/c         C   s   t  |  j ƒ S(   s   Array row number(   t   lenR   (   R   t   qindex(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   rowCount@   s    c         C   s   d S(   s   Array column counti   (    (   R   R"   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   columnCountD   s    c         C   sv   | d k r; |  j  j d d „  ƒ |  j  j d d „  ƒ n- | d k rJ n | d k rY n | d k rh n  |  j ƒ  d S(	   s   Overriding sort methodi    R   c         S   s   |  d S(   Ni   (    (   t
   breakpoint(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   <lambda>L   R   c         S   s   t  j |  d ƒ S(   Ni    (   t   ospt   basename(   R%   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   N   R   i   i   i   N(   R   t   sortR   (   R   t   columnt   order(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR)   H   s    
c         C   sn   | t  j k r t ƒ  St | ƒ } | t  j k rc t d ƒ t d ƒ t d ƒ d f } t | | ƒ St ƒ  Sd S(   s   Overriding method headerDatat   Filet   Linet	   ConditionR   N(   R   t   DisplayRoleR   t   intt
   Horizontalt   _(   R   t   sectiont   orientationt   rolet   i_columnt   headers(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt
   headerDataW   s    $c         C   s   |  j  | j ƒ  | j ƒ  S(   s   Return current value(   R   t   rowR*   (   R   t   index(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt	   get_valueb   s    c         C   sã   | j  ƒ  s t ƒ  S| t j k rr | j ƒ  d k rV t j |  j | ƒ ƒ } t | ƒ S|  j | ƒ } t | ƒ Snm | t j k r› t t	 t j
 t j Bƒ ƒ S| t j k rß | j ƒ  d k rÕ |  j | ƒ } t | ƒ St ƒ  Sn  d S(   s   Return data at table indexi    N(   t   isValidR   R   R/   R*   R'   R(   R;   t   TextAlignmentRoleR0   t	   AlignLeftt   AlignVCentert   ToolTipRole(   R   R:   R5   t   value(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   f   s    

c         C   s   |  j  ƒ  |  j ƒ  d  S(   N(   t   beginResetModelt   endResetModel(   R   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   z   s    
(   t   __name__t
   __module__t   __doc__R   R   R   R#   R$   R   t   DescendingOrderR)   R/   R8   R;   R   R   (    (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   '   s   			t   BreakpointDelegatec           B   s   e  Z d d  „ Z RS(   c         C   s   t  j |  | ƒ d  S(   N(   R   R   (   R   R   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   €   s    N(   RD   RE   R   R   (    (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyRH      s   t   BreakpointTableViewc           B   sh   e  Z e e e e ƒ Z e e e ƒ Z e ƒ  Z e ƒ  Z d  „  Z	 d „  Z
 d „  Z d „  Z d „  Z RS(   c         C   s_   t  j |  | ƒ t |  | ƒ |  _ |  j |  j ƒ t |  ƒ |  _ |  j |  j ƒ |  j ƒ  d  S(   N(	   R   R   R   t   modelt   setModelRH   t   delegatet   setItemDelegatet   setup_table(   R   R   R   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   Š   s    c         C   sN   |  j  ƒ  j t ƒ |  j ƒ  |  j d ƒ |  j t ƒ |  j d t j	 ƒ d S(   s   Setup tablei    N(
   t   horizontalHeadert   setStretchLastSectiont   Truet   adjust_columnst   columnAtt   setSortingEnabledt   Falset   sortByColumnR   RG   (   R   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyRN   “   s
    
c         C   s(   x! t  d ƒ D] } |  j | ƒ q Wd S(   s&   Resize three first columns to contentsi   N(   t   ranget   resizeColumnToContents(   R   t   col(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyRR   œ   s    c         C   sš   |  j  | j ƒ  ƒ } |  j j rt |  j j | j ƒ  d } |  j j | j ƒ  d } |  j j | t | ƒ d ƒ n  | j ƒ  d k r– |  j	 j ƒ  n  d S(   s   Reimplement Qt methodi    i   R   i   N(
   t   indexAtt   posRJ   R   R9   t	   edit_gotot   emitR0   R*   t"   set_or_edit_conditional_breakpoint(   R   t   eventt   index_clickedt   filenamet   line_number_str(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   mouseDoubleClickEvent¡   s    c            sŽ  ˆ  j  | j ƒ  ƒ } g  } t ˆ  ƒ ˆ  _ t ˆ  t d ƒ d ‡  f d †  ƒ} | j | ƒ ˆ  j j rZˆ  j j | j	 ƒ  d } t
 ˆ  j j | j	 ƒ  d ƒ } t d k sÚ | | ‡  f d † } | | ‡  f d † } n* | | ‡  f d	 † } | | ‡  f d
 † } t ˆ  t d ƒ d | ƒ}	 | j d |	 ƒ t ˆ  t d ƒ d | ƒ}
 | j |
 ƒ n  t ˆ  j | ƒ ˆ  j j | j ƒ  ƒ | j ƒ  d  S(   Ns   Clear breakpoints in all filest	   triggeredc              s   ˆ  j  j ƒ  S(   N(   t   clear_all_breakpointsR]   (    (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   ±   R   i    i   t   pysidec            s   ˆ  j  j | | ƒ S(   N(   t   clear_breakpointR]   (   t   _checkedRa   t   lineno(   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   ¸   s    c            s%   ˆ  j  j | | d ƒ ˆ  j j ƒ  f S(   NR   (   R\   R]   R^   (   Rh   Ra   Ri   (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   º   s    c            s   ˆ  j  j |  | ƒ S(   N(   Rg   R]   (   Ra   Ri   (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   ¾   s    c            s%   ˆ  j  j |  | d ƒ ˆ  j j ƒ  f S(   NR   (   R\   R]   R^   (   Ra   Ri   (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   À   s    s   Clear this breakpoints   Edit this breakpoint(   RZ   R[   R   t
   popup_menuR   R2   R   RJ   R   R9   R0   R    t   insertR   t   popupt	   globalPost   accept(   R   R_   R`   t   actionst   clear_all_breakpoints_actionRa   Ri   t
   clear_slott	   edit_slott   clear_breakpoint_actiont   edit_breakpoint_action(    (   R   sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   contextMenuEvent«   s4     		(   RD   RE   R   t   strR0   R\   Rg   Re   R^   R   RN   RR   Rc   Ru   (    (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyRI   „   s   								
t   BreakpointWidgetc           B   sk   e  Z d  Z d Z e ƒ  Z e ƒ  Z e e e ƒ Z	 e e e e ƒ Z
 d „  Z d „  Z d „  Z d „  Z RS(   s   
    Breakpoint widget
    s   1.0.0c            sÏ   t  j ˆ  | ƒ ˆ  j d ƒ t ˆ  ˆ  j ƒ  ƒ ˆ  _ t ƒ  } | j ˆ  j ƒ ˆ  j | ƒ ˆ  j j	 j
 ‡  f d †  ƒ ˆ  j j j
 ‡  f d †  ƒ ˆ  j j j
 ‡  f d †  ƒ ˆ  j j j
 ‡  f d †  ƒ d  S(   Nt   Breakpointsc              s   ˆ  j  j ƒ  S(   N(   Re   R]   (    (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   æ   R   c            s   ˆ  j  j |  | ƒ S(   N(   Rg   R]   (   t   s1t   lino(   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   è   R   c            s   ˆ  j  j |  | | ƒ S(   N(   R\   R]   (   Ry   Rz   t   s2(   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   ê   R   c              s   ˆ  j  j ƒ  S(   N(   R^   R]   (    (   R   (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR&   ì   R   (   R
   R   t   setWindowTitleRI   t   _load_all_breakpointst
   dictwidgetR	   t	   addWidgett	   setLayoutRe   t   connectRg   R\   R^   (   R   R   t   layout(    (   R   sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   Ü   s    	c         C   sU   t  j d d i  ƒ } x9 t | j ƒ  ƒ D]% } t j | ƒ s( | j | ƒ q( q( W| S(   Nt   runR   (   R   t   getR   R   R'   t   isfilet   pop(   R   t   bp_dictRa   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR}   î   s
    c         C   s   d  S(   N(    (   R   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   get_dataõ   s    c         C   sF   |  j  ƒ  } |  j j j | ƒ |  j j ƒ  |  j j d t j ƒ d  S(   Ni    (   R}   R~   RJ   R   RR   RV   R   RG   (   R   R‡   (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyR   ø   s    (   RD   RE   RF   t   VERSIONR   Re   R^   Rv   R0   Rg   R\   R   R}   Rˆ   R   (    (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyRw   Ò   s   					c          C   sF   d d l  m }  |  ƒ  } t d ƒ } | j ƒ  t j | j ƒ  ƒ d S(   s   Run breakpoint widget testiÿÿÿÿ(   t   qapplicationN(   t   spyder.utils.qthelpersRŠ   Rw   R   t   showt   syst   exitt   exec_(   RŠ   t   appt   widget(    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   test  s
    	
t   __main__(%   RF   t   os.patht   pathR'   R   t   qtpyR    t   qtpy.compatR   t   qtpy.QtCoreR   R   R   R   t   qtpy.QtWidgetsR   R   R   R	   R
   t   spyder.config.baseR   t   spyder.config.mainR   R‹   R   R   R2   t   KeyErrort   errort   gettextR   RH   RI   Rw   R’   RD   (    (    (    sH   lib/python2.7/site-packages/spyder_breakpoints/widgets/breakpointsgui.pyt   <module>   s*   "(XN0		