ó
)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 i e j	 d 6e j
 d 6e j d 6e j d 6e j d 6Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿNi   i   i   i   i   c         C   sV  t  j j t j ƒ r‚t t j d ƒ } | j ƒ  } | j ƒ  t j	 j
 j | ƒ } | j } | j d k rs d GHd S| j d ƒ r˜ | j d j d k n t |  _ |  j rº |  j j ƒ  nÐ | j d ƒ r"| j d ƒ r"t | j d j ƒ t | j d j ƒ g } |  j j | d	 | d
 ƒ n  | j d ƒ rŠ| j d ƒ rŠt | j d j ƒ t | j d j ƒ g } |  j j | d	 | d
 ƒ n  | j d ƒ rµ| j d j d k rµt n t |  _ | j d ƒ rÝ| j d j n d |  _ | j d ƒ r| j d j n d |  _ | j d ƒ r˜| j d j } | j ƒ  } g  | D] }	 t |	 ƒ ^ q@}
 t |
 ƒ |  _ | j d ƒ rŒt | j d j ƒ n d	 |  _ n	 d |  _ | j d ƒ rÆt | j d j ƒ n d |  _! | j d ƒ rî| j d j n t j" |  _# | j d ƒ r| j d j n t j$ |  _% | j d ƒ rD| j d j n d |  _& | j d ƒ rl| j d j n d |  _' | j d ƒ r”| j d j n d |  _( | j d ƒ rÂ| j d j d k n t |  _) | j d ƒ rð| j d j d k n t |  _* | j d  ƒ rt | j d  j ƒ n d! |  _+ | j d" ƒ rL| j d" j d k n t |  _, | j d# ƒ rz| j d# j d k n t |  _- | j d$ ƒ r¨| j d$ j d k n t |  _. | j d% ƒ r| j d& ƒ r| j d% j d k t | j d& j ƒ g |  _/ n t d' g |  _/ | j d( ƒ r5| j d( j d k n t |  _0 | j d) ƒ r]| j d) j n d |  _1 | j d* ƒ r…| j d* j n d |  _2 | j d+ ƒ r­| j d+ j n d, |  _3 | j d- ƒ rÛ| j d- j d k n t |  _4 | j d. ƒ r	t | j d. j ƒ n d/ |  _5 | j d0 ƒ r7t | j d0 j ƒ n d/ |  _6 | j d1 ƒ r†t | j d1 j ƒ |  _7 |  j7 t8 k rd
 |  _7 qn	 d
 |  _7 | j d2 ƒ r®| j d2 j n d3 |  _9 | j d4 ƒ rÜt | j d4 j ƒ n d5 |  _: | j d6 ƒ r
