σ
dςτ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 e j	 d  d d l
 Z
 d d l Z d d l Z d d l Z d d l m Z d e
 j f d     YZ e j e  d S(	   u&   Widget for displaying inline messages.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0(   t	   pygimplibt   MessageLabelc           B` s   e  Z d  Z d Z d Z d Z d Z d Z d   Z e	 j
 d d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   uΦ   
  This class defines a widget to display a label, and optionally additional
  information in a popup below the label. The popup is also available if the
  label text does not fit the width of the parent widget.
  i   i   i   i  iΘ   c         C` s   t    j d t  d |  _ g  |  _ d  |  _ d  |  _ |  j   t	 j
 j |  j |  j  |  _ |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j |  j j   |  j j   g } x | D] } |  j j |  qβ Wd  S(   Nt   homogeneousu    u   size-allocateu   clickedu   showu   hide(   t   supert   __init__t   Falset   _label_textt   _popup_text_linest   Nonet   _message_typet   _clear_delayt	   _init_guit   pgt   guit   PopupHideContextt   _popup_moret   _button_moret   _popup_hide_contextt   _label_messaget   connectt   _on_label_message_size_allocatet   _on_button_more_clickedt   _on_popup_more_showt   _on_popup_more_hidet   _scrolled_window_moret   get_hscrollbart   get_vscrollbart,   exclude_widget_from_hiding_with_button_press(   t   selft5   wigets_to_exclude_from_hiding_popup_with_button_presst   widget(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR	   $   s     				
c         C` s   | s/ d |  _  g  |  _ |  j j |  j   d S| j   j d  } | d } | d j   | d } | j d  s | d 7} n  | |  _  | d |  _ | |  _ | |  _	 |  j j
 d j t j t j j |  j      | t j k r|  j |  j	 |  j  n |  j |  j	 |  j d  d S(   uH  
    Set the `text` of the label. The text is displayed in bold style.
    
    If the text is too wide to fit the label or the text has multiple lines,
    ellipsize the label and display a button that displays a popup containing
    the full text when clicked. Only the first line is displayed in the label.
    
    If `clear_delay` is not `None` and `message_type` is not
    `gtk.MESSAGE_ERROR`, make the message automatically disappear after the
    specified delay in milliseconds. The timer is stopped if the popup is
    displayed and restarted if the popup gets hidden.
    u    Nu   
i    i   u   .u	   <b>{}</b>(   R   R   R   t   set_textt   stript   splitt   uppert   endswithR   R   t
   set_markupt   formatt   gobjectt   markup_escape_textR   t   utilst   safe_encode_gtkt   gtkt   MESSAGE_ERRORt   _timeout_remove_strictt   _timeout_add_strictR   (   R!   t   textt   message_typet   clear_delayt   linest
   first_line(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR$   >   s&    		
				(c         C` s  t  j   |  _ |  j j d d  |  j j t j  t  j t d   |  _ |  j j	 t
  t  j   |  _ |  j j |  j  |  j j |  j d t
 d t
 |  j j t  j t  j t  j  d t d t t  j   |  _ |  j j t  j  |  j j |  j  |  j j   |  j j   |  j j t
  t  j   |  _ |  j j t  j  |  j j  |  j!  |  j j" |  j!  |  j j# t  t  j$   |  _% |  j% j& t  j' t  j(  |  j% j) t  j*  |  j% j |  j  t  j+ d t  j,  |  _- |  j- j. t  |  j- j/ t  j0 j1  |  j- j2 d |  j3  |  j- j |  j%  |  j- j   |  j- j   |  j |  j4  |  j |  j d t
 d t
 |  j |  j d t d t d  S(   Ng        g      ΰ?u   _Moret   expandt   fillt   typeu   width-request(5   R/   t   LabelR   t   set_alignmentt   set_ellipsizet   pangot   ELLIPSIZE_ENDt   _t   _label_button_moret   set_use_underlinet   Truet   HBoxt   _hbox_button_moret   set_spacingt$   _MORE_BUTTON_LABEL_AND_ARROW_SPACINGt
   pack_startt   Arrowt
   ARROW_DOWNt	   SHADOW_INR
   t   ButtonR   t
   set_relieft   RELIEF_NONEt   addt   show_allt   hidet   set_no_show_allt   TextViewt   _text_view_moret   set_wrap_modet	   WRAP_WORDt   set_left_margint   _TEXT_VIEW_MARGINt   set_right_margint   set_editablet   ScrolledWindowR   t
   set_policyt   POLICY_AUTOMATICt   POLICY_NEVERt   set_shadow_typet   SHADOW_ETCHED_INt   Windowt   WINDOW_POPUPR   t   set_resizablet   set_type_hintt   gdkt   WINDOW_TYPE_HINT_TOOLTIPt   set_propertyt   _POPUP_WIDTHt    _MESSAGE_AND_MORE_BUTTON_SPACING(   R!   (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR   e   sH    		%c         C` sZ   t  j j |  j  |  j   j k s9 t |  j  d k rI |  j j	   n |  j j
   d  S(   Ni   (   R   R   t   get_label_full_text_widthR   t   get_allocationt   widtht   lenR   R   t   showRQ   (   R!   t   labelt
   allocation(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR      s
    c         C` sΓ   t  |  j  } t j j |  j  |  j j   j k rL | j d |  j	  n  d j
 |  j   } t j   } | j t j j |   |  j j |  |  j j t j j |     |  j j   d  S(   Ni    u   
(   t   listR   R   R   Rj   R   Rk   Rl   t   insertR   t   joinR%   R/   t
   TextBufferR$   R-   R.   RT   t
   set_bufferR   t   movet   get_position_below_widgetRn   (   R!   t   buttonR6   R3   t   text_buffer(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR      s    c         C` sU   |  j  j   |  j j |  j j    |  j t j k rQ |  j	 |  j
 |  j  n  d  S(   N(   R   t&   connect_button_press_events_for_hidingR   t
   set_screenR   t
   get_screenR   R/   R0   R1   R   R$   (   R!   t   popup(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR   ͺ   s    c         C` s?   |  j  j   |  j t j k r; |  j |  j |  j d   n  d  S(   N(	   R   t)   disconnect_button_press_events_for_hidingR   R/   R0   R2   R   R$   R   (   R!   R}   (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR   ²   s    c         O` s2   |  j  |  r. t j j | | d  | |  n  d  S(   N(   t   _should_clear_text_after_delayR   t
   invocationt   timeout_add_strictR   (   R!   t   delayt   funct   argst   kwargs(    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR2   Έ   s    c         C` s&   |  j  |  r" t j j |  n  d  S(   N(   R   R   R   t   timeout_remove_strict(   R!   R   R   (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR1   Ό   s    c         C` sE   | d  k	 oD | d k oD t j d k oC d t j k oA d k  n S(   Ni    u   nti   i
   i   (   i   i
   i    (   i   i
   i   (   R   t   ost   namet   gimpt   version(   R!   R5   (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR   ΐ   s    N(   t   __name__t
   __module__t   __doc__Ri   RG   RX   Rh   t   _MAX_POPUP_HEIGHTR	   R/   R0   R   R$   R   R   R   R   R   R2   R1   R   (    (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyR      s    	'	-						(   R   t
   __future__R    R   R   R   t   future.builtinsR   t   pygtkt   requireR/   R+   R>   R   t   export_layersR   R   RD   R   t   type_register(    (    (    sI   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/message_label.pyt   <module>   s   "
²                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                # -*- coding: utf-8 -*-

"""Functions to display message dialogs."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import traceback

import pygtk
pygtk.require('2.0')
import gtk

from export_layers import pygimplib as pg

from export_layers import exceptions


def display_message(
      message,
      message_type,
      parent=None,
      buttons=gtk.BUTTONS_OK,
      message_in_text_view=False,
      button_response_id_to_focus=None,
      message_markup=False):
  return pg.gui.display_message(
    message,
    message_type,
    title=pg.config.PLUGIN_TITLE,
    parent=parent,
    buttons=buttons,
    message_in_text_view=message_in_text_view,
    button_response_id_to_focus=button_response_id_to_focus,
    message_markup=message_markup)


def display_failure_message(
      main_message, failure_message, details, parent=None, report_description=None,
      display_details_initially=False):
  if report_description is None:
    report_description = _(
      'If you believe this is an error in the plug-in, you can help fix it'
      ' by sending a report with the text in the details to one of the sites below')
  
  pg.gui.display_alert_message(
    title=pg.config.PLUGIN_TITLE,
    app_name=pg.config.PLUGIN_TITLE,
    parent=parent,
    message_type=gtk.MESSAGE_WARNING,
    message_markup=main_message,
    message_secondary_markup=failure_message,
    details=details,
    display_details_initially=display_details_initially,
    report_uri_list=pg.config.BUG_REPORT_URL_LIST,
    report_description=report_description,
    focus_on_button=True)


def display_processing_failure_message(exception, parent=None):
  display_failure_message(
    _('There was a problem during processing:'),
    failure_message=str(exception),
    details=traceback.format_exc(),
    parent=parent)


def display_invalid_image_failure_message(parent=None):
  display_failure_message(
    _('There was a problem during processing.'
      ' Do not close the image during processing,'
      ' keep it open until the processing is finished successfully.'),
    failure_message='',
    details=traceback.format_exc(),
    parent=parent)


def display_import_export_settings_failure_message(main_message, details, parent=None):
  display_failure_message(
    main_message,
    failure_message='',
    details=details,
    parent=parent,
    report_description=_(
      'If you believe this is an error in the plug-in, you can help fix it'
      ' by sending a report with the file and the text in the details to one of the sites below'))


def get_failing_action_message(action_and_item_or_action_error):
  if isinstance(action_and_item_or_action_error, exceptions.ActionError):
    action, item = action_and_item_or_action_error.action, action_and_item_or_action_error.item
  else:
    action, item = action_and_item_or_action_error
  
  if 'procedure' not in action.tags and 'constraint' not in action.tags:
    raise ValueError('an action must have the "procedure" or "constraint" tag')
  
  if item is not None:
    if 'procedure' in action.tags:
      message_template = _('Failed to apply procedure "{}" on "{}" because:')
    elif 'constraint' in action.tags:
      message_template = _('Failed to apply constraint "{}" on "{}" because:')
  
    return message_template.format(action['display_name'].value, item.orig_name)
  else:
    if 'procedure' in action.tags:
      message_template = _('Failed to apply procedure "{}" because:')
    elif 'constraint' in action.tags:
      message_template = _('Failed to apply constraint "{}" because:')
    
    return message_template.format(action['display_name'].value)
                                                                                                                                                                                                                                                                                                           