
ddc           @` s^  d  Z  d d l m Z m Z m Z m Z d d l Td d l Z e j d  d d l	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d	 l m Z d
 d l m Z d
 d l m Z d
 d l m Z d
 d l m Z d d d g Z d e	 j f d     YZ d e f d     YZ d e f d     YZ e
 j  e  e
 j  e  e
 j  e  d S(   uy   GTK text entries (fields) with enhanced features.

Enhanced features include undo/redo history and a customizable popup.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0i   (   t   fileformats(   t   path(   t   utilsi   (   t   cell_renderers(   t   entry_expander(   t   entry_popup(   t   entry_undo_contextu   ExtendedEntryu   FilenamePatternEntryu   FileExtensionEntryt   ExtendedEntryc           B` s   e  Z d  Z d   Z e d    Z e d  Z d   Z e d  Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   u  
  This class is a subclass of `gtk.Entry` with additional capabilities:
  
  * undo/redo of text,
  * placeholder text,
  * expandable width of the entry.
  
  Attributes:
  
  * `undo_context` (read-only) - `EntryUndoContext` instance to handle undo/redo
    actions.
  
  * `placeholder_text` (read-only) - Placeholder text displayed if the entry is
    empty or matches the placeholder text. If `None`, the entry has no
    placeholder text.
  c         O` s   | j  d d  |  _ | j  d d  |  _ | j  d d  |  _ t   j | |   t j |   |  _	 d |  _
 t j |  |  j |  j  |  _ t |  _ |  j d |  j  |  j d |  j  |  j d |  j  d S(	   u  
    Parameters:
    
    * `minimum_width_chars` - Minimum width specified as a number of characters.
      The entry will not shrink below this width.
    
    * `maximum_width_chars` - Maximum width specified as a number of characters.
      The entry will not expand above this width.
    
    * `placeholder_text` - Text to display as a placeholder if the entry is
      empty. If `None`, do not display any placeholder.
    u   minimum_width_charsiu   maximum_width_charsu   placeholder_textu   focus-in-eventu   focus-out-eventu   realizeN(   t   popt   _minimum_width_charst   _maximum_width_charst   Nonet   _placeholder_textt   supert   __init__t   entry_undo_context_t   EntryUndoContextt   _undo_contextt   _popupt   entry_expander_t   EntryExpandert	   _expandert   Falset   _has_placeholder_text_assignedt   connectt!   _on_extended_entry_focus_in_eventt"   _on_extended_entry_focus_out_eventt   connect_aftert    _on_after_extended_entry_realize(   t   selft   argst   kwargs(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   3   s    		c         C` s   |  j  S(   N(   R   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   undo_contextQ   s    c         C` sG   |  j    s |  j |  r9 |  j   |  j | |  n
 |  j   d S(   u  
    Replace the current contents of the entry with the specified text.
    
    If the entry does not have focus and the text is empty or matches the
    placeholder text, assign the placeholder text.
     
    If `enable_undo` is `True`, add the assignment to the undo history.
    N(   t	   has_focust   _should_assign_placeholder_textt   _unassign_placeholder_textt   _do_assign_textt   _assign_placeholder_text(   R"   t   textt   enable_undo(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   assign_textU   s    	
c         C` s   |  j  s t   j   Sd Sd S(   u   
    If the entry text does not match the placeholder text, return the entry
    text (i.e. what `gtk.Entry.get_text()` would return), otherwise return an
    empty string.
    t    N(   R   R   t   get_text(   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR/   d   s    	c         C` s   |  j  d k	 r t |  j  _ n  | s3 t |  j _ n  t | t  sT t j	 |  } n  |  j
 |  | sv t |  j _ n  |  j  d k	 r t |  j  _ n  d S(   u   
    Use this method to set text instead of `assign_text()` if it is not desired
    to handle placeholder text assignment.
    N(   R   R   R   t   trigger_popupR   t   undo_enabledt
   isinstancet   bytest   pgutilst   safe_encode_gtkt   set_textt   True(   R"   R+   R,   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR)   o   s    c         C` s   t  j |  j    S(   N(   R4   t   safe_decode_gtkR/   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   _get_text_decoded   s    c         C` sT   |  j  d  k	 rP t |  _ |  j   r= |  j t j t j	  n  |  j
 |  j   n  d  S(   N(   R   R   R7   R   t   get_realizedt!   _modify_font_for_placeholder_textt   gtkt   STATE_INSENSITIVEt   pangot   STYLE_ITALICR)   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR*      s
    	c         C` sI   |  j  rE t |  _  |  j t j t j  |  j d  |  j j	   n  d  S(   NR.   (
   R   R   R;   R<   t   STATE_NORMALR>   t   STYLE_NORMALR)   R   t   save_last_value(   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR(      s
    		c         C` sM   |  j  t j |  j j |  |  j   j   } | j |  |  j |  d  S(   N(	   t   modify_textR<   R@   t   stylet   fgt   get_pango_contextt   get_font_descriptiont	   set_stylet   modify_font(   R"   t   state_for_colorRD   t   font_description(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR;      s    c         C` s#   | p" |  j  d  k	 o" | |  j  k S(   N(   R   R   (   R"   R+   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR'      s    c         C` s   |  j    d  S(   N(   R(   (   R"   t   entryt   event(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR      s    c         C` s&   |  j  |  j    r" |  j   n  d  S(   N(   R'   R9   R*   (   R"   RL   RM   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR      s    c         C` s&   |  j  |  j    r" |  j   n  d  S(   N(   R'   R9   R*   (   R"   RL   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR!      s    (   t   __name__t
   __module__t   __doc__R   t   propertyR%   R   R-   R/   R)   R9   R*   R(   R;   R'   R   R   R!   (    (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   !   s   									t   FilenamePatternEntryc           B` s  e  Z d  Z d Z d Z \ Z Z Z Z e	 j
 e	 j
 e	 j
 e	 j
 g Z d   Z e d    Z d   Z d   Z d	   Z d
   Z d   Z d   Z d e d  Z d   Z d   Z e e d  Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ RS(   uh  
  This class is a subclass of `ExtendedEntry` used for the purpose of typing a
  pattern for filenames (e.g. for exported layers as separate images). A popup
  displaying the list of suggested items (components of the pattern) is
  displayed while typing.
  
  Additional attributes:
  
  * `popup` (read-only) - `EntryPopup` instance serving as the popup.
  i   i    i   i   c         O` s  | j  d d  |  _ d   | D |  _ g  | D] } | d ^ q/ } |  j d k	 r |  j | k r t d j |  j |    n  |  j d k	 r | | j |  j  d n d | d <t   j | |   d |  _	 d |  _
 t |  _ d |  _ t j |  j    |  _ t j |  |  j |  |  _ |  j |  j _ |  j |  j _ |  j |  j _ |  j |  j _ |  j |  j _ |  j  |  j _! |  j" |  j _# |  j$   |  j%   |  j& d |  j'  |  j& d	 |  j(  |  j& d
 |  j)  |  j& d |  j*  |  j& d |  j+  d S(   u  
    Parameters:
    
    * `suggested_items` - List of
      `(item name displayed in popup, text to insert in entry,
        regular expression matching item name, description)`
      tuples describing each item.
    
    * `default_item` - The second element of an item from the `suggested_items`
      that is displayed as placeholder text, or `None` for no default item. This
      argument replaces the `placeholder_text` parameter from `ExtendedEntry`.
    u   default_itemc         S` s!   i  |  ] } | d  | d  q S(   i   i   (    (   t   .0t   item(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pys
   <dictcomp>   s   	 i   u:   default item "{0}" not in the list of suggested items: {1}i    u   placeholder_textu    u   insert-textu   delete-textu   notify::cursor-positionu   changedu   focus-out-eventN(,   R   R   t   _default_item_valuet   _item_regexes_and_descriptionst
   ValueErrort   formatt   indexR   R   t   _cursor_positiont*   _cursor_position_before_assigning_from_rowR7   t0   _reset_cursor_position_before_assigning_from_rowt   _last_field_with_tooltipR>   t   LayoutRF   t   _pango_layoutt   entry_popup_t
   EntryPopupt   _COLUMN_TYPESR   t   _filter_suggested_itemst   filter_rows_funct   _on_assign_from_selected_rowt   on_assign_from_selected_rowt   _assign_last_valuet   on_assign_last_valuet   _on_row_left_mouse_button_presst   on_row_left_mouse_button_presst   _on_entry_changed_conditiont%   on_entry_changed_show_popup_conditiont   _on_entry_key_presst   on_entry_key_presst#   _on_entry_after_assign_by_key_presst"   on_entry_after_assign_by_key_presst   _create_field_tooltipt   _add_columnsR   t&   _on_filename_pattern_entry_insert_textt&   _on_filename_pattern_entry_delete_textt1   _on_filename_pattern_entry_notify_cursor_positiont"   _on_filename_pattern_entry_changedt*   _on_filename_pattern_entry_focus_out_event(   R"   t   suggested_itemsR#   R$   RT   t   suggested_item_values(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR      s>    3				

c         C` s   |  j  S(   N(   R   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   popup  s    c         C` s#   | p" |  j  d k	 o" | |  j  k S(   u   
    Unlike the parent method, use the value of the suggested item rather than
    its display name to determine whether placeholder text should be assigned.
    N(   RU   R   (   R"   R+   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR'     s    c         C` s   t  j d t  j  |  _ |  j j t  j j  |  j j t  |  j j	 d  t  j
   |  _ |  j j t  t  j d t  |  _ |  j j |  j d t d t t  j   |  _ |  j j t  j  |  j j |  j  |  j j   |  j j |  j  d  S(   Nt   typeu   gtk-tooltipst   homogeneoust   expandt   fill(   R<   t   Windowt   WINDOW_POPUPt   _field_tooltip_windowt   set_type_hintt   gdkt   WINDOW_TYPE_HINT_TOOLTIPt   set_resizableR   t   set_namet   Labelt   _field_tooltip_textt   set_selectableR7   t   HBoxt   _field_tooltip_hboxt
   pack_startt   Framet   _field_tooltip_framet   set_shadow_typet   SHADOW_ETCHED_INt   addt   show_all(   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRq     s    	c         C` s2   |  j  j j t j d  t j   d |  j  d  S(   NR+   (   R   t	   tree_viewt   append_columnR<   t   TreeViewColumnR   t   CellRendererTextt   _COLUMN_ITEM_NAMES(   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRr   %  s    c         C` s&   |  j    t t j |   |  _ d  S(   N(   t   get_positiont   lenR4   R8   RZ   (   R"   RL   t   new_textt   new_text_lengtht   position(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRs   )  s    c         C` s   | |  _  d  S(   N(   RZ   (   R"   RL   t   startt   end(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRt   -  s    c         C` s   |  j    |  _ t j j |  j   |  j  } | d  k rG |  j   d  St j j | |  j	  } | |  j	 k r| |  j   d  S| |  j
 k r | |  _
 t } n t } |  j |  j	 | |  d  S(   N(   R   RZ   t   pgpatht   StringPatternt   get_field_at_positionR9   R   t   _hide_field_tooltipt   get_first_matching_field_regexRV   R]   R7   R   t   _show_field_tooltip(   R"   RL   t   property_spect   fieldt   matching_field_regext   force_update_position(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRu   0  s"    	
	
		c         C` sY   |  j  j   s | rU | d  k r+ d } n  |  j j |  |  j  j   |  j   n  d  S(   Nu    (   R   t
   get_mappedR   R   t
   set_markupt   showt   _update_field_tooltip_position(   R"   t   tooltip_textR   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   J  s    	c         C` s#   |  j  j   r |  j  j   n  d  S(   N(   R   R   t   hide(   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   R  s    c         C` s   |  j  |  j d t d  S(   Nt   place_above(   t   _update_window_positionR   R7   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   V  s    c   	      C` s   |  j    j   } | r |  j   |  j  } |  j j t j |   t |  j j	   d |  j
   d t |  j   j | j   j d   } | d | } n
 | d } | s | d |  j   j } n | d | j   j } | j | |  d  S(   Ni    i   (   t
   get_windowt
   get_originR9   RZ   R_   R6   R4   R5   t   mint   get_pixel_sizet   get_layout_offsetst   maxt   get_allocationt   widtht   heightt   move(	   R"   t   windowt   move_with_text_cursorR   t   entry_absolute_positiont   text_up_to_cursor_positiont   x_offsett   xt   y(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   Y  s    (
c         C` s   |  j  r d  |  _ n  d  S(   N(   R\   R   R[   (   R"   RL   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRv   p  s    	c         C` s   |  j    d  S(   N(   R   (   R"   RL   RM   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRw   t  s    c         C` sz   | | |  j  } |  j   } |  j d k rr t |  |  j k rr | |  j d d k rr | rr | d d k rr t St Sd  S(   Ni    i   u   [(   t   _COLUMN_ITEMS_TO_INSERTR9   RZ   R   R   R7   (   R"   Rx   t   row_iterRT   t   current_text(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRc   w  s    $-c         C` s   |  j  d  k r |  j |  _  n  |  j  } t | | |  j  } t j |  j j  } | d k r t	 |  | k r | | d d k r | d } n  |  j
 t j | |  | | |   |  j | t	 |   |  j   |  _ | |  _  | | f S(   Ni    i   u   [(   R[   R   RZ   t   strR   R4   R8   R   t   last_assigned_entry_textR   R-   R5   t   set_positionR   (   R"   t
   tree_modelt   selected_tree_itert   cursor_positiont   suggested_itemR   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRe     s    		c         C` sZ   t  |  _ |  j |  t |  _ |  j d  k	 r= |  j |  _ n  |  j |  j  d  |  _ d  S(   N(   R   R\   R)   R7   R[   R   RZ   R   (   R"   t
   last_value(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRg     s    		c         C` s   |  j    } | r t |  d k r t |  |  j k r | |  j d d k o | |  j d d k o t j j | |  j d  S| d d k Sn t Sd  S(   Ni   u   [i   i    (   R9   R   RZ   R   R   R   R7   (   R"   R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRk     s    '	c         C` sS   d  |  _ |  j j   \ } } | d  k	 rO | rO |  j j d | | f g  n  d  S(   Nu   insert(   R   R[   R   t   assign_from_selected_rowR%   t	   undo_push(   R"   R   R+   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRi     s    	c         C` s&   | d k r" |  j    d  |  _ n  | S(   Nu   Returnu   KP_Enteru   Escape(   u   Returnu   KP_Enteru   Escape(   R   R   R[   (   R"   t   key_namet	   tree_patht   stop_event_propagation(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRm     s    
c         C` sm   g  } | r% | j  d | | f  n  | d  k	 rP | rP | j  d | | f  n  | ri |  j j |  n  d  S(   Nu   deleteu   insert(   t   appendR   R%   R   (   R"   t   previous_positiont   previous_textR   R+   t   undo_push_list(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRo     s    (   i    i   i   i   N(%   RN   RO   RP   t   _BUTTON_MOUSE_LEFTt   _COLUMNSR   R   t   _COLUMN_REGEX_TO_MATCHt   _COLUMN_ITEM_DESCRIPTIONSt   gobjectt   TYPE_STRINGRb   R   RQ   Rz   R'   Rq   Rr   Rs   Rt   Ru   R   R   R   R   R   R7   R   Rv   Rw   Rc   Re   Rg   Rk   Ri   Rm   Ro   (    (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRR      s2   
	;												
		
			t   FileExtensionEntryc           B` s>  e  Z d  Z d Z \ Z Z e j e j g Z	 d   Z
 e d    Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z e d  Z 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$ e% d    Z& d   Z' d   Z( RS(    u  
  This class is a subclass of `ExtendedEntry` used for the purpose of specifying
  a file extension.
  
  A popup displaying the list of available file formats in GIMP and the
  corresponding file extensions is displayed. If a row contains multiple file
  extensions, the user is able to select a particular file extension. By
  default, the first file extension in the row is used.
  
  Additional attributes:
  
  * `popup` (read-only) - `EntryPopup` instance serving as the popup.
  i    i   c         O` sJ  t    j | |   g  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 g  |  _
 t j |  |  j |  j t 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&   j" d |  j'  d  S(   Nu   motion-notify-eventu   realizeu   changed((   R   R   t   _tree_view_columns_rectsR   t   _cell_renderer_descriptiont   _cell_renderer_extensionst   _highlighted_extension_rowt   _highlighted_extension_indext   _highlighted_extensiont%   _extensions_separator_text_pixel_sizet   _extensions_text_pixel_rectsR`   Ra   Rb   t   _get_file_formatst   pgfileformatst   file_formatsR   t   _filter_file_formatsRd   Re   Rf   R)   Rh   Ri   Rj   t   _on_key_press_before_show_popupt$   on_entry_key_press_before_show_popupt   _on_tab_keys_pressedRn   Ro   Rp   Rr   R   R   t!   _on_tree_view_motion_notify_eventR    t   _on_after_tree_view_realizet   get_selectiont   _on_tree_selection_changed(   R"   R#   R$   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s0    								!
c         C` s   |  j  S(   N(   R   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRz     s    c         O` s$   t    j | |   |  j d  d  S(   Ni(   R   R)   R   (   R"   R#   R$   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR)     s    c         ` s`   d    f d  } t j     _ t j     _ |   j d   j  |   j d   j  d  S(   Nc         ` s3   t  j | |  i | | 6 }   j j j |  d  S(   N(   R<   R   R   R   R   (   t   cell_renderert   cell_renderer_propertyt   column_numbert   column_titlet   column(   R"   (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   _add_column  s    u   textu   markup-list(	   R   R<   R   R   t   cell_renderers_t   CellRendererTextListR   t   _COLUMN_DESCRIPTIONt   _COLUMN_EXTENSIONS(   R"   R   (    (   R"   sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRr     s
    c         C` s&   |  j  t | j  t | j   d  S(   N(   t   _highlight_extension_at_post   intR   R   (   R"   R   RM   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s    c         C` s   |  j  |  j j d  t j |  j j j     |  _ |  j	   g  |  j
 D]- } |  j j j d |  j j j |   ^ qJ |  _ d  S(   Nu   text-list-separatori    (   i    (   t   _get_text_pixel_sizeR   t   get_propertyR>   R^   R   R   RF   R   t!   _fill_extensions_text_pixel_rectsR   t   get_cell_areat
   get_columnR   (   R"   R   R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s    !
c         C` s  t  j |  j j j    } x|  j j D]v} | d } t |  d k r|  j | | |  j d  } x| D]
} | j	 |  j
 j d  7_	 | j	 |  j j j d  7_	 | j	 |  j j j |  j  j   7_	 | | d k r | j |  j d d 7_ qm | | d k rG| j	 |  j d d 8_	 | j |  j d d 7_ qm | j	 |  j d d 8_	 | j |  j d 7_ qm W|  j j |  q( |  j j g   q( Wd  S(   Ni   i    u   xpadu   horizontal-separatori   i(   R>   R^   R   R   RF   t   rowsR   t   _get_text_pixel_rectsR   R   R   R   t   style_get_propertyR   R   t   get_spacingR   R   R   (   R"   t   pango_layoutt   file_formatt   file_extensionst   text_pixel_rectst   rect(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   %  s(    
 c         C` s   |  j    d  S(   N(   t   _unhighlight_extension(   R"   t   tree_selection(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   C  s    c         C` s   |  j  |  j   | |  S(   N(   t   _entry_text_matches_rowR9   (   R"   R   R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   F  s    c         ` sO   | | |  j  } | r1 t   f d   | D  St   f d   | D  Sd  S(   Nc         3` s'   |  ] }   j    | j    k Vq d  S(   N(   t   lower(   RS   t	   extension(   t
   entry_text(    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pys	   <genexpr>N  s    c         3` s'   |  ] }   j    | j    k Vq d  S(   N(   R  (   RS   R  (   R  (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pys	   <genexpr>P  s    (   R   t   any(   R"   R  R   R   t
   full_matcht
   extensions(    (   R  sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR  I  s    c         C` sU   | | |  j  } | t |  k r6 t |  d } n  |  j | |  d | | f S(   Ni   i    (   R   R   R)   (   R"   R   R   t   extension_indexR  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRe   R  s
    c         C` st   d |  j    } } |  j d  k r: |  j j   \ } } n  |  j |  j  d |  j } } |  j | | | |  d  S(   Ni    (   R/   R   R   R   R   R)   R   t
   _undo_push(   R"   R   R   R   R+   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRi   [  s    c         C` s   |  j    d  S(   N(   R
  (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   f  s    c         C` s   | d k r |  j  j j   j   \ } } | d  k	 r | d k rR |  j |  n | d k rn |  j |  n  d |  j   } } |  j |  j	  |  j
 | | d |  j	  t Sn  | S(   Nu   Tabu   KP_Tabu   ISO_Left_Tabi    (   u   Tabu   KP_Tabu   ISO_Left_Tab(   u   Tabu   KP_Tab(   R   R   R   t   get_selectedR   t   _highlight_extension_nextt   _highlight_extension_previousR/   R)   R   Ro   R7   (   R"   R   t   selected_tree_pathR   t   unused_t	   tree_iterR   R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR   i  s    c         C` s   |  j  | | | |  d  S(   N(   R  (   R"   R   R   R   R+   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyRo     s    c         C` sm   g  } | r% | j  d | | f  n  | d  k	 rP | rP | j  d | | f  n  | ri |  j j |  n  d  S(   Nu   deleteu   insert(   R   R   R%   R   (   R"   R   R   R   R+   R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR    s    c         C` s   d   } |  j  | |  d  S(   Nc         S` s   |  d | S(   Ni   (    (   t   highlighted_extension_indext   len_extensions(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   _select_next_extension  s    (   t   _highlight_extension(   R"   t   selected_row_pathR  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR    s    	c         C` s   d   } |  j  | |  d  S(   Nc         S` s   |  d | S(   Ni   (    (   R  R  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   _select_previous_extension  s    (   R  (   R"   R  R   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR    s    	c         C` s   | d  k	 r |  j   |  j j j |  } | d |  _ |  j j | |  j } t |  d k r | ss d |  _	 n" t |  d k r | d |  _	 n  d  S|  j
 d  k r d |  _
 n  | |  j
 t |   |  _
 |  j   |  j j |  n  d  S(   Ni    i   u    (   R   t   _unhighlight_extension_properR   t   rows_filteredt   convert_path_to_child_pathR   R  R   R   R   R   t   _highlight_extension_propert   refresh_row(   R"   R  t   extension_index_selection_funct   row_pathR  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR    s"    

c         C` s   | |  j  |  j j k } | s? |  j d  k	 r; |  j   n  d  S|  j j j | |  } | d  k rg d  S|  j j	 j
 | d  } |  j | d | d  } | |  j k r d  S| d  k	 r |  j | d |  n
 |  j   d  S(   Ni    i   (   R   R   R   R   R   R
  R   R   t   get_path_at_posR"  R#  t   _get_extension_index_at_posR   t   _highlight_extension_at_index(   R"   R   R   t   is_in_extensions_columnt   path_paramst   selected_path_unfilteredR  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s    c         C` s   |  j  | } | s d  Sd } xE | D]= } | j | k oN | j | j k n rW Pn  | d 7} q$ W| t |  k  } | r | Sd  Sd  S(   Ni    i   (   R   R   R   R   R   (   R"   t   cell_xt   selected_rowt   extension_rectsR  t   extension_rectt   matches_extension(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR)    s    )c         C` sb   | d  k	 r^ |  j   |  j j j |  } | d |  _ | |  _ |  j   |  j j |  n  d  S(   Ni    (	   R   R!  R   R"  R#  R   R   R$  R%  (   R"   R  R  R'  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR*    s    
	
c         C` s   |  j  j |  j |  j } | |  j |  _ |  j  j j j t	 j
 } |  j  j j j t	 j
 } d j | j   | j   | |  j  | |  j <d  S(   Nu2   <span background="{0}" foreground="{1}">{2}</span>(   R   R  R   R   R   R   R   RD   t   bgR<   t   STATE_SELECTEDRE   RX   t	   to_string(   R"   R  t   bg_colort   fg_color(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR$    s    		c         C` sN   |  j    |  j d  k	 r8 |  j j |  j f d t n  d  |  _ d  |  _ d  S(   Nt   is_path_filtered(   R!  R   R   R   R%  R   R   (   R"   (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR
    s
    
	c         C` sj   |  j  d  k	 rf |  j d  k	 rf |  j j |  j  |  j } |  j d  k	 rf |  j | |  j <d  |  _ qf n  d  S(   N(   R   R   R   R   R  R   R   (   R"   R  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR!    s    c         C` s/   g  |  D]$ } | j    r | j | j g ^ q S(   N(   t   is_installedt   descriptionR  (   R   R  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s    c         C` s   | j  |  | j   S(   N(   R6   R   (   R"   R+   R  (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s    c         C` sd   g  } d } xQ | D]I } |  j  | |  } | j t j j | d |   | | d | 7} q W| S(   Ni    (   R   R   R<   R   t	   Rectangle(   R"   R  R  t   separator_pixel_widthR  t   extension_xR  t   extension_pixel_size(    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR    s    (   i    i   ()   RN   RO   RP   R   R   R   R   R   t   TYPE_PYOBJECTRb   R   RQ   Rz   R)   Rr   R   R   R   R   R   R   R  Re   Ri   R   R   Ro   R  R  R  R  R   R)  R*  R$  R
  R!  t   staticmethodR   R   R  (    (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyR     s>   	#																									(!   RP   t
   __future__R    R   R   R   t   future.builtinst   pygtkt   requireR<   R   R>   R.   R   R   R   R   R   R4   R   R   R	   R   R
   R`   R   R   t   __all__t   EntryR   RR   R   t   type_register(    (    (    sM   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/entries.pyt   <module>   s2   "
	  [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 # -*- coding: utf-8 -*-

"""Class modifying `gtk.Entry` instances to expand/shrink in width dynamically.
"""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import pango

__all__ = [
  'EntryExpander',
]


class EntryExpander(object):
  """
  This class enables the specified `gtk.Entry` to have a flexible width, bounded
  by the specified minimum and maximum number of characters (width in
  characters).
  """
  
  def __init__(self, entry, minimum_width_chars, maximum_width_chars):
    self._entry = entry
    self._minimum_width_chars = minimum_width_chars
    self._maximum_width_chars = maximum_width_chars
    
    if self._minimum_width_chars > self._maximum_width_chars:
      raise ValueError(
        'minimum width in characters ({0}) cannot be greater than maximum ({1})'.format(
          self._minimum_width_chars, self._maximum_width_chars))
    
    self._minimum_width = -1
    self._maximum_width = -1
    self._entry.set_width_chars(self._minimum_width_chars)
    
    self._pango_layout = pango.Layout(self._entry.get_pango_context())
    
    self._entry.connect('changed', self._on_entry_changed)
    self._entry.connect('size-allocate', self._on_entry_size_allocate)
  
  def _on_entry_changed(self, entry):
    if self._entry.get_realized():
      self._update_entry_width()
  
  def _on_entry_size_allocate(self, entry, allocation):
    if self._minimum_width == -1:
      self._minimum_width = self._entry.get_allocation().width
      self._maximum_width = (
        int((self._minimum_width / self._minimum_width_chars)
            * self._maximum_width_chars)
        + 1)
    
    self._update_entry_width()
  
  def _update_entry_width(self):
    self._pango_layout.set_text(self._entry.get_text())
    
    offset_pixel_width = (
      (self._entry.get_layout_offsets()[0] + self._entry.get_property('scroll-offset'))
      * 2)
    text_pixel_width = self._pango_layout.get_pixel_size()[0] + offset_pixel_width
    self._entry.set_property(
      'width-request',
      max(min(text_pixel_width, self._maximum_width), self._minimum_width))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 