t | j d6 j ƒ n d7 |  _; | j d8 ƒ r8t | j d8 j ƒ n d9 |  _< | j d: ƒ rft | j d: j ƒ n d; |  _= | j d< ƒ r”| j d< j d k n t |  _> | j d= ƒ rò| j d= j } | d!  d k rÜt | d! g n t | d' g |  _? n t d> g |  _? | j d? ƒ rV| j d? j } | d!  d k r@t | d! g n t | d' g |  _@ n t d@ g |  _@ | j dA ƒ rº| j dA j } | d!  d k r¤t | d! g n t | d' g |  _A n t d@ g |  _A | j dB ƒ rè| j dB j n dC |  _B | j dD ƒ r&	|  jC jD jE t | j dD j ƒ ƒ n |  jC jD jE dE ƒ | j dF ƒ rn	|  jC jF jE t | j dF j ƒ ƒ n |  jC jF jE dG ƒ | j dH ƒ rÙ	|  jC jG jH | j dH j d k ƒ |  jC jI jH | j dH j d k ƒ n  | j dI ƒ rþ	| j dI j d k n t |  _J | j dJ ƒ r,
| j dJ j d k n t |  _K | j dK ƒ rZ
| j dK j d k n t |  _L | j dL ƒ rˆ
| j dL j d k n t |  _M | j dM ƒ r¶
| j dM j d k n t |  _N | j dN ƒ rä
| j dN j d k n t |  _O | j dO ƒ r| j dO j n dP |  _P g  |  _Q | j dQ ƒ rR| j dQ j j t jR ƒ } x3 | D]( }	 |	 rP|  jQ jS tT jU |	 ƒ ƒ qPqPWqRnÐd |  _ d |  _ d |  _ t j" |  _# t j$ |  _% d |  _' d |  _& d |  _( t |  _) t |  _* d! |  _+ t |  _, t |  _- t |  _. t d' g |  _/ t |  _ t |  _0 d |  _1 d |  _2 d, |  _3 d
 |  _7 d/ |  _5 d/ |  _6 d3 |  _9 d5 |  _: d7 |  _; d9 |  _< d; |  _= t |  _> t d> g |  _? t d@ g |  _@ t d@ g |  _A dC |  _B |  jC jD jE dE ƒ |  jC jF jE dG ƒ t |  _J t |  _K t |  _L t |  _M t |  _N t |  _O d |  _! t |  _4 dP |  _P g  |  _Q t |  _ d S(R   s%   Load the Preferences from Config Filet   rt   configs   invalid config file!Nt   win_is_maximizedt   Truet
   win_size_wt
   win_size_hi    i   t   win_position_xt   win_position_yt   toolbar_visiblet   Falset   file_dirt    t	   file_namet	   node_patht   cursor_positiont
   hpaned_posiª   t   syntax_highlightingt   style_schemet	   text_fonts   Sans 9t	   tree_fonts   Sans 8t	   code_fonts   Monospace 9t   show_line_numberst   spaces_instead_tabst
   tabs_widthi   t   line_wrappingt   auto_indentt   systrayt   autosavet   autosave_vali   t   expand_treet   expanded_collapsed_stringt   pick_dirt	   link_typet   webst   show_node_name_labelt
   table_rowsi   t   table_columnst   toolbar_icon_sizet   table_column_modet   renamet   table_col_mini(   t   table_col_maxi<   t   limit_undoable_stepsi   t   cherry_wrap_widthi‚   t   start_on_systrayt   weblink_custom_actions
   firefox %st   filelink_custom_actions   xdg-open %st   folderlink_custom_actiont   timestamp_formats   %Y/%m/%d - %H:%Mt   codebox_widthi¼  t   codebox_heightid   t   codebox_width_pixelst   check_versiont   backup_copyt   autosave_on_quitt   tree_right_sidet   show_white_spacest   highl_curr_linet   nodes_iconst   ct   recent_docs(V   t   ost   patht   isfilet   const   CONFIG_PATHt   filet   readt   closet   xmlt   domt   minidomt   parseStringt
   firstChildt   nodeNamet   hasAttributet
   attributest   valueR	   R   t   windowt   maximizet   intt   resizet   moveR   R   R
   R   t   splitt   tupleR   R   t   NoneR   t   CUSTOM_COLORS_IDR   t   STYLE_SCHEME_DEFAULTR   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R"   R#   R$   R%   t
   ICONS_SIZER&   R(   R)   R*   R+   R,   R-   R.   R/   R0   t   gladet   spinbutton_codebox_widtht	   set_valuet   spinbutton_codebox_heightt   radiobutton_codebox_pixelst
   set_activet   radiobutton_codebox_percentR4   R5   R6   R7   R8   R9   R:   R<   t
   CHAR_SPACEt   appendt   base64t	   b64decode(   t   instt   config_file_descriptort
   config_strRF   t   dom_itert   win_sizet   win_positiont   str_path_list_of_strt   path_list_of_strt   elementt   path_list_of_intt   temp_strt   temp_recent_docs(    (    s   modules/config.pyt   config_file_load   s"   
	.	 4((1	.++(((.......(((... 	(.....666(&&#&......(	 &																																					c         C   s  |  j  r t |  _  t } n t } |  j j d |  j ƒ |  j j d |  j ƒ |  j ƒ  |  j	 j
 j |  j ƒ |  j	 j j |  j ƒ |  j	 j j |  j ƒ |  j j |  j ƒ |  j	 j j |  j ƒ |  j j |  j ƒ |  j	 j j |  j ƒ |  j j |  j ƒ |  j	 j j |  j ƒ |  j r3|  j j t j  ƒ n |  j j t j! ƒ |  j	 j" j |  j ƒ |  j j# |  j$ ƒ |  j	 j% j |  j$ ƒ |  j	 j& j |  j' ƒ |  j	 j( j |  j) d ƒ |  j	 j( j* |  j) d ƒ |  j	 j+ j |  j) d ƒ |  j	 j, j |  j- ƒ |  j	 j. j |  j/ ƒ |  j	 j0 j |  j1 ƒ |  j	 j2 j |  j3 ƒ |  j	 j4 j |  j5 ƒ |  j	 j6 j |  j7 ƒ |  j	 j8 j |  j9 ƒ |  j	 j: j |  j; ƒ |  j	 j: j* |  j' ƒ |  j	 j< j |  j= d ƒ |  j	 j> j* |  j= d ƒ |  j	 j> j? |  j= d ƒ |  j	 j@ j |  jA d ƒ |  j	 jB j* |  jA d ƒ |  j	 jB j? |  jA d ƒ |  j	 jC j |  jD d ƒ |  j	 jE j* |  jD d ƒ |  j	 jE j? |  jD d ƒ |  j	 jF j? |  jG ƒ |  j	 jH j |  jI d k ƒ |  j	 jJ j |  jI d k ƒ |  j	 jK j |  jI d k ƒ |  j	 jL j |  jM d k ƒ |  j	 jN j |  jM d	 k ƒ |  j	 jO j |  jM d
 k ƒ |  j	 jP j |  jM d k ƒ |  j	 jQ j |  jM d k ƒ |  j	 jR j |  jS d k ƒ |  j	 jT j |  jS d k ƒ |  j	 jU j |  jS d k ƒ |  j	 jV j |  jW ƒ |  j	 jX j |  jY ƒ |  j	 jZ j |  j[ ƒ |  j	 j\ j |  j] ƒ |  j	 j^ j |  j_ ƒ |  j	 j` j |  ja ƒ |  jb j d |  ja ƒ |  jc jd d ƒ j d |  je ƒ |  jc jd d ƒ jf t jg ƒ |  jc jd d ƒ j d th |  ji ƒ |  j) d rõ|  jj ƒ  n  | rt |  _  n  d S(   s&   Apply the Preferences from Config Filet   positiont   visiblei   i    R!   t   nodeRB   R'   t   deletet   addt   leftt   rightR;   t   bt   ns
   wrap-widths   /ToolBars	   icon-sizeN(k   t   user_activeR	   R   t   hpanedt   set_propertyR   t   header_node_name_labelR"   t   set_treeview_fontRY   t   fontbutton_treet   set_font_nameR   t   fontbutton_textR   t   fontbutton_codeR   t
   sourceviewt   set_show_line_numbersR   t   checkbutton_line_numsR^   t!   set_insert_spaces_instead_of_tabsR   t   checkbutton_spaces_tabst   set_tab_widthR   t   spinbutton_tab_widthR[   R   t   set_wrap_modet   gtkt	   WRAP_WORDt	   WRAP_NONEt   checkbutton_line_wrapt   set_auto_indentR   t   checkbutton_auto_indentt   checkbutton_systrayR   t   spinbutton_autosaveR   t   set_sensitivet   checkbutton_autosavet   checkbutton_expand_treeR   t   checkbutton_newer_versionR4   t    checkbutton_backup_before_savingR5   t   checkbutton_autosave_on_quitR6   t   checkbutton_tree_right_sideR7   t   checkbutton_show_white_spacesR8   t"   checkbutton_highlight_current_lineR9   t   checkbutton_start_on_systrayR,   t   checkbutton_custom_weblink_cmdR-   t   entry_custom_weblink_cmdt   set_textt   checkbutton_custom_filelink_cmdR.   t   entry_custom_filelink_cmdt!   checkbutton_custom_folderlink_cmdR/   t   entry_custom_folderlink_cmdt   entry_timestamp_formatR0   t   radiobutton_link_websiteR    t   radiobutton_link_node_anchort   radiobutton_link_filet   table_column_rename_radiobuttonR&   t   table_column_delete_radiobuttont   table_column_add_radiobuttont   table_column_left_radiobuttont   table_column_right_radiobuttont   radiobutton_node_icon_cherryR:   t   radiobutton_node_icon_bullett   radiobutton_node_icon_nonet   spinbutton_table_rowsR#   t   spinbutton_table_columnsR$   t   spinbutton_table_col_minR(   t   spinbutton_table_col_maxR)   t   spinbutton_limit_undoable_stepsR*   t!   spinbutton_tree_nodes_names_widthR+   t   renderer_textt   uit
   get_widgetR   t	   set_stylet   TOOLBAR_ICONSRX   R%   t   autosave_timer_start(   Rd   t   user_active_restore(    (    s   modules/config.pyt   config_file_apply²   sŒ    			
	 #  c         C   s©  t  j j j ƒ  } | j d ƒ } | j d t |  j j d ƒ j	 d ƒ ƒ ƒ | j d |  j
 ƒ | j d |  j ƒ | j d t |  j ƒ ƒ |  j s|  j j ƒ  } |  j j ƒ  } | j d t | d	 ƒ ƒ | j d
 t | d ƒ ƒ | j d t | d	 ƒ ƒ | j d t | d ƒ ƒ n  | j d t |  j j	 d ƒ ƒ ƒ |  j d@ k rÅg  } x0 |  j j |  j ƒ D] } | j t | ƒ ƒ qjW| j d d j | ƒ ƒ | j d t |  j j	 d ƒ ƒ ƒ n  | j d |  j ƒ | j d |  j ƒ | j d |  j ƒ | j d |  j ƒ | j d |  j ƒ | j d t |  j ƒ ƒ | j d t |  j ƒ ƒ | j d t |  j ƒ ƒ | j d t |  j  ƒ ƒ | j d t |  j! ƒ ƒ | j d t |  j" ƒ ƒ | j d t |  j# d	 ƒ ƒ | j d  t |  j# d ƒ ƒ | j d! |  j$ ƒ | j d" |  j% ƒ | j d# t |  j& j	 d ƒ ƒ ƒ | j d$ t |  j' ƒ ƒ | j d% t |  j( ƒ ƒ | j d& t |  j) ƒ ƒ | j d' |  j* ƒ | j d( t |  j+ ƒ ƒ | j d) t |  j, ƒ ƒ | j d* t |  j- ƒ ƒ | j d+ t |  j. ƒ ƒ | j d, t |  j/ ƒ ƒ | j d- t |  j0 d	 ƒ |  j0 d ƒ | j d. t |  j1 d	 ƒ |  j1 d ƒ | j d/ t |  j2 d	 ƒ |  j2 d ƒ | j d0 |  j3 ƒ | j d1 t |  j4 ƒ ƒ |  j4 sät5 |  ƒ | j d2 |  j6 ƒ n  | j d3 t t7 |  j8 j9 j: ƒ  ƒ ƒ ƒ | j d4 t t7 |  j8 j; j: ƒ  ƒ ƒ ƒ | j d5 t |  j8 j< j= ƒ  ƒ ƒ | j d6 t |  j> ƒ ƒ | j d7 t |  j? ƒ ƒ | j d8 t |  j@ ƒ ƒ | j d9 t |  jA ƒ ƒ | j d: t |  jB ƒ ƒ | j d; t |  jC ƒ ƒ | j d< |  jD ƒ |  jE rMg  } x' |  jE D] } | j tF jG | ƒ ƒ qWtH jI j | ƒ } n d= } | j d> | ƒ | jJ | ƒ | jK ƒ  }	 tL tH jM d? ƒ }
 |
 jN |	 ƒ |
 jO ƒ  d@ S(A   s#   Save the Preferences to Config FileR   R   s   /ToolBarRr   R
   R   R   R   i    R   i   R   R   R   Rq   R   t    R   s   cursor-positionR   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/   R0   R   R   R1   R2   R3   R4   R5   R6   R7   R8   R9   R:   R   R<   t   wN(P   RE   RF   RG   t   Documentt   createElementt   setAttributet   strR·   R¸   t   get_propertyR
   R   R   RN   t   get_positiont   get_sizeR{   t   curr_tree_iterRU   t	   treestoret   get_pathRa   t   joint   curr_bufferR   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/   R0   R   t"   get_tree_expanded_collapsed_stringR   RP   RY   RZ   t	   get_valueR\   R]   t
   get_activeR4   R5   R6   R7   R8   R9   R:   R<   Rb   t	   b64encodeR@   R`   t   appendChildt   toxmlRB   RA   t   writeRD   (   Rd   RF   R   Ri   Rh   Rk   Rl   Ro   t   str_recent_docst   string_textRe   (    (    s   modules/config.pyt   config_file_saveü   s–    +	"%"(((	
(("	c         C   s|   d } |  j  j ƒ  } x5 | d k rL | t | |  ƒ 7} |  j  j | ƒ } q Wt | ƒ d k ro | d |  _ n	 d |  _ d S(   sG   Returns a String Containing the Info about Expanded and Collapsed NodesR   i    i   N(   RÈ   t   get_iter_firstRU   t'   get_tree_expanded_collapsed_string_itert	   iter_nextt   lenR   (   Rd   R   t	   tree_iter(    (    s   modules/config.pyRÌ   J  s     c         C   s   d | j  |  d | j j | j  j |  ƒ ƒ f } | j  j |  ƒ }  x5 |  d k r| | t |  | ƒ 7} | j  j |  ƒ }  qH W| S(   s3   Iter of the Info about Expanded and Collapsed Nodess   _%s,%si   N(   RÈ   t   treeviewt   row_expandedRÉ   t   iter_childrenRU   R×   RØ   (   RÚ   Rd   R   (    (    s   modules/config.pyR×   T  s    "c         C   s²   |  j  j ƒ  |  j d k r  d Si  } |  j j d ƒ } x/ | D]' } | j d ƒ } | d | | d <q? W|  j j ƒ  } x2 | d k r­ t | | |  ƒ |  j j | ƒ } q| Wd S(   sH   Parses the String Containing the Info about Expanded and Collapsed NodesR   Nt   _t   ,i   i    (	   RÛ   t   collapse_allR   RS   RÈ   RÖ   RU   t'   set_tree_expanded_collapsed_string_iterRØ   (   Rd   t   expanded_collapsed_dictt   expanded_collapsed_vectorRl   t   coupleRÚ   (    (    s   modules/config.pyt"   set_tree_expanded_collapsed_string^  s     c         C   s£   t  | j |  d ƒ } | | k rX | | d k rX | j j | j j |  ƒ d t ƒn  | j j |  ƒ }  x2 |  d k rž t |  | | ƒ | j j	 |  ƒ }  qm Wd S(   s0   Iter of the Expanded and Collapsed Nodes Parsingi   R   t   open_allN(
   RÃ   RÈ   RÛ   t
   expand_rowRÉ   R	   RÝ   RU   Rá   RØ   (   RÚ   Râ   Rd   t   node_id(    (    s   modules/config.pyRá   l  s    %(   R=   t   syst   xml.dom.minidomRE   R‹   t   pangot
   subprocessRb   R@   t   ICON_SIZE_MENUt   ICON_SIZE_SMALL_TOOLBARt   ICON_SIZE_LARGE_TOOLBARt   ICON_SIZE_DNDt   ICON_SIZE_DIALOGRX   Rp   R½   RÕ   RÌ   R×   Rå   Rá   (    (    (    s   modules/config.pyt   <module>   s   T!	•	J	N	
	
	