
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	 d d l	 m
 Z
 d d l Z d d l m Z d d l m Z e j d	    Z d
   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z  d   Z! d   Z" e# d d  Z$ d e# d  Z& d d e# e# e# d  Z' e e# e e d  Z( d   Z) e j e j* d   Z+ d e, f d      YZ- d a. d!   Z/ d"   Z0 d#   Z1 d S($   u   Additional functions dealing with GIMP objects (images, layers, etc.) not
defined in the GIMP procedural database (PDB) or the GIMP Python API.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *N(   t   pdbi   (   t
   invocation(   t   utilsc         c` s+   t  j |   z	 d VWd t  j |   Xd S(   u   
  Wrap the enclosing block of code into one GIMP undo group for the specified
  image.
  
  Use this function as a context manager:
    
    with undo_group(image):
      # do stuff
  N(   R   t   gimp_image_undo_group_startt   gimp_image_undo_group_end(   t   image(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt
   undo_group   s    	c         C` sP   |  j  | j d k  o% |  j  k  n oO |  j | j d k  oM |  j k  SS(   u   
  Return `True` if the layer is inside the image canvas (partially or
  completely). Return `False` if the layer is completely outside the image
  canvas.
  i    i   (   t   widtht   offsetst   height(   R
   t   layer(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   is_layer_inside_image'   s    *c         C` sT  |  } t  j | j | j | j  } t  j | t  j |   t  j | t  j |   | j t	 j
 k r t  j | t  j |   n  t  j |  \ } } xB | D]: } | j |  } | j t j | j | j | j   q W| j d k	 rt  j | | j  n t  j | | j  t j d k rPt  j |  } | rPt  j | |  qPn  | S(   u   
  Create a new image with metadata (dimensions, base type, parasites, etc.)
  copied from `image_to_copy_metadata_from`.
  
  Layers, channels or paths are not copied. For a full image copy, use
  `pdb.gimp_image_duplicate()`.
  i   i
   N(   i   i
   (   R   t   gimp_image_newR   R   t	   base_typet   gimp_image_set_resolutiont   gimp_image_get_resolutiont   gimp_image_set_unitt   gimp_image_get_unitt	   gimpenumst   INDEXEDt   gimp_image_set_colormapt   gimp_image_get_colormapt   gimp_image_get_parasite_listt   parasite_findt   parasite_attacht   gimpt   Parasitet   namet   flagst   datat   filenamet   Nonet   gimp_image_set_filenamet   versiont   gimp_image_get_metadatat   gimp_image_set_metadata(   t   image_to_copy_metadata_fromR
   t	   new_imaget   unused_t   parasite_namesR    t   parasitet   image_string_metadata(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   create_image_from_metadata2   s&    #c         C` s5   g  t  j   D]$ } t j | j  |  k r | ^ q S(   u   Returns a list of currently opened images in GIMP matching the given file
  path.
  
  Images are returned as `gimp.Image` instances.
  
  Matching is performed via the `gimp.Image.filename` attribute.
  (   R   t
   image_listt   pgutilst   safe_decode_gimpR#   (   t   image_filepathR
   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   find_images_by_filepathZ   s    	c         C` sv   t  |   } | rl | d k r: t | t |  d  } n% | d k  r_ t | t |   } n  | | } n d } | S(   u  Returns the currently opened image in GIMP matching the given file path.
  
  If no match is found, `None` is returned.
  
  The image is returned as `gimp.Image` instance.
  
  Matching is performed via the `gimp.Image.filename` attribute.
  
  For multiple matches, the first matching image is returned by default. There
  may be multiple opened images from the same file path, but there is no way to
  tell which image is the one the user desires to work with. To adjust which
  image to return, pass a custom `index` value indicating the position to
  return. If the index is out of bounds, the highest possible index is returned
  given a positive value and the lowest possible index given a negative value.
  i    i   N(   R4   t   mint   lent   maxR$   (   R3   t   indext   imagesR
   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   find_image_by_filepathh   s    c         ` sC   t  t d  r t j    St   f d   t j   D d  Sd S(   u   Returns a currently opened image in GIMP matching the given ID.
  
  If no match is found, `None` is returned.
  
  The image is returned as `gimp.Image` instance.
  
  Matching is performed via the `gimp.Image.ID` attribute.
  u	   _id2imagec         3` s$   |  ] } | j    k r | Vq d  S(   N(   t   ID(   t   .0R
   (   t   image_id(    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pys	   <genexpr>   s    N(   t   hasattrR   t	   _id2imaget   nextR0   R$   (   R=   (    (   R=   sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   find_image_by_id   s    	c         C` s   | j  t j  } t |  d k  r( d St | d t |  |   } | d k rT d St |  d k rj | S| } d } x: | d D]. } t | | j  } | d k r d S| } q W| S(   u  Returns a `gimp.Item` given the image, item class name and item path.
  
  The item class name corresponds to one of the GIMP item classes, e.g.
  `'Layer'` or `'Channel'`.
  
  The item path consists of the item name and all of its parent layer groups,
  separated by '/'. For example, if the item name is 'Left' its parent groups
  are 'Hands' (immediate parent) and 'Body (parent of 'Hands'), then the item
  path is 'Body/Hands/Left'.
  i   i    N(   t   splitR1   t   GIMP_ITEM_PATH_SEPARATORR6   R$   t   _find_item_by_name_in_childrent   _get_children_from_imaget   children(   R
   t   item_class_namet	   item_patht   item_path_componentst   matching_image_childt   parentt   matching_itemt   parent_or_item_name(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt!   get_item_from_image_and_item_path   s"    
c         C` s(   x! | D] } | j  |  k r | Sq Wd  S(   N(   R    R$   (   t	   item_nameRF   t   child(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyRD      s    c         C` ss   t  t |  } | t j t j f k r. |  j S| t j k rD |  j S| t j k rZ |  j St	 d j
 |    d  S(   NuE   invalid item type "{}"; must be Layer, GroupLayer, Channel or Vectors(   t   getattrR   t   Layert
   GroupLayert   layerst   Channelt   channelst   Vectorst   vectorst	   TypeErrort   format(   R
   RG   t	   item_type(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyRE      s    c         C` s   |  d k r d Sg  } | rZ |  j d k	 rS |  j j d k	 rS | j |  j j  qZ d Sn  t j |  j j d  } t |   } t j	 j
 d   | |  g D  } | j | | g  | S(   u   Returns item as a list of [item class name, item path] or [image file path,
  item class name, item path].
  
  Item class name and item path are described in
  `get_item_from_image_and_item_path()`.
  u   utf-8c         s` s!   |  ] } t  j | j  Vq d  S(   N(   R1   R2   R    (   R<   t   parent_or_item(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pys	   <genexpr>   s    N(   R$   R
   R#   t   appendR1   t   safe_decodet	   __class__t   __name__t   _get_item_parentsRC   t   joint   extend(   t   itemt   include_imaget   item_as_pathRG   t   parentsRH   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   get_item_as_path   s    !	c         C` s?   g  } |  j  } x) | d  k	 r: | j d |  | j  } q W| S(   Ni    (   RK   R$   t   insert(   Rd   Rg   t   current_parent(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyRa      s    	c         C` s(   x! |  j  D] } t j |  |  q
 Wd S(   u1   
  Remove all layers from the specified image.
  N(   RT   R   t   gimp_image_remove_layer(   R
   R   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   remove_all_layers   s    c         C` s(   x! |  j  D] } t j |  |  q
 Wd S(   u1   
  Remove all layers from the specified image.
  N(   RV   R   t   gimp_image_remove_channel(   R
   t   channel(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   remove_all_channels   s    c         C` s(   x! |  j  D] } t j |  |  q
 Wd S(   u:   
  Remove all paths (vectors) from the specified image.
  N(   RX   R   t   gimp_image_remove_vectors(   R
   t   path(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   remove_all_paths  s    c         C` s"   t  |   t |   t |   d S(   uJ   
  Remove all items (layers, channels, paths) from the specified image.
  N(   Rl   Ro   Rr   (   R
   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   remove_all_items  s    

c         C` s#   t  j |   r t  j |   n  d S(   u\   
  Delete the specified image. If the image does not exist, do not raise any
  exception.
  N(   R   t   gimp_image_is_validt   gimp_image_delete(   R
   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   try_delete_image  s    c         C` s   t  j |  t j j |    } | t | j  k s? | d k  rH d } n  t  j | j | |  } t j j |   | _ | r t j j	 | j  d | _ n  t  j
 | | d t | j   t  j |  | S(   uA  
  Load an image as a layer given its file path to an existing `image`. Return
  the layer.
  
  The layer is loaded at the end of the image.
  
  Layers names are basenames of the corresponding files. If
  `strip_file_extension` is `True`, remove the file extension from layer names.
  
  If the file contains multiple layers, specify the index of the desired layer
  to load. Only top-level layers are supported (i.e. not layers inside layer
  groups). If the index is greater than the number of layers in the loaded
  image or is negative, load and return the last layer.
  i    iN(   R   t   gimp_file_loadt   osRq   t   basenameR6   RT   t   gimp_layer_new_from_drawableR    t   splitextt   gimp_image_insert_layerR$   Ru   (   t   filepathR
   t   strip_file_extensiont   layer_to_load_indext   loaded_imageR   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt
   load_layer%  s    !	c         C` sb   | d k } | r' t j d d  } n  x |  D] } t | | |  q. W| r^ t j |  n  | S(   up  
  Load multiple layers to one image. Return the image.
  
  The layers are loaded at the end of the image.
  
  If `image` is `None`, create a new image. If `image` is not `None`, load the
  layers to the specified image.
  
  Layers names are basenames of the corresponding files. If
  `strip_file_extension` is `True`, remove the file extension from layer names.
  i   N(   R$   R   t   ImageR   R   t   gimp_image_resize_to_layers(   t	   filepathsR
   R~   t   create_new_imageR}   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   load_layersF  s    c         C` s   t  j |  |  } t  j | | | |  | r t  j | t  t | t j  s t j d k rr t  j	 | t  n  t  j
 | t  q n  | r t  j | t  n  | r t  j |  r t |  } n  | S(   u  
  Copy the specified layer into the specified image, parent layer group and
  position in the group. Return the copied layer.
  
  If `parent` is `None`, insert the layer in the main stack (outside of any
  layer group).
  
  If `remove_lock_attributes` is `True`, remove all lock-related attributes
  (lock position, alpha channel, etc.) for the layer copy.
  
  If `set_visible` is `True`, set the layer's visible state to `True`.
  
  If `merge_group` is `True` and the layer is a group, merge the group into a
  single layer.
  i   i
   (   i   i
   (   R   Rz   R|   t   gimp_item_set_lock_contentt   Falset
   isinstanceR   RS   R&   t   gimp_item_set_lock_positiont   gimp_layer_set_lock_alphat   gimp_item_set_visiblet   Truet   gimp_item_is_groupt   merge_layer_group(   R   R
   RK   t   positiont   remove_lock_attributest   set_visiblet   merge_groupt
   layer_copy(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   copy_and_paste_layer_  s    c         ` s  d d d  }   f d   } d   } d   } d       f d   }	 d    d	    t  f d
    d D  o t  f d    d D  }
 |
 s t St  f d    d D  } | r | r t St j d d t j  } | |   } t j |  | | | | |  t } x3 | j	 D]( } t j
 |  r/t } |	 |  q/q/W| |  } | r| r| rx@ | j	 D]5 } | j d k	 r| |  qt j | t j  qW| |  } n  t j |  | S(   uQ  
  Return `True` if the contents of all specified layers are identical, `False`
  otherwise. Layer groups are also supported.
  
  The default values of the optional parameters correspond to how the layers are
  displayed in the image canvas.
  
  If `compare_alpha_channels` is `True`, perform comparison of alpha channels.
  
  If `compare_has_alpha` is `True`, compare the presence of alpha channels in
  all layers - if some layers have alpha channels and others do not, then do not
  perform full comparison and return `False`.
  
  If `apply_layer_attributes` is `True`, take the layer attributes (opacity,
  mode) into consideration when comparing, otherwise ignore them.
  
  If `apply_layer_masks` is `True`, apply layer masks if they are enabled. If
  the masks are disabled or `apply_layer_masks` is `False`, layer masks are
  ignored.
  i    c         S` sp   t  j |   } t  j |  | | |  x' | D] } t | |  | d d t q, Wx | j D] } t | _ qY W| S(   Ni    R   (   R   t   gimp_layer_group_newR|   R   R   RF   t   visible(   R
   RT   RK   R   t   layer_groupR   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   _copy_layers  s    c         ` s   x | j  D] } t j |  r. t |  } q
 | j d k sO | j t j k r | rj   |  | |  } q d | _ t j | _ n  | j d  k	 r
 | r t j
 |  r t j | t j  q t j | t j  q
 q
 Wd  S(   Ng      Y@(   RF   R   R   R   t   opacityt   modeR   t   NORMAL_MODEt   maskR$   t   gimp_layer_get_apply_maskt   gimp_layer_remove_maskt
   MASK_APPLYt   MASK_DISCARD(   R
   R   t   apply_layer_attributest   apply_layer_masksR   (   t   _apply_layer_attributes(    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   _process_layers  s    !	c         S` s   t  j |  j d _ x |  j d D] } t | _ q! Wx |  j d D] } t | _ t j d	 k r~ t	 j
 |  t  j d
 d  } n t	 j |  t  j d d  } | d } | d k } | s t St | _ qB Wt S(   Ni    i   i   i
   i   g      ?i   g        (   i   i
   gp?(   R   t   DIFFERENCE_MODERF   R   R   R   R   R   R&   R   t   gimp_drawable_histogramt   HISTOGRAM_VALUEt   gimp_histogram(   R   R   t   histogram_datat
   percentilet	   identical(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   _is_identical  s     	
c         S` sF   t  j |  j  t  j |  t  } t  j |  t  j |  t j  d  S(   N(	   R   t   gimp_edit_copyR   t   gimp_edit_pasteR   t   gimp_floating_sel_anchorR   R   R   (   R   t   floating_sel(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   _set_mask_to_layer  s    c         S` sK   t  j |   } t  j |  | | d  t  j |  | | d  t |  } | S(   Ni    (   R   R   R|   t   gimp_image_reorder_itemR   (   R
   R   t   parent_groupt
   temp_group(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s
    c         ` s     |    |   d  S(   N(    (   R   (   t$   _extract_alpha_channel_to_layer_maskt   _remove_alpha_channel(    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt)   _prepare_for_comparison_of_alpha_channels  s    
c         S` s9   t  j |  t j  } t  j |  |  t  j |  t  d  S(   N(   R   t   gimp_layer_create_maskR   t   ADD_ALPHA_MASKt   gimp_layer_add_maskt   gimp_layer_set_apply_maskR   (   R   R   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s    c         S` s   t  j |   d  S(   N(   R   t   gimp_layer_flatten(   R   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s    c         3` s%   |  ] }   d  j  | j  k Vq d S(   i    N(   R   (   R<   R   (   RT   (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pys	   <genexpr>  s    i   c         3` s%   |  ] }   d  j  | j  k Vq d S(   i    N(   R   (   R<   R   (   RT   (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pys	   <genexpr>  s    c         3` s%   |  ] }   d  j  | j  k Vq d S(   i    N(   t   type(   R<   R   (   RT   (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pys	   <genexpr>  s    N(   R$   t   allR   R   R   R   t   RGBR   R   RF   t   gimp_drawable_has_alphaR   R   t   gimp_drawable_fillt
   WHITE_FILLRu   (   RT   t   compare_alpha_channelst   compare_has_alphaR   R   R   R   R   R   R   t   all_layers_have_same_sizet   all_layers_are_same_image_typeR
   R   t	   has_alphaR   R   (    (   R   R   R   RT   sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   compare_layers  sB    					   c      
   C` s@  t  j |   s* t d j |  j    n  |  j } t |   d } |  j d k	 r |  j t  j	 | |   f } t  j
 | |  d d  n  g  | j D] } | j ^ q } x | j D] } t | _ q Wt |  _ t  j | t j  } x) t | j |  D] \ } } | | _ q W| r6t  j
 | | | d | d  n  Wd QX| S(   u   
  Merge layers in the specified layer group belonging to the specified image
  into one layer.
  
  This function can handle both top-level and nested layer groups.
  u   "{}": not a layer groupi    i   N(    (   R   R   RY   RZ   R    R
   R   RK   R$   t   gimp_image_get_item_positionR   RT   R   R   R   t   gimp_image_merge_visible_layersR   t   EXPAND_AS_NECESSARYt   zip(   R   R
   t   orig_parent_and_posR   t   orig_layer_visibilityt   merged_layer_groupt   orig_visible(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s(    		!c         c` s7   t  j   } t  j |   z	 d VWd t  j |  Xd S(   u   
  Temporarily redirect GIMP messages to the specified message handler.
  
  Use this function as a context manager:
    
    with redirect_messages():
      # do stuff
  N(   R   t   gimp_message_get_handlert   gimp_message_set_handler(   t   message_handlert   orig_message_handler(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   redirect_messagesB  s
    
	t   GimpMessageFilec           B` sG   e  Z d  Z e j d d d  Z d   Z d   Z d   Z	 d   Z
 RS(   ue  
  This class provides a file-like way to write output as GIMP messages.
  
  You can use this class to redirect output or error output to the GIMP console.
  
  Parameters:
  
  * `message_handler` - Handler to which messages are output. Possible values
    are the same as for `pdb.gimp_message_get_handler()`.
  
  * `message_prefix` - If not `None`, prepend this string to each message.
  
  * `message_delay_milliseconds` - Delay in milliseconds before displaying the
    output. This is useful to aggregate multiple messages into one in order to
    avoid printing an excessive number of message headers.
  i    c         C` sU   | |  _  | d  k	 r! t |  n d |  _ | |  _ d |  _ d  |  _ |  j |  _ d  S(   Nu    i   (   t   _message_handlerR$   t   strt   _message_prefixt   _message_delay_millisecondst   _buffer_sizet   _orig_message_handlert   _message_buffer(   t   selfR   t   message_prefixt   message_delay_milliseconds(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   __init__g  s    	!			c         C` s<   t  j   |  _ t  j |  j  |  j |  |  j |  _ d  S(   N(   R   R   R   R   R   t   _writet   write(   R   R"   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR   v  s    c         C` s^   t  |  j  |  j k  r@ |  j | 7_ t j |  j |  j  n t j |  j  |  j   d  S(   N(   R6   R   R   t   pginvocationt   timeout_add_strictR   t   flusht   timeout_remove_strict(   R   R"   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s
    c         C` s)   t  j t j |  j   |  j |  _ d  S(   N(   R   t   messageR1   t   safe_encode_gimpR   R   (   R   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR     s    c         C` s&   |  j  d  k	 r" t j |  j   n  d  S(   N(   R   R$   R   R   (   R   (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   close  s    N(   R`   t
   __module__t   __doc__R   t   ERROR_CONSOLER$   R   R   R   R   R   (    (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyR   U  s   	
		c           C` s2   t  r
 d St j t j t j t j t j  a  d S(   u   
  Prevent the default progress bar in GIMP from updating by installing a dummy
  progress callback. Subsequent calls to this function without a matching call
  to `unsuppress_gimp_progress()` have no effect.
  N(   t   _dummy_progress_callbackR   t   progress_installR1   t
   empty_func(    (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   suppress_gimp_progress  s    c           C` s!   t  s
 d St j t   d a  d S(   u   
  Undo suppression of the default progress bar in GIMP caused by calling
  `suppress_gimp_progress()`. Calling this function before calling
  `suppress_gimp_progress()` has no effect.
  N(   R   R   t   progress_uninstallR$   (    (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   unsuppress_gimp_progress  s    c         C` s(   t  |  d  o' t  |  d  o' t |   S(   uP   
  Return `True` if the given function is a PDB procedure, `False` otherwise.
  u	   proc_nameu   params(   R>   t   callable(   t   function(    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   is_pdb_procedure  s    (2   R   t
   __future__R    R   R   R   t   future.builtinsRx   t
   contextlibR   R   R   t    R   R   R   R1   t   contextmanagerR   R   R/   R4   R:   RA   RN   RD   RE   R   Rh   Ra   Rl   Ro   Rr   Rs   Rv   R   R   R$   R   R   R   R   R   R   t   objectR   R   R   R   R   (    (    (    sJ   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/pdbutils.pyt   <module>   sR   "
		(			%			
						!	&	*?		                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   # -*- coding: utf-8 -*-

"""Interface for updating the progress of the work done so far."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *


class ProgressUpdater(object):
  """
  This class wraps the behavior of a progress bar used in GUIs.
  
  This class in particular can be used if no progress update is desired.
  
  To use this in the GUI for a progress bar, subclass this class and override
  the `_fill_progress_bar()` and `_set_text_progress_bar()` methods.
  
  Attributes:
  
  * `progress_bar` - Progress bar (GUI element).
  
  * `num_total_tasks` - Number of total tasks to complete.
  
  * `num_finished_tasks` (read-only) - Number of tasks finished so far.
  """
  
  def __init__(self, progress_bar, num_total_tasks=0):
    self.progress_bar = progress_bar
    self.num_total_tasks = num_total_tasks
    
    self._num_finished_tasks = 0
  
  @property
  def num_finished_tasks(self):
    return self._num_finished_tasks
  
  def update_tasks(self, num_tasks=1):
    """
    Advance the progress bar by a given number of tasks finished.
    
    Raises:
    
    * `ValueError` - Number of finished tasks exceeds the number of total tasks.
    """
    if self._num_finished_tasks + num_tasks > self.num_total_tasks:
      raise ValueError('number of finished tasks exceeds the number of total tasks')
    
    self._num_finished_tasks += num_tasks
    
    self._fill_progress_bar()
  
  def update_text(self, text):
    """
    Update text in the progress bar. Use `None` or an empty string to remove the
    text.
    """
    if text is None:
      text = ''
    self._set_text_progress_bar(text)
  
  def reset(self):
    """
    Empty the progress bar and remove its text.
    """
    self._num_finished_tasks = 0
    if self.num_total_tasks > 0:
      self._fill_progress_bar()
    self._set_text_progress_bar('')
  
  def _fill_progress_bar(self):
    """
    Fill in `num_finished_tasks`/`num_total_tasks` fraction of the progress bar.
    
    This is a method to be overridden by a subclass that implements a
    GUI-specific progress updater.
    """
    pass
  
  def _set_text_progress_bar(self, text):
    """
    Set the text of the progress bar.
    
    This is a method to be overridden by a subclass that implements a
    GUI-specific progress updater.
    """
    pass
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     