ó
dòôdc           @` sô  d  Z  d d l m Z m Z m Z m Z d d l Td d l Z d d l Z d 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 e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ  d! e f d" „  ƒ  YZ! d# e f d$ „  ƒ  YZ" d% e f d& „  ƒ  YZ# d' e f d( „  ƒ  YZ$ d) e f d* „  ƒ  YZ% d+ e f d, „  ƒ  YZ& d- e f d. „  ƒ  YZ' d/ e f d0 „  ƒ  YZ( d1 e f d2 „  ƒ  YZ) d3 e) f d4 „  ƒ  YZ* d5 e f d6 „  ƒ  YZ+ d7 e f d8 „  ƒ  YZ, d9 e f d: „  ƒ  YZ- d; e f d< „  ƒ  YZ. d= e f d> „  ƒ  YZ/ d? e f d@ „  ƒ  YZ0 dA e f dB „  ƒ  YZ1 dC e f dD „  ƒ  YZ2 dE e f dF „  ƒ  YZ3 dG e f dH „  ƒ  YZ4 dI e f dJ „  ƒ  YZ5 d dK „ Z6 dL „  Z7 dM g Z8 xU e j9 e j: e; e j< ƒ D]7 \ Z= Z> e? e> e ƒ rµe> e k	 rµe8 j@ e= ƒ qµqµWd S(N   u>   `setting.presenter.Presenter` subclasses for GTK GUI elements.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0i   (   t   gui(   t   utilsi   (   t	   presentert   GtkPresenterc           B` sS   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   u3   Abstract `Presenter` subclass for GTK GUI elements.c         O` s#   d  |  _ t j j |  | | Ž d  S(   N(   t   Nonet   _event_handler_idt
   presenter_t	   Presentert   __init__(   t   selft   argst   kwargs(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR      s    	c         C` s   |  j  j ƒ  S(   N(   t   _elementt   get_sensitive(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   "   s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_sensitive(   R   t	   sensitive(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   %   s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_visible(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   (   s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_visible(   R   t   visible(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   +   s    c         C` s"   |  j  j |  j |  j ƒ |  _ d  S(   N(   R   t   connectt   _VALUE_CHANGED_SIGNALt   _on_value_changedR
   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _connect_value_changed_event.   s    	c         C` s    |  j  j |  j ƒ d  |  _ d  S(   N(   R   t
   disconnectR
   R	   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _disconnect_value_changed_event2   s    (   t   __name__t
   __module__t   __doc__t   Truet	   _ABSTRACTR   R   R   R   R   R   R   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR      s   						t   IntSpinButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   ud   `Presenter` subclass for `gtk.SpinButton` elements.
  
  Value: Integer value of the spin button.
  u   value-changedc         C` s
   t  | ƒ S(   N(   t   _create_spin_button(   R   t   setting(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _create_gui_element?   s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_value_as_int(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt
   _get_valueB   s    c         C` s   |  j  j | ƒ d  S(   N(   R   t	   set_value(   R   t   value(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt
   _set_valueE   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR#   7   s
   		t   FloatSpinButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uk   `Presenter` subclass for `gtk.SpinButton` elements.
  
  Value: Floating point value of the spin button.
  u   value-changedc         C` s   t  | d d ƒS(   Nt   digitsi   (   R$   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   Q   s    c         C` s   |  j  j ƒ  S(   N(   R   t	   get_value(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   T   s    c         C` s   |  j  j | ƒ d  S(   N(   R   R)   (   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   W   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR,   I   s
   		t   CheckButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uz   `Presenter` subclass for `gtk.CheckButton` elements.
  
  Value: Checked state of the check button (checked/unchecked).
  u   clickedc         C` s   t  j | j d t ƒS(   Nt   use_underline(   t   gtkt   CheckButtont   display_namet   False(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   c   s    c         C` s   |  j  j ƒ  S(   N(   R   t
   get_active(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   f   s    c         C` s   |  j  j | ƒ d  S(   N(   R   t
   set_active(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   i   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR/   [   s
   		t   CheckButtonNoTextPresenterc           B` s   e  Z d  Z d „  Z RS(   už   `Presenter` subclass for `gtk.CheckButton` elements without text next to
  the checkbox.
  
  Value: Checked state of the check button (checked/unchecked).
  c         C` s   t  j d  d t ƒS(   NR0   (   R1   R2   R	   R4   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   t   s    (   R   R   R    R&   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR7   m   s   t   CheckButtonLabelPresenterc           B` s    e  Z d  Z d „  Z d „  Z RS(   u^   `Presenter` subclass for `gtk.CheckButton` elements.
  
  Value: Label of the check button.
  c         C` s   t  j |  j j ƒ  ƒ S(   N(   t   pgutilst   safe_decode_gtkR   t	   get_label(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ~   s    c         C` s   |  j  j t j | ƒ ƒ d  S(   N(   R   t	   set_labelR9   t   safe_encode_gtk(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+      s    (   R   R   R    R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR8   x   s   	t   CheckMenuItemPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uy   `Presenter` subclass for `gtk.CheckMenuItem` elements.
  
  Value: Checked state of the menu item (checked/unchecked).
  u   toggledc         C` s   t  j | j ƒ S(   N(   R1   t   CheckMenuItemR3   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&      s    c         C` s   |  j  j ƒ  S(   N(   R   R5   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(      s    c         C` s   |  j  j | ƒ d  S(   N(   R   R6   (   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   “   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR>   …   s
   		t   ExpanderPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uz   `Presenter` subclass for `gtk.Expander` elements.
  
  Value: `True` if the expander is expanded, `False` if collapsed.
  u   notify::expandedc         C` s&   t  j d | j ƒ } | j t ƒ | S(   Nt   label(   R1   t   ExpanderR3   t   set_use_underlineR!   (   R   R%   t   expander(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   Ÿ   s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_expanded(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ¤   s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_expanded(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   §   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR@   —   s
   		t   ComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uf   `Presenter` subclass for `gimpui.IntComboBox` elements.
  
  Value: Item selected in the combo box.
  u   changedc         C` sY   | j  ƒ  } x7 t d t | ƒ d ƒ D] } t j | | ƒ | | <q% Wt j t | ƒ ƒ S(   Ni    i   (   t!   get_item_display_names_and_valuest   ranget   lenR9   R=   t   gimpuit   IntComboBoxt   tuple(   R   R%   t   labels_and_valuest   i(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ³   s    c         C` s   |  j  j ƒ  S(   N(   R   R5   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   »   s    c         C` s   |  j  j | ƒ d  S(   N(   R   R6   (   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   ¾   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRG   «   s
   		t   EntryPresenterc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   uP   `Presenter` subclass for `gtk.Entry` elements.
  
  Value: Text in the entry.
  c         C` s
   t  j ƒ  S(   N(   R1   t   Entry(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   È   s    c         C` s   t  j |  j j ƒ  ƒ S(   N(   R9   R:   R   t   get_text(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   Ë   s    c         C` s-   |  j  j t j | ƒ ƒ |  j  j d ƒ d  S(   Niÿÿÿÿ(   R   t   set_textR9   R=   t   set_position(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   Î   s    (   R   R   R    R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRP   Â   s   		t   ImageComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   up   `Presenter` subclass for `gimpui.ImageComboBox` elements.
  
  Value: `gimp.Image` selected in the combo box.
  u   changedc         C` s
   t  j ƒ  S(   N(   RK   t   ImageComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   Ü   s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_image(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ß   s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   ui   Sets a `gimp.Image` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_image(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   â   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRU   Ô   s
   		t   ItemComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uÒ   `Presenter` subclass for `gui.GimpItemComboBox` elements.
  
  If the setting references a `gimp.Image`, only drawables from that image will
  be displayed.
  
  Value: `gimp.Item` selected in the combo box.
  u   changedc         C` s   t  t j | ƒ S(   N(   t   _create_item_combo_boxt   pgguit   GimpItemComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ö   s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_item(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ù   s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   uh   Sets a `gimp.Item` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_item(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   ü   s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRY   ë   s
   		t   DrawableComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uÙ   `Presenter` subclass for `gimpui.DrawableComboBox` elements.
  
  If the setting references a `gimp.Image`, only drawables from that image will
  be displayed.
  
  Value: `gimp.Drawable` selected in the combo box.
  u   changedc         C` s   t  t j | ƒ S(   N(   RZ   RK   t   DrawableComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&     s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_drawable(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(     s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   ul   Sets a `gimp.Drawable` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_drawable(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+     s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR_     s
   		t   LayerComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uÐ   `Presenter` subclass for `gimpui.LayerComboBox` elements.
  
  If the setting references a `gimp.Image`, only layers from that image will be
  displayed.
  
  Value: `gimp.Layer` selected in the combo box.
  u   changedc         C` s   t  t j | ƒ S(   N(   RZ   RK   t   LayerComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   *  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_layer(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   -  s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   ui   Sets a `gimp.Layer` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_layer(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   0  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRc     s
   		t   ChannelComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uÖ   `Presenter` subclass for `gimpui.ChannelComboBox` elements.
  
  If the setting references a `gimp.Image`, only channels from that image will
  be displayed.
  
  Value: `gimp.Channel` selected in the combo box.
  u   changedc         C` s   t  t j | ƒ S(   N(   RZ   RK   t   ChannelComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   D  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_channel(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   G  s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   uk   Sets a `gimp.Channel` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_channel(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   J  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRg   9  s
   		t   VectorsComboBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uÕ   `Presenter` subclass for `gimpui.VectorsComboBox` elements.
  
  If the setting references a `gimp.Image`, only vectors from that image will
  be displayed.
  
  Value: `gimp.Vectors` selected in the combo box.
  u   changedc         C` s   t  t j | ƒ S(   N(   RZ   RK   t   VectorsComboBox(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ^  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_active_vectors(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   a  s    c         C` s#   | d k	 r |  j j | ƒ n  d S(   uk   Sets a `gimp.Vectors` instance to be selected in the combo box.
    
    Passing `None` has no effect.
    N(   R	   R   t   set_active_vectors(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   d  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRk   S  s
   		t   ColorButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uz   `Presenter` subclass for `gimpui.ColorButton` elements.
  
  Value: `gimpcolor.RGB` instance representing color in RGB.
  u   color-changedc         C` s"   t  j | j d d | j t  j ƒ S(   Nid   i   (   RK   t   ColorButtonR3   R*   t   COLOR_AREA_FLAT(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   u  s    c         C` s   |  j  j ƒ  S(   N(   R   t	   get_color(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   y  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t	   set_color(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   |  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRo   m  s
   		t   ParasiteBoxPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   u]   `Presenter` subclass for `gui.ParasiteBox` elements.
  
  Value: `gimp.Parasite` instance.
  u   parasite-changedc         C` s   t  j | j ƒ S(   N(   R[   t   ParasiteBoxR*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ˆ  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_parasite(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ‹  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_parasite(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   Ž  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRt   €  s
   		t   DisplaySpinButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   u   `Presenter` subclass for `gtk.SpinButton` elements.
  
  Value: `gimp.Display` instance, represented by its integer ID in the spin
  button.
  u   value-changedc         C` sl   t  | j d d ƒ } t j t j d | d d d d d d	 d
 d ƒ d d ƒ} | j t ƒ | j | ƒ | S(   Nu   IDi    R*   t   lowert   upperi   i    t	   step_incri   t	   page_incri
   R-   I       (   t   getattrR*   R1   t
   SpinButtont
   Adjustmentt   set_numericR!   R)   (   R   R%   t
   display_idt   spin_button(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ›  s    			c         C` s   t  j |  j j ƒ  ƒ S(   N(   t   gimpt   _id2displayR   R'   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ­  s    c         C` s   |  j  j | j ƒ d  S(   N(   R   R)   t   ID(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   °  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRx   ’  s
   		t   ExtendedEntryPresenterc           B` s    e  Z d  Z d „  Z d „  Z RS(   uX   `Presenter` subclass for `gui.ExtendedEntry` elements.
  
  Value: Text in the entry.
  c         C` s   t  j |  j j ƒ  ƒ S(   N(   R9   R:   R   RR   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   º  s    c         C` s   |  j  j t j | ƒ ƒ d  S(   N(   R   t   assign_textR9   R=   (   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   ½  s    (   R   R   R    R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR†   ´  s   	t   FileExtensionEntryPresenterc           B` s   e  Z d  Z d „  Z RS(   u]   `Presenter` subclass for `gui.FileExtensionEntry` elements.
  
  Value: Text in the entry.
  c         C` s
   t  j ƒ  S(   N(   R[   t   FileExtensionEntry(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   Ç  s    (   R   R   R    R&   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRˆ   Á  s   t   FolderChooserWidgetPresenterc           B` sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   us   `Presenter` subclass for `gtk.FileChooserWidget` elements used as folder
  choosers.
  
  Value: Current folder.
  c         O` s&   t  j |  | | Ž |  j ƒ  |  _ d  S(   N(   R   R   t   _get_location_toggle_buttont   _location_toggle_button(   R   R   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   Ò  s    c         C` s   t  j d t  j ƒ S(   Nt   action(   R1   t   FileChooserWidgett!   FILE_CHOOSER_ACTION_SELECT_FOLDER(   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ×  s    c         C` sN   |  j  ƒ  s |  j j ƒ  } n |  j j ƒ  } | d  k	 rF t j | ƒ Sd  Sd  S(   N(   t   _is_location_entry_activeR   t   get_current_foldert   get_filenameR	   R9   R:   (   R   t   dirpath(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   Ú  s    c         C` s   |  j  j t j | ƒ ƒ d  S(   N(   R   t   set_current_folderR9   R=   (   R   R“   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   å  s    c         C` s9   |  j  j ƒ  d j ƒ  d j ƒ  d j ƒ  d j ƒ  d S(   Ni    (   R   t   get_children(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR‹   è  s    *c         C` s   |  j  j ƒ  S(   N(   RŒ   R5   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   í  s    (	   R   R   R    R   R&   R(   R+   R‹   R   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRŠ   Ë  s   					t   FolderChooserButtonPresenterc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   us   `Presenter` subclass for `gtk.FileChooserButton` elements used as folder
  choosers.
  
  Value: Current folder.
  c         C` s)   t  j d | j ƒ } | j t  j ƒ | S(   Nt   title(   R1   t   FileChooserButtonR3   t
   set_actionR   (   R   R%   t   button(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ø  s    c         C` s0   |  j  j ƒ  } | d  k	 r( t j | ƒ Sd  Sd  S(   N(   R   R’   R	   R9   R:   (   R   R“   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ý  s    c         C` s   |  j  j t j | ƒ ƒ d  S(   N(   R   R”   R9   R=   (   R   R“   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+     s    (   R   R   R    R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR–   ñ  s   		t   BrushSelectButtonPresenterc           B` sA   e  Z d  Z d Z d d d d g Z d „  Z d „  Z d „  Z RS(	   uh   `Presenter` subclass for `gimpui.BrushSelectButton` elements.
  
  Value: Tuple representing a brush.
  u	   brush-setu
   brush-nameu   brush-opacityu   brush-spacingu   brush-paint-modec         C` s   t  j | j | j Œ S(   N(   RK   t   BrushSelectButtonR3   R*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&     s    c         C` s   |  j  j ƒ  S(   N(   R   t	   get_brush(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(     s    c         C` s:   x3 t  |  j | ƒ D] \ } } |  j j | | ƒ q Wd  S(   N(   t   zipt   _BRUSH_PROPERTIESR   t   set_property(   R   R*   t   property_namet   property_value(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+     s    (   R   R   R    R   RŸ   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR›   	  s   		t   FontSelectButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   ug   `Presenter` subclass for `gimpui.FontSelectButton` elements.
  
  Value: String representing a font.
  u   font-setc         C` s   t  j | j | j ƒ S(   N(   RK   t   FontSelectButtonR3   R*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   %  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_font(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   (  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_font(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   +  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR£     s
   		t   GradientSelectButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   uo   `Presenter` subclass for `gimpui.GradientSelectButton` elements.
  
  Value: String representing a gradient.
  u   gradient-setc         C` s   t  j | j | j ƒ S(   N(   RK   t   GradientSelectButtonR3   R*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   7  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_gradient(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   :  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_gradient(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   =  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR§   /  s
   		t   PaletteSelectButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   us   `Presenter` subclass for `gimpui.PaletteSelectButton` elements.
  
  Value: String representing a color palette.
  u   palette-setc         C` s   t  j | j | j ƒ S(   N(   RK   t   PaletteSelectButtonR3   R*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   I  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_palette(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   L  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_palette(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   O  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR«   A  s
   		t   PatternSelectButtonPresenterc           B` s/   e  Z d  Z d Z d „  Z d „  Z d „  Z RS(   um   `Presenter` subclass for `gimpui.PatternSelectButton` elements.
  
  Value: String representing a pattern.
  u   pattern-setc         C` s   t  j | j | j ƒ S(   N(   RK   t   PatternSelectButtonR3   R*   (   R   R%   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   [  s    c         C` s   |  j  j ƒ  S(   N(   R   t   get_pattern(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ^  s    c         C` s   |  j  j | ƒ d  S(   N(   R   t   set_pattern(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   a  s    (   R   R   R    R   R&   R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR¯   S  s
   		t   ArrayBoxPresenterc           B` sk   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 RS(   už   `Presenter` subclass for `gui.ArrayBox` elements.
  
  Value: Tuple of values of type `element_type` specified in the passed
  `gui.ArraySetting` instance.
  u   array-box-changedu   array-box-item-changedc         O` s,   d  |  _ t ƒ  |  _ t j |  | | Ž d  S(   N(   R	   t   _item_changed_event_handler_idt   sett   _array_elements_with_eventsR   R   (   R   R   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   o  s    	c         C` s8   t  j |  ƒ x$ |  j j ƒ  D] } | j j ƒ  q Wd  S(   N(   R   t   update_setting_valuet   _settingt   get_elementsR   (   R   t   array_element(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR·   u  s    c         C` s/   t  j |  ƒ |  j j |  j |  j ƒ |  _ d  S(   N(   R   R   R   R   t   _ITEM_CHANGED_SIGNALt   _on_item_changedR´   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR   {  s    	c         C` s-   t  j |  ƒ |  j j |  j ƒ d  |  _ d  S(   N(   R   R   R   R   R´   R	   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR     s    c         ` sÅ   ‡  ‡ ‡ f d †  } ‡  ‡ ‡ f d †  } ‡ f d †  } ‡ ‡ f d †  } t  j ˆ j ˆ j ˆ j ƒ ‰  | ˆ  _ x1 t t ˆ ƒ ƒ D] } ˆ  j ˆ | j	 | ƒ q… W| ˆ  _ | ˆ  _
 | ˆ  _ ˆ  S(   Nc         ` s   ˆ j  ˆ | ˆ  ƒ S(   N(   t   _add_array_element(   t   array_element_valuet   index(   t	   array_boxR   R%   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _add_existing_elementˆ  s    c         ` s"   ˆ j  d |  ƒ } ˆ j | ˆ  ƒ S(   NR*   (   t   add_elementR½   (   R¾   R¿   Rº   (   RÀ   R   R%   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _add_new_element‹  s    c         ` s   ˆ  j  |  | ƒ d  S(   N(   t   reorder_element(   t   orig_positiont   new_position(   R%   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _reorder_element  s    c         ` s   ˆ  j  j ˆ |  ƒ ˆ |  =d  S(   N(   R¶   t   remove(   t   position(   R   R%   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _remove_element’  s    (   R[   t   ArrayBoxt   element_default_valuet   min_sizet   max_sizet   on_add_itemRI   RJ   t   add_itemR*   t   on_reorder_itemt   on_remove_item(   R   R%   RÁ   RÃ   RÇ   RÊ   t   element_index(    (   RÀ   R   R%   sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR&   ‡  s    				c         C` s   t  d „  |  j j ƒ  Dƒ ƒ S(   Nc         s` s   |  ] } | j  Vq d  S(   N(   R*   (   t   .0Rº   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pys	   <genexpr>¥  s    (   RM   R¸   R¹   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   ¤  s    c         ` sG   ‡  f d †  } ˆ  j  j } | ˆ  j  _ ˆ  j  j | ƒ | ˆ  j  _ d  S(   Nc         ` s   ˆ  j  ˆ  j | ˆ  j ƒ S(   N(   R½   R¸   R   (   R¾   R¿   (   R   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRÁ   ¨  s    (   R   RÏ   t
   set_values(   R   R*   RÁ   t   orig_on_add_item(    (   R   sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   §  s
    c         G` s   |  j  j |  j ƒ  ƒ d  S(   N(   t   _setting_value_synchronizert   apply_gui_value_to_settingR(   (   R   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR¼   ²  s    c         ` sU   ‡  f d †  } | j  ƒ  | |  j k rK | j d | ƒ |  j j | ƒ n  | j j S(   Nc         ` s   ˆ  j  d ƒ d  S(   Nu   array-box-item-changed(   t   emit(   Rº   (   RÀ   (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _on_array_box_item_changed¶  s    u   value-changed(   t   set_guiR¶   t   connect_eventt   addR   t   element(   R   Rº   RÀ   RÚ   (    (   RÀ   sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR½   µ  s    
(   R   R   R    R   R»   R   R·   R   R   R&   R(   R+   R¼   R½   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR³   e  s   								t   WindowPositionPresenterc           B` s    e  Z d  Z d „  Z d „  Z RS(   u´   `Presenter` subclass for window or dialog elements
  (`gtk.Window`, `gtk.Dialog`) to get/set its position.
  
  Value: Current position of the window as a tuple with 2 integers.
  c         C` s   |  j  j ƒ  S(   N(   R   t   get_position(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   É  s    c         C` s   | r |  j  j | Œ  n  d S(   u~   Sets a new position of the window (i.e. move the window).
    
    The window is not moved if `value` is `None` or empty.
    N(   R   t   move(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   Ì  s    (   R   R   R    R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRß   Â  s   	t   WindowSizePresenterc           B` s    e  Z d  Z d „  Z d „  Z RS(   u¬   `Presenter` subclass for window or dialog elements
  (`gtk.Window`, `gtk.Dialog`) to get/set its size.
  
  Value: Current size of the window as a tuple with 2 integers.
  c         C` s   |  j  j ƒ  S(   N(   R   t   get_size(   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   Ü  s    c         C` s   | r |  j  j | Œ  n  d S(   ue   Sets a new size of the window.
    
    The window is not resized if `value` is `None` or empty.
    N(   R   t   resize(   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   ß  s    (   R   R   R    R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRâ   Õ  s   	t   PanedPositionPresenterc           B` s    e  Z d  Z d „  Z d „  Z RS(   uS   `Presenter` subclass for `gtk.Paned` elements.
  
  Value: Position of the pane.
  c         C` s   |  j  j ƒ  S(   N(   R   Rà   (   R   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR(   î  s    c         C` s   |  j  j | ƒ d  S(   N(   R   RT   (   R   R*   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR+   ñ  s    (   R   R   R    R(   R+   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRå   è  s   	c         C` s½   t  |  d ƒ r* |  j d  k	 r* |  j } n d } t  |  d ƒ rZ |  j d  k	 rZ |  j } n d } t j t j d |  j d | d | d d	 d
 d ƒ d | ƒ} | j t	 ƒ | j
 |  j ƒ | S(   Nu	   min_valuei   i    u	   max_valueR*   Ry   Rz   R{   i   R|   i
   R-   I       I    ÿÿÿÿI       (   t   hasattrt	   min_valueR	   t	   max_valueR1   R~   R   R*   R€   R!   R)   (   R%   R-   Rç   Rè   R‚   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyR$   õ  s"    				c         C` s?   t  | j d ƒ r4 d „  } |  d | d | j j ƒ S|  ƒ  Sd  S(   Nu   imagec         S` s
   |  | k S(   N(    (   t   imaget   itemt   setting_image(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   _image_matches_setting_image  s    t
   constraintt   data(   Ræ   R*   Ré   (   t   item_combo_box_typeR%   Rì   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyRZ     s
    	u   GtkPresenter(A   R    t
   __future__R    R   R   R   t   future.builtinst   inspectt   syst   pygtkt   requireR1   Rƒ   RK   t    R   R[   R   R9   R   R   R   R   R#   R,   R/   R7   R8   R>   R@   RG   RP   RU   RY   R_   Rc   Rg   Rk   Ro   Rt   Rx   R†   Rˆ   RŠ   R–   R›   R£   R§   R«   R¯   R³   Rß   Râ   Rå   R$   RZ   t   __all__t
   getmemberst   modulesR   t   isclasst   namet   class_t
   issubclasst   append(    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/setting/presenters_gtk.pyt   <module>   sd   "
"
&]		)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 # -*- coding: utf-8 -*-

"""Loading and saving settings."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *
import future.utils

import abc
import ast
import collections
import io
import os
import traceback
import types

try:
  import cPickle as pickle
except ImportError:
  import pickle

try:
  import json
except ImportError:
  _json_module_found = False
else:
  _json_module_found = True

import gimp
import gimpenums
import gimpshelf

from .. import constants as pgconstants
from .. import utils as pgutils

from . import group as group_
from . import settings as settings_
from . import utils as utils_

from ._sources_errors import *

__all__ = [
  'Source',
  'GimpShelfSource',
  'GimpParasiteSource',
  'PickleFileSource',
  'JsonFileSource',
]


class Source(future.utils.with_metaclass(abc.ABCMeta, object)):
  """Abstract class for reading and writing settings to a source.
  
  Attributes:
  
  * `source_name` - A unique identifier to distinguish entries from different
    GIMP plug-ins or procedures.
  
  * `source_type` - If `'persistent'`, this indicates that the setting source
    should store settings permanently. If `'session'`, this indicates that the
    source should store settings within a single GIMP session (i.e. until the
    currently running GIMP instance is closed).
  """
  
  _IGNORE_LOAD_TAG = 'ignore_load'
  _IGNORE_SAVE_TAG = 'ignore_save'
  
  _MAX_LENGTH_OF_OBJECT_AS_STRING_ON_ERROR_OUTPUT = 512
  
  def __init__(self, source_name, source_type):
    self.source_name = source_name
    self.source_type = source_type
    
    self._settings_not_loaded = []
  
  @property
  def settings_not_loaded(self):
    """List of all settings and groups that were not found in the data or their
    `setting_source` attribute is not `None` and does does not contain
    `source_type`.
    """
    return list(self._settings_not_loaded)
  
  def read(self, settings_or_groups):
    """Reads setting attributes from data and assigns them to existing settings
    specified in the `settings_or_groups` iterable, or creates settings within
    groups specified in `settings_or_groups`.
    
    If a setting value from the source is invalid, the setting will be reset to
    its default value.
    
    All settings that were not loaded in the source will be stored in the
    `settings_not_loaded` property. This property is reset on each call to
    `read()`.
    
    The following criteria determine whether a setting specified in
    `setting_or_groups` is not loaded:
    
    * The setting is not found in the source.
    
    * The setting or any of its parent groups contains 'ignore_load' in its
      `tags` attribute.
    
    * The setting does not contain `source_type` in its `setting_sources`
      attribute.
    
    Raises:
    
    * `SourceNotFoundError` - Could not find the source having the `source_name`
      attribute as its name.
    
    * `SourceInvalidFormatError` - Existing data in the source have an invalid
      format. This could happen if the source was edited manually.
    """
    data = self.read_data_from_source()
    if data is None:
      raise SourceNotFoundError(
        _('Could not find setting source "{}".').format(self.source_name))
    
    self._settings_not_loaded = []
    
    self._update_settings(settings_or_groups, data)
  
  def _update_settings(self, settings_or_groups, data):
    data_dict = self._create_data_dict(data)
    
    for setting_or_group in settings_or_groups:
      setting_path = setting_or_group.get_path()
      
      if setting_path in data_dict:
        setting_dict = data_dict[setting_path]
        
        if isinstance(setting_or_group, settings_.Setting):
          self._check_if_setting_dict_has_value(setting_dict, setting_path)
          self._update_setting(setting_or_group, setting_dict)
        elif isinstance(setting_or_group, group_.Group):
          self._check_if_setting_dict_has_settings(setting_dict, setting_path)
          self._update_group(setting_or_group, setting_dict, setting_path, data_dict)
        else:
          raise TypeError('settings_or_groups must contain only Setting or Group instances')
      else:
        self._settings_not_loaded.append(setting_or_group)
  
  def _create_data_dict(self, data):
    # Creates a (setting/group path, dict/list representing the setting/group) mapping.
    # The entries in the mapping are listed in the depth-first order.
    data_dict = collections.OrderedDict()
    data_dict[None] = data
    
    current_list_and_parents = []
    
    self._check_if_is_list(data)
    
    for dict_ in reversed(data):
      current_list_and_parents.insert(0, (dict_, []))
    
    while current_list_and_parents:
      current_dict, parents = current_list_and_parents.pop(0)
      
      self._check_if_is_dict(current_dict)
      self._check_if_dict_has_required_keys(current_dict)
      
      key = utils_.SETTING_PATH_SEPARATOR.join(parents + [current_dict['name']])
      data_dict[key] = current_dict
      
      if 'settings' in current_dict:
        parents.append(current_dict['name'])
        
        child_list = current_dict['settings']
        
        self._check_if_is_list(child_list)
        
        for child_dict in reversed(child_list):
          current_list_and_parents.insert(0, (child_dict, list(parents)))
    
    return data_dict
  
  def _update_group(self, group, group_dict, group_path, data_dict):
    if not self._should_group_be_loaded(group):
      return
    
    matching_dicts = self._get_matching_dicts_for_group_path(data_dict, group_path)
    prefixes_to_ignore = set()
    matching_children = self._get_matching_children(
      group, group_path, matching_dicts, prefixes_to_ignore)
    matching_dicts = self._filter_matching_dicts(
      matching_dicts, matching_children, prefixes_to_ignore)
    
    # `matching_dicts` is assumed to contain children in depth-first order,
    # which simplifies the algorithm quite a bit.
    for path, dict_ in matching_dicts.items():
      if 'value' in dict_:  # dict_ is a `Setting`
        if path in matching_children:
          self._check_if_is_setting(matching_children[path], path)
          self._update_setting(matching_children[path], dict_)
        else:
          self._add_setting_to_parent_group(dict_, path, matching_children)
      elif 'settings' in dict_:  # dict_ is a `Group`
        if path in matching_children:
          # Nothing else to do. Group attributes will not be updated since
          # setting attributes are also not updated.
          self._check_if_is_group(matching_children[path], path)
        else:
          self._add_group_to_parent_group(dict_, path, matching_children)
      else:
        raise SourceInvalidFormatError(
          ('Error while parsing data from a source: every dictionary must always contain'
           ' either "value" or "settings" key'))
  
  def _get_matching_dicts_for_group_path(self, data_dict, group_path):
    return collections.OrderedDict(
      (path, dict_) for path, dict_ in data_dict.items()
      if path is not None and path.startswith(group_path) and path != group_path)
  
  def _get_matching_children(self, group, group_path, matching_dicts, prefixes_to_ignore):
    matching_children = collections.OrderedDict()
    
    for child in group.walk(include_groups=True):
      child_path = child.get_path()
      
      if self._IGNORE_LOAD_TAG in child.tags:
        prefixes_to_ignore.add(child_path)
      
      if any(child_path.startswith(prefix) for prefix in prefixes_to_ignore):
        continue
      
      matching_children[child_path] = child
      
      if child_path not in matching_dicts:
        if isinstance(child, group_.Group):
          # Only append empty groups since non-empty groups are further descended.
          if len(child) == 0:
            self._settings_not_loaded.append(child)
        else:
          self._settings_not_loaded.append(child)
    
    matching_children[group_path] = group
    
    return matching_children
  
  def _filter_matching_dicts(self, matching_dicts, matching_children, prefixes_to_ignore):
    filtered_matching_dicts = collections.OrderedDict()
    
    for path, dict_ in matching_dicts.items():
      if self._IGNORE_LOAD_TAG in dict_.get('tags', []) and path not in matching_children:
        prefixes_to_ignore.add(path)
      
      if any(path.startswith(prefix) for prefix in prefixes_to_ignore):
        continue
      
      filtered_matching_dicts[path] = dict_
    
    return filtered_matching_dicts
  
  def _update_setting(self, setting, setting_dict):
    if not self._should_setting_be_loaded(setting):
      return
    
    try:
      setting.set_value(setting_dict['value'])
    except settings_.SettingValueError:
      setting.reset()
  
  def _should_setting_be_loaded(self, setting):
    if self._IGNORE_LOAD_TAG in setting.tags:
      return False
    
    if setting.setting_sources is not None and self.source_type not in setting.setting_sources:
      self._settings_not_loaded.append(setting)
      return False
    
    return True
  
  def _should_group_be_loaded(self, group):
    return self._IGNORE_LOAD_TAG not in group.tags
  
  def _should_dict_be_loaded(self, dict_):
    setting_sources = dict_.get('setting_sources', None)
    if setting_sources is not None and self.source_type not in setting_sources:
      return False
    
    return True
  
  def _add_setting_to_parent_group(self, dict_, path, matching_children):
    if not self._should_dict_be_loaded(dict_):
      return
    
    parent_path = path.rsplit(utils_.SETTING_PATH_SEPARATOR, 1)[0]
    
    # If the assertion fails for some reason, then `matching_dicts` does not
    # contain children in depth-first order or children of ignored parents are
    # not ignored.
    assert parent_path in matching_children
    
    parent_group = matching_children[parent_path]
    
    child_setting_dict = dict(dict_)
    child_setting_dict.pop('value', None)
    
    parent_group.add([child_setting_dict])
    
    child_setting = parent_group[dict_['name']]
    
    if 'value' in dict_:
      self._update_setting(child_setting, dict_)
    
    matching_children[child_setting.get_path()] = child_setting
  
  def _add_group_to_parent_group(self, dict_, path, matching_children):
    parent_path = path.rsplit(utils_.SETTING_PATH_SEPARATOR, 1)[0]
    
    # If the assertion fails for some reason, then `matching_dicts` does not
    # contain children in depth-first order or children of ignored parents are
    # not ignored.
    assert parent_path in matching_children
    
    parent_group = matching_children[parent_path]
    
    child_group_kwargs = dict(dict_)
    # Child settings will be created separately.
    child_group_kwargs.pop('settings')
    child_group = group_.Group(**child_group_kwargs)
    
    parent_group.add([child_group])
    
    matching_children[child_group.get_path()] = child_group
  
  def write(self, settings_or_groups):
    """Writes data representing settings specified in the `settings_or_groups`
    iterable.
    
    Settings in the source but not specified in `settings_or_groups` are kept
    intact.
    
    Some settings may not be saved. The following criteria determine whether a
    setting is not saved:
    
    * The setting or any of its parent groups contains 'ignore_save' in its
      `tags` attribute.
    
    * The setting does not contain `source_type` in its `setting_sources`
      attribute.
    
    Raises:
    
    * `SourceInvalidFormatError` - Existing data in the source have an invalid
      format. This could happen if the source was edited manually.
    """
    data = self.read_data_from_source()
    if data is None:
      data = []
    
    self._update_data(settings_or_groups, data)
    
    self.write_data_to_source(data)
  
  def _update_data(self, settings_or_groups, data):
    for setting_or_group in settings_or_groups:
      # Create all parent groups if they do not exist.
      # `current_list` at the end of the loop will hold the immediate parent of
      # `setting_or_group`.
      current_list = data
      for parent in setting_or_group.parents:
        parent_dict = self._find_dict(current_list, parent)[0]
        
        if parent_dict is None:
          parent_dict = dict(settings=[], **parent.to_dict())
          current_list.append(parent_dict)
        
        current_list = parent_dict['settings']
      
      if isinstance(setting_or_group, settings_.Setting):
        self._setting_to_data(current_list, setting_or_group)
      elif isinstance(setting_or_group, group_.Group):
        self._group_to_data(current_list, setting_or_group)
      else:
        raise TypeError('settings_or_groups must contain only Setting or Group instances')
  
  def _setting_to_data(self, group_list, setting):
    if not self._should_setting_be_saved(setting):
      return
    
    setting_dict, index = self._find_dict(group_list, setting)
    
    if setting_dict is not None:
      # Overwrite the original setting dict
      group_list[index] = setting.to_dict(source_type=self.source_type)
    else:
      group_list.append(setting.to_dict(source_type=self.source_type))
  
  def _group_to_data(self, group_list, group):
    if not self._should_group_be_saved(group):
      return
    
    # Clear the group in the source as its child settings may be reordered or
    # removed in the memory.
    self._clear_group_in_data(group, group_list)
    
    settings_or_groups_and_dicts = [(group, group_list)]
    
    while settings_or_groups_and_dicts:
      setting_or_group, parent_list = settings_or_groups_and_dicts.pop(0)
      
      if isinstance(setting_or_group, settings_.Setting):
        self._setting_to_data(parent_list, setting_or_group)
      elif isinstance(setting_or_group, group_.Group):
        if not self._should_group_be_saved(setting_or_group):
          continue
        
        current_group_dict = self._find_dict(parent_list, setting_or_group)[0]
        
        if current_group_dict is None:
          current_group_dict = dict(settings=[], **setting_or_group.to_dict())
          parent_list.append(current_group_dict)
        
        for child_setting_or_group in reversed(setting_or_group):
          settings_or_groups_and_dicts.insert(
            0, (child_setting_or_group, current_group_dict['settings']))
      else:
        raise TypeError('only Setting or Group instances are allowed as the first element')
  
  def _should_setting_be_saved(self, setting):
    if self._IGNORE_SAVE_TAG in setting.tags:
      return False
    
    if setting.setting_sources is not None and self.source_type not in setting.setting_sources:
      return False
    
    return True
  
  def _should_group_be_saved(self, group):
    return self._IGNORE_SAVE_TAG not in group.tags
  
  def _clear_group_in_data(self, group, parent_list):
    group_in_parent, index = self._find_dict(parent_list, group)
    
    if group_in_parent is not None:
      parent_list[index]['settings'] = []
  
  def _find_dict(self, data_list, setting_or_group):
    self._check_if_is_list(data_list)
    
    if isinstance(setting_or_group, settings_.Setting):
      key = 'value'
    else:
      key = 'settings'
    
    for i, dict_ in enumerate(data_list):
      self._check_if_is_dict(dict_)
      
      if 'name' in dict_ and dict_['name'] == setting_or_group.name and key in dict_:
        return dict_, i
    
    return None, None
  
  def _check_if_is_list(self, list_):
    if (not isinstance(list_, collections.Iterable)
        or isinstance(list_, types.StringTypes)
        or isinstance(list_, dict)):
      raise SourceInvalidFormatError(
        'Error while parsing data from a source: Not a list: {}'.format(
          self._truncate_str(list_)))
  
  def _check_if_is_dict(self, dict_):
    if not isinstance(dict_, dict):
      raise SourceInvalidFormatError(
        'Error while parsing data from a source: Not a dictionary: {}'.format(
          self._truncate_str(dict_)))
  
  def _check_if_dict_has_required_keys(self, dict_):
    if 'name' not in dict_:
      raise SourceInvalidFormatError(
        'Error while parsing data from a source: every dictionary must always contain "name" key')
    
    if (('value' not in dict_ and 'settings' not in dict_)
        or ('value' in dict_ and 'settings' in dict_)):
      raise SourceInvalidFormatError(
        ('Error while parsing data from a source: every dictionary must always contain'
         ' either "value" or "settings" key'))
  
  def _check_if_setting_dict_has_value(self, setting_dict, setting_path):
    if 'value' not in setting_dict:
      raise SourceInvalidFormatError(
        ('Error while parsing data from a source: "value" key not found in dictionary'
         ' representing setting "{}"').format(setting_path))
  
  def _check_if_setting_dict_has_settings(self, setting_dict, setting_path):
    if 'settings' not in setting_dict:
      raise SourceInvalidFormatError(
        ('Error while parsing data from a source: "settings" key not found in dictionary'
         ' representing setting group "{}"').format(setting_path))
  
  def _check_if_is_setting(self, setting, setting_path):
    if not isinstance(setting, settings_.Setting):
      raise SourceInvalidFormatError(
        'expected a Setting instance, found Group instead: "{}"'.format(setting_path))
  
  def _check_if_is_group(self, group, group_path):
    if not isinstance(group, group_.Group):
      raise SourceInvalidFormatError(
        'expected a Group instance, found Setting instead: "{}"'.format(group_path))
  
  @staticmethod
  def _truncate_str(obj, max_length=_MAX_LENGTH_OF_OBJECT_AS_STRING_ON_ERROR_OUTPUT):
    str_ = str(obj)
    if len(str_) > max_length:
      str_ = str_[:max_length] + '... (truncated)'
    
    return str_
  
  @abc.abstractmethod
  def clear(self):
    """Removes all settings from the source.
    
    Settings not belonging to `source_name` are kept intact.
    
    This method is useful if settings are renamed, since the old settings would
    not be removed and would thus lead to bloating the source.
    """
    pass
  
  @abc.abstractmethod
  def has_data(self):
    """Returns `True` if the source contains data, `False` otherwise."""
    pass
  
  @abc.abstractmethod
  def read_data_from_source(self):
    """Reads data representing settings from the source.
    
    Usually you do not need to call this method. Use `read()` instead which
    assigns values to existing settings or creates settings dynamically from the
    data.
    
    If the source does not exist, `None` is returned.
    
    Raises:
    
    * `SourceInvalidFormatError` - Data could not be read due to being corrupt.
    """
    pass
  
  @abc.abstractmethod
  def write_data_to_source(self, data):
    """Writes data representing settings to the source.
    
    The entire setting source is overwritten by the specified data.
    Settings not specified thus will be removed.
    
    Usually you do not need to call this method. Use `write()` instead which
    creates an appropriate persistent representation of the settings that can
    later be loaded via `read()`.
    """
    pass


class GimpShelfSource(Source):
  """Class for reading and writing settings to the GIMP shelf.
  
  This class is appropriate to maintain settings within a single GIMP session
  as the GIMP shelf is reset when closing GIMP.
  """
  
  def __init__(self, source_name, source_type='session'):
    super().__init__(source_name, source_type)
  
  def clear(self):
    gimpshelf.shelf[self._get_key()] = None
  
  def has_data(self):
    try:
      data = gimp.get_data(self._get_key())
    except Exception:
      return False
    else:
      return bool(data)
  
  def read_data_from_source(self):
    try:
      return gimpshelf.shelf[self._get_key()]
    except KeyError:
      return None
    except Exception:
      raise SourceInvalidFormatError(
        _('Settings for this plug-in may be corrupt.\n'
          'To fix this, save the settings again or reset them.'))
  
  def write_data_to_source(self, data):
    gimpshelf.shelf[self._get_key()] = data
  
  def _get_key(self):
    return pgutils.safe_encode_gimp(self.source_name)


class GimpParasiteSource(Source):
  """Class reading and writing settings to the `parasiterc` file maintained by
  GIMP.
  
  This class is useful as a persistent source (i.e. permanent storage) of
  settings.
  """
  
  def __init__(self, source_name, source_type='persistent'):
    super().__init__(source_name, source_type)
    
    self._parasite_filepath = os.path.join(gimp.directory, 'parasiterc')
  
  def clear(self):
    if gimp.parasite_find(self.source_name) is None:
      return
    
    gimp.parasite_detach(self.source_name)
  
  def has_data(self):
    return gimp.parasite_find(self.source_name) is not None
  
  def read_data_from_source(self):
    parasite = gimp.parasite_find(self.source_name)
    if parasite is None:
      return None
    
    try:
      data = pickle.loads(parasite.data)
    except Exception:
      raise SourceInvalidFormatError(
        _('Settings for this plug-in stored in "{}" may be corrupt.'
          ' This could happen if the file was edited manually.'
          '\nTo fix this, save the settings again or reset them.').format(
            self._parasite_filepath))
    
    return data
  
  def write_data_to_source(self, data):
    gimp.parasite_attach(
      gimp.Parasite(self.source_name, gimpenums.PARASITE_PERSISTENT, pickle.dumps(data)))


class PickleFileSource(Source):
  """Class reading and writing settings to a file, formatted using the Python
  `pickle` module.
  
  This class is useful as a persistent source (i.e. permanent storage) of
  settings. This class is appropriate to use when saving settings to a file path
  chosen by the user.
  """
  
  _SOURCE_NAME_CONTENTS_SEPARATOR = ' '
  
  def __init__(self, source_name, filepath, source_type='persistent'):
    super().__init__(source_name, source_type)
    
    self._filepath = filepath
  
  @property
  def filepath(self):
    return self._filepath
  
  def clear(self):
    all_data = self.read_all_data()
    if all_data is not None and self.source_name in all_data:
      del all_data[self.source_name]
      
      self.write_all_data(all_data)
  
  def has_data(self):
    """Returns `True` if the source contains data and the data have a valid
    format, `'invalid_format'` if the source contains some data, but the data
    have an invalid format, and `False` otherwise.
    
    `'invalid_format'` represents an ambiguous value since there is no way to
    determine if there are data under `source_name` or not.
    """
    try:
      data = self.read_data_from_source()
    except SourceError:
      return 'invalid_format'
    else:
      return data is not None
  
  def read_data_from_source(self):
    all_data = self.read_all_data()
    if all_data is not None and self.source_name in all_data:
      return self._get_settings_from_pickled_data(all_data[self.source_name])
    else:
      return None
  
  def write_data_to_source(self, data):
    raw_data = self._pickle_settings(data)
    
    all_data = self.read_all_data()
    if all_data is None:
      all_data = collections.OrderedDict([(self.source_name, raw_data)])
    else:
      all_data[self.source_name] = raw_data
    
    self.write_all_data(all_data)
  
  def read_all_data(self):
    """Reads the contents of the entire file into a dictionary of
    (source name, contents) pairs.
    
    The dictionary also contains contents from other source names if they exist.
    """
    if not os.path.isfile(self._filepath):
      return None
    
    all_data = collections.OrderedDict()
    
    try:
      with io.open(self._filepath, 'r', encoding=pgconstants.TEXT_FILE_ENCODING) as f:
        for line in f:
          split = line.split(self._SOURCE_NAME_CONTENTS_SEPARATOR, 1)
          if len(split) == 2:
            source_name, contents = split
            all_data[source_name] = contents
    except Exception:
      raise SourceReadError(traceback.format_exc())
    else:
      return all_data
  
  def write_all_data(self, all_data):
    """Writes `all_data` into the file, overwriting the entire file contents.
    
    `all_data` is a dictionary of (source name, contents) pairs.
    """
    try:
      with io.open(self._filepath, 'w', encoding=pgconstants.TEXT_FILE_ENCODING) as f:
        for source_name, contents in all_data.items():
          f.write(source_name + self._SOURCE_NAME_CONTENTS_SEPARATOR + contents + '\n')
    except Exception:
      raise SourceWriteError(traceback.format_exc())
  
  def _get_settings_from_pickled_data(self, contents):
    try:
      return pickle.loads(ast.literal_eval(contents))
    except Exception:
      raise SourceInvalidFormatError(traceback.format_exc())
  
  def _pickle_settings(self, settings):
    try:
      return repr(pickle.dumps(settings))
    except Exception:
      raise SourceInvalidFormatError(traceback.format_exc())


class JsonFileSource(Source):
  """Class reading and writing settings to a JSON file.
  
  This class is useful as a persistent source (i.e. permanent storage) of
  settings. This class is appropriate to use when saving settings to a file path
  chosen by the user.
  
  Compared to `PickleFileSource`, JSON files are more readable and, if need be,
  easy to modify by hand.
  """
  
  def __init__(self, source_name, filepath, source_type='persistent'):
    if not _json_module_found:
      raise RuntimeError('"json" module not found')
    
    super().__init__(source_name, source_type)
    
    self._filepath = filepath
  
  @property
  def filepath(self):
    return self._filepath
  
  def clear(self):
    all_data = self.read_all_data()
    if all_data is not None and self.source_name in all_data:
      del all_data[self.source_name]
      
      self.write_all_data(all_data)
  
  def has_data(self):
    """Returns `True` if the source contains data and the data have a valid
    format, `'invalid_format'` if the source contains some data, but the data
    have an invalid format, and `False` otherwise.
    
    `'invalid_format'` represents an ambiguous value since there is no way to
    determine if there are data under `source_name` or not.
    """
    try:
      data = self.read_data_from_source()
    except SourceError:
      return 'invalid_format'
    else:
      return data is not None
  
  def read_data_from_source(self):
    all_data = self.read_all_data()
    if all_data is not None and self.source_name in all_data:
      return all_data[self.source_name]
    else:
      return None
  
  def write_data_to_source(self, data):
    all_data = self.read_all_data()
    if all_data is None:
      all_data = collections.OrderedDict([(self.source_name, data)])
    else:
      all_data[self.source_name] = data
    
    self.write_all_data(all_data)
  
  def read_all_data(self):
    """Reads the contents of the entire file into a dictionary of
    (source name, contents) pairs.
    
    The dictionary also contains contents from other source names if they exist.
    """
    if not os.path.isfile(self._filepath):
      return None
    
    all_data = collections.OrderedDict()
    
    try:
      with io.open(self._filepath, 'r', encoding=pgconstants.TEXT_FILE_ENCODING) as f:
        all_data = json.load(f)
    except Exception:
      raise SourceReadError(traceback.format_exc())
    else:
      return all_data
  
  def write_all_data(self, all_data):
    """Writes `all_data` into the file, overwriting the entire file contents.
    
    `all_data` is a dictionary of (source name, contents) pairs.
    """
    try:
      with io.open(self._filepath, 'w', encoding=pgconstants.TEXT_FILE_ENCODING) as f:
        # Workaround for Python 2 code to properly handle Unicode strings
        raw_data = json.dumps(all_data, f, sort_keys=False, indent=4, separators=(',', ': '))
        f.write(unicode(raw_data))
    except Exception:
      raise SourceWriteError(traceback.format_exc())
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         