ó
)sEOc           @   sp   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e j e j @Z d d d „  ƒ  YZ	 d S(   iÿÿÿÿNt   CodeBoxesHandlerc           B   s§   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s   Handler of the CodeBoxesc         C   s   | |  _  d S(   s   Lists Handler bootN(   t   dad(   t   selfR   (    (    s   modules/codeboxes.pyt   __init__    s    c         G   s*   |  j  j |  j ƒ |  j  j j d ƒ d S(   s   Cut CodeBoxs   cut-clipboardN(   R   t   object_set_selectiont   curr_codebox_anchort
   sourceviewt   emit(   R   t   args(    (    s   modules/codeboxes.pyt   codebox_cut$   s    c         G   s*   |  j  j |  j ƒ |  j  j j d ƒ d S(   s   Copy CodeBoxs   copy-clipboardN(   R   R   R   R   R   (   R   R   (    (    s   modules/codeboxes.pyt   codebox_copy)   s    c         G   sI   |  j  j |  j ƒ |  j  j j t |  j  j j ƒ  ƒ |  j  j j ƒ  d S(   s   Delete CodeBoxN(	   R   R   R   t   curr_buffert   delete_selectiont   TrueR   t   get_editablet
   grab_focus(   R   R   (    (    s   modules/codeboxes.pyt   codebox_delete.   s    "c         C   s;   t  j j | j ƒ } | d k r7 |  j j j j ƒ  n  d S(   s(   Catches CodeBoxHandle Dialog key pressest   ReturnN(   t   gtkt   gdkt   keyval_namet   keyvalR   t   gladet   codeboxhandledialog_button_okt   clicked(   R   t   widgett   eventt   keyname(    (    s   modules/codeboxes.pyt    on_key_press_codeboxhandledialog4   s     c         C   sž  |  j  j j ƒ  rE |  j  j j ƒ  \ } } |  j  j j | | ƒ } n d } |  j  j j j t	 d ƒ ƒ |  j  j j j
 ƒ  } |  j  j j j ƒ  | d k rŸ d Si t |  j  j j j ƒ  ƒ d 6t |  j  j j j ƒ  ƒ d 6|  j  j j j ƒ  d 6|  j  j |  j  j j j ƒ  d d 6|  j  j j j ƒ  d 6|  j  j j j ƒ  d	 6| d
 6} | ri|  j  j j | | ƒ n  |  j  j j |  j  j j ƒ  ƒ } |  j | | ƒ d S(   s   Insert Code Boxs   Insert a CodeBoxi   Nt   frame_widtht   frame_heightt   width_in_pixelst   syntax_highlightingt   highlight_bracketst   show_line_numberst	   fill_text(   R   R   t   get_has_selectiont   get_selection_boundst   get_textt   NoneR   t   codeboxhandledialogt	   set_titlet   _t   runt   hidet   intt   spinbutton_codebox_widtht	   get_valuet   spinbutton_codebox_heightt   radiobutton_codebox_pixelst
   get_activet   prog_lang_liststoret   combobox_prog_lang_codeboxt   get_active_itert!   checkbutton_codebox_matchbracketst   checkbutton_codebox_linenumberst   deletet   get_iter_at_markt
   get_insertt   codebox_insert(   R   t   iter_sel_startt   iter_sel_endR#   t   responset   codebox_dictt   iter_insert(    (    s   modules/codeboxes.pyt   codebox_handle9   s*     $
 !c   	      C   sæ  | s |  j  j } n  | j | ƒ } | d | _ | d | _ | d | _ | d | _ | d | _ | d | _ t	 j
 ƒ  | _ | j j |  j  j j |  j  j ƒ ƒ |  j  j | j | j ƒ | j j | j ƒ | j j d |  j  j ƒ | j j d |  j  j ƒ | j j d	 |  j  j ƒ | d
 rN| j j | d
 ƒ | j j t ƒ n  t	 j | j ƒ | _ | j j t	 j ƒ |  j  j r•| j j t ƒ n  |  j  j  r´| j j! t" ƒ n  | j j# t$ j% |  j  j& ƒ ƒ | j j' | j ƒ | j j( |  j  j) ƒ | j j* |  j  j+ ƒ | j j, |  j  j- ƒ | j j d |  j. | ƒ | j j d |  j/ | ƒ | j j d |  j0 | ƒ |  j  j1 r•| j j2 t3 j4 ƒ n | j j2 t3 j5 ƒ t3 j6 ƒ  } | j7 t3 j8 t3 j8 ƒ | j9 | j ƒ t3 j: ƒ  | _; |  j< | ƒ | j; j9 | ƒ |  j  j j= | j; | ƒ x9 t3 j> t3 j? t3 j@ t3 jA g D] } | j jB | d ƒ q>W| j; jC t3 jD ƒ | j; jE ƒ  | r¬| jF | ƒ } |  j  jG jH | | | ƒ n6 |  j  jI râ|  j  jG jJ |  j  jK |  j  jL d ƒ n  d S(   s   Insert Code BoxR   R   R   R    R!   R"   s   insert-texts   delete-ranges   modified-changedR#   s   populate-popupt   key_press_events   button-press-eventi   i   N(M   R   R   t   create_child_anchorR   R   R   R    R!   R"   t   gtksourceview2t   Buffert   sourcebuffert   set_style_schemet   sourcestyleschememanagert
   get_schemet   style_schemet!   set_sourcebuffer_syntax_highlightt   set_highlight_matching_bracketst   connectt   on_text_insertiont   on_text_removalt   on_modified_changedt   set_textt   set_modifiedt   Falset   ViewR   t   set_smart_home_endt   SMART_HOME_END_BEFOREt   highl_curr_linet   set_highlight_current_lineR   t   show_white_spacest   set_draw_spacest   DRAW_SPACES_FLAGSt   modify_fontt   pangot   FontDescriptiont	   code_fontt   set_show_line_numberst!   set_insert_spaces_instead_of_tabst   spaces_instead_tabst   set_tab_widtht
   tabs_widtht   set_auto_indentt   auto_indentt$   on_sourceview_populate_popup_codeboxt   on_key_press_sourceview_codeboxt   on_mouse_button_clicked_codeboxt   line_wrappingt   set_wrap_modeR   t	   WRAP_WORDt	   WRAP_NONEt   ScrolledWindowt
   set_policyt   POLICY_AUTOMATICt   addt   Framet   framet   codebox_apply_width_heightt   add_child_at_anchort   TEXT_WINDOW_LEFTt   TEXT_WINDOW_RIGHTt   TEXT_WINDOW_TOPt   TEXT_WINDOW_BOTTOMt   set_border_window_sizet   set_shadow_typet   SHADOW_NONEt   show_allt   get_iter_at_child_anchort   state_machinet   apply_object_justificationt   user_activet   update_statet	   treestoret   curr_tree_iter(	   R   R@   R?   t   codebox_justificationt   text_buffert   anchort   scrolledwindowt   wint	   text_iter(    (    s   modules/codeboxes.pyR;   P   sh     %
   %c         G   sJ   |  j  j r! |  j  j d 7_ n |  j  j d 7_ |  j |  j  t ƒ d S(   s   Increase CodeBox Widthi
   i   N(   R   R   R   Rt   R   (   R   R   (    (    s   modules/codeboxes.pyt   codebox_increase_width„   s     c         G   s   |  j  j rM |  j  j d d k r‹ |  j  j d 8_ |  j |  j  t ƒ q‹ n> |  j  j d d k r‹ |  j  j d 8_ |  j |  j  t ƒ n  d S(   s   Increase CodeBox Widthi
   i   N(   R   R   R   Rt   R   (   R   R   (    (    s   modules/codeboxes.pyt   codebox_decrease_widthŠ   s    c         G   s)   |  j  j d 7_ |  j |  j  t ƒ d S(   s   Increase CodeBox Widthi
   N(   R   R   Rt   R   (   R   R   (    (    s   modules/codeboxes.pyt   codebox_increase_height•   s    c         G   sB   |  j  j d d k r> |  j  j d 8_ |  j |  j  t ƒ n  d S(   s   Increase CodeBox Widthi
   N(   R   R   Rt   R   (   R   R   (    (    s   modules/codeboxes.pyt   codebox_decrease_heightš   s    c         C   se   | j  r | j } n |  j j ƒ  | j d } | j j | | j ƒ | ra |  j j d t ƒ n  d S(   s)   Apply Width and Height Changes to CodeBoxid   t   nbufN(	   R   R   R   t   get_text_window_widthRs   t   set_size_requestR   t   update_window_save_neededR   (   R   R‡   t   from_shortcutR   (    (    s   modules/codeboxes.pyRt       s    	 c         C   s•  |  j  j r! t |  j  _ t } n t } |  j  j j j |  j j ƒ |  j  j j	 j |  j j
 ƒ |  j  j j j |  j j ƒ |  j  j j j |  j j ƒ |  j  j j j |  j j ƒ |  j  j j j |  j j ƒ |  j  j j j |  j  j |  j j ƒ ƒ |  j  j j j t d ƒ ƒ | r)t |  j  _ n  |  j  j j j ƒ  } |  j  j j j ƒ  | d k rad S|  j  j |  j  j j j ƒ  d |  j _ |  j  j |  j j |  j j ƒ t  |  j  j j j! ƒ  ƒ |  j _ t  |  j  j j	 j! ƒ  ƒ |  j _
 |  j  j j j" ƒ  |  j _ |  j  j j j" ƒ  |  j _ |  j j j# |  j j ƒ |  j  j j j" ƒ  |  j _ |  j j$ j% |  j j ƒ |  j& |  j ƒ |  j  j' d t ƒ d S(   s   Change CodeBox Propertiess   Edit CodeBoxi   NR   ((   R   R   RS   R   R   R.   t	   set_valueR   R   R0   R   R1   t
   set_activeR   t   radiobutton_codebox_percentR6   R!   R7   R"   R4   t   set_active_itert   get_combobox_prog_lang_iterR    R(   R)   R*   R+   R,   R3   R5   RK   RF   R-   R/   R2   RL   R   R`   Rt   R’   (   R   t   actiont   user_active_restoreR>   (    (    s   modules/codeboxes.pyt   codebox_change_properties¨   s:    	(  )!!c         C   sª   | j  t j j @r¦ t j j | j ƒ } | |  _ | d k rj | j  t j j @r] |  j ƒ  q£ |  j	 ƒ  q¦ | d k r¦ | j  t j j @r– |  j
 ƒ  q£ |  j ƒ  q¦ n  d S(   s2   Extend the Default Right-Click Menu of the CodeBoxt   periodt   commaN(   t   stateR   R   t   CONTROL_MASKR   R   R   t	   MOD1_MASKRŒ   R‹   RŽ   R   (   R   R   R   R‡   R   (    (    s   modules/codeboxes.pyRh   Æ   s    	c         C   s2   | |  _  | j d k r. |  j j |  j  ƒ n  d S(   s   Catches mouse buttons clicksi   N(   R   t   buttonR   R   (   R   R   R   R‡   (    (    s   modules/codeboxes.pyRi   Ô   s    	c         C   s)   |  j  j | t j |  ƒ |  j  j ƒ d S(   s2   Extend the Default Right-Click Menu of the CodeBoxN(   R   t   menu_populate_popupt   const   get_popup_menu_entries_codeboxt   orphan_accel_group(   R   t   textviewt   menuR‡   (    (    s   modules/codeboxes.pyRg   Ú   s    N(   t   __name__t
   __module__t   __doc__R   R	   R
   R   R   RA   R'   R;   R‹   RŒ   R   RŽ   RS   Rt   R›   Rh   Ri   Rg   (    (    (    s   modules/codeboxes.pyR       s"   						4							(    (
   R   RD   R]   t   osR£   t   supportt   DRAW_SPACES_ALLt   DRAW_SPACES_NEWLINER[   R    (    (    (    s   modules/codeboxes.pyt   <module>   s   $