ó
âdc           @` sz   d  Z  d d l m Z m Z m Z m Z d d l Td d l Z e j d  d d l	 Z	 d g Z
 d e f d     YZ d S(	   u;   Class providing drag-and-drop capability to any GTK widget.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0u   DragAndDropContextt   DragAndDropContextc           B` sĹ   e  Z d  Z d   Z d d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z e d
    Z d   Z e d    Z e d    Z d   Z e d    Z e d    Z RS(   uK   
  This class adds drag-and-drop capability to the specified GTK widget.
  c         C` s   |  j    |  _ d  |  _ d  S(   N(   t   _get_unique_drag_typet
   _drag_typet   Nonet   _last_widget_dest_drag(   t   self(    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyt   __init__   s    c         C` ső   | d k r d } n  | d k r* d	 } n  | j d |  j | |  | j t j j |  j d d f g t j j  | j d |  j	 | |  | j
 t j |  j d d f g t j j  | j d |  j |  | j d |  j  | j d |  j  d S(
   uŻ  
    Enable dragging for the specified `widget`.
    
    `get_drag_data_func` is a function that returns data as a string describing
    the dragged widget.
    
    `drag_data_receive_func` is a function that processes the data returned by
    `get_drag_data_func`.
    
    `get_drag_data_args` and `drag_data_receive_args` are optional arguments for
    `get_drag_data_func` and `drag_data_receive_func`, respectively.
    
    The displayed `widget` is used as the drag icon. If the item box is wrapped
    in a scrolled window, specify the `scrolled_window` instance so that the
    default drag icon is assigned if `widget` is partially hidden inside the
    scrolled window.
    u   drag-data-geti    u   drag-data-receivedu
   drag-beginu   drag-motionu   drag-failedN(    (    (   R   t   connectt   _on_widget_drag_data_gett   drag_source_sett   gtkt   gdkt   BUTTON1_MASKR   t   ACTION_MOVEt   _on_widget_drag_data_receivedt   drag_dest_sett   DEST_DEFAULT_ALLt   _on_widget_drag_begint   _on_widget_drag_motiont   _on_widget_drag_failed(   R
   t   widgett   get_drag_data_funct   drag_data_receive_funct   get_drag_data_argst   drag_data_receive_argst   scrolled_window(    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyt
   setup_drag   s,    		(%c         C` s"   t  d j |  j j t |     S(   Nu   {}_{}(   t   strt   formatt	   __class__t   __name__t   id(   R
   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   N   s    c         C` s    | j  | j d | |    d  S(   Ni   (   t   sett   target(   R
   R   t   drag_contextt   selection_datat   infot	   timestampR   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   Q   s    	c	   
      G` s   | | j  |	  d  S(   N(   t   data(
   R
   R   R'   t   drop_xt   drop_yR(   R)   R*   R   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   \   s    c         C` s8   |  j  | |  } | d  k	 r4 | j | d d  n  d  S(   Ni    (   t   _get_drag_icon_pixbufR   t   set_icon_pixbuf(   R
   R   R'   R   t   drag_icon_pixbuf(    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   i   s    c         C` s   | |  _  d  S(   N(   R	   (   R
   R   R'   R,   R-   R*   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   n   s    c         C` s,   |  j  d  k	 r( |  j  j   d  |  _  n  d  S(   N(   R	   R   t   drag_unhighlight(   R
   R   R'   t   result(    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR   r   s    c      	   C` sÜ   | j    d  k r d  S| d  k	 r5 |  j |  r5 d  S|  j |  x t j   r^ t j   qE W| j   } t j j	 t j j
 t d | j | j  } | j | j    | j   d d d d | j | j  } |  j |  | S(   Ni   i    (   t
   get_windowR   tC   _are_items_partially_hidden_because_of_visible_horizontal_scrollbart(   _setup_widget_to_add_border_to_drag_iconR   t   events_pendingt   main_iterationt   get_allocationR   t   Pixbuft   COLORSPACE_RGBt   Falset   widtht   heightt   get_from_drawablet   get_colormapt(   _restore_widget_after_creating_drag_icon(   R
   R   R   t   widget_allocationt   pixbufR0   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR.   w   s6    					c         C` s"   |  j    d  k	 o! |  j    j   S(   N(   t   get_hscrollbarR   t
   get_mapped(   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR4      s    c         C` s   |  j  |  |  j |  d  S(   N(   t   _remove_focus_outlinet   _add_border(   R
   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR5   Ł   s    c         C` s    |  j    r |  j t  n  d  S(   N(   t	   has_focust   set_can_focusR;   (   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyRE   §   s    c         C` s   |  j    d  S(   N(   t   drag_highlight(   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyRF   Ź   s    c         C` s   |  j  |  |  j |  d  S(   N(   t   _add_focus_outlinet   _remove_border(   R
   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR@   °   s    c         C` s   |  j  t  d  S(   N(   RH   t   True(   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyRJ   ´   s    c         C` s   |  j    d  S(   N(   R1   (   R   (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyRK   ¸   s    N(   R#   t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R.   t   staticmethodR4   R5   RE   RF   R@   RJ   RK   (    (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyR      s&   		-							%		(   RN   t
   __future__R    R   R   R   t   future.builtinst   pygtkt   requireR   t   __all__t   objectR   (    (    (    s[   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/drag_and_drop_context.pyt   <module>   s   "
	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           # -*- coding: utf-8 -*-

"""Widget containing a text label that can be optionally edited."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import pygtk
pygtk.require('2.0')
import gtk
import gobject

__all__ = [
  'EditableLabel',
]


class EditableLabel(gtk.VBox):
  """
  This class is a GTK widget that displays a label and an edit button to allow
  editing the label. Pressing `Enter` or focusing out of the editable text entry
  displays the label again.
  
  Signals:
  
  * `'changed'` - The user finished editing the label text.
  """
  
  _LABEL_EDIT_BUTTON_SPACING = 4
  
  __gsignals__ = {b'changed': (gobject.SIGNAL_RUN_FIRST, None, ())}
  
  def __init__(self, text=None, **kwargs):
    super().__init__(self, **kwargs)
    
    self._label = gtk.Label(text)
    self._label.set_alignment(0.0, 0.5)
    self._label.show_all()
    self._label.set_no_show_all(True)
    
    self._button_edit = gtk.Button()
    self._button_edit.set_relief(gtk.RELIEF_NONE)
    self._button_edit_icon = gtk.image_new_from_pixbuf(
      self._button_edit.render_icon(gtk.STOCK_EDIT, gtk.ICON_SIZE_MENU))
    self._button_edit.add(self._button_edit_icon)
    
    self._hbox = gtk.HBox(homogeneous=False)
    self._hbox.set_spacing(self._LABEL_EDIT_BUTTON_SPACING)
    self._hbox.pack_start(self._label, expand=True, fill=True)
    self._hbox.pack_start(self._button_edit, expand=False, fill=False)
    
    self._entry = gtk.Entry()
    self._entry.show_all()
    self._entry.set_no_show_all(True)
    
    self._entry.hide()
    
    self.pack_start(self._hbox, expand=False, fill=False)
    self.pack_start(self._entry, expand=False, fill=False)
    
    self._button_edit.connect('clicked', self._on_button_edit_clicked)
    self._entry.connect('activate', self._on_entry_finished_editing)
    self._entry.connect('focus-out-event', self._on_entry_finished_editing)
  
  @property
  def label(self):
    return self._label
  
  def _on_button_edit_clicked(self, button):
    self._hbox.hide()
    
    self._entry.set_text(self._label.get_text())
    self._entry.grab_focus()
    self._entry.set_position(-1)
    self._entry.show()
  
  def _on_entry_finished_editing(self, entry, *args):
    self._entry.hide()
    
    self._label.set_text(self._entry.get_text())
    self._hbox.show()
    
    self.emit('changed')


gobject.type_register(EditableLabel)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   