
)sEOc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z y d  d l Z e Z Wn e Z n Xd  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d d d     YZ d d d     YZ  d S(   iNt   GladeWidgetsWrapperc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s&   Handles the retrieval of glade widgetsc         C   sY   yF t  j   |  _ |  j j t j  |  j j |  |  j j |  Wn d GHn Xd  S(   Ns   Failed to load the glade file(   t   gtkt   Buildert   glade_widgetst   set_translation_domaint   const   APP_NAMEt   add_from_filet   connect_signals(   t   selft   glade_file_patht   gui_instance(    (    s   modules/core.pyt   __init__"   s     c         C   s   |  j  j |  S(   s;   Gives us the ability to do: wrapper['widget_name'].action()(   R   t
   get_object(   R	   t   key(    (    s   modules/core.pyt   __getitem__*   s    c         C   sB   |  j  j |  } | d k r. t d |  n  t |  | |  | S(   s8   Gives us the ability to do: wrapper.widget_name.action()s   Widget %r not foundN(   R   R   t   Nonet   AttributeErrort   setattr(   R	   t   attrt
   new_widget(    (    s   modules/core.pyt   __getattr__.   s
     (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s   modules/core.pyR       s   		t
   CherryTreec           B   st	  e  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   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   Z d   Z d   Z d   Z  d   Z! dd   Z# 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-   Z0 d.   Z1 d/   Z2 d0   Z3 d1   Z4 d2   Z5 d3   Z6 e7 d4  Z8 d5   Z9 d6   Z: d7   Z; d8   Z< d9   Z= d:   Z> d; d<  Z? d=   Z@ d>   ZA d?   ZB d@   ZC dA   ZD dB   ZE dC   ZF dD   ZG dE   ZH dF   ZI dG   ZJ dH   ZK dI   ZL dJ   ZM dK   ZN dL   ZO dM   ZP dN   ZQ dO   ZR dP   ZS dQ   ZT dR   ZU dS   ZV dT   ZW dU   ZX dV   ZY de7 dW  ZZ dX   Z[ dY   Z\ ddZ  Z] d[   Z^ d\   Z_ d]   Z` d^   Za d_   Zb d`   Zc da   Zd db   Ze dc   Zf dd   Zg de   Zh ddf  Zi ddg  Zj dh   Zk di   Zl dj   Zm dk   Zn dl   Zo dm   Zp dn   Zq do   Zr dp   Zs dq   Zt dr   Zu ds   Zv dt   Zw du   Zx dv   Zy dw   Zz dx   Z{ dy   Z| dz   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   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   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z de7 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   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z dde7 e7 e7 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z dd  Z d   Z 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d  Z d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 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   Z d   Z d   Z d   Z d   Z ddd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 d   Z d   Z d   Zd   Zd   Zd  Zd  Zd  Zd  ZRS(  s   Application's GUIc      	   C   s	  | |  _  d |  _ t |  _ t j |   |  _ t j |   |  _	 t
 j |   |  _ t j |   |  _ t j |   |  _ t j |   |  _ t j |   |  _ t j |   |  _ t j |   |  _ t j   |  _  t! j"   } xP t# j$ D]E } t! j% j& t# j' t# j$ |  } t! j( |  } | j) | |  q W| j*   y0 t! j+   } | j, d t  | j, d t  Wn n Xd t- j. d <t/ t# j' d |   |  _0 |  j0 j1 |  _1 t! j2   }	 |  j1 j) |	  | |  _3 t4 j5 |   t! j6 d  }
 |
 j7 t# j8 |    t! j9   |  _: |  j: j; |
 d  |  j1 j< |  j: j=    |  j: j> t# j?  |	 j@ |  j: jA d	  tB tB  |	 j@ |  j: jA d
  tB tB  t! jC   |  _D t! jE   |  _F |  jF jG t! jH t! jH  t! jE   |  _I |  jI jG t! jH t! jH  t! j2   |  _J t! jK   |  _L |  jJ j@ |  jL tB tB  |  jJ j@ |  jI  |  jM rb|  jD jN |  jJ  |  jD jO |  jF  n& |  jD jN |  jF  |  jD jO |  jJ  |	 j@ |  jD  t! jP   |  _Q |  jQ jR d  |  _S |	 j@ |  jQ tB tB  t! jT tU tU tV jW tX tU tY tU tV jZ  |  _[ t! j\ |  j[  |  _] |  j] j^ tB  |  j] j_ t! j% j` d t! ja d f g t! j% jb  |  j] jc t! jd d t! ja d f g t! j% jb  t! je   |  _f t! jg   |  _h |  jh j, d ti jj  |  jh jk d |  jl  t! jm   |  _n |  jn j@ |  jf tB  |  jn j@ |  jh t  |  jn jo |  jf d d |  jn jo |  jh d d |  j] jp |  jn  |  j] jq   |  _r |  j] jk d |  js  |  j] jk d |  jt  |  j] jk d |  ju  |  j] jk d |  jv  |  j] jk d |  jw  |  j] jk d |  jx  |  jF j) |  j]  t! jy   |  _z |  j{   |  j1 jk d |  j|  |  j1 jk d |  j}  |  j1 jk d |  j~  |  j1 jk d |  j  j  |  jF jk d |  j}  |  j0 j jk d |  j  |  j0 j jk d |  j  |  j0 j jk d |  j  |  j0 j jk d |  j j  |  j0 j jk d |  j j  t j   |  _ t j   |  _ |  j j tB  |  j j t j  |  j jk d |  j  |  j jk d |  j  |  j jk d |  j  |  j jk d |  j  |  j jk d |  j j  |  j jk d |  j j  |  j jk d  |  j j  |  j j d!  |  j j d!  tB |  _ t! j   |  _ |  jI j) |  j  tB |  _ d& |  _ g  |  _ g  |  _ i  |  _ d& |  _ d& |  _ d& |  _ d& |  _ i d& d" 6d& d# 6|  _ i  |  _ d d g |  _ tB |  _ d& |  _ tX d  |  _ |  j0 j j t# j  t j |   |  j1 j   |  j1 j   t4 j |   |  j   |  j   |  j   |  j rj	|  j   |  j r	|  j1 j   q	n |  j: jA d$  j, d% tB  |  j |  |  j r	|  j   n
 |  j   d& S('   s   GUI Startupt    s   gtk-button-imagess   gtk-menu-imagest   0t   UBUNTU_MENUPROXYs   cherrytree.gladet   Actionsi    s   /MenuBars   /ToolBart   CT_DNDs	   wrap-modet   editedt   stock_idt   texti   s   cursor-changeds   button-press-eventt   key_press_events   drag-motions   drag-data-receiveds   drag-data-gets   window-state-events   size-allocatet   destroys   populate-popups   motion-notify-events   event-afters   visibility-notify-events   copy-clipboards   cut-clipboards   paste-clipboardi   t   ft   bs   /MenuBar/FileMenu/ExitAppt   visibleN(   t   bosst   filetypet   Truet   user_activet	   clipboardt   ClipboardHandlert   clipboard_handlert   listst   ListsHandlert   lists_handlert   tablezt   TablesHandlert   tables_handlert	   codeboxest   CodeBoxesHandlert   codeboxes_handlert   machinest   StateMachinet   state_machinet
   XMLHandlert   xml_handlert   exportst   Export2Htmlt   html_handlert   findreplacet   FindReplacet   find_handlert   ctdbt   CTDBHandlert   ctdb_handlert   printingt   PrintHandlert   print_handlerR   t   IconFactoryR   t   STOCKS_N_FILESt   gdkt   pixbuf_new_from_filet
   GLADE_PATHt   IconSett   addt   add_defaultt   settings_get_defaultt   set_propertyt   ost   environR    t   gladet   windowt   VBoxt   country_langt   configt   config_file_loadt   ActionGroupt   add_actionst   get_entriest	   UIManagert   uit   insert_action_groupt   add_accel_groupt   get_accel_groupt   add_ui_from_stringt   UI_INFOt
   pack_startt
   get_widgett   Falset   HPanedt   hpanedt   ScrolledWindowt   scrolledwindow_treet
   set_policyt   POLICY_AUTOMATICt   scrolledwindow_textt	   vbox_textt   Labelt   header_node_name_labelt   tree_right_sidet   add1t   add2t	   Statusbart	   statusbart   get_context_idt   statusbar_context_idt	   TreeStoret   strt   gobjectt   TYPE_PYOBJECTt   longt   intt   TYPE_BOOLEANt	   treestoret   TreeViewt   treeviewt   set_headers_visiblet   drag_source_sett   BUTTON1_MASKt   TARGET_SAME_WIDGETt   ACTION_MOVEt   drag_dest_sett   DEST_DEFAULT_ALLt   CellRendererPixbuft   renderer_pixbuft   CellRendererTextt   renderer_textt   pangot   WRAP_WORD_CHARt   connectt   tree_cell_editedt   TreeViewColumnt   columnt   set_attributest   append_columnt   get_selectiont   treeviewselectiont   on_node_changedt   on_mouse_button_clicked_treet   on_key_press_cherrytreet   on_drag_motion_cherrytreet   on_drag_data_recv_cherrytreet   on_drag_data_get_cherrytreet
   AccelGroupt   orphan_accel_groupt   menu_tree_createt   on_window_state_eventt$   on_window_n_tree_size_allocate_eventt   on_key_press_windowt   on_window_destroy_eventt   inputdialogt   on_key_press_input_dialogt   anchorhandledialogt   on_key_press_anchorhandledialogt   choosenodedialogt   on_key_press_choosenodedialogt   tablehandledialogt   on_key_press_tablehandledialogt   codeboxhandledialogt    on_key_press_codeboxhandledialogt   gtksourceview2t   StyleSchemeManagert   sourcestyleschememanagert   Viewt
   sourceviewt   set_sensitivet   set_smart_home_endt   SMART_HOME_END_BEFOREt   on_sourceview_populate_popupt!   on_sourceview_motion_notify_eventt   on_sourceview_event_aftert%   on_sourceview_visibility_notify_eventt   copyt   cutt   pastet   set_left_margint   set_right_margint   hovering_over_linkt   TextTagTablet	   tag_tablet   go_bk_fw_clickR   t   highlighted_objt	   bookmarkst   bookmarks_menu_itemst   nodes_names_dictt   passwordt   curr_tree_itert   curr_window_n_tree_widtht   curr_buffert   curr_colorst   nodes_cursor_post
   latest_tagt   file_updatet   autosave_timer_idt   node_id_countert   aboutdialogt   set_versiont   VERSIONt   supportt   set_menu_items_recent_documentst   show_allt   presentt   config_file_applyt   combobox_country_lang_initt   combobox_style_scheme_initt   combobox_prog_lang_initt   systrayt   status_icon_enablet   start_on_systrayt   hidet   file_startup_loadt   check_versiont   check_for_newer_versiont#   update_selected_node_statusbar_info(   R	   t   lang_strt   open_with_fileR'   t   factoryt
   stock_namet   pixbuft   iconsett   gtk_settingst	   vbox_maint   actions(    (    s   modules/core.pyR   9   s"   			 
 		-
													


	
	 	 c         G   sD  |  j  j |  j  |  j  j |  j t d   x t j   rK t j   q2 Wy t j	 t
 j d d } | j   j d d  } | t
 j k r t j t d  d | |  j  |  j  j |  j  |  j   n7 |  j  j |  j  |  j  j |  j t d  d |  Wn6 |  j  j |  j  |  j  j |  j t d	   n Xd
 S(   s   Check for a Newer Versions   Checking for Newer Version...t   timeouti   s   
R   s   A Newer Version Is Available!s    (%s)s$   This is the Latest Version Availables?   Failed to Retrieve Latest Version Information - Try Again LaterN(   Ru   t   popRw   t   pusht   _R   t   events_pendingt   main_iterationt   urllib2t   urlopenR   t   NEWER_VERSION_URLt   readt   replaceR   R   t   dialog_infoRU   R   (   R	   t   argst   fdt   latest_version(    (    s   modules/core.pyR      s      !(c         C   s   |  j  d k rg | t j k rF | t j k r8 t j | St j d Sq~ | t j k r` t j | Sd Sn |  j  d k rz d Sd Sd S(   s)   Returns the Stock Id given the Node Levelt   ci   s   Gray CherryR%   s   Node Bullets   Node NoIconN(   t   nodes_iconsR   t   CUSTOM_COLORS_IDt   NODES_ICONSt
   CODE_ICONS(   R	   t
   node_levelt	   node_code(    (    s   modules/core.pyt   get_node_icon   s       c   	      C   s  |  j  j   r: |  j   r: t j t d  |  j  d S|  j  j   \ } } |  j t	 j
 k r |  j  j | |  } | d k r | j   } q | d k r | j   } q | d k r | j   } q n! |  j j |  j  | | d | } | j   } | j   } |  j  j | |  |  j  j |  } |  j t	 j
 k rP|  j  j | |  n, |  j  j |  j  j   |  |  j j |  |  j  j |  j  j |  |  j  j |   d S(   s8   Change the Case of the Selected Text/the Underlying Words   No Text is SelectedNt   lt   ut   tt   change_case(   R   t   get_has_selectiont   apply_tag_try_automatic_boundsR   t   dialog_warningR   RU   t   get_selection_boundst   syntax_highlightingR   R   t   get_textt   lowert   uppert   swapcaseR-   t(   rich_text_get_from_text_buffer_selectiont
   get_offsett   deletet   get_iter_at_offsett   insertt	   move_markt
   get_insertt   from_xml_string_to_buffert   select_range(	   R	   t   change_typet
   iter_startt   iter_endt   text_to_change_caset	   rich_textt   start_offsett
   end_offsett   iter_insert(    (    s   modules/core.pyt   text_selection_change_case   s4       	c         G   s   |  j  d  d S(   s9   Toggles the Case of the Selected Text/the Underlying WordR  N(   R"  (   R	   R   (    (    s   modules/core.pyt   text_selection_toggle_case  s    c         G   s   |  j  d  d S(   s8   Uppers the Case of the Selected Text/the Underlying WordR  N(   R"  (   R	   R   (    (    s   modules/core.pyt   text_selection_upper_case  s    c         G   s   |  j  d  d S(   s8   Lowers the Case of the Selected Text/the Underlying WordR  N(   R"  (   R	   R   (    (    s   modules/core.pyt   text_selection_lower_case  s    c         G   s  |  j  j   rK|  j  j   \ } } | j   } | j   } |  j t j k r |  j  j | |  } t j | k r t j | } n  |  j  j	 | |  n |  j
 j |  j  | |  } t j | k r|  j  j	 | t j  |  j  j | d  } |  j  j |  j  j   |  n  |  j
 j |  |  j  j |  j  j |  |  j  j |   n|  j j   \ } } | d k r|  j  j |  j  j    } |  j  j	 | t j  n |  j t j k r|  j  j | |  } |  j  j	 | t j |  n |  j
 j |  j  | |  } | j   } |  j  j	 | t j  |  j  j | d  } |  j  j |  j  j   |  |  j
 j |  |  j j |  j |  j d  d S(   s'   Duplicates the Whole Row or a Selectioni   i   N(   R   R  R  R  R  R   R   R  t   CHAR_NEWLINER  R-   R  R  R  R  R  R  R0   t   get_paragraph_itersR   t   get_iter_at_markR9   t   update_stateR   R   (   R	   R   R  R  t   sel_start_offsett   sel_end_offsett   text_to_duplicateR  (    (    s   modules/core.pyt   text_row_selection_duplicate  sF    		c         G   s  |  j  j   \ } } | d k rK |  j j |  j j    } | j   } n  t } | j   t } | j   } | j	   s} d S| j	   s t
 } n2 x/ | j   t j k r | j	   s t
 } Pq q W| s | j   n  | j   } |  j t j k r|  j j | |  } |  j j | |  |  j j |  } | sI| d t j k rY| t j 7} n  |  j j | |  |  j | t |  d  n |  j j | |  } | j   | j   }	 |  j j |  j | | d t
 }
 |  j j | |  |  j j |  } | s| d t j k r'|	 d 7}	 t
 } n t } |  j j |  j j   |  |  j j |
  | ru|  j j t j  n  |  j | |	 d  |  j j |  j |  j d  d S(   s&   Moves Up the Current Row/Selected RowsNii   t   exclude_iter_sel_endi   (    R0   R'  R   R   R(  R  R   Rf   t   forward_chart   backward_charR)   t   get_charR   R&  R  R  R   R  R  R  R  t   set_selection_at_offset_n_deltat   lenR-   R  R  R  t   insert_at_cursorR9   R)  R   R   (   R	   R   R  R  t   last_line_situationt   missing_leading_newlinet   destination_itert   destination_offsett   text_to_movet   diff_offsetsR  t   append_newline(    (    s   modules/core.pyt   text_row_upF  sZ    
  	  	
	 c         G   s  |  j  j   \ } } | d k rK |  j j |  j j    } | j   } n  | j   s[ d St } | j   } x/ | j	   t
 j k r | j   sp t } Pqp qp W| j   | j   } |  j t
 j k r|  j j | |  } |  j j | |  | t |  8} |  j j |  } | s+| d t
 j k r;| t
 j 7} n  | rQt
 j | } n  |  j j | |  | s|  j | t |  d  q|  j | d t |  d  nQ|  j j | |  } | j   | j   } |  j j |  j | | d t }	 |  j j | |  | | 8} |  j j |  } | s=| d t
 j k rP| d 7} t }
 n t }
 |  j j |  j j   |  | r| d 7} |  j j t
 j  n  |  j j |	  |
 r|  j j t
 j  n  | s|  j | | d  n |  j | d | d  |  j j |  j |  j d  d S(   s(   Moves Down the Current Row/Selected RowsNii   i   R.  i   (   R0   R'  R   R   R(  R  R   R/  Rf   R1  R   R&  R)   R  R  R   R  R  R3  R  R  R2  R-   R  R  R4  R  R9   R)  R   R   (   R	   R   R  R  R6  R7  R8  R9  R:  R  R;  (    (    s   modules/core.pyt   text_row_downw  sf     
  !	

	
 c         G   s   |  j  j   \ } } | d k rK |  j j |  j j    } | j   } n  | j   ri | j   ri d S|  j j	 | |  |  j
 j |  j |  j d  d S(   s   Deletes the Whole RowNi   (   R0   R'  R   R   R(  R  R   R/  R0  R  R9   R)  R   R   (   R	   R   R  R  (    (    s   modules/core.pyt   text_row_delete  s     c         G   s   |  j  j   \ } } | d k rK |  j j |  j j    } | j   } n  | j   ri | j   ri d S|  j j	 | |  |  j
 j d  d S(   s   Cut a Whole RowNs   cut-clipboard(   R0   R'  R   R   R(  R  R   R/  R0  R  R   t   emit(   R	   R   R  R  (    (    s   modules/core.pyt   text_row_cut  s     c         G   s   |  j  j   \ } } | d k rK |  j j |  j j    } | j   } n  | j   ri | j   ri d S|  j j	 | |  |  j
 j d  d S(   s   Copy a Whole RowNs   copy-clipboard(   R0   R'  R   R   R(  R  R   R/  R0  R  R   R?  (   R	   R   R  R  (    (    s   modules/core.pyt   text_row_copy  s     c         C   sn   |  j  s d St j j | j  } | j t j j @rj | d k rN |  j   qj | d k rj |  j   qj n  d S(   s   Catches Window key pressesNt   Leftt   Right(	   R   R   RJ   t   keyval_namet   keyvalt   statet	   MOD1_MASKt   go_backt
   go_forward(   R	   t   widgett   eventt   keyname(    (    s   modules/core.pyR     s    	   c         C   s$  |  j  s d St j j | j  } | j t j j @r | d k rN |  j   q| d k rg |  j   q| d k r |  j	   q| d k r|  j
   qnw| j t j j @r na| j t j j @r nK| d k r|  j |  j |  j   } | r|  j |  qn| d k r?|  j j |  j   } | r|  j |  qn | d k ry|  j j |  j   } | r|  j |  qn | d k r|  j j |  j   } | r|  j |  qn` | d k r|  j   nG | d k r|  j   n. | d k r|  j j d d d d	 | j  n  | j d
  d S(   s   Catches Tree key pressesNt   Upt   DownRB  RC  t   Returnt   Deletet   Menui    R"   (   R   R   RJ   RD  RE  RF  t
   SHIFT_MASKt   node_upt	   node_downt	   node_leftt   node_change_fatherRG  t   CONTROL_MASKt   get_tree_iter_prev_siblingR   t   treeview_safe_set_cursort	   iter_nextt   iter_parentt   iter_childrent	   node_editt   node_deletet	   menu_treet   popupR   t   timet   stop_emission(   R	   RJ  RK  RL  t	   prev_itert	   next_itert   father_itert
   child_iter(    (    s   modules/core.pyR     sN    	           "c         G   sC   |  j  j  j   t j j @r/ |  j  j  j   n |  j  j  j   d S(   s   Toggle Fullscreen StateN(   RU   t	   get_stateR   RJ   t   WINDOW_STATE_FULLSCREENt   unfullscreent
   fullscreen(   R	   R   (    (    s   modules/core.pyt   fullscreen_toggle  s    c   	      C   s>   |  j  j | |  } | r: | \ } } | j | |  n  t S(   s   Cherry Tree drag motion(   R   t   get_dest_row_at_post   set_drag_dest_rowR)   (	   R	   RJ  t   drag_contextt   xt   yt	   timestampt	   drop_infot	   drop_patht   drop_pos(    (    s   modules/core.pyR     s
    c         C   s  |  j  j | |  } | r| \ }	 }
 |
 s9 t j }
 n  |  j j |	  } |  j sX t S|  j |  j d } |  j | d | k r d GHt S|  j j |  } xP | r |  j | d | k r t	 j
 t d  |  j  t S|  j j |  } q W|
 t j k r=|  j |  j |  } |  j |  j |  j j |  | t  nG |
 t j k rq|  j |  j |  j j |  |  n |  j |  j |  |  j d k r|  j d t  qn  t S(   s   Cherry Tree drag data receivedi   s$   drag node and drop node are the sames(   The new father can't be one of his sons!R   t   change_icon(   R   Rl  R   t   TREE_VIEW_DROP_BEFORER   t   get_itert	   drag_iterRf   R[  R   t   dialog_errorR   RU   RX  t   node_move_afterR)   t   TREE_VIEW_DROP_AFTERR   t   treeview_refresh(   R	   RJ  Rn  Ro  Rp  t   selection_datat   infoRq  Rr  Rs  Rt  t	   drop_itert   drag_node_idt   move_towards_top_iterRc  (    (    s   modules/core.pyR     s6     	 	(% c         C   s5   |  j  j   \ } } | |  _ | j d d d  t S(   s   Cherry Tree drag data receivedt   UTF8_STRINGi   t   fake(   R   t   get_selectedRx  t   setR)   (   R	   RJ  Rn  R}  R~  Rq  t
   tree_modelt	   tree_iter(    (    s   modules/core.pyR   "  s    	c         C   s8   t  j j | j  } | d k r4 |  j j j   n  d S(   s%   Catches ChooseNode Dialog key pressesRO  N(   R   RJ   RD  RE  RT   t   choosenodedialog_button_okt   clicked(   R	   RJ  RK  RL  (    (    s   modules/core.pyR   )  s     c         C   s8   t  j j | j  } | d k r4 |  j j j   n  d S(   s'   Catches AnchorHandle Dialog key pressesRO  N(   R   RJ   RD  RE  RT   t   anchorhandledialog_button_okR  (   R	   RJ  RK  RL  (    (    s   modules/core.pyR   .  s     c         C   s8   t  j j | j  } | d k r4 |  j j j   n  d S(   s    Catches Input Dialog key pressesRO  N(   R   RJ   RD  RE  RT   t   input_dialog_ok_buttonR  (   R	   RJ  RK  RL  (    (    s   modules/core.pyR   3  s     c      	   C   sI  t  j d d d t d  d |  j d |  j  } | s: d St } | d d k r |  j | d t } | rt t } q | d k r d SnD | d d k r |  j | t  } | r t } q | d k r d Sn  | ry: | d d k r |  j	 |  n |  j	 d |  t } Wqt } qXn  | sEt  j
 t d  | |  j  d Sd S(   sQ   Appends Nodes at the Bottom of the Current Ones, Importing from a CherryTree Filet   filter_patterns   *.ct*t   filter_names   CherryTree Documentt   curr_foldert   parentNit   dt   zt	   main_fileR%   Ro  R   s!   "%s" is Not a CherryTree Document(   R  R  (   R%   Ro  (   R  R  (   R   t   dialog_file_selectR   t   file_dirRU   Rf   t   file_get_cherrytree_dataR)   R   t   nodes_add_from_cherrytree_dataRy  (   R	   t   actiont   filepatht   document_loaded_okt   cherrytree_stringt	   source_db(    (    s   modules/core.pyt   nodes_add_from_cherrytree_file8  s<    	  	  	 
 c      	   C   s   t  j d d d t d  d |  j d |  j  } | d k r@ d Sy) t | d  } | j   } | j   Wn" t  j	 d	 | |  j    d SXt
 j   } | j |  } |  j |  d S(
   s!   Add Nodes Parsing a NoteCase FileR  s   *.ncdR  s   NoteCase DocumentR  R  Nt   rs   Error importing the file %s(   R   R  R   R  RU   R   t   openR   t   closeRy  t   importst   NotecaseHandlert   get_cherrytree_xmlR  (   R	   R  R  t   file_descriptort   notecase_stringt   notecaseR  (    (    s   modules/core.pyt   nodes_add_from_notecase_fileU  s"    	 c         C   s   t  j d |  j d |  j  } | d k r. d Sy) t | d  } | j   } | j   Wn" t  j d | |  j    d SXt	 j
   } | j |  } |  j |  d S(   s!   Add Nodes Parsing a TuxCards FileR  R  NR  s   Error importing the file %s(   R   R  R  RU   R   R  R   R  Ry  R  t   TuxCardsHandlerR  R  (   R	   R  R  R  t   tuxcards_stringt   tuxcardsR  (    (    s   modules/core.pyt   nodes_add_from_tuxcards_fileh  s     c         C   sZ   t  j d |  j d |  j  } | d k r. d St j |  } | j   } |  j |  d S(   s#   Add Nodes Parsing a KeepNote FolderR  R  N(	   R   t   dialog_folder_selectR  RU   R   R  t   KeepnoteHandlerR  R  (   R	   R  t
   folderpatht   keepnoteR  (    (    s   modules/core.pyt   nodes_add_from_keepnote_foldery  s     c         C   s   t  j j t  j j d  d  } t j d | d |  j  } | d k rL d St j	 |  } | j
   } |  j |  | j |   d S(   s!   Add Nodes Parsing a Tomboy Foldert   ~s   .local/share/tomboyR  R  N(   RR   t   patht   joint
   expanduserR   R  RU   R   R  t   TomboyHandlerR  R  t   set_links_to_nodes(   R	   R  t   start_folderR  t   tomboyR  (    (    s   modules/core.pyt   nodes_add_from_tomboy_folder  s    ! c         C   s   t  j j t  j j d  d  } t j d | d |  j  } | d k rL d St j	 |  } | j
   r | j   } |  j |  n  d S(   s!   Add Nodes Parsing a Basket FolderR  s   .kde/share/apps/basket/basketsR  R  N(   RR   R  R  R  R   R  RU   R   R  t   BasketHandlert   check_basket_structureR  R  (   R	   R  R  R  t   basketR  (    (    s   modules/core.pyt   nodes_add_from_basket_folder  s    ! c      	   C   s   t  j d d d t d  d |  j d |  j  } | d k r@ d Sy8 t | d  } t j   } | j	 |  } | j
   Wn" t  j d	 | |  j    d SX|  j |  d S(
   s    Add Nodes Parsing a Treepad FileR  s   *.hjtR  s   Treepad DocumentR  R  NR  s   Error importing the file %s(   R   R  R   R  RU   R   R  R  t   TreepadHandlerR  R  Ry  R  (   R	   R  R  R  t   treepadR  (    (    s   modules/core.pyt   nodes_add_from_treepad_file  s     	 c      	   C   s   t  j d d d t d  d |  j d |  j  } | d k r@ d Sy8 t | d  } t j   } | j	 |  } | j
   Wn" t  j d	 | |  j    d SX|  j |  d S(
   s   Add Nodes Parsing a Knowit FileR  s   *.knoR  s   Knowit DocumentR  R  NR  s   Error importing the file %s(   R   R  R   R  RU   R   R  R  t   KnowitHandlerR  R  Ry  R  (   R	   R  R  R  t   knowitR  (    (    s   modules/core.pyt   nodes_add_from_knowit_file  s     	 c      	   C   s   t  j d d d t d  d |  j d |  j  } | d k r@ d Sy) t | d  } | j   } | j   Wn" t  j	 d	 | |  j    d SXt
 j   } | j |  } |  j |  d S(
   s   Add Nodes Parsing a Leo FileR  s   *.leoR  s   Leo DocumentR  R  NR  s   Error importing the file %s(   R   R  R   R  RU   R   R  R   R  Ry  R  t
   LeoHandlerR  R  (   R	   R  R  R  t
   leo_stringt   leoR  (    (    s   modules/core.pyt   nodes_add_from_leo_file  s"    	 c         C   s  |  j  r t |  _  t } n t } t } |  j } d } |  j r|  j j d  |  j |  j |  j d <|  j j	   t k r t |  _
 |  j j t  |  j j |  j |  j d  n  t j d t d  d |  j d t j t j Bd t j t j t j t j f  } | j |  j  | j t j  t j d t d	   } t j d t d
   }	 |	 j |  | j   }
 |
 j |  |
 j |	  |
 j   | j    } |	 j!   r|  j } n  | j"   | t j k r| rt |  _  n  d Sn  y | sKt# j$ t% j& d |  } |  j' j( | d t d | rw|  j) r?|  j* j+   n  t } qwn, |  j, j- | d t d | | j.   t } Wn
   n X| r|  j/   | s|  j j0   } n  | r| |  _ |  j |  j d |  _ |  j1 j2 d  |  j1 j2 |  j  |  j |  j d |  _3 |  j j4 d |  j5  |  j3 t% j6 k r|  j j4 d |  j7  |  j j4 d |  j8  |  j1 j9 t: j; |  j<   n |  j1 j9 t: j; |  j=   |  j1 j> t  |  j? j@ d tA jB |  j |  j d  d  |  j? jC t  |  j jD |  j |  j d  |  jE   |  j | d |  j k r}|  j jF |  j jG |  j |  j | d   |  j1 jH |  j jI   d  q}qn tJ jK d |  j  | rt |  _  n  d S(   sF   Adds Nodes to the Tree Parsing a CherryTree XML String / CherryTree DBs   cursor-positioni   t   titles   Who is the Father?R  t   flagst   buttonst   labels   The Tree Roots   The Selected NodeNR   t   discard_idst   tree_fatheri   i   s   modified-changeds   insert-texts   delete-ranges   <big><b><i>i   s   </i></b></big>g333333?s!   Error Parsing the CherryTree File(L   R*   Rf   R)   R   R   R   t   get_propertyR   R   t   get_modifiedR   t   set_modifiedR9   R)  R   t   DialogR   RU   t   DIALOG_MODALt   DIALOG_DESTROY_WITH_PARENTt   STOCK_CANCELt   RESPONSE_REJECTt   STOCK_OKt   RESPONSE_ACCEPTt   set_transient_fort   set_positiont   WIN_POS_CENTER_ON_PARENTt   RadioButtont	   set_groupt   get_content_areaRd   R   t   runt
   get_activeR#   t   ret   subR   t	   BAD_CHARSR;   t   dom_to_treestoret   expand_treeR   t
   expand_allRD   t   read_db_fullR  t   update_window_save_neededt   get_iter_firstR   t
   set_bufferR  R   t   on_modified_changedR   t   on_text_insertiont   on_text_removalt   modify_fontR   t   FontDescriptiont	   text_fontt	   code_fontR   Rp   t   set_textt   cgit   escapet   set_use_markupt   node_selected_changedt   objects_buffer_refresht   place_cursorR  t   scroll_to_markR  R   Ry  (   R	   R  t   cherrytree_dbt   user_active_restoret   file_loadedt   former_nodeR  t   dialogt   radiobutton_roott   radiobutton_curr_nodet   content_areat   response(    (    s   modules/core.pyR    s    					'	!	
 
 		 

 
 	/
.% c         C   s   |  j  j   d S(   s   Expand all Tree NodesN(   R   R  (   R	   R  (    (    s   modules/core.pyt   nodes_expand_all  s    c         C   s   |  j  j   d S(   s   Collapse all Tree NodesN(   R   t   collapse_all(   R	   R  (    (    s   modules/core.pyt   nodes_collapse_all  s    c         C   s   |  j  t j k r~ xM | j   D]? } y/ | j   j d  d k rS | j t  n  Wq q Xq W|  j | t j	 |    n |  j | t j
 |    d S(   s#   Extend the Default Right-Click Menut   stocks	   gtk-pasteN(   R  R   R   t   get_childrent	   get_imageR  R   R)   t   menu_populate_popupt   get_popup_menu_entries_textt   get_popup_menu_entries_code(   R	   t   textviewt   menut   menuitem(    (    s   modules/core.pyR     s     c   
      C   s  | s |  j  j   } n  d } x| D]} | d d k rm t j   } | r] | j |  q| j |  n| d d k r t j   } t j | d  } | j t j	 | d t j
   | j |  | j |  n| d d k r d } q% n t j | d  } | j d | d  | j t j	 | d t j
   | j | d	  | d rt j | d  \ } } x: d
 d d d d g D]# }	 |	 | d k r|  j } PqqW| j d | | | t j  n  | r| j |  n | j |  | j   q% Wd S(   s.   Populate the given menu with the given entriesi    t	   separators   submenu-starti   i   s   submenu-endt   activatei   i   RM  RN  RB  RC  RP  N(   R^   Ra   R   R   t   SeparatorMenuItemt   appendRQ  t   ImageMenuItemt	   set_imaget   image_new_from_stockt   ICON_SIZE_MENUt   set_submenuR   t   set_tooltip_textt   accelerator_parseR   t   add_acceleratort   ACCEL_VISIBLEt   show(
   R	   R  t   entriest   accel_groupt   curr_submenut
   attributest	   menu_itemR   t   modt   element(    (    s   modules/core.pyR  *  sB        
	 c         C   s~   t  j   |  _ |  j j d  j   } x | D] } | j |  q. W|  j | t j	 |    |  j |  j t j	 |    d S(   s   Create the Tree Menuss   /MenuBar/TreeMenuN(
   R   RQ  R_  R^   Re   t   get_submenut   removeR  R   t   get_popup_menu_tree(   R	   t   top_menu_treeR  (    (    s   modules/core.pyR   L  s    c         C   sB   | j  t j j @r> | j t j j @r2 t |  _ q> t |  _ n  d S(   s   Catch Window's EventsN(   t   changed_maskR   RJ   t   WINDOW_STATE_MAXIMIZEDt   new_window_stateR)   t   win_is_maximizedRf   (   R	   RU   RK  (    (    s   modules/core.pyR   U  s    c         G   s   |  j  j j   |  j  j j   t |  j  j j    } |  j d | k rw | |  j d <|  j d k rw |  j
   qw n  |  j d r |  j d k r |  j   n  t j |   d S(   s   Opens the Preferences Dialogi   i    N(   RT   t
   prefdialogR  R   R}   t   spinbutton_autosavet	   get_valuet   autosaveR   R   t   autosave_timer_stopt   autosave_timer_startRX   t   config_file_save(   R	   R   t   new_autosave_value(    (    s   modules/core.pyt   dialog_preferences_  s      c         C   s+   t  j |  j d d d |  j  |  _ d S(   s   Start Autosave Timeri   i  i<   N(   Rz   t   timeout_addR-  t   autosave_timer_iterR   (   R	   (    (    s   modules/core.pyR/  l  s    c         C   s   t  j |  j  d |  _ d S(   s   Stop Autosave TimerN(   Rz   t   source_removeR   R   (   R	   (    (    s   modules/core.pyR.  p  s    c         C   s>   |  j  s- |  j d k r: |  j j   t k r: |  j   n  t S(   s   Iteration of the AutosaveN(   R   R   R   R   R  R)   t	   file_save(   R	   (    (    s   modules/core.pyR4  u  s    -c         C   s   t  rs t j d d t j  |  _ |  j j t j  |  j j d  |  j j d  |  j j	 |  j
 j d   nK t j   |  _ |  j j d  |  j j d |  j  |  j j t d   d S(	   s   Creates the Stats Icont
   cherrytrees   indicator-messagess   indicator-messages-news   /SysTrayMenuR   s   button-press-events#   CherryTree Hierarchical Note TakingN(   t   HAS_APPINDICATORt   appindicatort	   Indicatort   CATEGORY_APPLICATION_STATUSt   indt
   set_statust   STATUS_ACTIVEt   set_attention_icont   set_icont   set_menuR^   Re   R   t
   StatusIcont   status_icont   set_from_stockR   t   on_mouse_button_clicked_systrayt   set_tooltipR   (   R	   (    (    s   modules/core.pyR   {  s    c         G   sJ   |  j  j   r |  j  j   n' |  j  j   |  j  j   |  j  j   d  S(   N(   RU   t   has_toplevel_focusR   R  t	   deiconifyR   (   R	   R   (    (    s   modules/core.pyt   toggle_show_hide_main_window  s
     c         C   s]   | j  d k r |  j   n= | j  d k rY |  j j d  j d d d | j  | j  n  d S(   s6   Catches mouse buttons clicks upon the system tray iconi   i   s   /SysTrayMenuN(   t   buttonRI  R^   Re   R`  R   Ra  (   R	   RJ  RK  (    (    s   modules/core.pyRE    s      c         C   s   |  j  d 7_  |  j  S(   s.   Returns the node_ids, all Different Each Otheri   (   R   (   R	   (    (    s   modules/core.pyt   node_id_get  s    c         C   s   | |  j  k r | |  _  n  d S(   s>   Updates the Maximum node_id Value Considering the Received OneN(   R   (   R	   t   node_id(    (    s   modules/core.pyt   node_id_add  s     c         C   sO   | j    |  _ |  j |  j d t j k rK |  j j t j	 |  j   n  d S(   s"   A New Font For the Text was Choseni   N(
   t   get_font_nameR  R   R   R   R   R   R  R   R  (   R	   t   picker(    (    s   modules/core.pyt   on_fontbutton_text_font_set  s    c         C   sO   | j    |  _ |  j |  j d t j k rK |  j j t j	 |  j   n  d S(   s"   A New Font For the Text was Choseni   N(
   RN  R  R   R   R   R   R   R  R   R  (   R	   RO  (    (    s   modules/core.pyt   on_fontbutton_code_font_set  s    c         C   s   | j    |  _ |  j   d S(   s"   A New Font For the Tree was ChosenN(   RN  t	   tree_fontt   set_treeview_font(   R	   RO  (    (    s   modules/core.pyt   on_fontbutton_tree_font_set  s    c         C   s-   |  j  j d t j |  j   |  j   d S(   s   Update the TreeView Fonts	   font-descN(   R   RQ   R   R  RR  R|  (   R	   (    (    s   modules/core.pyRS    s    c         C   s   |  j  r |  j s" t j |   n  |  j j d  | rv |  j j   } x, | rr |  j	 |  |  j j
 |  } qJ Wn  |  j j |  j  |  j r |  j j   n t j |   |  j j |  j j |  j   n  d S(   s   Refresh the TreeviewN(   R   R  RX   t"   get_tree_expanded_collapsed_stringR   t	   set_modelR   R   R  t   change_icon_iterRZ  R  t"   set_tree_expanded_collapsed_stringt
   set_cursort   get_pathR   (   R	   Ru  R  (    (    s   modules/core.pyR|    s    		 		 c         C   sv   |  j  |  j j |  |  j | d  |  j | d <|  j j |  } x) | rq |  j |  |  j j |  } qI Wd S(   s   Changing all icons type - iteri   i    N(   R  R   t
   iter_depthR\  RW  RZ  (   R	   R  t   child_tree_iter(    (    s   modules/core.pyRW    s    	c         C   s  | r3 t  j j |  |  _ t  j j |  |  _ n |  j j rL d |  _ d S|  j r|  j rt  j j t  j j	 |  j |  j   r|  j
 t  j j	 |  j |  j   |  j r |  j j   n t j |   |  j d k rfy |  j j |  j  } Wn d } n X| rl|  j |  |  j j   |  j j |  j j |  j   |  j j |  j j   d  qln d } | s|  j j   } | r|  j j |  j j |   |  j j   qqn d |  _ |  j    t! |  _" d S(   s.   Try to load a file if there are the conditionsR   Ng333333?(#   RR   R  t   basenamet	   file_namet   dirnameR  R'   t   running_windowst   isfileR  t	   file_loadR  R   R  RX   RX  t	   node_pathR   R   Rw  RY  R   t
   grab_focusR   R  R  t   cursor_positionR  R  R  RY  RZ  t   update_window_save_not_neededRf   R   (   R	   R   t   node_iter_to_focus(    (    s   modules/core.pyR     s<    	9"	   
"	
c         C   s/   |  j  r+ | j   t k r+ |  j d  n  d S(   s%   When the modification flag is changedt   nbufN(   R*   R  R)   R  (   R	   t   sourcebuffer(    (    s   modules/core.pyR    s    c      
   G   s  |  j    r( t j t d  |  j  nh|  j   s8 d St |  j  d k ra |  j d  |  j n d } t j	 | d d |  j d t d	  d
 |  j
 d |  j } t } | d k r t } n  | s |  j |  } |  j | d t s t } q n  | r$t |  j  d k r |  j d |  _ n  d St j j |  |  _
 t j j |  |  _ t j |  |  |  j   |  j j |  j |  j d  |  j   d S(   s"   Save the file providing a new names   The Tree is Empty!Ni   iR   R  s   *.ctR  s   CherryTree DocumentR  R  t   first_writei   (   t   tree_is_emptyR   R
  R   RU   t   dialog_choose_data_storageR3  R^  R(   t   dialog_file_save_asR  Rf   R   R)   t   filepath_extension_fixt
   file_writeRR   R  R_  R]  t   add_recent_documentRf  R9   R)  R   R   R  (   R	   R   t   filename_hintR  t   restore_filetype(    (    s   modules/core.pyt   file_save_as  s6      /	 	  
c         C   s;   d |  j  } t |  d k  s/ | d | k r7 | | S| S(   s-   Check a filepath to have the proper extensions   .cti   i(   R(   R3  (   R	   R  t	   extension(    (    s   modules/core.pyRn    s    " c         G   s   |  j  d k r |  j d k r |  j   rF t j t d  |  j  q |  j t j	 j
 |  j  |  j  d t r |  j   |  j j |  j |  j d  q n
 |  j   d S(   s   Save the fileR   s   The Tree is Empty!Rj  i   N(   R  R^  Rk  R   R
  R   RU   Ro  RR   R  R  Rf   Rf  R9   R)  R   R   Rs  (   R	   R   (    (    s   modules/core.pyR6    s     *
$R   c         C   s  |  j  rDt j j t j  s1 t j t j  n  | r= d n d } t j j t j t j j | d  |   } | r t	 | d  } q| r.| s d t
 |   k r |  j |  _ n  |  j j |  |  _ d t
 |   k r+|  j j   |  ` q+qA| d k rAd
 G| GH|  j j | |  } | j   qAq|  j j |  j  n | r\t	 | d  } n | r| sd t
 |   k r|  j |  _ n  |  j j |  |  _ d t
 |   k r |  j j   |  ` q q| d k rd
 G| GH|  j j | |  } | j   qn |  j j |  j  | rw| j |  | j   | rw| rwd t
 |   k rt|  j rt|  j j   |  ` qtqwn  |  j  rt j d d !d k r t j |  }	 t j |  }
 |	 s|
 rt j t d  |  j    n  d |  j  |	 t j |
 } n( d |  j  t j |  t j |  f } | rF| rF|  j j   n  t j | d t } | rqt j |  q| s|  j j  |  |  _ |  j j! j" |  qn  d S(   s)   File Write Low Level (ctd, ctb, ctz, ctx)R  R%   it   wt   dbt   db_oldt   at   st   nt	   exportingi    i   t   wins|   The Contemporary Presence of Single and Double Quotes in the File Path Prevents 7za.exe to Work, Please Change the File Names   7za a -p%s -bd -y s   7za a -p%s -bd -y %s %st   shellN(   Rx  Ry  Rz  (   Rx  Ry  Rz  (#   R   RR   R  t   isdirR   t
   TMP_FOLDERt   mkdirR  R]  R  t   dirRv  Rw  RD   t   new_dbR  t   pending_data_writet   writet   syst   platformR   t   windows_cmd_prepare_pathRy  R   RU   t
   CHAR_SPACER  R  t
   subprocesst   callR)   R#  t   get_connected_db_from_dbpatht   remove_at_quit_setRN   (   R	   R  t
   xml_stringRj  R{  t   last_lettert   filepath_tmpR  t   exp_dbt   filepath_4wint   filepath_tmp_4wint   bash_strt   ret_code(    (    s   modules/core.pyt   file_write_low_level  sz    	 ,  	  	
		  c         C   s  |  j  d k rJ y |  j j   } WqP t j d | |  j    t SXn d } |  j r t j	 j
 |  r t j | | t j  n  yg |  j j |  j t d   x t j   r t j   q W|  j | | |  |  j j |  j  t SWn" t j d | |  j    t SXd S(	   s
   File WriteR  R  s   %s write failed - tree to xmlR   s   Writing to Disk...s!   %s write failed - writing to diskN(   R  R  (   R(   R;   t   treestore_to_domR   Ry  RU   Rf   t   backup_copyRR   R  Ra  t   shutilR   R   t
   CHAR_TILDERu   R   Rw   R   R   R   R   R  R   R)   (   R	   R  Rj  R  (    (    s   modules/core.pyRo  [  s*      c      	   G   sQ   t  j d d d t d  d |  j d |  j  } | d k r@ d S|  j |  d S(   s2   Opens a dialog to browse for a cherrytree filepathR  s   *.ct*R  s   CherryTree DocumentR  R  N(   R   R  R   R  RU   R   t   filepath_open(   R	   R   R  (    (    s   modules/core.pyt	   file_opens  s    	 c         C   s   |  j    s d S|  j |  |  j r6 |  j j   n  |  j j   } | d k r} |  j j |  j j	 |   |  j
 j   n  d S(   s   Opens an existing filepathN(   t   resetRb  R  R   R  R   R  R   RY  RZ  R   Rd  (   R	   R  t   first_node_iter(    (    s   modules/core.pyR  |  s     	 c            s  t  j d t d  d |  j d t  j t  j Bd t  j t  j t  j t  j	 f    j
 t  j   j d d  t  j d t d	   } t  j d t d
   } | j |  t |  j  d k r |  j d d k r | j t  q | j t  n  t  j d t d   } t  j d t d   } | j |  t  j     j t  t  j   } | j t  t  j   } | j   | j |  t  j d d t d  d      j   j t    j |  |  j r| j t  | j t    j t  n' | j t  | j t    j t   j   } | j |  | j |  | j t  j    | j |  | j |  | j    | j     f d   }	    f d   }
 | j! d |
   j! d |	   j"   } | j#   } i | j#   d 6 j$   d 6| j$   d 6}  j%   | t  j	 k r0t S| d r| d d k rgt& j' t d  |  j  t S| d | d k rt& j' t d  |  j  t S| d s|  j(   rt S| d |  _ n	 d  |  _ | r|  j rd |  _* qd |  _* n |  j r	d |  _* n	 d |  _* t S(!   sB   Choose the CherryTree data storage type (xml or db) and protectionR  s"   Choose Storage Type and ProtectionR  R  R  i^  iR  s   XML Files   SQLite Filei   R  R  s   Not Protecteds   Password Protecteds   <b>s   Enter the New Password Twices   </b>c            sH   t  j j | j  d k rD   j   } | j   } | d j   n  d  S(   NRO  i    (   R   RJ   RD  RE  t   get_action_areaR  R  (   RJ  RK  t
   button_boxR  (   R  (    s   modules/core.pyt*   on_key_press_edit_data_storage_type_dialog  s    c            s7   |  j    r&  j t    j   n  j t  d  S(   N(   R  R   R)   Rd  Rf   (   RJ  (   t   entry_passw_1t   passw_frame(    s   modules/core.pyt    on_radiobutton_protected_toggled  s    t   toggledR"   t   ont   p1t   p2R   s"   The Password Fields Must be Filleds'   The Two Inserted Passwords Do Not MatchRo  R%   (   R  R  N(+   R   R  R   RU   R  R  R  R  R  R  R  R  t   set_default_sizeR  R  R3  R^  t
   set_activeR)   t   Entryt   set_visibilityRf   RV   Rd   t   Framet   get_label_widgetR  RN   R   R   R  t
   HSeparatorR   R   R  R  R  R#   R   Ry  t   is_7za_availableR   R(   (   R	   R   t   radiobutton_xmlt   radiobutton_dbt   radiobutton_unprotectedt   radiobutton_protectedt   entry_passw_2t
   vbox_passwR  R  R  R   t   storage_type_is_xmlt   new_protection(    (   R  R  R  s   modules/core.pyRl    s    	 	

 
 		 	 	c         C   s<   t  j d d t } | r8 t j t d  |  j  t St S(   s+   Check 7za binary executable to be availablet   7zaR}  sZ   Binary Executable '7za' Not Found, Check The Package 'p7zip-full' to be Installed Properly(   R  R  R)   R   Ry  R   RU   Rf   (   R	   R  (    (    s   modules/core.pyR    s
    c            s|  t  j d t d  | d |  j d t  j t  j Bd t  j t  j t  j t  j	 f      j
 d d    j |  j    j t  j  t  j   } | j t    j   } | j |    f d   }   j d	 |    j   t j d
 d !d k s  j   } | j t  j j |   n    j     j   } | j   }   j   x t  j   rdt  j    qKW| t  j	 k rxd S| S(   s-   Prompts a Dialog Asking for the File PasswordR  s   Enter Password for %sR  R  R  i,  ic            sH   t  j j | j  d k rD   j   } | j   } | d j   n  d  S(   NRO  i    (   R   RJ   RD  RE  R  R  R  (   RJ  RK  R  R  (   t   enter_password_dialog(    s   modules/core.pyt"   on_key_press_enter_password_dialog  s    R"   i    i   R|  R   (!   R   R  R   RU   R  R  R  R  R  R  R  R  R  R  R  R  Rf   R  Rd   R   R   R  R  t
   get_windowt   focusRJ   t   x11_get_server_timeR   R  R  R#   R   R   (   R	   R^  t   entryR  R  t
   the_windowR   t   passw(    (   R  s   modules/core.pyt   dialog_insert_password  s6    	


  c         C   s	  t  } | d d k rt } |  j t j j |   } | sA d S| rS | |  _ n  |  j   sc d St j j	 t
 j  s t j t
 j  n  | d d k r d n d } t j j t
 j t j j | d  |   } t j d d !d k rUt j d	 t
 j  } t j |  } | s| r9t j t d
  |  j  d Sd | | t
 j | }	 n( d | t j t
 j  t j |  f }	 t j |	 d t }
 |
 d k rt j t d  |  j  d Sn3 | d d k rd G| d GHt  S| rd |  _ n  | d d k ryW | rt | d  } n t | d  } | j   } | j   | rWt j |  n  Wn d GH  t  SXt j t
 j d |  Sym | r|  j  j! |  } n |  j  j! |  } | r| d d k rt j |  q|  j  j" j# |  n  Wn d GH  t  SX| Sd S(   sE   returns the cherrytree xml string or db descriptor given the filepathiR  Ro  R  R%   i    i   R|  s   -os|   The Contemporary Presence of Single and Double Quotes in the File Path Prevents 7za.exe to Work, Please Change the File Names   7za e -p%s -bd -y s   7za e -p%s -bd -y -o%s %sR}  s   Wrong Passwords   bad filepath[-1]R  s!   error reading from plain text xmlR   s   error connecting to dbN(   R  Ro  (   R  R%   (   R  R  ($   Rf   R)   R  RR   R  R]  R   R   R  R~  R   R  R  R  R  R  R   R  Ry  R   RU   R  R  R  R  R  R  R   R  R#  R  R  RD   R  R  RN   (   R	   R  R  t   password_protectedt   password_strR  R  t   dest_dir_4winR  R  R  R  R  Rv  (    (    s   modules/core.pyR    sx        ,  
   c         C   s  t  } | d d k rV d |  _ |  j | d t } | rC t } q | d k r d SnV | d d k r d	 |  _ |  j | t  |  _ |  j r t } q |  j d k r d Sn  | rt  } |  j r t  |  _ t } n t  } t  } |  j d k r|  j j | d t  r1t } q1n |  j	 j
 |  j d t  t } | rt j j |  |  _ t j j |  |  _ |  j d |  _ t j |  |  t j |   |  j   n  | rt |  _ qn  | st j t d  | |  j  d |  _ n  d S(   s!   Loads a .CTD into a GTK TreeStoreit   ctdt   ctzR  R  Nt   ctbt   ctxR%   R  R  is!   "%s" is Not a CherryTree DocumentR   (   R  R  (   R  R  (   R  R  (   Rf   R(   R  R)   R   Rv  R*   R;   R  RD   R  RR   R  R_  R  R]  R^  R   Rp  t   set_bookmarks_menu_itemsRf  Ry  R   RU   (   R	   R  R  R  R  R  (    (    s   modules/core.pyRb  ;  sN    	 	 		 	 			 c         G   s   |  j    r |  j   n  d S(   s   Starts a new unsaved instanceN(   R  t   node_add(   R	   R   (    (    s   modules/core.pyt   file_newe  s     c         C   s   |  j    r |  j   r t S|  j d k rI |  j j d  d |  _ n  |  j j   d |  _	 d |  _
 t d  |  _ |  j   |  j j   |  j j t  d t |   k r |  j r |  j j   n  x! |  j j D] } t j |  q W|  j j   t S(   s   Reset the ApplicationR   i    Rv  N(   Rk  t   check_unsavedRf   R   R   R   R  R   t   clearR^  R   R|   R   Rf  R9   R  R   R   R  Rv  R  RD   R  RR   R#  R)   (   R	   R  (    (    s   modules/core.pyR  i  s$     		
  c         C   s
  |  j  d k r, t j t d  |  j  d St j |  j  } | d k rN d St j |   } |  j	 } |  j
 } |  j   s d S| d k r t j |  |  j   } |  j |  } | j |  } | r| j |  j  |  qn| d k r{t j |  |  j   } |  j |  } | j |  } | r| j |  j  |  | d
 k rx|  j  rx|  j j |  j |  j  d  |  j   qxqny |  j d	  |  j
 } | j |  } | r| j |  | d k r|  j  r|  j j |  j |  j  d  |  j   qn  | |  _	 | |  _
 d S(   s)   Export the Selected Node and its Subnodess   No Node is Selected!Ni    i   i   R%   Ro  i   i(   R%   Ro  (   R%   Ro  (   R   R   R   R
  R   RU   t$   dialog_selnode_selnodeandsub_alltreeR<   t
   Export2CTDR   R(   Rl  t   get_node_hierarchical_nameRn  t   get_single_ct_filepatht   node_export_to_ctdt   node_and_subnodes_export_to_ctdR9   R)  R   R  R^  t   nodes_all_export_to_ctd(   R	   R  t   export_typet   ctd_handlert   restore_passwRr  t   proposed_namet   ctd_filepath(    (    s   modules/core.pyt   export_to_ctd{  sF     		 	c         G   s  |  j  d k r, t j t d  |  j  d St j |  j  } | d k rN d St j |   } | d k r t j	 |  |  j   } | j
 |  } | r| j |  j |  qne | d k r t j	 |  |  j   } | j |  r| j |  j   qn | j |  j  r| j   n  d S(   s   Export To Plain Texts   No Node is Selected!Ni    i   i   (   R   R   R   R
  R   RU   R  R<   t
   Export2TxtR  t   get_single_txt_filepatht   node_export_to_txtR   t   prepare_txt_foldert   nodes_all_export_to_txtR^  (   R	   R   R  t   txt_handlerR  t   txt_filepatht   folder_name(    (    s   modules/core.pyt   export_to_txt  s$     c         G   s  |  j  d k r, t j t d  |  j  d St j |  j  } | d k rN d S| d k r t j |  |  j   } |  j j	 |  r|  j j
 |  j   qn | d k r)t j |  |  j   } |  j j	 |  r|  j j |  j   |  j d	 k r&|  j  r&|  j j |  j |  j  d  |  j   q&qnh |  j j	 |  j  r|  j j   |  j d
 k r|  j  r|  j j |  j |  j  d  |  j   qn  d S(   s   Export to HTMLs   No Node is Selected!Ni    i   i   R%   Ro  i   (   R%   Ro  (   R%   Ro  (   R   R   R   R
  R   RU   R  R  R>   t   prepare_html_foldert   node_export_to_htmlt   nodes_all_export_to_htmlR(   R9   R)  R   R  R^  (   R	   R   R  R  (    (    s   modules/core.pyt   export_to_html  s,     c         C   sX   |  j  j d k r' t j   |  j  _ n  t j |  j j |  j  j |  j  j  |  j  _ d S(   s   Print Page Setup OperationsN(	   RG   t   settingsR   R   t   PrintSettingst   print_run_page_setup_dialogRT   RU   t
   page_setup(   R	   R  (    (    s   modules/core.pyt   export_print_page_setup  s
    	c         C   s   |  j  s& t j t d  |  j  d St j |  j  } | d k rH d St j |   } | d k rv | j |  j   n) | d k r | j	 |  j   n
 | j	   d S(   s   Start Print Operationss   No Node is Selected!Ni    i   i   (
   R   R   R
  R   RU   R  R<   t   ExportPrintt   node_export_printt   nodes_all_export_print(   R	   R  R  t   pdf_handler(    (    s   modules/core.pyt   export_print  s    	 c         C   s   t  } x" |  j | | | d  r* t } q	 W| rC | j |  } n | j   } x7 | r |  j | | |  rv t } n  | j |  } qR W| S(   s*   Sorts the Tree Level and All the Sublevelsi   (   Rf   t   node_siblings_sort_iterationR)   R\  R  t   tree_sort_level_and_sublevelsRZ  (   R	   t   modelRe  t	   ascendingt	   movementst   curr_sibling(    (    s   modules/core.pyR    s    
 	 	c         G   s)   |  j  |  j d t  r% |  j   n  d S(   s   Sorts the Tree AscendingN(   R  R   R   R)   R  (   R	   R   (    (    s   modules/core.pyt   tree_sort_ascending  s     c         G   s)   |  j  |  j d t  r% |  j   n  d S(   s   Sorts the Tree DescendingN(   R  R   R   Rf   R  (   R	   R   (    (    s   modules/core.pyt   tree_sort_descending  s     c         G   s   |  j  s& t j t d  |  j  d S|  j j |  j   } t } x% |  j |  j | t	 d  rh t	 } qD W| r| |  j
   n  d S(   s5   Sorts all the Siblings of the Selected Node Ascendings   No Node is Selected!Ni   (   R   R   R
  R   RU   R   R[  Rf   R  R)   R  (   R	   R   Re  R  (    (    s   modules/core.pyt   node_siblings_sort_ascending  s    	
 c         G   s   |  j  s& t j t d  |  j  d S|  j j |  j   } t } x% |  j |  j | t d  rh t	 } qD W| r| |  j
   n  d S(   s6   Sorts all the Siblings of the Selected Node Descendings   No Node is Selected!Ni   (   R   R   R
  R   RU   R   R[  Rf   R  R)   R  (   R	   R   Re  R  (    (    s   modules/core.pyt   node_siblings_sort_descending  s    	
 c         C   s   | r | j  |  } n | j   } | s. t S| j |  } t } x | d k r | r | | | j   | | | j   k  s | r | | | j   | | | j   k r | j | |  t } n | } | j |  } qF W| S(   sB   Runs One Sorting Iteration, Returns True if Any Swap was NecessaryN(   R\  R  Rf   RZ  R   R  t   swapR)   (   R	   R  Re  R  R   R  t   next_siblingt   swap_executed(    (    s   modules/core.pyR    s      ./	c         G   s^   |  j  d k r, t j t d  |  j  d S|  j |  j   |  j j |  j	 |  j  d  d S(   s[   Change the Selected Node's Children Syntax Highlighting to the Father's Syntax Highlightings   No Node is Selected!Ni   (
   R   R   R   R
  R   RU   t   node_inherit_syntax_iterR   R  R   (   R	   R   (    (    s   modules/core.pyt   node_inherit_syntax+  s
    c         C   s[  |  j  j |  } xB| d k rV|  j  | d |  j  | d k r4|  j |  |  j  | d |  j  | d <|  j |  j  j |  |  j  | d  |  j  | d <|  j |  j  | d | |  j  | d  |  j  | d t j k r|  j	 |  j  | d |  j  | d  n  |  j
 j |  j  | d  |  j   n  |  j |  |  j  j |  } q Wd S(   s$   Iteration of the Node Inherit Syntaxi   i    i   i   N(   R   R\  R   t   get_textbuffer_from_tree_iterR  R[  t   switch_buffer_text_sourceR   R   t!   set_sourcebuffer_syntax_highlightRD   t   pending_edit_db_node_propR  R  RZ  (   R	   t   iter_fathert
   iter_child(    (    s   modules/core.pyR  3  s"    "c         G   s   |  j  d k r, t j t d  |  j  d S|  j |  j |  j   } | d k r |  j j |  j  |  |  j	 |  j  |  |  j
 j |  j |  j  d  |  j
 j |  j | d  |  j j |  j j |  j    |  j   n  d S(   s   Node up one positions   No Node is Selected!Ni   (   R   R   R   R
  R   RU   RX  R   R  t   nodes_sequences_swapRD   t   pending_edit_db_node_hierR   RY  RZ  R  (   R	   R   Rc  (    (    s   modules/core.pyRS  G  s    c         G   s   |  j  d k r, t j t d  |  j  d S|  j j |  j   } | d k r |  j j |  j  |  |  j	 |  j  |  |  j
 j |  j |  j  d  |  j
 j |  j | d  |  j j |  j j |  j    |  j   n  d S(   s   Node down one positions   No Node is Selected!Ni   (   R   R   R   R
  R   RU   R   RZ  R  R  RD   R  R   RY  RZ  R  (   R	   R   t   subseq_iter(    (    s   modules/core.pyRT  U  s    c         G   s   |  j  d k r, t j t d  |  j  d S|  j j |  j   } | d k r |  j |  j  |  j j |  |  |  j	 d k r |  j
 d t  q n  d S(   s   Node left one positions   No Node is Selected!NR   Ru  (   R   R   R   R
  R   RU   R   R[  Rz  R   R|  R)   (   R	   R   Re  (    (    s   modules/core.pyRU  c  s     c         C   s5  | d k r. |  j j | | |  j |  } nA | rS |  j j | |  j |  } n |  j j | |  j |  } |  j | |  |  j j |  |  j d t  | d k r |  j	 j
 |  j j |  t  n |  j	 j
 |  j j |  t  | |  _ |  j j |  } |  j	 j |  |  j	 j |  |  j   d S(   s+   Move a node to a father and after a brotherN(   R   R   t   insert_aftert   prependR  t   node_move_childrenR#  t   nodes_sequences_fixR)   R   t
   expand_rowRZ  R   t   collapse_rowRY  R  (   R	   t   iter_to_moveRe  t   brother_itert	   set_firstt   new_node_itert   new_node_path(    (    s   modules/core.pyRz  o  s     "  "	c         C   sg   |  j  j |  } xN | d k rb |  j  j | |  j  |  } |  j | |  |  j  j |  } q Wd S(   s*   Move the children from a father to anotherN(   R   R\  R   R  R  RZ  (   R	   t
   old_fathert
   new_fathert   children_iter_to_movet   new_children_iter(    (    s   modules/core.pyR    s
    c   
      G   s%  |  j  d k r, t j t d  |  j  d S|  j |  j  d } |  j j |  j   } | d k ru |  j | d } n d } |  j   |  j	 j
 j   |  j	 j j   |  j	 j j t d   |  j	 j j t  |  j	 j j   } |  j	 j j   | d k rd S|  j j   \ } } |  j | d } | | k rRt j t d  |  j  d S| d k r| | k rt j t d  |  j  d S|  j j |  }	 xP |	 r|  j |	 d | k rt j t d  |  j  d S|  j j |	  }	 qW|  j |  j  |  |  j d	 k r!|  j d
 t  n  d S(   s   Node browse for a new fathers   No Node is Selected!Ni   s   Select the New Fatheri   s.   The new father can't be the very node to move!s/   The new choosed father is again the old father!s(   The new father can't be one of his sons!R   Ru  (   R   R   R   R
  R   RU   R   R[  t    node_choose_view_exist_or_createRT   t   link_dialog_top_vboxR   t   frame_link_anchorR   t	   set_titlet   hbox_link_node_anchorR   R)   R  t   treeviewselection_2R  Ry  R   Rz  R   R|  (
   R	   R   t   curr_node_idt   old_father_itert   old_father_node_idR   R  Re  t   new_father_node_idR  (    (    s   modules/core.pyRV    sD     
 	 c         C   s  d t  |   k r&t j |  j  |  _ |  j j t  t j   |  _ t j	   |  _
 t j   |  _ |  j j |  j t  |  j j |  j
 t  |  j j |  j d d |  j j |  j
 d d |  j j |  j  |  j j   |  _ |  j j d |  j  |  j j j |  j  |  j j j   n  | d k rT|  j j |  j j |  j   n: |  j |  } | d k r|  j j |  j j |   n  d S(   s/   If The View Was Never Used, this will Create Itt
   treeview_2R    i    R!   i   s   button-press-eventN(   R  R   R   R   R#  R   Rf   R   t   renderer_pixbuf_2R   t   renderer_text_2R   t   column_2Rd   R)   R   R   R   R  R   t"   on_mouse_button_clicked_treeview_2RT   t   scrolledwindow_choosenodeRN   R   R   RY  RZ  R   t   get_tree_iter_from_node_id(   R	   t   node_sel_idt   tree_iter_sel(    (    s   modules/core.pyR    s(    " c         C   s?   | j  d k r d S| j t j j k r; |  j j j   n  d S(   s   Catches mouse buttons clicksi   N(   RJ  t   typeR   RJ   t   _2BUTTON_PRESSRT   R  R  (   R	   RJ  RK  (    (    s   modules/core.pyR'    s      c         C   su   |  j  j   } x_ | d k rp |  j  | d | k r9 | S|  j | |  } | d k r[ | S|  j  j |  } q Wd S(   s-   Given a Node Id, Returns the TreeIter or Nonei   N(   R   R  R   t#   get_tree_iter_from_node_id_childrenRZ  (   R	   RL  R  R\  (    (    s   modules/core.pyR)    s      c         C   sx   |  j  j |  } x_ | d k rs |  j  | d | k r< | S|  j | |  } | d k r^ | S|  j  j |  } q Wd S(   s9   Iterative function searching for Node Id between Childreni   N(   R   R\  R   R.  RZ  (   R	   Re  RL  R  R\  (    (    s   modules/core.pyR.    s      c         C   su   |  j  j   } x_ | d k rp |  j  | d | k r9 | S|  j | |  } | d k r[ | S|  j  j |  } q Wd S(   s-   Given a Node Id, Returns the TreeIter or Nonei   N(   R   R  R   t%   get_tree_iter_from_node_name_childrenRZ  (   R	   t	   node_nameR  R\  (    (    s   modules/core.pyt   get_tree_iter_from_node_name  s      c         C   sx   |  j  j |  } x_ | d k rs |  j  | d | k r< | S|  j | |  } | d k r^ | S|  j  j |  } q Wd S(   s9   Iterative function searching for Node Id between Childreni   N(   R   R\  R   R/  RZ  (   R	   Re  R0  R  R\  (    (    s   modules/core.pyR/    s      c         C   s6   |  j  j |  } |  j j |  |  j j |  d S(   s*   Set Cursor being sure the Node is ExpandedN(   R   RZ  R   t   expand_to_pathRY  (   R	   R  t	   tree_path(    (    s   modules/core.pyRY    s    c         C   sB   | j    r+ |  j j j t  d |  _ n |  j j j t  d S(   s   Table Column Rename Toggledt   renameN(   R  RT   t   table_column_rename_entryR   R)   t   table_column_modeRf   (   R	   t   radiobutton(    (    s   modules/core.pyt*   on_table_column_rename_radiobutton_toggled  s    c         C   s   | j    r d |  _ n  d S(   s   Table Column Delete ToggledR  N(   R  R6  (   R	   R7  (    (    s   modules/core.pyt*   on_table_column_delete_radiobutton_toggled  s     c         C   sB   | j    r+ |  j j j t  d |  _ n |  j j j t  d S(   s   Table Column Delete ToggledRN   N(   R  RT   t   table_column_new_entryR   R)   R6  Rf   (   R	   R7  (    (    s   modules/core.pyt'   on_table_column_add_radiobutton_toggled  s    c         C   s   | j    r d |  _ n  d S(   s   Table Column Left Toggledt   leftN(   R  R6  (   R	   R7  (    (    s   modules/core.pyt(   on_table_column_left_radiobutton_toggled  s     c         C   s   | j    r d |  _ n  d S(   s   Table Column Right Toggledt   rightN(   R  R6  (   R	   R7  (    (    s   modules/core.pyt)   on_table_column_right_radiobutton_toggled  s     c         C   s   t  j d  d S(   s    Show the application's Home Pages"   http://www.giuspen.com/cherrytree/N(   t
   webbrowserR  (   R	   R  t   data(    (    s   modules/core.pyt   on_help_menu_item_activated  s    c         C   s;   t  j d d k r  t  j d n d } t j d |  d S(	   s   Show the strftime Manual Paget   LANGUAGEt   det   est   frR   s   http://man.cx/strftime%283%29/N(   s   des   ess   fr(   RR   RS   R@  R  (   R	   R  RA  t	   page_lang(    (    s   modules/core.pyt   on_button_strftime_help_clicked  s    &c         C   s,   t  | j    |  _ |  j j |  j  d S(   s%   Tabs Width (in chars) Change HandlingN(   R}   R,  t
   tabs_widthR   t   set_tab_width(   R	   t
   spinbutton(    (    s   modules/core.pyt%   on_spinbutton_tab_width_value_changed  s    c         C   s   t  | j    |  _ d S(   s$   Limit Undoable Steps Change HandlingN(   R}   R,  t   limit_undoable_steps(   R	   RK  (    (    s   modules/core.pyt0   on_spinbutton_limit_undoable_steps_value_changed  s    c         C   s9   t  | j    |  _ |  j j d |  j  |  j   d S(   s!   Cherry Wrap Width Change Handlings
   wrap-widthN(   R}   R,  t   cherry_wrap_widthR   RQ   R|  (   R	   RK  (    (    s   modules/core.pyt2   on_spinbutton_tree_nodes_names_width_value_changed"  s    c         C   sG   | j    r t |  j d <n t |  j d <|  j j j |  j d  d S(   s/   Custom Web Link Clicked Action Toggled Handlingi    N(   R  R)   t   weblink_custom_actionRf   RT   t   entry_custom_weblink_cmdR   (   R	   t   checkbutton(    (    s   modules/core.pyt)   on_checkbutton_custom_weblink_cmd_toggled(  s     c         C   s   | j    |  j d <d S(   s%   Custom Web Link Clicked Action Editedi   N(   R  RQ  (   R	   R  (    (    s   modules/core.pyt#   on_entry_custom_weblink_cmd_changed.  s    c         C   sG   | j    r t |  j d <n t |  j d <|  j j j |  j d  d S(   s0   Custom File Link Clicked Action Toggled Handlingi    N(   R  R)   t   filelink_custom_actionRf   RT   t   entry_custom_filelink_cmdR   (   R	   RS  (    (    s   modules/core.pyt*   on_checkbutton_custom_filelink_cmd_toggled2  s     c         C   s   | j    |  j d <d S(   s&   Custom File Link Clicked Action Editedi   N(   R  RV  (   R	   R  (    (    s   modules/core.pyt$   on_entry_custom_filelink_cmd_changed8  s    c         C   sG   | j    r t |  j d <n t |  j d <|  j j j |  j d  d S(   s2   Custom Folder Link Clicked Action Toggled Handlingi    N(   R  R)   t   folderlink_custom_actionRf   RT   t   entry_custom_folderlink_cmdR   (   R	   RS  (    (    s   modules/core.pyt,   on_checkbutton_custom_folderlink_cmd_toggled<  s     c         C   s   | j    |  j d <d S(   s(   Custom Folder Link Clicked Action Editedi   N(   R  RZ  (   R	   R  (    (    s   modules/core.pyt&   on_entry_custom_folderlink_cmd_changedB  s    c         C   s   | j    |  _ d S(   s   Timestamp Format EditedN(   R  t   timestamp_format(   R	   R  (    (    s   modules/core.pyt!   on_entry_timestamp_format_changedF  s    c         C   s&  |  j  s d S| j   |  _ |  j r t s` d t |   k rS |  j j d t  q |  j   n2 d t |   k r |  j	 j
 t j  n
 |  j   |  j j d  j d t  |  j j j t  n^ t s |  j j d t  n |  j	 j
 t j  |  j j d  j d t  |  j j j t  d S(   s   SysTray Toggled HandlingNRC  R&   R<  s   /MenuBar/FileMenu/ExitApp(   R*   R  R   R8  R  RC  RQ   R)   R   R<  R=  R9  R>  R^   Re   RT   t   checkbutton_start_on_systrayR   Rf   t   STATUS_PASSIVE(   R	   RS  (    (    s   modules/core.pyt   on_checkbutton_systray_toggledJ  s$    	 	  
 c         C   s%   | j    r t |  _ n	 t |  _ d S(   s+   Start Minimized on SysTray Toggled HandlingN(   R  R)   R   Rf   (   R	   RS  (    (    s   modules/core.pyt'   on_checkbutton_start_on_systray_toggled]  s     c         C   s[   | j    |  j d <|  j d r= |  j d k r= |  j   n  |  j j j |  j d  d S(   s   Autosave Toggled Handlingi    N(   R  R-  R   R   R.  RT   R+  R   (   R	   RS  (    (    s   modules/core.pyt   on_checkbutton_autosave_toggledb  s     c         C   sE   | j    |  _ |  j r. |  j j t j  n |  j j t j  d S(   s   Lines Wrapping Toggled HandlingN(   R  t   line_wrappingR   t   set_wrap_modeR   t	   WRAP_WORDt	   WRAP_NONE(   R	   RS  (    (    s   modules/core.pyt    on_checkbutton_line_wrap_toggledh  s    	 c         C   s&   | j    |  _ |  j j |  j  d S(   s.   Insert Spaces Instead of Tabs Toggled HandlingN(   R  t   spaces_instead_tabsR   t!   set_insert_spaces_instead_of_tabs(   R	   RS  (    (    s   modules/core.pyt"   on_checkbutton_spaces_tabs_toggledn  s    c         C   s,   |  j  j j   |  _ |  j j |  j  d S(   s&   Automatic Indentation Toggled HandlingN(   RT   t   checkbutton_auto_indentR  t   auto_indentR   t   set_auto_indent(   R	   RS  (    (    s   modules/core.pyt"   on_checkbutton_auto_indent_toggleds  s    c         C   s&   | j    |  _ |  j j |  j  d S(   s   Show Line Num Toggled HandlingN(   R  t   show_line_numbersR   t   set_show_line_numbers(   R	   RS  (    (    s   modules/core.pyt    on_checkbutton_line_nums_toggledx  s    c         C   s   | j    |  _ d S(   s   Expand Tree When Loaded ToggledN(   R  R  (   R	   RS  (    (    s   modules/core.pyt"   on_checkbutton_expand_tree_toggled}  s    c         C   s   | j    |  _ d S(   s-   Automatically Check for Newer Version ToggledN(   R  R   (   R	   RS  (    (    s   modules/core.pyt$   on_checkbutton_newer_version_toggled  s    c         C   s   | j    |  _ d S(   s   Backup Before Save ToggledN(   R  R  (   R	   RS  (    (    s   modules/core.pyt+   on_checkbutton_backup_before_saving_toggled  s    c         C   s   | j    |  _ d S(   s   Autosave on Quit ToggledN(   R  t   autosave_on_quit(   R	   RS  (    (    s   modules/core.pyt'   on_checkbutton_autosave_on_quit_toggled  s    c         C   s8   | j    |  _ |  j r4 t j t d  |  j  n  d S(   s   Show White Spaces Toggleds=   This Change will have Effect Only After Restarting CherryTreeN(   R  t   highl_curr_lineR*   R   R   R   RU   (   R	   RS  (    (    s   modules/core.pyt-   on_checkbutton_highlight_current_line_toggled  s    	c         C   s8   | j    |  _ |  j r4 t j t d  |  j  n  d S(   s   Show White Spaces Toggleds=   This Change will have Effect Only After Restarting CherryTreeN(   R  t   show_white_spacesR*   R   R   R   RU   (   R	   RS  (    (    s   modules/core.pyt(   on_checkbutton_show_white_spaces_toggled  s    	c         C   s   |  j  s d S| j   |  _ |  j j   j } |  j j   j } |  j j |  j  |  j j |  j  |  j r |  j j	 |  j  |  j j
 |  j  |  j j d |  n9 |  j j	 |  j  |  j j
 |  j  |  j j d |  d S(   s&   Display Tree on the Right Side ToggledNt   position(   R*   R  Rq   Rj   t   get_allocationt   widthRn   Rh   R#  Rr   Rs   RQ   (   R	   RS  t
   tree_widtht
   text_width(    (    s   modules/core.pyt&   on_checkbutton_tree_right_side_toggled  s    	 	c         C   s8   |  j  j j | j    |  j  j j | j    d S(   s"   Import Table from CSV File ToggledN(   RT   t   tablehandle_frame_tableR   R  t   tablehandle_frame_col(   R	   RS  (    (    s   modules/core.pyt*   on_checkbutton_table_ins_from_file_toggled  s    c         C   s&   | j    r d |  _ n  |  j   d S(   s   Show/Hide Relative Framest   websN(   R  t	   link_typet   link_type_changed_on_dialog(   R	   R7  (    (    s   modules/core.pyt#   on_radiobutton_link_website_toggled  s     c         C   s&   | j    r d |  _ n  |  j   d S(   s   Show/Hide Relative Framest   nodeN(   R  R  R  (   R	   RS  (    (    s   modules/core.pyt'   on_radiobutton_link_node_anchor_toggled  s     c         C   s&   | j    r d |  _ n  |  j   d S(   s   Show/Hide Relative Framest   fileN(   R  R  R  (   R	   R7  (    (    s   modules/core.pyt    on_radiobutton_link_file_toggled  s     c         C   s&   | j    r d |  _ n  |  j   d S(   s   Show/Hide Relative Framest   foldN(   R  R  R  (   R	   R7  (    (    s   modules/core.pyt"   on_radiobutton_link_folder_toggled  s     c         C   sX   |  j  j j |  j d k  |  j  j j |  j d k  |  j  j j |  j d k  d S(   s?   Change the Graphic of the Dialog according to the New Link TypeR  R  R  R  N(   s   files   fold(   RT   t   frame_link_website_urlR   R  R  t   frame_link_filepath(   R	   (    (    s   modules/core.pyR    s    c         C   s8   | j    r4 d |  _ |  j r4 |  j d t  q4 n  d S(   s!   Change Variable Value AccordinglyR   Ru  N(   R  R   R*   R|  R)   (   R	   R7  (    (    s   modules/core.pyt'   on_radiobutton_node_icon_cherry_toggled  s    		 c         C   s8   | j    r4 d |  _ |  j r4 |  j d t  q4 n  d S(   s!   Change Variable Value AccordinglyR%   Ru  N(   R  R   R*   R|  R)   (   R	   R7  (    (    s   modules/core.pyt'   on_radiobutton_node_icon_bullet_toggled  s    		 c         C   s8   | j    r4 d |  _ |  j r4 |  j d t  q4 n  d S(   s!   Change Variable Value AccordinglyRz  Ru  N(   R  R   R*   R|  R)   (   R	   R7  (    (    s   modules/core.pyt%   on_radiobutton_node_icon_none_toggled  s    		 c         C   s   | j  d k r4 |  j j d d d | j  | j  n | j  d k r |  j j t | j  t | j	   } | r |  j j
 | d  r |  j j | d  q |  j j | d t  q n1 | j  d k r | j t j j k r |  j   n  d S(   s   Catches mouse buttons clicksi   i   i    i   N(   RJ  R_  R`  R   Ra  R   t   get_path_at_posR}   Ro  Rp  t   row_expandedR  R  Rf   R,  R   RJ   R-  R]  (   R	   RJ  RK  t   path_at_click(    (    s   modules/core.pyR     s    %'$c         C   sl   | t  j k rX t j   } | j |  j j |  j   |  j | |  | j	 t
  | St j |  j  Sd S(   s'   Returns a New Instantiated SourceBufferN(   R   R   R   t   Buffert   set_style_schemeR   t
   get_schemet   style_schemeR  t   set_highlight_matching_bracketsR)   R   t
   TextBufferR   (   R	   R  Ri  (    (    s   modules/core.pyt   buffer_create  s    c         C   s8  t  j t t  |  _ |  j j t d  t j g  t j	   |  _
 |  j
 j   |  _ d |  j k rw |  j j d  n  x? t |  j  D]. } |  j j |  j
 j |  j   | g  q Wxx |  j j |  j j g D]^ } | j |  j  t  j   } | j | t  | j | d d  | j |  j |  j   q Wd S(   s;   Init The Programming Languages Syntax Highlighting ComboBoxs   Disabled (Custom Colors)t   defR!   i    N(   R   t	   ListStoreRy   t   prog_lang_liststoreR  R   R   R   R   t   LanguageManagert   language_managert   get_language_idst   available_languagesR#  t   sortedt   get_languaget   get_nameRT   t   combobox_prog_langt   combobox_prog_lang_codeboxRV  R   Rd   R)   t   add_attributet   set_active_itert   get_combobox_prog_lang_iterR  (   R	   t   language_idt   comboboxt   cell(    (    s   modules/core.pyR     s     ,c         C   s`   |  j  j   } xJ | d k rN |  j  | d | k r9 Pq |  j  j |  } q W|  j  j   S| S(   s1   Returns the Language iter Given the Language Namei   N(   R  R  R   RZ  (   R	   t   prog_languaget	   curr_iter(    (    s   modules/core.pyR    s     c         C   s   |  j  j j   } |  j | d } | |  j k r | |  _ t j t d  |  j  t	 t
 j d  } | j |  | j   n  d S(   s   New Country Language Choosedi    sC   The New Language will be Available Only After Restarting CherryTreeRu  N(   RT   t   combobox_country_languaget   get_active_itert   country_lang_liststoreRW   R   R   R   RU   R  R   t	   LANG_PATHR  R  (   R	   R  t   new_itert   new_langt   lang_file_descriptor(    (    s   modules/core.pyt$   on_combobox_country_language_changed  s    	c         C   s   |  j  j } t j t  |  _ | j |  j  t j   } | j | t	  | j
 | d d  x$ t j D] } |  j j | g  qg W| j |  j |  j   | j d |  j  d S(   s"   Init The Country Language ComboBoxR!   i    t   changedN(   RT   R  R   R  Ry   R  RV  R   Rd   R)   R  R   t   AVAILABLE_LANGSR  R  t   get_combobox_country_lang_iterRW   R   R  (   R	   R  R  RW   (    (    s   modules/core.pyR     s    c         C   s`   |  j  j   } xJ | d k rN |  j  | d | k r9 Pq |  j  j |  } q W|  j  j   S| S(   s1   Returns the Language iter Given the Language Namei    N(   R  R  R   RZ  (   R	   t   country_languageR  (    (    s   modules/core.pyR  #  s     c         C   s[   |  j  j j   } |  j | d } | |  j k rW | |  _ t j t d  |  j  n  d S(   s   New Style Scheme Choosedi    s=   This Change will have Effect Only After Restarting CherryTreeN(	   RT   t   combobox_style_schemeR  t   style_scheme_liststoreR  R   R   R   RU   (   R	   R  R  t	   new_style(    (    s   modules/core.pyt    on_combobox_style_scheme_changed,  s
    	c         C   s   |  j  j } t j t  |  _ | j |  j  t j   } | j | t	  | j
 | d d  g  } x= t |  j j    D]& } |  j j | g  | j |  qy W|  j | k r | d |  _ n  | j |  j |  j   | j d |  j  d S(   s   Init The Style Scheme ComboBoxR!   i    R  N(   RT   R  R   R  Ry   R  RV  R   Rd   R)   R  R  R   t   get_scheme_idsR  R  R  t   get_combobox_style_scheme_iterR   R  (   R	   R  R  t   style_schemes_listR  (    (    s   modules/core.pyR   4  s     c         C   s`   |  j  j   } xJ | d k rN |  j  | d | k r9 Pq |  j  j |  } q W|  j  j   S| S(   s9   Returns the Style Scheme iter Given the Style Scheme Namei    N(   R  R  R   RZ  (   R	   R  R  (    (    s   modules/core.pyR  D  s     c         C   sD   |  j  |  j |  d } | j |  j j |   | j t  d S(   s;   Set the given syntax highlighting to the given sourcebufferi   N(   R  R  t   set_languageR  R  t   set_highlight_syntaxR)   (   R	   Ri  R  R  (    (    s   modules/core.pyR  M  s    c         C   sB   |  j  | d } |  j  | d |  j  | d <| |  j  | d <d S(   s'   Swap the sequences num of the two itersi   N(   R   (   R	   t
   first_itert   second_itert   first_iter_seq(    (    s   modules/core.pyR  S  s    c         C   s   | r |  j  j |  n |  j  j   } d } x | d k r | d 7} |  j  | d | k r | |  j  | d <|  j j |  j  | d  n  | r |  j | |  n  |  j  j |  } q0 Wd S(   s!   Parse Tree and Fix Node Sequencesi    i   i   i   N(   R   R\  R  R   RD   R  R  RZ  (   R	   Re  t   process_childrenR  t   node_sequence(    (    s   modules/core.pyR  Y  s    '
c   	      G   s  |  j  j j t  |  j d t d  d t  } | d k rA d S|  j   |  j	 |  j  j
 j   d |  _ |  j r |  j j |  j  n d } | r |  j j |  d n d } |  j | |  j  } |  j   } |  j d k r>|  j j | |  j | | |  j |  j  | |  j d |  j  j j   |  j  j j   g  } nT |  j j | | | |  j |  j  | |  j d |  j  j j   |  j  j j   g  } |  j j |  |  j | t  | |  j | <|  j j |  } |  j j |  |  j  j!   d S(   s8   Add a node having common father with the selected node'sR  s   Insert the New Node Name...t   syntax_highlightNi   i    ("   RT   t   checkbutton_readonlyR  Rf   t   dialog_inputR   R)   R   R  R  R  R  R  R   R   R[  R[  R  RK  R
  R  t   tags_searching_entryR  R  R  RD   t   pending_new_db_nodeR  R   RZ  R   RY  R   Rd  (	   R	   R   R0  Re  R  t   cherryt   new_node_idR  R  (    (    s   modules/core.pyR  f  sD     
 $"	c   	   
   G   s  |  j  d k r, t j t d  |  j  d S|  j j j t	  |  j
 d t d  d t  } | d k r|  j   |  j |  j j j   d |  _ |  j  r |  j j |  j   d n d } |  j | |  j  } |  j   } |  j j |  j  | | |  j |  j  | |  j d |  j j j   |  j j j   g  } |  j j |  |  j |  j  t	  | |  j | <|  j j |  } |  j j |  j   } |  j j  | t  |  j j! |  |  j" j#   n  d S(   s-   Add a node having as father the selected nodes   No Node is Selected!NR  s!   Insert the New Child Node Name...R  i   i    ($   R   R   R   R
  R   RU   RT   R  R  Rf   R  R)   R  R  R  R  R  R   R[  R  RK  R  R  R  R  R  RD   R  R  R   RZ  R   R  RY  R   Rd  (	   R	   R   R0  R  R  R  R  R  t   father_node_path(    (    s   modules/core.pyt   node_child_add  s6    
 (c         G   s  |  j  d k r, t j t d  |  j  d St d  |  j |  j  d } |  j j |  j   d k rx | t d  7} n  |  j j	 j
 |  |  j j	 j t  |  j j j   } |  j j j   | d k r d S|  j |  j |  j   } | d k r0|  j j |  j   } | d k r0|  j j |  j   } q0n  |  j d  |  j j |  j   d |  _  | d k r|  j j |  j j |   |  j j   n  d S(   s   Delete the Selected Nodes   No Node is Selected!Ns,   Are you sure to <b>Delete the node '%s'?</b>i   s9   

The node <b>has Children, they will be Deleted too!</b>t   ndel(   R   R   R   R
  R   RU   R   R\  RT   t   label_node_deleteR  R  R)   t   nodedeletedialogR  R   RX  RZ  R[  R  R#  R   RY  RZ  R   Rd  (   R	   R   t   warning_labelR   R  (    (    s   modules/core.pyR^    s.      	c         G   s  |  j  d k r, t j t d  |  j  d S|  j j j |  j	 |  j
 |  j  d   |  j j j |  j
 |  j  d  |  j j j |  j
 |  j  d  |  j d |  j
 |  j  d d t d	  d
 t  } | d k r d S|  j |  j j j   d |  _ |  j
 |  j  d t j k r|  j t j k rt j t d  |  j  sTt j |  _ d S|  j |  j |  j  |  j  |  j
 |  j  d |  _ ne |  j
 |  j  d t j k r|  j t j k r|  j |  j |  j  |  j  |  j
 |  j  d |  _ n  | |  j
 |  j  d <|  j |  j
 |  j  d <|  j j j   |  j
 |  j  d <|  j j j   |  j
 |  j  d <|  j |  j
 j |  j   |  j  |  j
 |  j  d <|  j t j k r|  j |  j |  j  n  |  j j |  j
 |  j  d  |  j    |  j! d  |  j j"   d S(   s(   Edit the Properties of the Selected Nodes   No Node is Selected!Ni   i   i   t
   entry_hinti   R  s#   Insert the New Name for the Node...R  sr   Entering the Automatic Syntax Highlighting you will Lose all Custom Colors for This Node, Do you want to Continue?i   i    t   npro(#   R   R   R   R
  R   RU   RT   R  R  R  R   R  R  R  R  R  R)   R  R  R  R   R   t   dialog_questionR  R   R  R  R  R[  R  R   t   set_editableR   R  Rd  (   R	   R   R0  (    (    s   modules/core.pyR]    sB    *!!	  //  
c         C   s  | t  j k r |  j | d j d |  j  |  j | d j d |  j  |  j | d j d |  j  |  j j t	 j
 |  j   |  j j d  |  j j t  nW |  j j t	 j
 |  j   |  j r |  j j t j  n  |  j r |  j j t  n  d S(   s3   Set sourceview properties according to current nodei   s   insert-texts   delete-ranges   mark-seti    N(   R   R   R   R   R  R  t   on_textbuffer_mark_setR   R  R   R  R  t   set_draw_spacest   set_highlight_current_lineRf   R  R{  R4   t   DRAW_SPACES_FLAGSRy  R)   (   R	   R  t   syntax_highl(    (    s   modules/core.pyt   sourceview_set_properties  s    	 	 c         C   s   |  j  r t |  _  t } n t } | j | j     } |  j |  |  j | d <|  j | d j |  |  j j	 |  j | d  |  j | d j
 d |  j  |  j | |  | r t |  _  n  |  j j |  j | d  d S(   s?   Switch TextBuffer -> SourceBuffer or SourceBuffer -> TextBufferi   s   modified-changedi   N(   R*   Rf   R)   R  t
   get_boundsR  R   R  R   R  R   R  R  RD   t   pending_edit_db_node_buff(   R	   t   text_bufferR  t   new_syntax_highlR  t	   node_text(    (    s   modules/core.pyR    s    			 c         G   sU  |  j  j   \ } } | d k r% d S|  j d k rW | | d | |  j d k rW d S|  j r |  j r |  j j d  |  j | |  j d <n  |  j j   r t	 |  _
 |  j j t  |  j j |  j |  j d  q n  | |  _ |  j |  j  |  _ |  j j |  j  |  j |  j d |  _ |  j j d |  j  |  j |  j |  j  |  j j t	  |  j j |  j |  j d  |  j j d t j |  j |  j d  d	  |  j j t	  |  j j |  j |  j d  |  j   |  j    | | d |  j k rQ|  j j! |  j j" |  j | | d   |  j j# |  j j$   d
  n  d S(   s1   Actions to be triggered from the changing of nodeNi   s   cursor-positioni   s   modified-changedi   s   <big><b><i>i   s   </i></b></big>g333333?(%   R   R  R   R   R*   R   R  R   R  R)   R   R  Rf   R9   R)  R   R  R   R  R  R   R  R  R   R  Rp   R  R  R  R  R  R  R   R  R  R  R  (   R	   R   R  R  (    (    s   modules/core.pyR   	  s8     .		'	$	/

+c         C   s9   |  j  | d s* |  j j | |  j  n  |  j  | d S(   s+   Returns the text buffer given the tree iteri   (   R   RD   t   read_db_node_contentRv  (   R	   R  (    (    s   modules/core.pyR  #	  s    c         C   s   | j    s, |  j r( t j |  d  n  d Sy | j   \ } } | j   | j   d k r | j   } | d k r t |  } d | k r t j |  | j	  q d | k r t j |  | j
  q d | k r t j |  | j
  q q n  Wn n Xd S(   R   Ni   R   t	   liststoreRi  (   R  R   R   t   set_object_highlightR   R  R  t   get_child_anchorR  t   eventboxt   frame(   R	   R  t	   text_itert	   text_markt   iter_sel_startt   iter_sel_endt   anchort
   anchor_dir(    (    s   modules/core.pyR  *	  s$    	      c         C   s&  |  j  s" |  j t  t |  _  n  | r | d k ra |  j r |  j j |  j |  j d  q q | d k r |  j r |  j j |  j |  j d  q q | d k r |  j r |  j j |  j |  j d  q q | d k r |  j j	   q n  | r"|  j r"|  j
 j |  j |  j d  n  d S(   s$   Window title preceeded by an asterixRh  i   R  R  t   bookN(   R   t   window_title_updateR)   R   RD   R  R   R  t   pending_rm_db_nodet   pending_edit_db_bookmarksR9   R)  (   R	   t   update_typet   new_state_machine(    (    s   modules/core.pyR  :	  s"    		$	$	$ c         C   s   |  j  t  t |  _ |  j d k r |  j j t  |  j j   } xS | j   } | d k r d t	 |  k r | j
 j t  n  | j   sG PqG qG n  d S(   s(   Window title not preceeded by an asterixRi  N(   R  Rf   R   R   R   R   R  t   get_start_iterR  R  Ri  R/  (   R	   R  R  (    (    s   modules/core.pyRf  M	  s    	  c         C   s   | rM |  j  d k r: |  j j d |  j  d t j  q |  j j d  nG |  j  d k r} |  j j |  j  d t j  n |  j j d t j  d S(   s   Update window titleR   t   *s    - CherryTree %ss   *CherryTrees   CherryTree %sN(   R^  RU   R  R   R   (   R	   t   save_needed(    (    s   modules/core.pyR  Y	  s     % !c         G   s   |  j  j   d S(   sD   Continue the previous replace (a_node/in_selected_node/in_all_nodes)N(   RA   t   replace_again(   R	   R   (    (    s   modules/core.pyR  b	  s    c         G   s$   |  j  j j t  |  j j   d S(   sC   Continue the previous search (a_node/in_selected_node/in_all_nodes)N(   RT   t    checkbutton_iterated_find_dialogR  Rf   RA   t
   find_again(   R	   R   (    (    s   modules/core.pyR   f	  s    c         G   s$   |  j  j j t  |  j j   d S(   s]   Continue the previous search (a_node/in_selected_node/in_all_nodes) but in Opposite DirectionN(   RT   R  R  Rf   RA   t	   find_back(   R	   R   (    (    s   modules/core.pyR  k	  s    c         G   s   |  j  j   d S(   s&   Replace a pattern in the selected NodeN(   RA   t   replace_in_selected_node(   R	   R   (    (    s   modules/core.pyR  p	  s    c         G   s=   |  j  d k r, t j t d  |  j  d S|  j j   d S(   s)   Search for a pattern in the selected Nodes   No Node is Selected!N(   R   R   R   R
  R   RU   RA   t   find_in_selected_node(   R	   R   (    (    s   modules/core.pyR  t	  s    c         G   s   |  j  j   d S(   s)   Replace the pattern in all the Tree NodesN(   RA   t   replace_in_all_nodes(   R	   R   (    (    s   modules/core.pyR  {	  s    c         G   s:   |  j    r) t j t d  |  j  d S|  j j   d S(   s*   Search for a pattern in all the Tree Nodess   The Tree is Empty!N(   Rk  R   R
  R   RU   RA   t   find_in_all_nodes(   R	   R   (    (    s   modules/core.pyR  	  s    c         G   s   |  j  j   d S(   s0   Replace the pattern between all the Node's NamesN(   RA   t   replace_in_nodes_names(   R	   R   (    (    s   modules/core.pyR  	  s    c         G   s:   |  j    r) t j t d  |  j  d S|  j j   d S(   s1   Search for a pattern between all the Node's Namess   The Tree is Empty!N(   Rk  R   R
  R   RU   RA   t   find_a_node(   R	   R   (    (    s   modules/core.pyR  	  s    c         C   so   | d k r. |  j j   } | d k r. d Sn  |  j j |  } x( | d k rj | } |  j j |  } qC W| S(   s<   Returns the last top level iter or None if the tree is emptyN(   R   R   R  RZ  (   R	   t	   node_iterRd  (    (    s   modules/core.pyt   get_tree_iter_last_sibling	  s     c         C   s   | j  |  } t |  d } d } xW | d k r~ | | d k r~ t |  } | | c d 8<t |  } | j |  } q( W| S(   sH   Returns the previous sibling iter or None if the given iter is the firsti   i    N(   RZ  R3  R   t   listt   tupleRw  (   R	   R  R  Rc  t   sibling_indexRc  t   node_path_listt	   prev_path(    (    s   modules/core.pyRX  	  s    c         G   s]   t  |  _ |  j j   } | rP |  j |  } | rC |  j |  qP |  j   n  t |  _ d S(   s   Go to the Previous Visited NodeN(   R)   R   R9   t   requested_previous_visitedR)  RY  RH  Rf   (   R	   R   R  R  (    (    s   modules/core.pyRH  	  s    	 c         G   s]   t  |  _ |  j j   } | rP |  j |  } | rC |  j |  qP |  j   n  t |  _ d S(   s   Go to the Next Visited NodeN(   R)   R   R9   t   requested_next_visitedR)  RY  RI  Rf   (   R	   R   R  R  (    (    s   modules/core.pyRI  	  s    	 c         G   s  |  j  d k r d S|  j t j k r|  j j |  j |  j  d  } | d k r|  j rl t	 |  _ t
 } n t	 } |  j j |  j | d  | d } x | D] } | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q q W|  j j d  |  j j |  j  |  j   |  j j |  j j | d   |  j j |  j j   d	  | rt
 |  _ n  |  j d
  qn, |  j j   r|  j j   |  j d
  n  d S(   s+   Step Back for the Current Node, if PossibleNi   i    i   R   t   tablet   codeboxi   g333333?Rh  (   R   R   R  R   R   R9   t   requested_previous_stateR   R*   Rf   R)   R;   t   dom_to_bufferR   t   load_embedded_image_elementt   load_embedded_table_elementt   load_embedded_codebox_elementR   R  R  R  R  R  R  R  t   can_undot   undo(   R	   R   t	   step_backR  t   pixbuf_table_vectorR!  (    (    s   modules/core.pyt   requested_step_back	  s:      			
   !
  c         G   s  |  j  d k r d S|  j t j k r|  j j |  j |  j  d  } | d k r|  j rl t	 |  _ t
 } n t	 } |  j j |  j | d  | d } x | D] } | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q q W|  j j d  |  j j |  j  |  j   |  j j |  j j | d   |  j j |  j j   d	  | rt
 |  _ n  |  j d
  qn, |  j j   r|  j j   |  j d
  n  d S(   s,   Step Ahead for the Current Node, if PossibleNi   i    i   R   R  R  i   g333333?Rh  (   R   R   R  R   R   R9   t   requested_subsequent_stateR   R*   Rf   R)   R;   R  R   R  R  R  R   R  R  R  R  R  R  R  t   can_redot   redo(   R	   R   t
   step_aheadR  R  R!  (    (    s   modules/core.pyt   requested_step_ahead	  s:      			
   !
  c         C   sU  |  j  s d S|  j j |  j |  j  d  } | d } t |  d k rQ|  j rd t |  _ t } n t } |  j j	 d  |  j
 j |  j | d  x | D] } | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q | d d k r |  j j |  j | d  q q W|  j j t  | rQt |  _ qQn  d S(	   s#   Buffer Refresh (Needed for Objects)Ni   i   i    R   R   R  R  (   R   R9   t   requested_current_stateR   R3  R*   Rf   R)   R   R  R;   R  R  R  R  R  (   R	   t   refreshR  R  R!  (    (    s   modules/core.pyR  	  s*    	  
			   ! c         C   s1   |  j  r- |  j j |  j |  j d |  n  d S(   s   Text insertion callbacki   N(   R*   R9   t   text_variationR   R   (   R	   Ri  R  t   text_insertedt   length(    (    s   modules/core.pyR  
  s    	c         C   s=   |  j  r9 |  j j |  j |  j d | j | |   n  d S(   s   Text removal callbacki   N(   R*   R9   R$  R   R   R  (   R	   Ri  t
   start_itert   end_iter(    (    s   modules/core.pyR  
  s    	c         C   sC   |  j  d k r, t j t d  |  j  d S|  j j t j	  d S(   s   Insert a Horizontal Lines   No Node is SelectedN(
   R   R   R   R
  R   RU   R   R4  R   t   HORIZONTAL_RULE(   R	   R  (    (    s   modules/core.pyt   horizontal_rule_insert
  s    c         C   sC  | d k r" |  j j j |  n  | d k rD |  j j j |  n |  j j j d  |  j j j   |  j j j d |  |  j j	 j d |  |  j j
 j d |  |  j j j d |  |  j j j d |  |  j j j   } |  j j j   | d k r;|  j j j   j d  } t |  d k r4| Sd Sn d Sd S(   s   Opens the Input DialogR   R&   i   s   utf-8i    N(   R   RT   R   R  t   input_entryR  Rd  t   search_options_frameRQ   t   replace_options_framet   syntax_highlighting_framet   tags_searching_frameR  R  R   R  t   decodeR3  (   R	   R  R  t
   search_optt   replace_optR  R   t
   input_text(    (    s   modules/core.pyR  
  s&       c         G   se   |  j  d k r, t j t d  |  j  d S|  j  d 7_  |  j j d  j d t j	 |  j   d S(   s&   Increase the Size of the Toolbar Iconsi   s=   The Size of the Toolbar Icons is already at the Maximum ValueNi   s   /ToolBars	   icon-size(
   t   toolbar_icon_sizeR   R   R   RU   R^   Re   RQ   RX   t
   ICONS_SIZE(   R	   R   (    (    s   modules/core.pyt   toolbar_icons_size_increase1
  s
    c         G   se   |  j  d k r, t j t d  |  j  d S|  j  d 8_  |  j j d  j d t j	 |  j   d S(   s&   Decrease the Size of the Toolbar Iconsi   s=   The Size of the Toolbar Icons is already at the Minimum ValueNs   /ToolBars	   icon-size(
   R4  R   R   R   RU   R^   Re   RQ   RX   R5  (   R	   R   (    (    s   modules/core.pyt   toolbar_icons_size_decrease9
  s
    c         G   sN   |  j  j d  j d  r4 |  j  j d  j   n |  j  j d  j   d S(   s   Toggle Show/Hide the Toolbars   /ToolBarR&   N(   R^   Re   R  R   R  (   R	   R   (    (    s   modules/core.pyt   toggle_show_hide_toolbarA
  s     c         G   s3   |  j  j d  r" |  j  j   n |  j  j   d S(   s   Toggle Show/Hide the TreeR&   N(   Rj   R  R   R  (   R	   R   (    (    s   modules/core.pyt   toggle_show_hide_treeF
  s    c         G   s3   |  j  j d  r" |  j  j   n |  j  j   d S(   s&   Toggle Show/Hide the Node Title HeaderR&   N(   Rp   R  R   R  (   R	   R   (    (    s   modules/core.pyt!   toggle_show_hide_node_name_headerL
  s    c         G   s'   |  j  r |  j j   n
 |  j   d S(   s#   Just Hide or Quit the gtk main loopN(   R   RU   R   t   quit_application_totally(   R	   R   (    (    s   modules/core.pyt   quit_applicationR
  s    	 c         G   s   |  j    s t |  _ d St j |   d t |   k rQ |  j rQ |  j j   n  x! |  j j	 D] } t
 j |  q^ W|  j j   t r d t |   k r |  j j t  n  d S(   s   The process is Shut DownNRv  RC  (   R  Rf   t   really_quitRX   R0  R  Rv  R  RD   R  RR   R#  RU   R#   R8  RC  t   set_visible(   R	   R   R  (    (    s   modules/core.pyR;  W
  s    	   c         C   s+   t  |  _ |  j   |  j s  t  S|  j Sd S(   s=   Before close the application (from the window top right X)...N(   R)   R=  R<  R   (   R	   RJ  RK  RA  (    (    s   modules/core.pyt   on_window_delete_eventb
  s
    	
	 c         C   s   |  j  d k r |  j j   t k s3 |  j t k r |  j rE d } n" |  j j j	   } |  j j j
   | d k r |  j   q n d } | d k r t St Sd S(   s=   Before close the current document, check for possible Unsavedi   i    i   N(   R   R   R   R  R)   R   Rw  RT   t
   exitdialogR  R   R6  Rf   (   R	   R   (    (    s   modules/core.pyR  i
  s    3	 	  c         G   s$   |  j  j j   |  j  j j   d S(   s:   Show the About Dialog and hide it when a button is pressedN(   RT   R   R  R   (   R	   R   (    (    s   modules/core.pyt   dialog_aboutu
  s    c         C   sN   |  j    s d S|  j j |  j j    } |  j t j j t j	  |  d S(   s   Insert an AnchorN(
   t   node_sel_and_rich_textR   R(  R  t   anchor_edit_dialogR   RJ   RK   R   t   ANCHOR_CHAR(   R	   R  R!  (    (    s   modules/core.pyt   anchor_handlez
  s     c         G   sH   |  j  j |  j  } | j   } | j   |  j |  j j | |  d S(   s   Edit an AnchorN(   R   t   get_iter_at_child_anchort   curr_anchor_anchorR   R/  RC  R   (   R	   R   R!  t
   iter_bound(    (    s   modules/core.pyt   anchor_edit
  s    
c         C   s  d t  |  k rD |  j j j | j  |  j j j t d   n, |  j j j d  |  j j j t d   |  j j j   |  j j	 j
   |  j j j   |  j j j   } |  j j j   | d k r d S|  j j j   j   } | d k rt j t d  |  j  d S| | _ | d k rn|  j j |  } | j   } |  j j | |  |  j j |  } n d } |  j | | |  d S(   s   Anchor Edit DialogR  s   Edit AnchorR   s   Insert Anchori   Ns   The Anchor Name is Mandatory!(   R  RT   t   anchor_insert_edit_entryR  R  R   R  R   Rd  t   anchor_enter_name_hboxR  t   scrolledwindow_anchors_listR   R  R  t   stripR   Ry  RU   R   R9   t   get_iter_alignmentR  R   R  R  t   image_insert(   R	   R   R!  RH  R   R  t   image_justificationt   image_offset(    (    s   modules/core.pyRC  
  s0     	c         G   sV   |  j    s d S|  j j |  j |  j |  j d  sR t j t d  |  j	  n  d S(   s   Insert Table Of ContentsNi   s!   Not Any H1 or H2 Formatting Found(
   RB  R;   t
   toc_insertR   R   R   R   R
  R   RU   (   R	   R   (    (    s   modules/core.pyRR  
  s     &c         G   s!   |  j    s d S|  j j   d S(   s   Insert TableN(   RB  R3   t   table_handle(   R	   R   (    (    s   modules/core.pyRS  
  s     c         G   s!   |  j    s d S|  j j   d S(   s   Insert Code BoxN(   RB  R6   t   codebox_handle(   R	   R   (    (    s   modules/core.pyRT  
  s     c         C   sF   |  j  s d S| j   r/ |  j j j d  n |  j j j d  d S(   s*   Radiobutton CodeBox Pixels/Percent ToggledNi  id   (   R*   R  RT   t   spinbutton_codebox_widtht	   set_value(   R	   R7  (    (    s   modules/core.pyt%   on_radiobutton_codebox_pixels_toggled
  s
    	 c         C   s_   |  j  d k r, t j t d  |  j  t S|  j t j	 k r[ t j t d  |  j  t St
 S(   s?   Returns True if there's not a node selected or is not rich texts   No Node is SelectedsK   Automatic Syntax Highlighting Must be Disabled in order to Use This FeatureN(   R   R   R   R
  R   RU   Rf   R  R   R   R)   (   R	   (    (    s   modules/core.pyRB  
  s    c         C   sd   | |  j  | d k r` | |  j  | d <|  j j d | d  |  j j t  |  j d  n  d S(   s&   A Tree Node Name is going to be Editedi   s   <big><b><i>s   </i></b></big>R  N(   R   Rp   R  R  R)   R  (   R	   R  R  t   new_text(    (    s   modules/core.pyR   
  s
    c      
   C   s  |  j    r) t j t d  |  j  d St j d t d   d |  j d t j t j Bd t j	 t j
 f  } | j d d  | j |  j  | j t j  t j d	 d
  } t j   } | j d t d  d  | j | d d d d  t j   } | j d t d  d  | j | d d d d
  t j   } | j d t d  d  | j | d d d
 d  t j   } | j d t d  d  | j | d d d d  t j   } | j d t d  d  | j | d d d d	  d |  _ d |  _ d |  _ d |  _ d |  _ |  j j   } x/ | d k r[|  j |  |  j j |  } q-W|  j   t j d |  j  } | j | d d
 d d  t j d |  j  } | j | d d
 d d
  t j d |  j  } | j | d d
 d
 d  t j d |  j  } | j | d d
 d d  t j d |  j  } | j | d d
 d d	  | j   } | j |  | j    | j!   j" t j#  | j$   | j%   d S(   s   Tree Summary Informations   The Tree is Empty!NR  R  R  R  i  i,  i   i   s   <b>s   Number of Text Nodess   </b>i    i   s   Number of Code Nodess   Number of Imagesi   s   Number of Tablesi   s   Number of CodeBoxess   %s(&   Rk  R   R
  R   RU   R   R  R  R  R  R  R  R  R  R  t   TableRo   t
   set_markupt   attacht   summary_nodes_text_numt   summary_nodes_code_numt   summary_images_numt   summary_tables_numt   summary_codeboxes_numR   R  R   t   tree_info_iterRZ  R  R  Rd   R   R  t
   set_layoutt   BUTTONBOX_SPREADR  R#   (   R	   R  R  R  R  R  R  (    (    s   modules/core.pyt	   tree_info
  sh    						


c         C   s  |  j  |  } |  j j |  } |  j | d t j k rM |  j d 7_ n |  j d 7_ d } d } d } x | D]w } | d d k r d t | d d  k r | d 7} qu | d d k r | d 7} qu | d d k ru | d 7} qu qu W| s| s| rFd G|  j | d GH|  j	 | 7_	 |  j
 | 7_
 |  j | 7_ n  |  j j |  } x/ | d	 k r|  j |  |  j j |  } q[Wd	 S(
   s"   Tree Summary Information Iterationi   i   i    R   R  R  R  s   node with object(s):N(   R  R9   t%   get_embedded_pixbufs_tables_codeboxesR   R   R   R\  R]  R  R^  R_  R`  R\  R   Ra  RZ  (   R	   R  R   R  t   curr_node_imagest   curr_node_tablest   curr_node_codeboxesR!  (    (    s   modules/core.pyRa    s0     *   c         G   s   |  j    s d S|  j j |  j j    } t j d |  j d |  j  } | d k rY d St	 j
 j |  |  _ t j j |  } |  j | |  j j |  j j     d S(   s   Insert/Edit ImageNR  R  (   RB  R   R(  R  R   R  t   pick_dirRU   R   RR   R  R_  R   RJ   RK   t   image_edit_dialog(   R	   R   R!  t   filenameR   (    (    s   modules/core.pyt   image_handle  s      c         C   s  | |  _  | j   |  _ | j   |  _ t |  j  |  j |  _ |  j   |  j j	 j
   } |  j j	 j   | d k r| d S| d k r |  j j |  } | j   } |  j j | |  |  j j |  } n d } |  j | |  j  j t |  j  t |  j  t j j  |  d S(   s   Insert/Edit Image Dialogi   N(   t   original_pixbuft	   get_widtht   temp_image_widtht
   get_heightt   temp_image_heightt   floatt   image_w_h_rationt   image_load_into_dialogRT   t   imageeditdialogR  R   R   R9   RN  R  R   R  R  RO  t   scale_simpleR}   R   RJ   t   INTERP_BILINEAR(   R	   R   t   insert_iterRH  R   RP  RQ  (    (    s   modules/core.pyRj  &  s(    	
 	c         C   sc  | s |  j  } n  | j   } | j |  } | | _ t j   | _ | j j t  d t	 |  k r | j j
 d |  j |  | j j | j  n | j j
 d |  j |  t j   | _ | j j | j  | j j | j  |  j j | j |  | j j   | r5| j |  } |  j j | | |  n* |  j r_|  j j |  j |  j d  n  d  S(   NR  s   button-press-eventi   (   R   R  t   create_child_anchorR   R   t   EventBoxR  t   set_visible_windowRf   R  R   t   on_mouse_button_clicked_anchorR  R  t   on_mouse_button_clicked_imaget   Imaget   imageRN   t   set_from_pixbufR   t   add_child_at_anchorR   R  R9   t   apply_object_justificationR*   R)  R   R   (   R	   R!  R   RP  R  RQ  R  R  (    (    s   modules/core.pyRO  <  s*     		c         G   sH   |  j  j |  j  } | j   } | j   |  j |  j j | |  d S(   s   Edit the selected ImageN(   R   RF  t   curr_image_anchorR   R/  Rj  R   (   R	   R   R!  RH  (    (    s   modules/core.pyt
   image_editT  s    
c      	   G   s   t  j d |  j d d d t d  d |  j  } | d k r@ d St |  d k  sb | d	 d
 k ro | d
 7} n  t j j	 |  |  _ y |  j
 j j | d  Wn$ t  j t d  | |  j  n Xd S(   s   Save to Disk the selected ImageR  R  s   *.pngR  s	   PNG ImageR  Ni   is   .pngt   pngs   Write to %s Failed(   R   Rm  Ri  R   RU   R   R3  RR   R  R_  R  R   t   saveRy  (   R	   R   Rk  (    (    s   modules/core.pyt
   image_save[  s     "   c         C   s?   |  j  j |  } | j   } | j   |  j  j | |  d S(   s   Put Selection Upon the ImageN(   R   RF  R   R/  R  (   R	   R  t
   iter_imageRH  (    (    s   modules/core.pyt   object_set_selectiong  s    
c         G   s    t  |  j _ |  j j d  d S(   s   Paste as Plain Texts   paste-clipboardN(   R)   R-   t   force_plain_textR   R?  (   R	   R   (    (    s   modules/core.pyt   paste_as_plain_textn  s    c         G   s$   |  j  |  j  |  j j d  d S(   s	   Cut Images   cut-clipboardN(   R  R  R   R?  (   R	   R   (    (    s   modules/core.pyt	   image_cuts  s    c         G   s$   |  j  |  j  |  j j d  d S(   s
   Copy Images   copy-clipboardN(   R  R  R   R?  (   R	   R   (    (    s   modules/core.pyt
   image_copyx  s    c         G   s=   |  j  |  j  |  j j t |  j j    |  j j   d S(   s   Delete ImageN(   R  R  R   t   delete_selectionR)   R   t   get_editableRd  (   R	   R   (    (    s   modules/core.pyt   image_delete}  s    c         C   s|   | |  _  |  j |  j   | j d k rV |  j j d  j d d d | j | j  n" | j t	 j
 j k rx |  j   n  t S(   s(   Catches mouse buttons clicks upon imagesi   s
   /ImageMenuN(   R  R  RJ  R^   Re   R`  R   Ra  R,  R   RJ   R-  R  R)   (   R	   RJ  RK  R  (    (    s   modules/core.pyR}    s    	. c         C   s|   | |  _  |  j |  j   | j d k rV |  j j d  j d d d | j | j  n" | j t	 j
 j k rx |  j   n  t S(   s(   Catches mouse buttons clicks upon imagesi   s   /AnchorMenuN(   RG  R  RJ  R^   Re   R`  R   Ra  R,  R   RJ   R-  RI  R)   (   R	   RJ  RK  R  (    (    s   modules/core.pyR|    s    	. c         C   s)  |  j  r t |  _  t } n t } |  j j j |  j  |  j j j |  j  |  j d k r |  j d k r |  j	 j
 t |  j  t |  j  t j j  } nb |  j d k r d } | |  j } n d } | |  j } |  j	 j
 t |  t |  t j j  } |  j j j |  | r%t |  _  n  d S(   s#   Load/Reload the Image Under Editingi  iX  N(   R*   Rf   R)   RT   t   spinbutton_image_widthRV  Ro  t   spinbutton_image_heightRq  Rm  Rv  R}   R   RJ   Rw  Rs  t   image_under_editingR  (   R	   R  R   Ro  Rq  (    (    s   modules/core.pyRt    s*    				 c         G   sQ   |  j  j d  |  _  d |  j |  _ |  j } |  j |  _ | |  _ |  j   d S(   s    Image Edit - Rotate 90 ClockWisei  i   N(   Rm  t   rotate_simpleRs  Rq  Ro  Rt  (   R	   R   t	   new_width(    (    s   modules/core.pyt   on_button_rotate_90_cw_clicked  s    		c         G   sQ   |  j  j d  |  _  d |  j |  _ |  j } |  j |  _ | |  _ |  j   d S(   s'   Image Edit - Rotate 90 CounterClockWiseiZ   i   N(   Rm  R  Rs  Rq  Ro  Rt  (   R	   R   R  (    (    s   modules/core.pyt   on_button_rotate_90_ccw_clicked  s    		c         C   sB   |  j  r> |  j j j   |  _ |  j |  j |  _ |  j   n  d S(   s"   Image Edit - Width Change HandlingN(   R*   RT   R  R,  Ro  Rs  Rq  Rt  (   R	   RK  (    (    s   modules/core.pyt'   on_spinbutton_image_width_value_changed  s    	c         C   sB   |  j  r> |  j j j   |  _ |  j |  j |  _ |  j   n  d S(   s#   Image Edit - Height Change HandlingN(   R*   RT   R  R,  Rq  Rs  Ro  Rt  (   R	   RK  (    (    s   modules/core.pyt(   on_spinbutton_image_height_value_changed  s    	c         G   s   |  j  d  d S(   s/   The Foreground Color Chooser Button was Pressedt
   foregroundN(   t	   apply_tag(   R	   R   (    (    s   modules/core.pyt   apply_tag_foreground  s    c         G   s   |  j  d  d S(   s/   The Background Color Chooser Button was Pressedt
   backgroundN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_background  s    c         G   s   |  j  d  d S(   s"   The Link Insert Button was Pressedt   linkN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_link  s    c         G   s   |  j  d d  d S(   s   The Bold Button was Pressedt   weightt   heavyN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_bold  s    c         G   s   |  j  d d  d S(   s   The Italic Button was Pressedt   stylet   italicN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_italic  s    c         G   s   |  j  d d  d S(   s    The Underline Button was Pressedt	   underlinet   singleN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_underline  s    c         G   s   |  j  d d  d S(   s$   The Strikethrough Button was Pressedt   strikethrought   trueN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_strikethrough  s    c         G   s   |  j  d d  d S(   s   The Small Button was Pressedt   scalet   smallN(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_small  s    c         G   s   |  j  d d  d S(   s   The H1 Button was PressedR  t   h1N(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_h1  s    c         G   s   |  j  d d  d S(   s   The H2 Button was PressedR  t   h2N(   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_h2  s    c         G   s5   |  j  j   \ } } |  j d d d | d | d S(   s$   The Justify Right Button was Pressedt   justificationR>  R  R  N(   R0   R'  R  (   R	   R   R  R  (    (    s   modules/core.pyt   apply_tag_justify_right  s    c         G   s5   |  j  j   \ } } |  j d d d | d | d S(   s#   The Justify Left Button was PressedR  R<  R  R  N(   R0   R'  R  (   R	   R   R  R  (    (    s   modules/core.pyt   apply_tag_justify_left  s    c         G   s5   |  j  j   \ } } |  j d d d | d | d S(   s%   The Justify Center Button was PressedR  t   centerR  R  N(   R0   R'  R  (   R	   R   R  R  (    (    s   modules/core.pyt   apply_tag_justify_center  s    c         C   s9  |  j  j |  j  j    } | j   } t } xN | d k r} | j   } t j d |  } | sd Pn | j	   st Pn  t
 } q0 W| s | j   n  xR | d k r | j   } t j d |  } | s | j	   Pq | j   s Pq q W| j |  r t S|  j  j |  j  j   |  |  j  j |  j  j   |  t
 Sd S(   s0   Try to Select a Word Forward/Backward the Cursors   \wN(   R   R(  R  R   Rf   R   R1  R  t   matchR/  R)   R0  t   equalR  t   get_selection_bound(   R	   R  R  t	   end_movedt   charR  (    (    s   modules/core.pyR	    s4      
 
  c         G   s@   |  j  t j k r/ t j t d  |  j  d S|  j j   d S(   s   Handler of the Bulleted ListsK   Automatic Syntax Highlighting Must be Disabled in order to Use This FeatureN(	   R  R   R   R   R
  R   RU   R0   t   list_bulleted_handler(   R	   R   (    (    s   modules/core.pyR     s    c         G   s@   |  j  t j k r/ t j t d  |  j  d S|  j j   d S(   s   Handler of the Numbered ListsK   Automatic Syntax Highlighting Must be Disabled in order to Use This FeatureN(	   R  R   R   R   R
  R   RU   R0   t   list_numbered_handler(   R	   R   (    (    s   modules/core.pyR  '  s    c         G   s@   |  j  t j k r/ t j t d  |  j  d S|  j j   d S(   s   Handler of the ToDo ListsK   Automatic Syntax Highlighting Must be Disabled in order to Use This FeatureN(	   R  R   R   R   R
  R   RU   R0   t   list_todo_handler(   R	   R   (    (    s   modules/core.pyR  .  s    c         G   sC   |  j  d d k r/ t j t d  |  j  n |  j |  j    d S(   s&   The Iterate Tagging Button was Pressedi    R   s9   No Previous Text Format Was Performed During This SessionN(   R   R   R
  R   RU   R  (   R	   R   (    (    s   modules/core.pyt   apply_tag_latest5  s     c         C   s  |  j  t j k r8 |  j r8 t j t d  |  j  d S| sJ |  j } n  | d k rB| d k rB| d k r"|  j
 d k r t j t d  |  j  d S| d k r d } n  | j   s| d k r |  j   s
t j t d  |  j  d Sq|  j   } | d k rp|  j   s4t j t d  |  j  d S|  j j j d  |  j j j d  |  j j j d  q| j   } | d |  _ |  j d	 k r|  j j j | d
  n |  j d1 k r|  j j j t j | d
   n |  j d k rst | d
  } t |  d k rt |  d k r4| d }	 n& | t | d  t | d
  d }	 |  j j j |	  qn' t j d |  j |  j  d	 |  _ d S|  j j j |  j d	 k  |  j j j |  j d k  |  j j j |  j d k  |  j j j |  j d k  n  | j   \ } } qBt j t d  |  j  d Sn  | d k r| d k r|  j  | d d  s|  j  | d d  rd	 |  _ |  j j j | j! | |   n  |  j" |  |  j j# j$ t d   |  j j% j&   |  j j' j&   |  j(   |  j j# j)   }
 |  j j# j*   |
 d
 k r1d S|  j d	 k r|  j j j!   j+   } | sbd St |  d k  s| d d !d k r| d d !d k rd | } n  d	 t j, | } q|  j d2 k r|  j j j!   j+   } | sd St j- |  } |  j t j, | } q|  j d k r|  j. j/   \ } } |  j j j!   j+   } d t j, t0 |  j1 | d  } t |  d k r| t j, | 7} qqq| d d k r|  j2 d r|  j j3 j4 |  j2 d  qnB | d d k r|  j2 d r|  j j3 j4 |  j2 d  qn d GH|  j j5 j)   }
 |  j j5 j*   |
 d k rMd S|  j j3 j6   |  j2 | d <|  j2 | d j7   } n  | d k r| | g |  _8 n  | j9   } x| D]} | j: d  } | d k r| d d !d k sF| d k r| d d !d k sF| d  k r'| d d! !d" k sF| d# k r]| d d$ !d% k r]| j; | | |  d S| d& k r| d d !d' k r| j; | | |  | | d k rNd Sq| d k r| d d$ !d( k r| j; | | |  q| d) k r| d d* !d+ k s8| d, k r| d d* !d- k s8| d k r| d d. !d/ k r| j; | | |  qqW| j< |  j= | |  | |  |  j r|  j> d0 t?  n  d S(3   s   Apply a tagsK   Automatic Syntax Highlighting Must be Disabled in order to Use This FeatureNR  s   No Node is SelectedR  s   No Text is SelectedR   i    R  i   R  R  R  i   i   s   Tag Name Not Recognized! (%s)s"   The Cursor is Not into a Paragraphi   s   http://i   s   https://s   Insert/Edit a LinkR$   R%   s   ERROR bad tag_propertyt   nameR  t   weight_R  i   t   style_R  i
   t
   underline_R  i   t   strikethrough_R  t   scale_t   justification_R  i   t   foreground_R  t   background_i   t   link_Rh  (   s   files   fold(   s   files   fold(@   R  R   R   R*   R   R
  R   RU   R   R   R   R  R	  t   link_check_around_cursorRT   t   link_website_entryR  t   entry_file_to_link_tot   link_anchor_entryt   splitR  t   base64t	   b64decodeR|   R3  Ry  t   radiobutton_link_websiteR  t   radiobutton_link_node_anchort   radiobutton_link_filet   radiobutton_link_folderR  t   next_chars_from_iter_areR  R  R   R  R  R  R  R  R  R   RM  R  t	   b64encodeR  R  Ry   R   R   t   colorselectiont   set_current_colort   colorselectiondialogt   get_current_colort	   to_stringR   t   get_tagsR  t
   remove_tagt   apply_tag_by_namet   apply_tag_exist_or_createR  R)   (   R	   t   tag_propertyt   property_valueR  R  R  t   link_node_idt   tag_property_valuet   vectort   anchor_nameR   t   link_urlt   link_uriR  R  t   link_anchort	   curr_tagst   curr_tagt   tag_name(    (    s   modules/core.pyR  :  s      	 # &		"
  & "       
	c         C   sb   | j    } xO t |  D]A } | j   | | k r9 t S| | d k r | j   r t Sq Wt S(   s=   Returns True if the Given Chars are the next 'num' after iteri   (   R   t   rangeR1  Rf   R/  R)   (   R	   R  t   numt   charst   itert   i(    (    s   modules/core.pyR    s      c         C   s  | d k r d } n | d k r* d } n  | d | } |  j  j t |   } | d k rt j t |   } | d k r | j | t j  n#| d k r | j | t j	  n| d k r | j | t j
  n| d k r | j | t j  n| d k r| j | t j  n| d	 k r=| j | t j  ny| d
 k r\| j | t  nZ| d k r~| j | t j  n8| d k r| j | t j  n| d k r| j | t j  n | d d !d k r| j d t j  | j d d  n | d d !d k r4| j d t j  | j d d  n | d d !d k rm| j d t j  | j d d  nI | d d !d k r| j d t j  | j d d  n | j | |  |  j  j |  n  t |  S(   sC   Check into the Tags Table whether the Tag Exists, if Not Creates itt   largeR  t   largoR  R   R  R  R  R  R  R<  R>  R  i    i   R  R  R  s   #00000000ffffR  s   #071c838e071cR  s   #8b8b69691414R  s   #7f7f7f7f7f7fN(   R   t   lookupRy   R   R   t   TextTagRQ   R   t   WEIGHT_HEAVYt   SCALE_X_SMALLt   SCALE_XX_LARGEt   SCALE_X_LARGEt   STYLE_ITALICt   UNDERLINE_SINGLER)   t   JUSTIFY_LEFTt   JUSTIFY_RIGHTt   JUSTIFY_CENTERRN   (   R	   R  R  R  t   tag(    (    s   modules/core.pyR    sV     	 	          c         C   s   |  j  j |  j  j    } | j   } x8 | D], } | j d  } | d d !d k r. Pq. q. Wd S| j   } | j |  s d S| j |  s d S|  j  j |  j  j   |  |  j  j |  j  j	   |  | d S(   s`   Check if the cursor is on a link, in this case select the link and return the tag_property_valueR  i    i   R  R   i   (
   R   R(  R  R  R  R   t   forward_to_tag_togglet   backward_to_tag_toggleR  R  (   R	   R  t   tagsR   R  R  (    (    s   modules/core.pyR    s       c         C   s  | j    } | d d k rb |  j d rN t j |  j d | d d t qt j | d  n+| d d k r8t j | d  } t	 j
 j |  s t j t d  | |  j  d S|  j d r t j |  j d t j |  d t qt j d d !d	 k rt	 j |  qt j d
 t j |  d t nU| d d k rt j | d  } t	 j
 j |  st j t d  | |  j  d S|  j d rt j |  j d t j |  d t qt j d d !d	 k rt	 j |  qt j d
 t j |  d t n| d d k rr|  j t | d   } | d k rht j t d  | d |  j  d S|  j |  |  j j   |  j j t j   j! d  |  j j" d  t# |  d k rt# |  d k r| d } n& | t# | d  t# | d  d } |  j$ |  } | d k r@t j% t d  | |  j  qo|  j& j' |  |  j j( |  j& j)   d  qn t j d | d |  j  d S(   s#   Function Called at Every Link Clicki    R  i   R}  R  s   The File Link '%s' is Not ValidNi   R|  s   xdg-open %sR  s!   The Folder Link '%s' is Not ValidR  s?   The Link Refers to a Node that Does Not Exist Anymore (Id = %s)i   s   No anchor named '%s' foundg333333?s   Tag Name Not Recognized! (%s)(*   R  RQ  R  R  R)   R@  R  R  R  RR   R  Ra  R   Ry  R   RU   RV  R  R  R  R  t	   startfileR~  RZ  R)  R|   R   RY  R   Rd  R  R   t   TEXT_WINDOW_TEXTRY  R  R3  t   link_seek_for_anchorR
  R   R  R  R  (   R	   R  R  R  R  R  t   iter_anchor(    (    s   modules/core.pyt   link_clicked  sX    %* #* #! &  "c         G   s   |  j  d k r0 t j d |  j d |  j  } n t j d |  j d |  j  } | d k r^ d S|  j  d k r t j j	 |  |  _ n  |  j
 j j |  d S(   sD   The Button to browse for a file path on the links dialog was pressedR  R  R  N(   R  R   R  Ri  RU   R  R   RR   R  R_  RT   R  R  (   R	   R   R  (    (    s   modules/core.pyt,   on_button_browse_for_file_to_link_to_clicked  s    !  c         C   s   |  j  j   } xk | j   } | d k rj d t |  k rj d t | j  k rj | j j | k rj | Sn  | j   s Pq q d S(   sS   Given an Anchor Name, Seeks for it in the Current Node and Returns the Iter or NoneR   R  N(   R   R  R  R   R  R   R  R/  (   R	   R  R  R  (    (    s   modules/core.pyR  %  s    9 c   
      G   s  |  j    |  j j   |  j j   \ } } |  j | d j   } xq | j   } | d k r d t	 |  k r d t	 | j
  k r |  j j | j
 j g  q n  | j   sF PqF qF |  j j   } | d k r t j t d  |  j  d S|  j j |  j j |   |  j j j   |  j j j   |  j j j t d   |  j j j   } |  j j j   | d k rvd S|  j j   \ } }	 |  j j j  |  j |	 d  d S(	   s0   Browse for Existing Anchors on the Selected Nodei   R   R  s)   There are No Anchors in the Selected NodeNs   Choose Existing Anchori   i    (!   t!   anchors_liststore_exist_or_createt   anchors_liststoreR  R  R  R   R  R  R   R  R   R  R  R/  R  R   R   R   RU   t   anchors_treeviewRY  RZ  RT   RK  R   RL  R  R   R  R  t   anchors_treeviewselectionR  R  (
   R	   R   R  R  R  R  t   anchor_first_iterR   t	   listmodelt   listiter(    (    s   modules/core.pyt    on_browse_anchors_button_clicked0  s2    
'  c         C   s   d t  |   k r t j t  |  _ t j |  j  |  _ t j   |  _ t j	 t
 d  |  j d d |  _ |  j j |  j  |  j j   |  _ |  j j d |  j  |  j j j |  j  |  j j j   n  d S(   s5   If Does Not Exist => Create Anchors Browser ListstoreR  s   Anchor NameR!   i    s   button-press-eventN(   R  R   R  Ry   R  R   R  R   t   anchors_renderer_textR   R   t   anchors_columnR   R   R  R   t$   on_mouse_button_clicked_anchors_listRT   RL  RN   R   (   R	   (    (    s   modules/core.pyR
  J  s    $c         C   s?   | j  d k r d S| j t j j k r; |  j j j   n  d S(   s   Catches mouse buttons clicksi   N(   RJ  R,  R   RJ   R-  RT   R  R  (   R	   RJ  RK  (    (    s   modules/core.pyR  W  s      c         C   s  t  } t  } t  } |  j j | |  } | j   t j k r] | j   } |  j j |  } n | j   t j	 t j
 g k r | j   } | j   r |  j j |  } q nH | j   t j k r | j   } | j d  r |  j j |  } q n  | r;|  j j t j  j t j j t j j   |  j j d  d S| j   } x| D]!}	 |	 j d  }
 |
 d d !d k rNt } |
 d j   } | d d k rt j | d
  } n | d d k rt | d
  |  j k r|  j t | d
  } n
 | d
 } t |  d k rkt |  d k r0| d } n* |
 d t | d  t | d
  d } | d | 7} n  PqNqNW| j   } | j    } | d k rd t! |  k rt } n= | j   | j    } | d k rd t! |  k rt } n  | |  j" k r
| |  _" n  | r'|  j j | j#  d S|  j" rq|  j j t j  j t j j t j j$   |  j j |  n, |  j j t j  j d  |  j j d  d S(   s   Looks at all tags covering the position (x, y) in the text view,
           and if one of them is a link, change the cursor to the HAND2 cursori   NR  i    i   R  i   R  R  i   R  i   t   #R  (   s   files   fold(%   Rf   R   t   get_iter_at_locationR1  R   t   CHAR_SQ_BR_OPENR   R0   t   is_list_todo_beginningR  t   CHAR_XR0  t   CHAR_SQ_BR_CLOSEt   backward_charsR  R   R  RY  RJ   t   Cursort   X_CURSORR  R   R  R  R)   R  R  R  R|   R   R3  t
   get_pixbufR  R   R  t   HAND2(   R	   Ro  Rp  t   hovering_linkt   hovering_anchort   hovering_todo_listR  t   text_iter_bisR  R   R  R  t   tooltipR  R  R   (    (    s   modules/core.pyt&   sourceview_cursor_and_tooltips_handler\  sl    . ) 
 * 	
 	 	.c         C   s  | j  t j j k rn| j d k rn| j t j t | j  t | j	   \ } } | j
 | |  } | j   } t j d | j    } | s d Sx2 | r | j   s Pn  t j d | j    } q W| j   t j d | j    } x2 | r| j   sPn  t j d | j    } q W| s3| j   n  |  j j |  j j   |  |  j j |  j j   |  n |  j t j k rd S| j  t j j k r| j d k r| j t j t | j  t | j	   \ } } |  j j
 | |  } | j   }	 |	 rJx|	 D]= }
 |
 j d  } | d d !d k r|  j | d  PqqWqt } | j   t j k rz|  j j  |  } n~ | j   t j! t j" g k r| j   r|  j j  |  } qn< | j   t j# k r| j$ d	  r|  j j  |  } qn  | r|  j j% |  qq| j d
 k r|  j j&   r| j t j t | j  t | j	   \ } } |  j j
 | |  } |  j j' |  qn| j  t j j( k rt j j) | j*  } | j+ t j j, @r| d k r|  j j- |  j j. |  j j    d
 t j!  qq| d k r|  j j. |  j j    } | d k rCt S| j   } | j$ d	  rw| j   t j0 k rwt S|  j j1 |  } | d d k rt S| j   } | d d k r| j$ d
  r| j   t j2 k r|  j j3 | |  t S| d d k r?| j$ d  r?| j   t j k r?|  j j3 | |  t S| d d k r| j$ d	  r| j   t j! k r| j   r| j   d k r| j$ t4 t5 | d    |  j j3 | |  t S| d r| j   } | j$ d
  |  j j3 | |  n  | d d k r.|  j j- | t j2 t j!  q| d d k rT|  j j- | d  q| d d } |  j j- | d |  |  j j6 | | j7   d  qn  t S(   s*   Called after every event on the SourceViewi   s   \wNR  i    i   R  i   i   i   RO  it   .s   [ ] s   %s. t   num2num(8   R,  R   RJ   R-  RJ  t   window_to_buffer_coordst   TEXT_WINDOW_WIDGETR}   Ro  Rp  R  R   R  R  R1  R/  R0  R   R  R  R  R  R   R   t   BUTTON_PRESSR   R  R  R  Rf   R  R0   R  R  R  R  R  t   todo_list_invert_checked_statusR  R  t	   KEY_PRESSRD  RE  RF  RR  R  R(  R   R&  t   get_paragraph_list_infot   CHAR_LISTBULR  R3  Ry   t   list_adjust_aheadR  (   R	   t	   text_viewRK  Ro  Rp  R  R  R  R  R  R   R  R"  RL  R!  t	   list_infot   iter_list_quitt   curr_num(    (    s   modules/core.pyR     s    $0 	 
	   005 $  444
   "c         C   s   |  j  j   s" |  j  j t  n  |  j t j k r8 d S|  j  j t j	 t
 | j  t
 | j   \ } } |  j | |  t S(   s,   Update the cursor image if the pointer movedN(   R   t   get_cursor_visiblet   set_cursor_visibleR)   R  R   R   R(  R   R)  R}   Ro  Rp  R%  Rf   (   R	   R0  RK  Ro  Rp  (    (    s   modules/core.pyR     s      3c         C   s   |  j  s t d  } n |  j |  j  d t j k rD t d  } n |  j |  j  d } |  j |  j  d r | d t d  7} n  |  j |  j  d r | d |  j |  j  d 7} n  |  j j |  j  |  j j |  j |  d S(	   s#   Update the statusbar with node infos   No Node is Selectedi   s	   Rich Texti   s     -  s	   Read Onlyi   N(	   R   R   R   R   R   Ru   R   Rw   R   (   R	   t   tooltip_text(    (    s   modules/core.pyR     s    	   c         C   sf   |  j  t j k r d S|  j j j   \ } } } |  j j t j | |  \ } } |  j	 | |  t
 S(   sd   Update the cursor image if the window becomes visible (e.g. when a window covering it got iconified)N(   R  R   R   R   RU   t   get_pointerR(  R   R)  R%  Rf   (   R	   R0  RK  t   wxt   wyR   t   bxt   by(    (    s   modules/core.pyR     s     !c         C   s+  |  j  s; i |  j j   j d 6|  j j   j d 6|  _  n |  j sH d S|  j  d |  j j   j k s |  j  d |  j j   j k r'|  j j   j |  j  d <|  j j   j |  j  d <|  j j   } x] | j   } | d k rd t	 |  k r| j
 r|  j j |  n  | j   s Pq q n  d S(   s   New Size Allocatedt   window_widthR  Nt   width_in_pixels(   R   RU   R~  R  Rj   R   R  R  R   R  R=  R6   t   codebox_apply_width_heightR/  (   R	   RJ  t
   allocationR  R  (    (    s   modules/core.pyR     s     		 ( c         C   s'   |  j  j   j |  j j   j t j S(   s   Get the Text Window Width(   RU   R~  R  Rj   R   t   MAIN_WIN_TO_TEXT_WIN_NORMALIZER(   R	   (    (    s   modules/core.pyt   get_text_window_width  s    c         G   s   |  j    s d S|  j j   rJ |  j   rJ t j t d  |  j  d S|  j j   \ } } |  j j	 | |  |  j
 d t  d S(   s1   Cleans the Selected Text from All Formatting TagsNs   No Text is SelectedRh  (   RB  R   R  R	  R   R
  R   RU   R  t   remove_all_tagsR  R)   (   R	   R   R  R  (    (    s   modules/core.pyt   remove_text_formatting  s     c         G   s   |  j  d k r, t j t d  |  j  d St |  j |  j  d  } | |  j k r |  j j	 |  t j
 |   |  j d  n  d S(   s*   Add the Current Node to the Bookmarks Lists   No Node is SelectedNi   R  (   R   R   R   R
  R   RU   Ry   R   R   R  R  R  (   R	   R   t   curr_node_id_str(    (    s   modules/core.pyt   bookmark_curr_node'  s    c         G   s#   t  j |   r |  j d  n  d S(   s   Handle the Bookmarks ListR  N(   R   t   bookmarks_handleR  (   R	   R   (    (    s   modules/core.pyRF  2  s    c         G   sL   |  j  d k r, t j t d  |  j  d S|  j j t j	 |  j
   d S(   s   Insert Timestamps   No Node is SelectedN(   R   R   R   R
  R   RU   R   R4  Ra  t   strftimeR^  (   R	   R   (    (    s   modules/core.pyt   timestamp_insert7  s    c         C   sO   |  j  j |  } |  j  j |  | j |  |  j  j |  j  j   |  d S(   s3   Set the Selection from given offset to offset+deltaN(   R   R  R  t   forward_charsR  R  (   R	   t   offsett   deltat   target(    (    s   modules/core.pyR2  >  s    c         C   s!   |  j  j   d k r t St Sd S(   s%   Return True if the treestore is emptyN(   R   R  R   R)   Rf   (   R	   (    (    s   modules/core.pyRk  E  s     N(  R   R   R   R   R   R  R"  R#  R$  R%  R-  R<  R=  R>  R@  RA  R   R   Rk  R   R   R   R   R   R   R  R  R  R  R  R  R  R  R  R   R  R  R  R   R  R   R   R2  R/  R.  R4  R   RI  RE  RK  RM  RP  RQ  RT  RS  Rf   R|  RW  R   R  Rs  Rn  R6  R  Ro  R  R  Rl  R  R  R  Rb  R  R  R  R  R  R  R  R  R  R  R  R  R  R   R  RS  RT  RU  Rz  R  RV  R  R'  R)  R.  R1  R/  RY  R8  R9  R;  R=  R?  RB  RH  RL  RN  RP  RT  RU  RX  RY  R\  R]  R_  Rb  Rc  Rd  Ri  Rl  Rp  Rs  Rt  Ru  Rv  Rx  Rz  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  Rf  R  R  R   R  R  R  R  R  R  R  R	  RX  RH  RI  R  R!  R  R  R  R*  R  R6  R7  R8  R9  R:  R<  R;  R?  R  RA  RE  RI  RC  RR  RS  RT  RW  RB  R   Rd  Ra  Rl  Rj  RO  R  R  R  R  R  R  R  R}  R|  Rt  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   RA  RC  RE  RF  RH  R2  Rk  (    (    (    s   modules/core.pyR   6   s  								*	1	9	
	
	
		 												
	
			K			"			
																 					@				
	S		 	:	*			(																	"		
	
	
	
																																									
															%			%																				
	
																						
		8		
																																				w		"		2							8	U						
				(    (    (!   R   R   R   Rz   R  RR   R  R  R@  R  R  R   R  Ra  R9  R)   R8  Rf   R   R   RX   R7   R+   R  R<   RE   R1   R.   R?   R4   RB   R    R   (    (    (    s   modules/core.pyt   <module>   s   0x
 
