ó
‹²,]c           @   sy  d  Z  d d l j Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z m Z m Z m Z m Z m Z m Z d d l m Z d d l m Z d d l m Z d d	 l m Z m Z d d
 l m Z d d l m Z d d l  m! Z! m" Z" m# Z# d d l$ m% Z% d d l& m' Z' d d l( m) Z) d d l* m+ Z+ d e f d „  ƒ  YZ, d e f d „  ƒ  YZ- d S(   s   Console History PluginiÿÿÿÿN(   t   PYQT5(   t   Signalt   Slot(   t	   QGroupBoxt   QHBoxLayoutt   QInputDialogt   QMenut   QToolButtont   QVBoxLayoutt   QWidget(   t   _(   t   SpyderPluginWidget(   t   PluginConfigPage(   t   is_text_stringt   to_text_string(   t   encoding(   t   icon_manager(   t   add_actionst   create_actiont   create_toolbutton(   t   normalize_eols(   t   Tabs(   t
   codeeditor(   t   FindReplacet   HistoryConfigPagec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  j d ƒ S(   Nt   history(   t   imat   icon(   t   self(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   get_icon%   s    c   	      C   s'  t  t d ƒ ƒ } |  j t d ƒ t d ƒ d d d d d d	 d d
 t d ƒ ƒ} t  t d ƒ ƒ } |  j t d ƒ d ƒ } |  j t d ƒ d ƒ } t ƒ  } | j | ƒ | j | ƒ t ƒ  } | j | ƒ | j | ƒ | j | ƒ t ƒ  } | j | ƒ | j | ƒ | j d ƒ |  j | ƒ d  S(   Nt   Settingss   History depth: s    entriest   max_entriest   min_i
   t   max_i'  t   stept   tips   Set maximum line counts   Source codes
   Wrap linest   wraps"   Scroll automatically to last entryt	   go_to_eofi   (   R   R
   t   create_spinboxt   create_checkboxR   t	   addWidgett	   setLayoutt
   addStretch(	   R   t   settings_groupt	   hist_spint   sourcecode_groupt   wrap_mode_boxt   go_to_eof_boxt   settings_layoutt   sourcecode_layoutt   vlayout(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt
   setup_page(   s*    			(   t   __name__t
   __module__R   R3   (    (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyR   $   s   	t
   HistoryLogc           B   sË   e  Z d  Z d Z e Z e ƒ  Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e ƒ  d „  ƒ Z e e ƒ d „  ƒ Z RS(   s   
    History log widget
    t
   historylogc         C   sí  d  |  _ d  |  _ d  |  _ d  |  _ g  |  _ g  |  _ t rU t j	 |  | d | ƒn t j	 |  | ƒ |  j
 ƒ  t ƒ  } t |  |  j ƒ |  _ |  j j j |  j ƒ |  j j j |  j ƒ t j d k r t ƒ  } | j d ƒ t | ƒ } | j d d d d ƒ | j |  j ƒ | j | ƒ n | j |  j ƒ t |  d t d ƒ d t j d ƒ ƒ} | j t j ƒ t  |  ƒ } t! | |  j ƒ | j" | ƒ |  j j# | ƒ t$ |  ƒ |  _% |  j% j& ƒ  |  j' |  j% ƒ | j |  j% ƒ |  j( | ƒ d  S(	   Nt   maint   darwins   tab-containeri    t   textt   OptionsR   t   tooloptions()   t   Nonet	   tabwidgett   menu_actionst
   dockviewert   wrap_actiont   editorst	   filenamesR    R   t   __init__t   initialize_pluginR   R   t   currentChangedt   connectt   refresh_plugint	   move_datat   move_tabt   syst   platformR	   t   setObjectNameR   t   setContentsMarginsR(   R   R
   R   R   t   setPopupModeR   t   InstantPopupR   R   t   setMenut   setCornerWidgetR   t   find_widgett   hidet   register_widget_shortcutsR)   (   R   t   parentt   layoutt   tab_containert
   tab_layoutt   options_buttont   menu(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyRD   L   sD    						
		c         C   s
   t  d ƒ S(   s   Return widget titles   History log(   R
   (   R   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   get_plugin_title~   s    c         C   s   t  j d ƒ S(   s   Return widget iconR   (   R   R   (   R   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   get_plugin_icon‚   s    c         C   s   |  j  j ƒ  S(   sq   
        Return the widget to give focus to when
        this plugin's dockwidget is raised on top-level
        (   R>   t   currentWidget(   R   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   get_focus_widget†   s    c         C   s   t  S(   s3   Perform actions before parent main window is closed(   t   True(   R   t
   cancelable(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   closing_plugin   s    c         C   s;   |  j  j ƒ  r! |  j  j ƒ  } n d } |  j j | ƒ d S(   s   Refresh tabwidgetN(   R>   t   countR^   R=   RS   t
   set_editor(   R   t   editor(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyRH   ‘   s    c         C   s‰   t  |  t d ƒ d t j d ƒ t d ƒ d |  j ƒ} t  |  t d ƒ d |  j ƒ|  _ |  j j |  j	 d ƒ ƒ | |  j g |  _
 |  j
 S(	   s*   Return a list of actions related to plugins
   History...R   s   Set history maximum entriest	   triggereds
   Wrap linest   toggledR$   N(   R   R
   R=   R   R   t   change_history_deptht   toggle_wrap_modeRA   t
   setCheckedt
   get_optionR?   (   R   t   history_action(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   get_plugin_actions™   s    c         C   s   |  j  j |  j  j |  ƒ d S(   s3   Action to be performed on first plugin registrationN(   R8   t   tabify_pluginst
   ipyconsole(   R   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   on_first_registration¥   s    c         C   sF   |  j  j |  j j ƒ |  j j |  ƒ |  j j j j j |  j ƒ d S(   s'   Register plugin in Spyder's main windowN(	   t   focus_changedRG   R8   t   plugin_focus_changedt   add_dockwidgett   consolet   shellt   refreshRH   (   R   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   register_plugin©   s    c         C   s@   |  j  ƒ  } |  j ƒ  } x! |  j D] } | j | | ƒ q" Wd S(   s   Update font from PreferencesN(   t   get_color_schemet   get_plugin_fontRB   t   set_font(   R   t   color_schemet   fontRe   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   update_font°   s    c   
      C   sÐ   d } |  j  ƒ  } d } |  j ƒ  } d } |  j | ƒ } |  j j | ƒ x€ |  j D]u } | | k r | | k rw | n d }	 | j | |	 ƒ n | | k r¬ | j | ƒ n  | | k rS | j	 | ƒ qS qS Wd S(   s*   Apply configuration file's plugin settingst   color_scheme_namet   plugin_fontR$   N(
   Rx   Ry   Rk   RA   Rj   RB   R=   Rz   t   set_color_schemeRi   (
   R   t   optionst   color_scheme_nt   color_scheme_ot   font_nt   font_ot   wrap_nt   wrap_oRe   t   scs(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   apply_plugin_settings·   s    c         C   sN   |  j  j | ƒ } |  j j | ƒ } |  j  j | | ƒ |  j j | | ƒ d S(   sU   
        Move tab (tabs themselves have already been moved by the tabwidget)
        N(   RC   t   popRB   t   insert(   R   t
   index_fromt   index_tot   filenameRe   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyRJ   Ê   s    c            s;  t  j | ƒ } | ˆ  j k r" d St j ˆ  ƒ } t j | ƒ d d k rS d } n d } | j d t d | d t ƒ | j	 j
 ‡  f d	 †  ƒ | j t ƒ ˆ  j ƒ  } | j ˆ  j ƒ  | ƒ | j ˆ  j d
 ƒ ƒ y t  j | ƒ \ } } Wn t t f k
 rd } n Xt | ƒ } g  t j d | ƒ D] } | j ƒ  ^ q+} ˆ  j d ƒ }	 t | ƒ |	 k r¬| | |	 d d } y t  j | | ƒ Wq¬t t f k
 r¨q¬Xn  | j | ƒ | j d ƒ ˆ  j j | ƒ ˆ  j j | ƒ ˆ  j j  | t j! | ƒ ƒ }
 ˆ  j" j# | ƒ ˆ  j j$ |
 | ƒ ˆ  j j% |
 ƒ d S(   sc   
        Add new history tab
        Slot for add_history signal emitted by shell instance
        Ni   s   .pyt   pyt   batt   linenumberst   languaget   scrollflagareac              s   ˆ  j  j ƒ  S(   N(   Rq   t   emit(    (   R   (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   <lambda>ä   t    R$   s7   # Previous history could not be read from disk, sorry

s   
R   t   eof(&   R   t   to_unicode_from_fsRC   R   t
   CodeEditort   ospt   splitextt   setup_editort   FalseRq   RG   t   setReadOnlyR`   Rx   Rz   Ry   Ri   Rk   t   readt   IOErrort   OSErrorR   t   ret   finditert   startt   lent   writet   set_textt   set_cursor_positionRB   t   appendR>   t   addTabt   basenameRS   Rd   t   setTabToolTipt   setCurrentIndex(   R   RŽ   Re   R’   R{   R:   R
   t   mt
   linebreakst   maxNlinet   index(    (   R   s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   add_historyÕ   sF    	
+c         C   s   t  | ƒ s$ t | j ƒ  d ƒ } n  t | ƒ } |  j j | ƒ } |  j | j | ƒ |  j d ƒ r| |  j | j d ƒ n  |  j	 j
 | ƒ d S(   sy   
        Append an entry to history filename
        Slot for append_to_history signal emitted by shell instance
        s   utf-8R%   R—   N(   R   R   t   toUtf8RC   R±   RB   R©   Rk   R¨   R>   R­   (   R   RŽ   t   commandR±   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   append_to_history  s    c         C   sV   t  j |  t d ƒ t d ƒ |  j d ƒ d d ƒ \ } } | rR |  j d | ƒ n  d S(   s   Change history max entriest   Historys   Maximum entriesR   i
   i'  N(   R   t   getIntR
   Rk   t
   set_option(   R   t   deptht   valid(    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyRh     s    	c         C   sH   |  j  d k r d Sx |  j D] } | j | ƒ q W|  j d | ƒ d S(   s   Toggle wrap modeNR$   (   R>   R=   RB   Ri   R¸   (   R   t   checkedRe   (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyRi     s
    (   R4   R5   t   __doc__t   CONF_SECTIONR   t   CONFIGWIDGET_CLASSR   Rq   RD   R\   R]   R_   R   Rb   RH   Rm   Rp   Rw   R}   R‰   RJ   R²   Rµ   R   Rh   t   boolRi   (    (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyR6   D   s(   		2											0	
(.   R¼   t   os.patht   pathRš   RK   R¢   t   qtpyR    t   qtpy.QtCoreR   R   t   qtpy.QtWidgetsR   R   R   R   R   R   R	   t   spyder.config.baseR
   t   spyder.pluginsR   t   spyder.plugins.configdialogR   t   spyder.py3compatR   R   t   spyder.utilsR   R   R   t   spyder.utils.qthelpersR   R   R   t   spyder.utils.sourcecodeR   t   spyder.widgets.tabsR   t   spyder.widgets.sourcecodeR   t   spyder.widgets.findreplaceR   R   R6   (    (    (    s5   lib/python2.7/site-packages/spyder/plugins/history.pyt   <module>   s&   4 