ó
âdc           @` sn   d  Z  d d l m Z m Z m Z m Z d d l Td d l Z d d l m	 Z
 d e
 j j f d     YZ d S(   u   Widget for placeholder GIMP objects (images, layers) such as "Current layer".

During processing, these placeholders are replaced with real objects.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *N(   t	   pygimplibt'   GimpObjectPlaceholdersComboBoxPresenterc           B` s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   uŜ   
  This class is a `setting.presenter.Presenter` subclass for
  `gimpui.IntComboBox` elements used for `placeholders.PlaceholderSetting`.
  
  Value: `placeholders.PlaceholderSetting` instance selected in the combo box.
  u   changedc         C` s^   g  } xB t  | j    D]. \ } } | j t j j | j  | f  q Wt j t	 |   S(   N(
   t	   enumeratet   get_allowed_placeholderst   extendt   pgt   utilst   safe_encode_gtkt   display_namet   gimpuit   IntComboBoxt   tuple(   t   selft   settingt   placeholder_names_and_valuest   indext   placeholder(    (    sH   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/placeholders.pyt   _create_gui_element   s
     c         C` s   |  j  j   |  j j   S(   N(   t   _settingt   get_allowed_placeholder_namest   _elementt
   get_active(   R   (    (    sH   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/placeholders.pyt
   _get_value#   s    c         C` s&   |  j  j |  j j   j |   d  S(   N(   R   t
   set_activeR   R   R   (   R   t   value(    (    sH   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/placeholders.pyt
   _set_value&   s    (   t   __name__t
   __module__t   __doc__t   _VALUE_CHANGED_SIGNALR   R   R   (    (    (    sH   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/placeholders.pyR      s
   			(   R!   t
   __future__R    R   R   R   t   future.builtinsR   t   export_layersR   R
   R   t   GtkPresenterR   (    (    (    sH   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/placeholders.pyt   <module>   s
   "
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    # -*- coding: utf-8 -*-

"""Base class for preview widgets."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import pygtk
pygtk.require('2.0')
import gtk


class Preview(gtk.VBox):
  
  def __init__(self):
    super().__init__(homogeneous=False)
    
    self._update_locked = False
    self._lock_keys = set()
    
    self._functions_to_invoke_at_update = []
  
  def update(self):
    """Updates the preview if update is not locked (see `lock_update()`)."""
    if self._update_locked:
      return True
    
    while self._functions_to_invoke_at_update:
      func, func_args, func_kwargs = self._functions_to_invoke_at_update.pop(0)
      func(*func_args, **func_kwargs)
    
    return False
  
  def lock_update(self, lock, key=None):
    """
    If `lock` is `True`, calling `update` will have no effect. Passing `False`
    to `lock` will enable updating the preview again.
    
    If `key` is specified to lock the update, the same key must be specified to
    unlock the preview. Multiple keys can be used to lock the preview; to unlock
    the preview, call this method with each of the keys.
    
    If `key` is specified and `lock` is `False` and the key was not used to lock
    the preview before, nothing happens.
    
    If `key` is `None`, lock/unlock the preview regardless of which function
    called this method. Passing `None` also removes previous keys that were used
    to lock the preview.
    """
    if key is None:
      self._lock_keys.clear()
      self._update_locked = lock
    else:
      if lock:
        self._lock_keys.add(key)
      else:
        if key in self._lock_keys:
          self._lock_keys.remove(key)
      
      self._update_locked = bool(self._lock_keys)
  
  def add_function_at_update(self, func, *func_args, **func_kwargs):
    """
    Add a function to a list of functions to invoke at the beginning of
    `update()`.
    
    The functions will be invoked in the order in which they were added and
    only if the preview is unlocked. This is useful to postpone invocation of
    functions until the preview is available again.
    """
    self._functions_to_invoke_at_update.append((func, func_args, func_kwargs))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 