σ
dςτdc           @` s«  d  Z  d d l m Z m Z m Z m Z e Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z y d d l Z Wn e k
 r e Z n Xe Z d d l Z e j d  d d l Z d d l Z d d l Z d d d d d	 d
 g Z d Z d d d e j e j e j Bd d d e d d e j e j e d  Z d   Z d   Z  d d e j! e d e d  Z" d a# d   a$ d d d  Z% d d d  Z& d   Z' d   Z( d   Z) d S(   uΈ  Widgets and functions to display GUI messages (particularly error messages),
imported before the rest of pygimplib is initialized.

This module contains:
* GTK exception dialog
* GTK generic message dialog
* wrapper for `sys.excepthook` that displays the GTK exception dialog when an
  unhandled exception is raised

This module should not be used directly. Use the `gui` package as the contents
of this module are included in the package.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNu   2.0u   display_alert_messageu   display_messageu   add_gui_excepthooku   set_gui_excepthooku   set_gui_excepthook_parentu&   set_gui_excepthook_additional_callbacki   c         C` sΦ  d t  j k p d t   k s* d   } n" t  j j d d  pI t   d } | d k rg | d  } n  | d k r d j | d   } n  | d k rΈ | d  j t j |   } n  |
 d k rΣ | d  }
 n  t j	 | d | d	 | } | j
 |  |  d k	 r| j |   n  | r-| j |  n  | rC| j |  n  | d k	 rFt j   } | j t  | j d
 | d  d  t j d t  } | j d  t |  } | j | d t d t |	 rt |	 |
 | d  |  } | j | d t d t n  | r| j t  n  | j |  | j j | d t d t n d } | j | |  | r| j |  } | d k	 r²| j |  q²n" | d k	 r²| r²| j |  n  | j   | j   } | j    | S(   uΜ  
  Display a message to alert the user about an error or an exception that
  occurred in the application.
  
  Parameters:
  
  * `title` - Message title.
  
  * `app_name` - Name of the application to use in the default contents of
    `message_secondary_markup`.
  
  * `parent` - Parent widget.
  
  * `message_type` - GTK message type (`gtk.MESSAGE_ERROR`, etc.).
  
  * `flags` - GTK dialog flags.
  
  * `message_markup` - Primary message text to display as markup.
  
  * `message_secondary_markup` - Secondary message text to display as markup.
  
  * `details` - Text to display in a box with details. If `None`, do not display
    any box.
  
  * `display_details_initially` - If `True`, display the details by default,
    otherwise hide them in an expander.
  
  * `report_uri_list` - List of (name, URL) pairs where the user can report
    the error. If no report list is desired, pass `None` or an empty sequence.
  
  * `report_description` - Text accompanying `report_uri_list`. If `None`, use
    default text. To suppress displaying the report description, pass an empty
    string.
  
  * `button_stock_id` - Stock ID of the button to close the dialog with.
  
  * `button_response_id` - Response ID of the button to close the dialog with.
  
  * `focus_on_button` - If `True`, focus on the button to close the dialog with.
    If `False`, focus on the box with details if `details` is not `None`,
    otherwise let the message dialog determine the focus widget.
  u   _c         S` s   |  S(   N(    (   t   str_(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   _s   s    u   Plug-inu)   <span font_size="large"><b>{0}</b></span>u   Oops. Something went wrong.uG   {0} encountered an unexpected error and has to close. Sorry about that!up   You can help fix this error by sending a report with the text in the details above to one of the following sitest   typet   flagsu   <b>u   Detailsu   </b>t   homogeneousi   t   expandt   fillu   (right-click to copy link)N(!   t   __builtin__t   __dict__t   globalst   gett   Nonet   formatt   gobjectt   markup_escape_textt   gtkt   MessageDialogt   set_transient_fort	   set_titlet
   set_markupt   format_secondary_markupt   Expandert   set_use_markupt   Truet	   set_labelt   VBoxt   Falset   set_spacingt   _get_details_windowt
   pack_startt&   _get_report_link_buttons_and_copy_icont   set_expandedt   addt   vboxt
   add_buttont   get_widget_for_responset	   set_focust   show_allt   runt   destroy(   t   titlet   app_namet   parentt   message_typeR   t   message_markupt   message_secondary_markupt   detailst   display_details_initiallyt   report_uri_listt   report_descriptiont   button_stock_idt   button_response_idt   focus_on_buttonR   t   dialogt   expandert   vbox_detailst   details_windowt   vbox_labels_reportt   buttont   response_id(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   display_alert_message8   sf    9"	

c         C` sέ   t  j   } | j t  j t  j  | j d d  | j t  j  t  j   } | j t	  | j
 t  j  | j t	  | j d  | j d  | j d  | j d  | j d  | j   j |   | j |  | S(   Ni  iΘ   i   i    i   (   R   t   ScrolledWindowt
   set_policyt   POLICY_AUTOMATICt   set_size_requestt   set_shadow_typet	   SHADOW_INt   TextViewt   set_editableR   t   set_wrap_modet	   WRAP_WORDt   set_cursor_visiblet   set_pixels_above_linest   set_pixels_below_linest   set_pixels_inside_wrapt   set_left_margint   set_right_margint
   get_buffert   set_textR$   (   t   details_textt   scrolled_windowt   exception_text_view(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyR    Ώ   s     c         ` s  |  s
 d  St j d t  } | rr| } t s? | d | 7} n  | d 7} t j |  } | j d d  | j d d  | j t	  | j
 t j  t j   } | j t j  | j t j | j t j t j    | j t d   | j d	   f d
    t j d t  } | j d  | j | d t	 d t	 | j | d t d t | j | d t d t n  g  }	 xF |  D]> \ }
 } t j | d |
 } | j d d  |	 j |  qWx' |	 D] } | j | d t d t qΘWt rx$ |	 D] } | j d	 d    qψWn  | S(   NR   u    u   :i    g      ΰ?i   i   u   Copy details to clipboardu   clickedc          ` s   t  j   j    S(   N(   R   t   clipboard_getRR   (   t   argst   kwargs(   R2   (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   <lambda>ο   t    R	   R
   t   labelc         S` s   t  j |  j    S(   N(   t
   webbrowsert   open_new_tabt   get_uri(   t
   linkbutton(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyRY     RZ   (   R   R   R   R   t   _webbrowser_module_foundt   Labelt   set_alignmentt   set_paddingt   set_line_wrapR   t   set_line_wrap_modet   pangoRJ   t   Buttont
   set_relieft   RELIEF_NONER$   t   image_new_from_pixbuft   render_icont
   STOCK_COPYt   ICON_SIZE_MENUt   set_tooltip_textR   t   connectt   HBoxR   R!   t
   LinkButtont   append(   R4   R5   t   label_report_text_instructionsR2   R%   t   label_report_textt   label_reportt   button_copy_to_clipboardt   hbox_label_report_and_copy_icont   report_linkbuttonst   namet   uriR_   (    (   R2   sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyR"   Υ   sN    
c      	   C` s  t  j d | d | d t  j t  j Bd |  } | j |  | d k	 rW | j |  n  | so t j |   }	 n |  }	 |	 j	 d d  }
 t
 |
  d k r―| j |
 d  | rt  j   } | j t  | j t  j  | j t  | j d  | j d  | j d  | j   j |
 d  t  j   } | j t  j t  j  | j d d	  | j t  j  | j |  | j   } | j | d
 t  d t  qΌ| j! |
 d  n | j |	  | d k	 rφ| j" |  } | d k	 rφ| j# |  qφn  | j$   | j%   } | j&   | S(   uk  
  Display a generic message.
  
  Parameters:
  
  * `message` - The message to display.
  
  * `message_type` - GTK message type (`gtk.MESSAGE_INFO`, etc.).
  
  * `title` - Message title.
  
  * `parent` - Parent GUI element.
  
  * `buttons` - Buttons to display in the dialog.
  
  * `message_in_text_view` - If `True`, display text the after the first newline
    character in a text view.
  
  * `button_response_id_to_focus` - Response ID of the button to set as the
    focus. If `None`, the dialog determines which widget gets the focus.
  
  * `message_markup` - If `True`, treat `message` as markup text.
  R.   R   R   t   buttonsu   
i   i    u   height-requestid   R	   R
   N('   R   R   t   DIALOG_MODALt   DIALOG_DESTROY_WITH_PARENTR   R   R   R   R   t   splitt   lenR   RG   RH   R   RI   RJ   RK   RL   RM   RN   RQ   RR   RA   RB   RC   t   set_propertyRE   RF   R$   t   get_message_areat   pack_endR   R   R'   R(   R)   R*   R+   (   t   messageR/   R,   R.   R{   t   message_in_text_viewt   button_response_id_to_focusR0   R9   t   processed_messaget   messagest	   text_viewRT   R%   R>   R?   (    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   display_message  sP     		

c          O` s   t  S(   N(   R   (   RW   RX   (    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyRY   e  RZ   c         ` s   | a      f d   } | S(   uY  
  Return a decorator that modifies `sys.excepthook` to display an error dialog
  for unhandled exceptions and terminates the application. `sys.excepthook` is
  restored after the decorated function is finished.
  
  The dialog will not be displayed for exceptions which are not subclasses of
  `Exception` (such as `SystemExit` or `KeyboardInterrupt`).
  
  Parameters:
  
  * `title` - Dialog title.
  
  * `report_uri_list` - List of (name, URL) tuples where the user can report
    the error. If no report list is desired, pass `None` or an empty sequence.
  
  * `parent` - Parent GUI element.
  c         ` s+   t  j         f d    } | S(   Nc         ` sG        f d   } t  j   | t  _  |  | |    t  _ d  S(   Nc      	   ` s#   t  |  | |     t   d  S(   N(   t   _gui_excepthook_generict   _gui_excepthook_parent(   t   exc_typet	   exc_valuet   exc_traceback(   R-   t   orig_sys_excepthookR4   R,   (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   _gui_excepthook  s    (   t   syst
   excepthook(   t   selfRW   RX   R   (   R-   t   funcR4   R,   (   R   sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   func_wrapper  s
    		(   t	   functoolst   wraps(   R   R   (   R-   R4   R,   (   R   sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   gui_excepthook~  s    '(   R   (   R,   R-   R4   R.   R   (    (   R-   R4   R,   sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   add_gui_excepthookh  s    c         ` s4   | a       f d   } t j  | t _ d S(   u#  
  Modify `sys.excepthook` to display an error dialog for unhandled exceptions.
  
  The dialog will not be displayed for exceptions which are not subclasses of
  `Exception` (such as `SystemExit` or `KeyboardInterrupt`).
  
  For information about parameters, see `add_gui_excepthook()`.
  c      	   ` s#   t  |  | |     t   d  S(   N(   R   R   (   R   R   R   (   R-   R   R4   R,   (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyR   §  s    N(   R   R   R   (   R,   R-   R4   R.   R   (    (   R-   R   R4   R,   sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   set_gui_excepthook  s    	c         C` s
   |  a  d S(   uέ   
  Set the parent GUI element to attach the exception dialog to when using
  `add_gui_excepthook()`. This function allows to modify the parent dynamically
  even after decorating a function with `add_gui_excepthook()`.
  N(   R   (   R.   (    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   set_gui_excepthook_parentΆ  s    c         C` s
   |  a  d S(   uU  
  Set a callback to be invoked at the beginning of exception handling. If the
  callback returns `True`, terminate exception handling at this point. Returning
  `True` consequently prevents the error dialog from being displayed and the
  application from being terminated.
  
  The callback takes the same parameters as `sys.excepthook`.
  N(   t#   _gui_excepthook_additional_callback(   t   callback(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt&   set_gui_excepthook_additional_callbackΑ  s    c   
      C` s±   t  |  | |  } | r d  S| |  | |  t |  t  r­ d j t j |  | |   }	 t d | d | d | d |	 d |  t j   d k r t j	   n  t
 j t  n  d  S(   Nu    R,   R-   R.   R2   R4   i    (   R   t
   issubclasst	   Exceptiont   joint	   tracebackt   format_exceptionR@   R   t
   main_levelt	   main_quitR   t   exitt   ERROR_EXIT_STATUS(
   R   R   R   R   R,   R-   R.   R4   t   callback_resultt   exception_message(    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyR   Ο  s"    	(*   t   __doc__t
   __future__R    R   R   R   t   unicodet   strR   R   R   R’   R\   t   ImportErrorR   R`   R   t   pygtkt   requireR   R   Rf   t   __all__R§   R   t   MESSAGE_ERRORR|   R}   t   STOCK_CLOSEt   RESPONSE_CLOSER@   R    R"   t
   BUTTONS_OKR   R   R   R   R   R   R   R   (    (    (    sO   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/pygimplib/_gui_messages.pyt   <module>   sh   "
	y		:P	2		                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             # -*- coding: utf-8 -*-

"""Functions related to directory manipulations, imported before the rest of
pygimplib is initialized.

This module should not be used directly. Use the `path` package as the contents
of this module are included in the package.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

str = unicode

import os

__all__ = [
  'make_dirs',
  'split_path',
]


# Taken from StackOverflow: http://stackoverflow.com/
# Question: http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python
# Answer:
# http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612
def make_dirs(dirpath):
  """
  Recursively create directories from the specified directory path.
  
  Do not raise exception if the directory path already exists.
  """
  try:
    os.makedirs(dirpath)
  except OSError as exc:
    if exc.errno == os.errno.EEXIST and os.path.isdir(dirpath):
      pass
    elif exc.errno == os.errno.EACCES and os.path.isdir(dirpath):
      # This can happen if `os.makedirs` is called on a root directory
      # in Windows (e.g. `os.makedirs('C:\\')`).
      pass
    else:
      raise


def split_path(path):
  """
  Split the specified path into separate path components.
  """
  path = os.path.normpath(path)
  path_components = []
  
  head = path
  while True:
    head, tail = os.path.split(head)
    if tail:
      path_components.insert(0, tail)
    else:
      if head:
        path_components.insert(0, head)
      break
  
  return path_components
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     