
ddc           @` 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 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 l Z d d l m Z d d l Z d d l Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m  Z  d d l m! Z! d d l m" Z# d d l m$ Z$ d d l m% Z& d d l' m Z( d d l' m) Z* d d l' m+ Z, d d l' m- Z. d d l' m/ Z0 d d l' m1 Z2 d d l' m3 Z4 e5 e j6 j7 d  r!e Z8 n e Z8 e9 e d  Z: e j; d    Z< d   Z= d   Z> d   Z? d   Z@ d   ZA d eB f d     YZC d  eB f d!     YZD d S("   u    Main module for the plug-in GUI.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   *Nu   2.0(   t   pdb(   t	   pygimplib(   t   actions(   t   batcher(   t   builtin_constraints(   t   builtin_procedures(   t
   exceptions(   t   renamer(   t   update(   t   utils(   t   message_label(   t   messages(   t   preview_image(   t   preview_name(   t   previews_controller(   t   progressu   jsonc      	   C` s  t  j d |  d t  j d t  j t  j Bd t  j  } | j |   | j t j	 j
  | j t j t d    | r t  j d t d  d t  } | j t  | j j | d	 t d
 t n  | j | j t  j   | j   | j   } | j   | r| j   n t } | | f S(   Nt   parentt   typet   flagst   buttonsu(   Are you sure you want to reset settings?t   labelu!   Remove procedures and constraintst   use_underlinet   expandt   fill(   t   gtkt   MessageDialogt   MESSAGE_WARNINGt   DIALOG_MODALt   DIALOG_DESTROY_WITH_PARENTt   BUTTONS_YES_NOt   set_transient_fort	   set_titlet   pgt   configt   PLUGIN_TITLEt
   set_markupt   gobjectt   markup_escape_textt   _t   CheckButtont   Falset
   set_activet   Truet   vboxt
   pack_startt	   set_focust   get_widget_for_responset   RESPONSE_NOt   show_allt   runt   destroyt
   get_active(   R   t   more_settings_shownt   dialogt   checkbutton_reset_actionst   response_idt   clear_actions(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   display_reset_prompt8   s(    			

c         c` s   |  t  j k } | r. | j   } | j   n  x t j   rJ t j   q1 Wz	 d  VWd  | rw | j |   | j   n  x t j   r t j   qz WXd  S(   N(	   t	   gimpenumst   RUN_INTERACTIVEt   get_positiont   hideR   t   events_pendingt   main_iterationt   movet   show(   t   run_modet   imaget   layert   output_filepatht   windowt   should_manipulate_windowt   window_position(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   handle_gui_in_exportV   s    	c         C` s"   |  d  k	 r |  j   t St Sd  S(   N(   t   Nonet   stopR/   R-   (   R   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   stop_batcherj   s    
c         ` s"   t  j      f d    } | S(   u'  
  This is a decorator for `Group.apply_gui_values_to_settings()` that prevents
  the decorated function from being invoked if there are invalid setting
  values. For the invalid values, an error message is displayed.
  
  This decorator is meant to be used in the `ExportLayersDialog` class.
  c         ` s)  y |  j  d j   |  j  d j   |  j  d j j   |  j  d j |  j  d j  |  j j |  j  d j |  j j	 <|  j j
 |  j  d j |  j j	 <|  j j d  k	 r |  j j j j	 g n g  |  j  d j |  j j	 <Wn9 t j j k
 r} |  j t |  t j | j  d  SX  |  | |  d  S(   Nu   mainu   guiu   gui/current_directoryu   main/output_directoryu   main/selected_layersu'   gui/name_preview_layers_collapsed_stateu"   gui/image_preview_displayed_layers(   t	   _settingst   apply_gui_values_to_settingst   guit   update_setting_valuet	   set_valuet   valuet   _name_previewt   selected_itemst   _imaget   IDt   collapsed_itemst   _image_previewt   itemRO   t   rawR%   t   settingt   SettingValueErrort   _display_inline_messaget   strR   t   MESSAGE_ERROR(   t   selft   argst   kwargst   e(   t   func(    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   func_wrapper{   s      E(   t	   functoolst   wraps(   Ri   Rj   (    (   Ri   s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   _set_settingsr   s    	c         C` sO   |  d j    t | | |  d j | j  } | sK | j |  d j  n  d S(   uJ  
  Set up the initial directory path for the current image according to the
  following priority list:
  
    1. Last export directory path of the current image
    2. Import directory path of the current image
    3. Last export directory path of any image (i.e. the current value of
       `'main/output_directory'`)
    4. The default directory path (default value) for `'main/output_directory'`
  
  Notes:
  
    Directory 3. is set upon loading `'main/output_directory'` from a persistent
    source.
    Directory 4. is set upon the instantiation of `'main/output_directory'`.
  u   gui/image_ids_and_directoriesu   main/output_directoryN(   t   update_image_ids_and_dirpathst   _update_directoryRW   R[   RV   (   t   settingst   current_directory_settingt   current_imaget   update_performed(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt6   _setup_image_ids_and_directories_and_initial_directory   s    c         C` s   | d k	 rA t | t  r0 t j j |  } n  |  j |  t S| j d k	 r| |  j t	 j
 j t j j | j    t St S(   u  
  Set the directory path to the setting according to the priority list below:
  
  1. `current_image_dirpath` if not `None`
  2. `current_image` - import path of the current image if not `None`
  
  If update was performed, return `True`, otherwise return `False`.
  N(   RO   t
   isinstancet   bytesR%   R   t   safe_decode_gimpRV   R/   t   filenamet   ost   patht   dirnameR-   (   R`   Rr   t   current_image_dirpath(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRo      s    	(c         C` s.   d   } |  d j  d | |  d | j  d  S(   Nc         S` s   | j  | |  j  d  S(   N(   t   update_dirpathRW   (   t   output_directoryt   image_ids_and_directoriest   current_image_id(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   on_output_directory_changed   s    u   main/output_directoryu   value-changedu   gui/image_ids_and_directories(   t   connect_eventR[   (   Rp   Rr   R   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   _setup_output_directory_changed   s    	
t   ExportLayersDialogc           B` s  e  Z d@ Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d Z d Z d Z d Z d Z d Z d Z d	 Z d
 Z d Z d Z dA d  Z e d    Z e d    Z e d    Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" e# d  Z$ dA d d  Z% e& d    Z' d   Z( e# d  Z) dA d  Z* d   Z+ d    Z, d!   Z- d"   Z. d#   Z/ e# d$  Z0 d%   Z1 d&   Z2 d'   Z3 e# d(  Z4 d)   Z5 d*   Z6 d+   Z7 d,   Z8 e& d-    Z9 d.   Z: e& d/    Z; d0   Z< d1   Z= d2   Z> d3   Z? d4   Z@ d5   ZA d6   ZB d7   ZC d8   ZD d9   ZE e# d:  ZF e# d;  ZG d<   ZH d=   ZI eJ jK dA d>  ZL d?   ZM RS(B   i  ib  i   i   i
   i   i   i   i   i(   id   i'  g      ?c      	   C` s*  | |  _  | |  _ |  j  j |  _ d  |  _ d  |  _ t j t	 j
 |  j |  j d |  j d d t j j |  j d j d  d |  j  |  _ t j d  d	 k r t j j   n  |  j   |  j   |  j   |  j   |  j   |  j   t j j |  j  | st j   n | |  |  j |  j  d  S(
   Nu   main/proceduresu   main/constraintst   overwrite_chooseru   main/overwrite_modeu   replacet	   item_treei   i   (   i   i   (    t   _initial_layer_treeRR   RH   RZ   RO   t   _message_settingt   _batchert   batcher_t   BatcherR?   t   RUN_NONINTERACTIVER%   t	   overwritet   NoninteractiveOverwriteChoosert   itemst   _batcher_for_previewst   gimpt   versiont   pdbutilst   suppress_gimp_progresst   _init_settingst   _init_gui_elementst   _assign_gui_to_settingst   _connect_eventst   _init_actionst   _finish_init_and_showRT   t&   set_gui_excepthook_additional_callbackt.   _display_inline_message_on_setting_value_errorR   t   maint   _dialog(   Re   t   initial_layer_treeRp   t   run_gui_func(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   __init__   s4    				
	





	
c         C` s   |  j  S(   N(   RX   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   name_preview  s    c         C` s   |  j  S(   N(   R]   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   image_preview  s    c         C` s   |  j  S(   N(   t   _folder_chooser(   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   folder_chooser#  s    c         C` s   |  j  d j j d  |  j  d j j d  |  j  j   } d j d   | j j   D  } t j j	 j
 | j j   k r t j | t j  n  t |  j  |  j  d |  j  t |  j  |  j  d  S(   Nu   main/proceduresu   ignore_loadu   main/constraintsu   

c         s` s   |  ] } | r | Vq d  S(   N(    (   t   .0t   message(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pys	   <genexpr>-  s    u   gui/current_directory(   RR   t   tagst   addt   loadt   joint   messages_per_sourcet   valuesR%   R`   t	   Persistort   FAILt   statuses_per_sourcet	   messages_t   display_messageR   R   Rt   RZ   R   (   Re   t   load_resultt   load_messages(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   '  s    c         C` s   |  j  d j j d  |  j  d j   } |  j  d | j k r] t j |  j  d d t n  |  j  d j j d  |  j  d j   } |  j  d | j k r t j |  j  d d t n  d  S(   Nu   main/proceduresu   ignore_loadt   add_initial_actionsu   main/constraints(   RR   R   t   discardR   t   settings_not_loadedR   t   clearR/   (   Re   t   result(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   5  s    c      	   C` s  t  j d t j j d t j j  |  _ |  j j   |  j j |  j	   |  j j
 |  j  |  j j t j  t j j |  j  t j   |  _ |  j j d t d  d  |  j j d d  t j d t j  |  _ t j d	 t  |  _ |  j j |  j  |  j j |  j d
 t d t d |  j |  j j |  j  |  j    t j   |  _! |  j! j d t d  d  |  j! j d d  t j"   |  _# |  j# j
 |  j$  |  j# j |  j!  t j%   |  _& |  j& j' |  j( d t) d t) |  j& j* |  j+ d t) d t) t j   |  _, |  j, j |  j# d
 t d t |  j, j |  j& d
 t) d t) t j-   |  _. |  j. j/ t j0  |  j. j1 |  j,  t j   |  _2 |  j2 j d j3 t4 j5 |  j6 d j7    |  j2 j d d  t j j8 d |  j9 d |  j:  |  _; |  j; j< t)  t j   |  _= |  j= j d j3 t4 j5 t d     |  j= j d d  t j d  |  _> |  j> j d d  t j j? t@ jA t@ jB  d |  jC d |  jD d |  j6 d jE |  _F |  jF j< t)  tG jH   |  _I t j" d	 t  |  _J |  jJ j |  j2 d
 t d t |  jJ j |  j= d
 t d t t j" d	 t  |  _K |  jK j |  jL  |  jK j |  jF d
 t d t |  jK j |  j> d
 t d t |  jK j |  j; d
 t d t t j" d	 t  |  _M |  jM j |  jN  |  jM j |  jJ d
 t d t |  jM j |  jK d
 t d t t j" d	 t  |  _O |  jO j |  jP  |  jO j
 |  jQ  |  jO j |  jM d
 t d t |  jO j |  jI d
 t) d t) tR jS |  j6 d tT jU t d  t d  d t d  |  _V tR jS |  j6 d tW jX t d  t d   d! t |  _Y t j" d	 t)  |  _Z |  jZ j |  j[  |  jZ j
 |  j\  |  jZ j |  jV d
 t) d t) |  jZ j |  jY d
 t) d t) tG jH   |  _] t j d	 t  |  _^ |  j^ j |  jZ d
 t) d t) |  j^ j |  j] d
 t d t t j   |  __ |  j_ j |  j  |  j_ j |  j d
 t) d t) |  j_ j |  jO d
 t d t t j%   |  _` |  j` j' |  j_ d t) d t |  j` j* |  j^ d t d t) t ja   |  _b |  jb j' |  j` d t) d t |  jb j* |  j. d t) d t) |  j jc t d"  t jd  |  _e |  je jf t jg  |  je jh   |  j jc t d#  t j  |  _i |  ji jh   |  j jj t jd t j g  t jk   |  _l |  jl jm t d$   |  jl jn t)  t j t d%   |  _o |  jo jp t)  t j"   |  _q |  jq j |  jo d
 t) d t) |  jq j t jr t js t jt  d
 t d t t jk   |  _u |  ju j1 |  jq  t jv t d&   |  _w t jv t d'   |  _x t jy t d(   |  _z t jy t d)   |  _{ t jy t d*   |  _| t jy t d+   |  _} t j~   |  _ |  j j |  jw  |  j j |  jx  |  j j |  jz  |  j j |  j{  |  j j |  j|  |  j j |  j}  |  j j   |  j j j |  jl d
 t d t |  j j j |  ju d
 t d t |  j j j |  ju t)  t r&t jk   |  _ |  j jm t d,   |  j j j |  j d
 t d t |  j j j |  j t)  n  t j   |  _ |  j j t j  |  j jn t)  t j"   |  _ |  j j |  jb d
 t) d t) |  j j
 |  j  |  j j j |  j  |  j j j |  j d
 t) d t) |  j j j |  j d
 t d t |  j j j |  j j d-  d  S(.   Nt   titlet   roleu   <b>u   Save in folder:u   </b>g        g      ?t   actiont   homogeneousR   R   t   paddingu   Previewt   resizet   shrinku
   <b>{}:</b>u   main/file_extensiont   minimum_width_charst   maximum_width_charsu   Save asu   .g      ?t   default_itemu   main/layer_filename_patternu   main/proceduresu   Add P_rocedure...u   Edit Proceduret   add_custom_action_textu   Add Custom Procedure...u   main/constraintsu   Add C_onstraint...u   Edit Constraintt   allow_custom_actionsu   _Exportu   _Cancelu   _Stopu	   _Settingsu   Show More Settingsu   Batch Editingu   Save Settingsu   Reset settingsu   Import Settings...u   Export Settings...u   _Helpi(   t   gimpuit   DialogR%   R&   R'   t   PLUGIN_NAMER   t   set_transientt   set_default_sizet   _DIALOG_SIZEt   set_border_widtht   _DIALOG_BORDER_WIDTHt   set_default_responseR   t   RESPONSE_CANCELRT   t   set_gui_excepthook_parentt   Labelt   _folder_chooser_labelR(   R+   t   set_alignmentt   FileChooserWidgett!   FILE_CHOOSER_ACTION_SELECT_FOLDERR   t   VBoxR-   t   _vbox_folder_choosert   set_spacingt   _DIALOG_VBOX_SPACINGR1   t   _SAVE_IN_FOLDER_LABEL_PADDINGt   _init_gui_previewst   _preview_labelt   HBoxt   _hbox_preview_labelt   _PREVIEW_LABEL_BORDER_WIDTHt   VPanedt   _vpaned_previewst   pack1RX   R/   t   pack2R]   t   _vbox_previewst   Framet   _frame_previewst   set_shadow_typet   SHADOW_ETCHED_OUTR   t   _file_extension_labelt   formatR)   R*   RR   t   display_namet   FileExtensionEntryt%   _FILE_EXTENSION_ENTRY_MIN_WIDTH_CHARSt%   _FILE_EXTENSION_ENTRY_MAX_WIDTH_CHARSt   _file_extension_entryt   set_activates_defaultt   _save_as_labelt
   _dot_labelt   FilenamePatternEntryt   renamer_t   get_field_descriptionst   FIELDSt'   _FILENAME_PATTERN_ENTRY_MIN_WIDTH_CHARSt'   _FILENAME_PATTERN_ENTRY_MAX_WIDTH_CHARSt   default_valuet   _filename_pattern_entryt   message_label_t   MessageLabelt   _label_messaget   _hbox_export_name_labelst   _hbox_export_name_entriest!   _HBOX_EXPORT_NAME_ENTRIES_SPACINGt   _hbox_export_namet    _HBOX_EXPORT_LABELS_NAME_SPACINGt   _hbox_export_name_and_messaget0   _HBOX_EXPORT_NAME_AND_MESSAGE_HORIZONTAL_SPACINGt*   _HBOX_EXPORT_NAME_AND_MESSAGE_BORDER_WIDTHt   actions_t	   ActionBoxR
   t   BUILTIN_PROCEDURESt   _box_proceduresR	   t   BUILTIN_CONSTRAINTSt   _box_constraintst   _hbox_actionst!   _MORE_SETTINGS_HORIZONTAL_SPACINGt   _MORE_SETTINGS_BORDER_WIDTHt   _label_message_for_edit_modet'   _vbox_actions_and_message_for_edit_modet   _vbox_chooser_and_settingst   _vpaned_chooser_and_actionst   HPanedt   _hpaned_settings_and_previewst
   add_buttont   RESPONSE_OKt   _button_runt	   set_flagst   CAN_DEFAULTRB   t   _button_closet   set_alternative_button_ordert   Buttont   _button_stopt	   set_labelt   set_no_show_allt   _label_button_settingst   set_use_underlinet   _hbox_button_settingst   Arrowt
   ARROW_DOWNt	   SHADOW_INt   _button_settingst   CheckMenuItemt   _menu_item_show_more_settingst   _menu_item_edit_modet   MenuItemt   _menu_item_save_settingst   _menu_item_reset_settingst   _menu_item_import_settingst   _menu_item_export_settingst   Menut   _menu_settingst   appendR5   t   action_areat   pack_endt   set_child_secondaryt   _webbrowser_module_foundt   _button_helpt   ProgressBart   _progress_bart   set_ellipsizet   pangot   ELLIPSIZE_MIDDLEt   _hbox_contentst   _DIALOG_CONTENTS_BORDER_WIDTHR0   t   reorder_child(   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   B  sD   '		

		(					
	

	
								!!	%"""""c         C` s8  |  j  j d |  j  |  j j d |  j d  |  j j d |  j  |  j j d |  j  t	 rz |  j
 j d |  j  n  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j  |  j j d |  j |  j d d  |  j j d	 |  j |  j d  |  j j d |  j |  j d
 d  |  j j d |  j   |  j j d |  j!  |  j j d |  j"  |  j# j d |  j$ j%  |  j& j d |  j$ j'  |  j$ j(   |  j$ j)   |  j* j d |  j+  |  j, j d |  j-  d  S(   Nu   action-box-item-addedu   clickedu
   processingu   toggledu   activateu   changedu   main/file_extensionu   invalid_file_extensionu   focus-out-eventu   main/layer_filename_patternu   invalid_layer_filename_patternu   key-press-eventu   delete-eventu   notify::is-activeu   notify::positionu   preview-updated(.   R	  t   connectt   _on_box_procedures_item_addedR  t   _on_button_run_clickedR  t   _on_button_close_clickedR  t   _on_button_stop_clickedR5  R6  t   _on_button_help_clickedR&  t   _on_button_settings_clickedR(  t(   _on_menu_item_show_more_settings_toggledR)  t   _on_menu_item_edit_mode_toggledR+  t   _on_save_settings_activateR,  t   _on_reset_settings_activateR-  t   _on_import_settings_activateR.  t   _on_export_settings_activateR   t   _on_text_entry_changedRR   t(   _on_file_extension_entry_focus_out_eventR   R   t   _on_dialog_key_press_eventt   _on_dialog_delete_eventt   _on_dialog_notify_is_activeR  t   _previews_controllert)   on_paned_outside_previews_notify_positionR   t)   on_paned_between_previews_notify_positiont#   connect_setting_changes_to_previewst   connect_name_preview_eventsR]   t   _on_image_preview_updatedRX   t   _on_name_preview_updated(   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR     sT    			
		
		c         C` s   x t  j   r t  j   q W|  j j j   |  j   |  j d t  |  j	 d j
 sm |  j j |  j  n  |  j j   |  j j d  |  j j   d  S(   Nt   update_name_previewu   main/edit_modei(   R   RC   RD   R   R0   R5   t   _show_hide_more_settingst   _update_gui_for_edit_modeR-   RR   RW   R2   R   R  t   grab_defaultt   set_positionRF   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   G  s    
c         C` s*  |  j  j i t j j j |  j g d 6t j j j |  j g d 6t j j j |  j	 g d 6t j j j |  j
 g d 6t j j j |  j j g d 6t j j j |  j g d 6t j j j |  j g d 6t j j j |  j g d 6t j j j |  j g d	 6t j j j |  j g d
 6t j j j |  j g d 6 d  S(   Nu   main/file_extensionu   main/layer_filename_patternu   main/edit_modeu   gui/show_more_settingsu"   gui/image_preview_automatic_updateu   gui/size/dialog_positionu   gui/size/dialog_sizeu(   gui/size/paned_outside_previews_positionu(   gui/size/paned_between_previews_positionu    gui/size/settings_vpane_positionu   gui/current_directory(   RR   t   initialize_guiR%   R`   t   SettingGuiTypest   extended_entryR   R   t   check_menu_itemR)  R(  R]   t   menu_item_update_automaticallyRM   R   t   window_sizet   paned_positionR  R   R  t   folder_chooser_widgetR   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   X  s    c      	   C` s   t  j |  j |  j |  j |  j d j |  j j |  j d j |  j j d |  j d  |  _ t	 j
 |  j |  j  |  _ t j |  j |  j |  j |  j  |  _ d  S(   Nu'   gui/name_preview_layers_collapsed_stateu   main/selected_layersu   selected_in_previewu   main/available_tags(   t   preview_name_t   NamePreviewR   RR   R   RW   RZ   R[   RX   t   preview_image_t   ImagePreviewR]   t   previews_controller_t   PreviewsControllerRQ  (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR   s  s    c   
      ` s  | d k s t  r4 t j j j t j j |  } n t j j j t j j |  } t j	 |  j
 d d t t j	 |  j
 d d t g  } x| |  j
 j d    D]e } | j d  k	 r t | j  d g k s | j d  j d  r | j j d	  | j |  q q W|  j   x | D] } | j j d	  qWt j |  j
 d
 d d i | d 6\ } } | t j k rt j t d j |   d | d |  j |  j   t j	 |  j
 d  t j	 |  j
 d  t Sg  }	 | s<x\ |  j
 d j d    D]> } | j d  j d  r| j j d  |	 j |  qqWn  |  j
 j i | d 6   x |	 D] } | j j d  q\Wt   f d   t j j  j! t j j  j" g D  rt j t d j |   d d j# d     j$ j%   D  d |  j t St& Sd  S(   Nu   pklu   main/proceduresR   u   main/constraintsc         S` s   d |  j  k S(   Nu   ignore_reset(   R   (   t   s(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   <lambda>  t    u   sessionu   rootu   gui/sizeu   ignore_resett   handle_invalidu   abortt   sourcesu
   persistentuL   Failed to import settings from file "{}". Settings must be reset completely.t   detailsR   u   guic         S` s   d |  j  k S(   Nu   ignore_load(   R   (   Rk  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRl    Rm  u   ignore_loadc         3` s$   |  ] } |   j  j   k Vq d  S(   N(   R   R   (   R   t   status(   R   (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pys	   <genexpr>  s   u(   Failed to import settings from file "{}"u   

c         s` s   |  ] } | r | Vq d  S(   N(    (   R   R   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pys	   <genexpr>  s    ('   t   _json_module_foundR%   R`   Ro  t   PickleFileSourceR&   t   SOURCE_NAMEt   JsonFileSourceR   R   RR   R-   t   walkt   setting_sourcesRO   t   listt   get_patht
   startswithR   R   R1  t   _reset_settingsR   R   t   ABORTR   t.   display_import_export_settings_failure_messageR+   R   R   R   t   anyR   t   SOURCE_NOT_FOUNDR   R   R   R   R/   (
   Re   t   filepatht   file_formatt   load_size_settingst   sourcet   settings_to_ignore_for_resetR`   Rq  R   t    size_settings_to_ignore_for_load(    (   R   s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   _load_settings  sX    !'
%	

 %
u   jsonc         C` s   | d  k r |  j j   } nk | d k s1 t rR t j j j t j j	 |  } n t j j j
 t j j	 |  } |  j j i | d 6 } t j j j | j j   k r t j t d j |   d d j d   | j j   D  d |  j t St Sd  S(   Nu   pklu
   persistentu&   Failed to export settings to file "{}"Rp  u   

c         s` s   |  ] } | r | Vq d  S(   N(    (   R   R   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pys	   <genexpr>  s    R   (   RO   RR   t   saveRr  R%   R`   Ro  Rs  R&   Rt  Ru  R   R   R   R   R   R}  R+   R   R   R   R   R-   R/   (   Re   R  R  t   save_resultR  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   _save_settings  s    !
c         C` s2   |  j    } | r. |  j t d  t j  n  d  S(   Nu   Settings successfully saved.(   R  Rb   R+   R   t   MESSAGE_INFO(   Re   t   save_successful(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt"   _save_settings_to_default_location  s    c         C` s   |  j  j   d  S(   N(   RR   t   reset(   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR{    s    c         C` s  | d k r- t  j } t  j } t d  } n9 | d k rZ t  j } t  j } t d  } n t d   t  j d | d |  j d |  } | j	 t
  | j | t  j t  j t  j  | j t  j t  j g  | d k rt  j t d	   } | j |  j  | j j | d
 t d t n d  } d } d }	 t rt  j   }
 |
 j t d  j |   |
 j d  | j |
  | } | d } n |	 } |	 d } t  j   } | j t d  j |	   | j d |	  | j |  t  j   } | j t d   | j d  | j |  | j   | j   } | t  j k rt  j! j" | j#    } t$ j% j& |  d } | r| r| j'   | k r| |	 7} q| | 7} n  t$ j% j& |  d } | r| d } q| } n d  } d  } | r| j(   } n t } | j)   | | | f S(   Nu   importu   Import Settingsu   exportu   Export Settingsu0   invalid action; valid values: "import", "export"R   R   R   u   Import size-related settingsR   R   u   .jsonu   .pklu   JSON file ({})u   application/jsoni   u   Pickle file ({})u   *u   Any file(*   R   t   FILE_CHOOSER_ACTION_OPENt
   STOCK_OPENR+   t   FILE_CHOOSER_ACTION_SAVEt
   STOCK_SAVEt
   ValueErrort   FileChooserDialogR   t   set_do_overwrite_confirmationR/   t   add_buttonsR  t   STOCK_CANCELR   R  R,   R   t,   _IMPORT_SETTINGS_CUSTOM_WIDGETS_BORDER_WIDTHR0   R1   R-   RO   Rr  t
   FileFiltert   set_nameR   t   add_mime_typet
   add_filtert   add_patternR5   R6   R%   R   t   safe_decode_gtkt   get_filenameRy   Rz   t   splitextt
   get_filterR8   R7   (   Re   R   t   add_file_extension_if_missingt   dialog_actiont	   button_okR   t   file_dialogt   check_button_load_size_settingst   json_file_extt   pickle_file_extt   filter_jsont   default_file_extt   default_file_formatt   filter_picklet
   filter_anyR<   R  t   file_extR  R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   _get_setting_filepath  s~    								


	
c         C` s   y | j  j   Wng t j j k
 rz } t j j |  j |  j j	 t
  |  j t |  t j |  |  j j t |  nh X|  j j t
 |  |  j | k r |  j d   n  |  j j |  j j	 t  t j j |  j |  j j  d  S(   N(   RT   RU   R%   R`   Ra   t
   invocationt   timeout_add_strictt4   _DELAY_NAME_PREVIEW_UPDATE_TEXT_ENTRIES_MILLISECONDSRX   t   set_sensitiveR-   Rb   Rc   R   Rd   t   lock_updateR/   R   RO   t   add_function_at_updateR   (   Re   t   entryR`   t   name_preview_lock_update_keyRh   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRL  5  s     			c         C` s   | j    d  S(   N(   t   apply_to_gui(   Re   R  t   eventR`   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRM  J  s    c         ` sI   t    f d   d d g D  rE t j |  j d   j j d  n  d  S(   Nc         3` s%   |  ] }   j  d  j | k Vq d S(   u	   orig_nameN(   R   RW   (   R   t   name(   R^   (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pys	   <genexpr>N  s   u   insert_background_layersu   insert_foreground_layersu   main/proceduresi    (   R~  R   t   reorderRR   R   R  (   Re   t   box_proceduresR^   (    (   R^   s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR@  M  s    c         C` s   |  j    d  S(   N(   RY  (   Re   t	   menu_item(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRF  R  s    c         C` s   |  j  j   rS |  j j   |  j j   |  j j   |  j j   |  j j   nU |  j	 d j
 t  |  j j   |  j j   |  j j   |  j j   |  j j   d  S(   Nu   main/edit_mode(   R(  R8   R  RF   R   RB   R   R   R   RR   RV   R-   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRY  U  s    c         C` s   |  j    d  S(   N(   RZ  (   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRG  g  s    c         C` s   |  j  j   rl |  j d j t  |  j j   |  j j   |  j	 j
 t d   |  j j
 t d   nF |  j j   |  j j   |  j	 j
 t d   |  j j
 t d   | r |  j j   n  d  S(   Nu   gui/show_more_settingsu   Runu   Closeu   Exportu   Cancel(   R)  R8   RR   RV   R/   R  RB   R  RF   R  R  R+   R  RX   R   (   Re   RX  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRZ  j  s    c         C` s@   t  j |  j  s  t j   d  S|  j d  k	 r< d  |  _ d  Sd  S(   N(   R   t   gimp_image_is_validRZ   R   t	   main_quitR   RO   (   Re   R:   t   property_spec(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRP  }  s    
	c         C` so   |  j    |  j d j rk | |  j k rk |  j d j t  |  j d j t d  t d   t	 j
  n  d  S(   Nu<   gui/image_preview_automatic_update_if_below_maximum_durationu"   gui/image_preview_automatic_updateu   {}

{}u#   Disabling automatic preview update.uu   The preview takes too long to update. You may turn automatic updates back on from the menu above the previewed image.(   t*   _display_warnings_and_tooltips_for_actionsRR   RW   t8   _MAXIMUM_IMAGE_PREVIEW_AUTOMATIC_UPDATE_DURATION_SECONDSRV   R-   Rb   R   R+   R   R  (   Re   t   previewt   errort   update_duration_seconds(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRV    s    

	c         C` s   |  j  d t  d  S(   Nt   clear_previous(   R  R-   (   Re   R  R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRW    s    c         C` sj   |  j  |  j d | |  j |  j |  j j t d  d | |  j |  j |  j j t d  d | d  S(   NR  u%   This procedure is skipped. Reason: {}u&   This constraint is skipped. Reason: {}(   t   _set_warning_on_actionsR   t   _set_action_skipped_tooltipsR	  t   skipped_proceduresR+   R  t   skipped_constraints(   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR    s    		c         C` s   t  j j | j  d k r. t |  j  } | S| j t  j   @t  j j k r t  j j t  j j	 | j   d k r |  j
   t St S(   Nu   Escapeu   s(   R   t   gdkt   keyval_namet   keyvalRQ   R   t   statet    accelerator_get_default_mod_maskt   CONTROL_MASKt   keyval_to_lowerR  R/   R-   (   Re   R:   R  t   stopped(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRN    s    '
c         C` s   t  j j |  j |  d  S(   N(   R%   RT   t   menu_popup_below_widgetR0  (   Re   t   button(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRE    s    c         C` s   |  j    d  S(   N(   R  (   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRH    s    c         C` so   |  j  d d  \ } } } | d  k	 rk |  j | | |  } |  j   | rk |  j t d  t j  qk n  d  S(   NR   u   importu   Settings successfully imported.(   R  RO   R  R  Rb   R+   R   R  (   Re   R  R  R  R  t   import_successful(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRJ    s    
c         C` sb   |  j  d d  \ } } } | d  k	 r^ |  j | |  } | r^ |  j t d  t j  q^ n  d  S(   NR   u   exportu   Settings successfully exported.(   R  RO   R  Rb   R+   R   R  (   Re   R  R  R  t   unused_t   export_successful(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRK    s
    c         C` s  t  d |  j d |  j d j  \ } } | t j k r| rh t j |  j d  t j |  j d  n. |  j d j j	 d  |  j d j j	 d  |  j
   |  j   | r t j |  j  n. |  j d j j d  |  j d j j d  |  j t d  t j  n  d  S(   NR   R9   u   gui/show_more_settingsu   main/proceduresu   main/constraintsu   ignore_resetu   Settings reset.(   R>   R   RR   RW   R   t   RESPONSE_YESR   R   R   R   R{  R  t   utils_t   clear_setting_sourcest   removeRb   R+   R  (   Re   R  R<   R=   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRI    s     	

c         C` s  |  j    |  j   \ |  _ } } t j |  j |  } | j |  j  t } |  j	 j
 t |  |  j j
 t |  zy$ |  j j t j |  j d    Wn t j k
 r } t } nOt j k
 r
} t j t j |  d t |  d t j   d |  j t } n t j k
 r;} t j | d |  j t } n t k
 rx} t j |  j   rb  qt j! d |  j  n X|  j d j" t  |  j d j#   |  j d j$ s|  j j% rt } n  |  j d j$ r|  j j% rt j& t' d  t( j) d |  j n  Wd  | j*   |  j	 j
 t |  |  j j
 t |  |  j d j$ rn|  j j+   |  j	 j+ d t  n  |  j, |  j  d  |  _ X| j. |  j d	 j/ j0   k r|  j d	 j" | j.  n  |  j d j# d
 g  |  j d j# d
 g  | rt( j1   n |  j2   | j3   d  S(   Nu   maint   failure_messageRp  R   u   special/first_plugin_runu   main/edit_modeu   No layers were exported.t   reset_itemsu   main/overwrite_modeu   sessionu   gui(4   t   _setup_gui_before_batch_runt   _setup_batcherR   t	   progress_t   ItemProgressIndicatorR8  t   install_progress_for_statust#   _progress_set_value_and_show_dialogR/   RX   R  R]   R6   R  t   get_settings_for_batcherRR   R   t   BatcherCancelErrorR-   t   ActionErrorR   t   display_failure_messaget   get_failing_action_messageRc   t	   tracebackt
   format_excR   t   BatcherErrort"   display_processing_failure_messaget	   ExceptionR   R  RZ   t%   display_invalid_image_failure_messageRV   R  RW   t   exported_raw_itemsR   R+   R   R  t   uninstall_progress_for_statusR   R  RO   t   overwrite_modeR   R   R  t   _restore_gui_after_batch_runR  (   Re   R  t   lock_update_keyR   t   progress_updatert   item_progress_indicatort   should_quitRh   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRA    sf    

 $	
			#


c         C` s2   |  j  d   |  j   |  j   |  j t  d  S(   N(   Rb   RO   t%   _reset_action_tooltips_and_indicatorst   _close_action_edit_dialogst   _set_gui_enabledR-   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  +  s    

c         C` s   |  j  t  d  S(   N(   R  R/   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  1  s    c         C` s   t  j j |  j   d |  j d j d d t  j j j d t  j	 j
 d |  j } t  j j |  j  } t j t j |  j |  j d |  j d d	 | d
 | d t d |  j g } | | | f S(   NR   u   main/overwrite_modeu   replacet   default_responseR   R   u   main/proceduresu   main/constraintsR   R  t   export_context_managert   export_context_manager_args(   R%   RT   t   GtkDialogOverwriteChoosert   _get_overwrite_dialog_itemsRR   R   R   t   OverwriteModest   CANCELR&   R'   R   t   GtkProgressUpdaterR8  R   R   R?   R@   RZ   RN   (   Re   R   R  R   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  4  s"    	
c         C` s3   t  t |  j d j j   |  j d j j     S(   Nu   main/overwrite_mode(   Rx  t   zipRR   R   R   t   items_display_names(   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  J  s    c         C` s   |  j  j |  |  j j |  |  j j |  x? |  j j D]1 } | |  j j |  j  f k r? | j |  q? q? W|  j j |  x3 |  j j D]% } | |  j k r | j |  q q W| r |  j j	 |  j
  |  j
 j d  n |  j j	 |  j  d  S(   Ni(   R8  t   set_visibleR  R  R   R0   R2  R  R&  R2   R   R\  (   Re   t   enabledt   childR  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  O  s    c         C` sP   |  j  j |  |  j j   s/ |  j j   n  x t j   rK t j   q2 Wd  S(   N(   R8  t   set_fractionR   t
   get_mappedRF   R   RC   RD   (   Re   t   fraction(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR  d  s
    c         C` s   t  j   d  S(   N(   R   R  (   Re   R:   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRO  o  s    c         C` s   t  j   d  S(   N(   R   R  (   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRB  r  s    c         C` s   t  |  j  d  S(   N(   RQ   R   (   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRC  u  s    c         C` sD   t  j j t j j  r' t j j } n t j j } t j |  d  S(   N(	   Ry   Rz   t   isfileR%   R&   t   LOCAL_DOCS_PATHt   DOCS_URLt
   webbrowsert   open_new_tab(   Re   R  t   docs_url(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRD  x  s    c         C` s   xy | j  D]n } | j   s
 | j j | k r_ | | j j d d } | j | j |   qx | rx | j d   qx q
 q
 Wd  S(   Ni    i   (   R   t   has_warningR   R  t   set_tooltipR   RO   (   Re   t
   action_boxt   skipped_actionsR   R  t   box_itemt   skipped_message(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR    s    c      	   C` s   |  j  |  j g } | j | j g } x t | |  D] \ } } x | j D] } | j j | k r | j t	 t
 j | j | | j j d d f  | | j j d d | | j j d d d |  j qJ | rJ | j t  qJ qJ Wq4 Wd  S(   Ni    i   i   R   (   R	  R  t   failed_procedurest   failed_constraintsR  R   R   R  t   set_warningR/   R   R  R   R-   (   Re   R   R  t   action_boxest   failed_actions_dictR  t   failed_actionsR  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR    s    !c         C` sO   xH |  j  |  j g D]4 } x+ | j D]  } | j d   | j t  q# Wq Wd  S(   N(   R	  R  R   R  RO   R  R-   (   Re   R  R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR    s    c         C` s?   x8 |  j  |  j g D]$ } x | j D] } | j   q# Wq Wd  S(   N(   R	  R  R   t   close_edit_dialog(   Re   R  R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR    s    c         C` sH   | |  _  |  j d j r% |  j } n	 |  j } | j | | |  j  d  S(   Nu   main/edit_mode(   R   RR   RW   R  R   t   set_textt'   _DELAY_CLEAR_LABEL_MESSAGE_MILLISECONDS(   Re   t   textt   message_typeR`   t   label_message(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRb     s
    		c         C` s:   t  | t j j  r2 |  j t |  t j  t St	 Sd  S(   N(
   t
   issubclassR%   R`   Ra   Rb   Rc   R   Rd   R/   R-   (   Re   t   exc_typet	   exc_valuet   exc_traceback(    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR     s    (   i  ib  N(N   t   __name__t
   __module__R   R   R=  R   R   R   R  R   R  R  R  R  R  R   R   R   R   R  R  R  RO   R   t   propertyR   R   R   R   R   R   R   R   R   R   R/   R  R  Rm   R  R{  R  RL  RM  R@  RF  RY  RG  RZ  RP  RV  RW  R  RN  RE  RH  RJ  RK  RI  RA  R  R  R  R  R  R  RO  RB  RC  RD  R  R  R  R  R   Rd   Rb   R   (    (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR      s   %				5			:	Z															D										
		
t   ExportLayersRepeatDialogc           B` sY   e  Z d  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(	   i   i  c         C` s|   | |  _  | |  _ |  j  j |  _ d  |  _ |  j j d g  |  j   t j	 j
 |  j  t j   |  j   |  j   d  S(   Nu   session(   t   _layer_treeRR   RH   RZ   RO   R   R   t	   _init_guiR%   RT   R   R   R   RD   RF   t   run_batcher(   Re   t
   layer_treeRp   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR     s    			


c         C` s  t  j d t j j d d   |  _ |  j j   |  j j |  j	  |  j j
 |  j d  t j   |  _ |  j j t d   t j   |  _ |  j j |  j d t d t t j   |  _ |  j j t j  t j d t  |  _ |  j j |  j  |  j j |  j d t d t |  j j |  j d t d t |  j j  j |  j d t d t |  j j! d |  j"  |  j j! d	 |  j#  d  S(
   NR   R   iu   _StopR   R   R   u   clickedu   delete-event($   R   R   R%   R&   R'   RO   R   R   R   t   _BORDER_WIDTHR   t   _DIALOG_WIDTHR   R  R  R  R+   t
   HButtonBoxt
   _buttonboxR1   R-   R7  R8  R9  R:  R;  R   t   _hbox_action_areaR   t   _HBOX_HORIZONTAL_SPACINGR/   R3  R0   R?  RC  RO  (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR*    s"    !"c         C` s  t  j j |  j  } t j |  j |  } | j   t j t	 j
 |  j |  j d |  j d d t  j j |  j d j  d | d t d |  j g |  _ z y- |  j j d |  j t j |  j d	   Wn| t j k
 r n t j k
 r} t j | d
 |  j n t k
 rE} t j |  j  r/  qt j d
 |  j  nD X|  j d j r|  j j  rt j! t" d  t# j$ d
 |  j n  Wd  | j%   Xd  S(   Nu   main/proceduresu   main/constraintsR   u   main/overwrite_modeR  R  R  R   u   mainR   u   main/edit_modeu   No layers were exported.(&   R%   RT   R   R8  R  R  R  R   R   R?   t   RUN_WITH_LAST_VALSRZ   RR   R   R   RW   RN   R   R   R6   R)  R  R  R   R  R  R   R  R  R   R  R  R  R   R+   R   R  R  (   Re   R  R  Rh   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR+    s>    

	 #c         C` s1   |  j  j j   |  j  j j   |  j  j   d  S(   N(   R   R0   R5   R2  RB   RF   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRF     s    c         C` s   |  j  j   d  S(   N(   R   RB   (   Re   (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRB     s    c         C` s   t  |  j  d  S(   N(   RQ   R   (   Re   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRC    s    c         C` s   t  |  j  d  S(   N(   RQ   R   (   Re   R:   R  (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyRO    s    (   R%  R&  R-  R2  R.  R   R*  R+  RF   RB   RC  RO  (    (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyR(    s   			$			(E   t   __doc__t
   __future__R    R   R   R   t   future.builtinst
   contextlibRk   Ry   R  R  t   ImportErrorR-   R5  R/   t   pygtkt   requireR   R)   R:  R   R   R?   R   t   export_layersR   R%   R   R   R   R	   R
   R   R   R   R   R   R  t   export_layers.guiR  R   R   R   R   R   Rg  R   Re  R   Ri  R   R  t   hasattrR`   Ro  Rr  RO   R>   t   contextmanagerRN   RQ   Rm   Rt   Ro   R   t   objectR   R(  (    (    (    s@   /home/josie/.config/GIMP/2.10/plug-ins/export_layers/gui/main.pyt   <module>   sf   "

			#			                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             # -*- coding: utf-8 -*-

"""Widget for displaying inline messages."""

from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *

import os

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pango

import gimp

from export_layers import pygimplib as pg


class MessageLabel(gtk.HBox):
  """
  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.
  """
  
  _MESSAGE_AND_MORE_BUTTON_SPACING = 2
  _MORE_BUTTON_LABEL_AND_ARROW_SPACING = 5
  
  _TEXT_VIEW_MARGIN = 3
  
  _POPUP_WIDTH = 400
  _MAX_POPUP_HEIGHT = 200
  
  def __init__(self):
    super().__init__(homogeneous=False)
    
    self._label_text = ''
    self._popup_text_lines = []
    self._message_type = None
    self._clear_delay = None
    
    self._init_gui()
    
    self._popup_hide_context = pg.gui.PopupHideContext(self._popup_more, self._button_more)
    
    self._label_message.connect('size-allocate', self._on_label_message_size_allocate)
    self._button_more.connect('clicked', self._on_button_more_clicked)
    
    self._popup_more.connect('show', self._on_popup_more_show)
    self._popup_more.connect('hide', self._on_popup_more_hide)
    
    wigets_to_exclude_from_hiding_popup_with_button_press = [
      self._popup_more,
      self._scrolled_window_more.get_hscrollbar(),
      self._scrolled_window_more.get_vscrollbar()]
    
    for widget in wigets_to_exclude_from_hiding_popup_with_button_press:
      self._popup_hide_context.exclude_widget_from_hiding_with_button_press(widget)
  
  def set_text(self, text, message_type=gtk.MESSAGE_ERROR, clear_delay=None):
    """
    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.
    """
    if not text:
      self._label_text = ''
      self._popup_text_lines = []
      self._label_message.set_text(self._label_text)
      return
    
    lines = text.strip().split('\n')
    
    first_line = lines[0]
    first_line = first_line[0].upper() + first_line[1:]
    if not first_line.endswith('.'):
      first_line += '.'
    
    self._label_text = first_line
    self._popup_text_lines = lines[1:]
    self._message_type = message_type
    self._clear_delay = clear_delay
    
    self._label_message.set_markup(
      '<b>{}</b>'.format(gobject.markup_escape_text(pg.utils.safe_encode_gtk(self._label_text))))
    
    if message_type == gtk.MESSAGE_ERROR:
      self._timeout_remove_strict(self._clear_delay, self.set_text)
    else:
      self._timeout_add_strict(self._clear_delay, self.set_text, None)
  
  def _init_gui(self):
    self._label_message = gtk.Label()
    self._label_message.set_alignment(0.0, 0.5)
    self._label_message.set_ellipsize(pango.ELLIPSIZE_END)
    
    self._label_button_more = gtk.Label(_('_More'))
    self._label_button_more.set_use_underline(True)
    
    self._hbox_button_more = gtk.HBox()
    self._hbox_button_more.set_spacing(self._MORE_BUTTON_LABEL_AND_ARROW_SPACING)
    self._hbox_button_more.pack_start(
      self._label_button_more, expand=True, fill=True)
    self._hbox_button_more.pack_start(
      gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_IN), expand=False, fill=False)
    
    self._button_more = gtk.Button()
    self._button_more.set_relief(gtk.RELIEF_NONE)
    self._button_more.add(self._hbox_button_more)
    self._button_more.show_all()
    self._button_more.hide()
    self._button_more.set_no_show_all(True)
    
    self._text_view_more = gtk.TextView()
    self._text_view_more.set_wrap_mode(gtk.WRAP_WORD)
    self._text_view_more.set_left_margin(self._TEXT_VIEW_MARGIN)
    self._text_view_more.set_right_margin(self._TEXT_VIEW_MARGIN)
    self._text_view_more.set_editable(False)
    
    self._scrolled_window_more = gtk.ScrolledWindow()
    self._scrolled_window_more.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER)
    self._scrolled_window_more.set_shadow_type(gtk.SHADOW_ETCHED_IN)
    self._scrolled_window_more.add(self._text_view_more)
    
    self._popup_more = gtk.Window(type=gtk.WINDOW_POPUP)
    self._popup_more.set_resizable(False)
    self._popup_more.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_TOOLTIP)
    self._popup_more.set_property('width-request', self._POPUP_WIDTH)
    self._popup_more.add(self._scrolled_window_more)
    self._popup_more.show_all()
    self._popup_more.hide()
    
    self.set_spacing(self._MESSAGE_AND_MORE_BUTTON_SPACING)
    self.pack_start(self._label_message, expand=True, fill=True)
    self.pack_start(self._button_more, expand=False, fill=False)
  
  def _on_label_message_size_allocate(self, label, allocation):
    if ((pg.gui.get_label_full_text_width(self._label_message)
         > self.get_allocation().width)
        or len(self._popup_text_lines) >= 1):
      self._button_more.show()
    else:
      self._button_more.hide()
  
  def _on_button_more_clicked(self, button):
    lines = list(self._popup_text_lines)
    
    if (pg.gui.get_label_full_text_width(self._label_message)
        > self._label_message.get_allocation().width):
      lines.insert(0, self._label_text)
    
    text = '\n'.join(lines).strip()
    
    text_buffer = gtk.TextBuffer()
    text_buffer.set_text(pg.utils.safe_encode_gtk(text))
    self._text_view_more.set_buffer(text_buffer)
    
    self._popup_more.move(*pg.gui.get_position_below_widget(self))
    self._popup_more.show()
  
  def _on_popup_more_show(self, popup):
    self._popup_hide_context.connect_button_press_events_for_hiding()
    
    self._popup_more.set_screen(self._button_more.get_screen())
    
    if self._message_type != gtk.MESSAGE_ERROR:
      self._timeout_remove_strict(self._clear_delay, self.set_text)
  
  def _on_popup_more_hide(self, popup):
    self._popup_hide_context.disconnect_button_press_events_for_hiding()
    
    if self._message_type != gtk.MESSAGE_ERROR:
      self._timeout_add_strict(self._clear_delay, self.set_text, None)
  
  def _timeout_add_strict(self, delay, func, *args, **kwargs):
    if self._should_clear_text_after_delay(delay):
      pg.invocation.timeout_add_strict(delay, func, None, *args, **kwargs)
  
  def _timeout_remove_strict(self, delay, func):
    if self._should_clear_text_after_delay(delay):
      pg.invocation.timeout_remove_strict(func)
  
  def _should_clear_text_after_delay(self, clear_delay):
    return (
      clear_delay is not None
      and clear_delay > 0
      and not (os.name == 'nt' and ((2, 10, 0) <= gimp.version < (2, 10, 6))))


gobject.type_register(MessageLabel)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               