ó
âdc           @` sq   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 g Z d e f d	     YZ d S(
   u>   Class simplifying hiding a popup window based on user actions.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Ni   (   t   utilsu   PopupHideContextt   PopupHideContextc           B` sb   e  Z d  Z d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(   uç   
  This class provides a simplified interface for connecting events to hide the
  specified popup window. If the user presses a button outside the popup or
  focuses out of the widget that spawned the popup, the popup is hidden.
  c         C` st   | |  _  | |  _ | d k	 r$ | n	 |  j  j |  _ d |  _ d |  _ d |  _ t   |  _	 |  j j
 d |  j  d S(   u8  
    Parameters:
    
    * `popup_to_hide` - A `gtk.Window` instance representing a popup to hide.
    
    * `popup_owner_widget` - A `gtk.Widget` instance that spawned the popup.
    
    * `hide_callback` - A function to hide the popup. If `None`,
      `popup_to_hide.hide()` is used to hide the popup.
    u   focus-out-eventN(   t   _popup_to_hidet   _popup_owner_widgett   Nonet   hidet   _hide_callbackt   _button_press_emission_hook_idt   _toplevel_configure_event_idt   _toplevel_positiont   sett   _widgets_with_entered_pointerst   connectt&   _on_popup_owner_widget_focus_out_event(   t   selft   popup_to_hidet   popup_owner_widgett   hide_callback(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyt   __init__   s    		!				c         C` s   t  j |  j d |  j  |  _ t j |  j  } | d  k	 r| | j   j	 |  j
  | j d |  j  |  _ | j   |  _ n  d  S(   Nu   button-press-eventu   configure-event(   t   gobjectt   add_emission_hookR   t$   _on_emission_hook_button_press_eventR   t   utils_t   get_toplevel_windowR	   t	   get_groupt
   add_windowR   R   t   _on_toplevel_configure_eventR   t   get_positionR   (   R   t   toplevel(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyt&   connect_button_press_events_for_hiding0   s    c         C` s   |  j  d  k	 r+ t j |  j d |  j   n  t j |  j  } | d  k	 r |  j d  k	 r | j |  j  r | j	 |  j  d  |  _ n  d  S(   Nu   button-press-event(
   R   R	   R   t   remove_emission_hookR   R   R   R   t   handler_is_connectedt
   disconnect(   R   R!   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyt)   disconnect_button_press_events_for_hiding?   s    c         C` s*   | j  d |  j  | j  d |  j  d  S(   Nu   enter-notify-eventu   leave-notify-event(   R   t   _on_widget_enter_notify_eventt   _on_widget_leave_notify_event(   R   t   widget(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyt,   exclude_widget_from_hiding_with_button_pressM   s    c         C` s   |  j    d  S(   N(   R   (   R   R)   t   event(    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR   Q   s    c         C` s   |  j  r t S|  j   t Sd  S(   N(   R   t   TrueR   t   False(   R   R)   R+   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR   T   s    	
c         C` s5   |  j  | j   k r" |  j   n  | j   |  _  d  S(   N(   R   R    R   (   R   R!   R+   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR   [   s    c         C` s   |  j  j |  d  S(   N(   R   t   add(   R   R)   R+   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR'   a   s    c         C` s   |  j  j |  d  S(   N(   R   t   discard(   R   R)   R+   (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR(   d   s    N(   t   __name__t
   __module__t   __doc__R	   R   R"   R&   R*   R   R   R   R'   R(   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyR      s   							(   R2   t
   __future__R    R   R   R   t   future.builtinsR   t    R   R   t   __all__t   objectR   (    (    (    sX   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/gui/popup_hide_context.pyt   <module>   s   "
	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                # -*- coding: utf-8 -*-

"""GTK progress bar updater."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import pygtk
pygtk.require("2.0")
import gtk

from .. import progress as pgprogress

__all__ = [
  "GtkProgressUpdater",
]


class GtkProgressUpdater(pgprogress.ProgressUpdater):
  
  def _fill_progress_bar(self):
    self.progress_bar.set_fraction(self._num_finished_tasks / self.num_total_tasks)
    self._force_update()
  
  def _set_text_progress_bar(self, text):
    self.progress_bar.set_text(text)
    self._force_update()
  
  def _force_update(self):
    # This is necessary for the GTK progress bar to be updated properly.
    # See http://faq.pygtk.org/index.py?req=show&file=faq23.020.htp
    while gtk.events_pending():
      gtk.main_iteration()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               