Ë
    c­øcŸ3  ã                   ó„   — d dl mZmZmZ ddlmZ ddlmZ ddlm	Z	 g d¢Z
 G d„ d«      Z G d	„ d
e«      Z G d„ de«      Zy)é    )ÚGtkÚ	GdkPixbufÚGLibé   )ÚDrMessageDialog)Ú!utilities_add_filechooser_filters)Úutilities_rgb_to_hexadecimal)ÚjpegÚjpgÚjpeÚpngÚtiffÚicoÚbmpc                   ó@   — e Zd Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zy	)
ÚDrSavingManagerc                 ó   — || _         y )N)Ú_window)ÚselfÚwindows     ú8/usr/lib/python3/dist-packages/drawing/saving_manager.pyÚ__init__zDrSavingManager.__init__   s	   € Ø€$…,ó    c                 óè  — |s| j                  «       sy|rd}| j                  j                  «       }|j                  «       �|s|r| j	                  «       }n|j
                  }|€y|j                  «       }| j                  |«      }|r|j                  j                  «       }	n|j                  }	|sd}
n| }
|dv }|r|sP	 | j                  j                  j                  d«      }|dk(  r| j                  ||
«      }| j                  |	||«      }	|j-                  d«       	 |	j/                  ||dgg «       |sQ||_        |j1                  «        |j3                  «        |j5                  «        | j                  j7                  «        |j-                  d«       |s9	 ||_        |j1                  «        |j5                  «        |j9                  «        yy# t        $ r}| j!                  dddd«      cY d}~S d}~wt"        $ r
}Y d}~yd}~wt$        $ r:}t'        |«       | j                  j)                  t+        d«      «       Y d}~�Œ;d}~ww xY w# t$        $ rM}|j-                  d«       t'        |«       | j                  j)                  t+        d«      |z  «       Y d}~yd}~ww xY w# t$        $ r<}t'        |«       | j                  j)                  t+        d	«      |z  «       Y d}~yd}~ww xY w)
z¶All parameters are booleans. The value of `allow_alpha` reflects the
		user's intention (action they activated), not a technical capability.
		It returns a boolean (true if success).FTN)r   zreplace-alphaÚaskzFailed to replace transparencyzFailed to save %szFailed to reload %s)Ú"_confirm_despite_ongoing_operationr   Úget_active_imageÚget_file_pathÚ_file_chooser_saveÚgfileÚget_pathÚ_get_formatÚ	selectionÚ
get_pixbufÚmain_pixbufÚ	gsettingsÚ
get_stringÚ_ask_overwrite_alphaÚ_replace_alphaÚWantAnotherFormatExceptionÚsave_current_imageÚWantToCancelExceptionÚ	ExceptionÚprintÚreveal_messageÚ_Úset_monitoringÚsavevÚconnect_gfile_monitoringÚremember_current_stateÚ	post_saveÚupdate_picture_titleÚreload_from_disk)r   Ú	is_exportÚto_newÚselection_onlyÚallow_alphaÚimager    Ú	file_pathÚfile_formatÚpixbufÚcan_save_asÚsupports_alphaÚreplacementÚes                 r   r+   z"DrSavingManager.save_current_image!   s�  € ñ 
 × GÑ GÔ IØ
áØ€6à
�,‰,×
'Ñ
'Ó
)€%à
×ÑÓÐ"¡f±Ø×"Ñ"Ó$�5à�;‰;€5à
€]Ø
Ø�n‰nÓ€)Ø× Ñ  Ó+€+áØ�O‰O×&Ñ&Ó(�6à×Ñ€6ñ 
ð �;ð �€;à 'Ð)€.Ù	™NðEØ—,‘,×(Ñ(×3Ñ3°OÓD€KØ�eÒØ×,Ñ,¨^¸[ÓI€[Ø× Ñ  ¨°eÓ<€Fð ×Ñ�uÔðà	‡<�<�	˜;¨¨°Ô3ñ Ø€E„KØ	×"Ñ"Ô$Ø	× Ñ Ô"Ø	‡O�OÔØ‡L�L×%Ñ%Ô'ð ×Ñ�tÔá	ð	Ø€E„KØ	×"Ñ"Ô$Ø	‡O�OÔØ	×ÑÔñ 
øôc %ò =à×"Ñ" 5¨$°°tÓ<Õ<ûÜ
ò äûÜ
ò EÜ	ˆ!„Hà‡L�L×Ñ¤Ð"BÓ C×DÒDûðEûô& 
ò Ø×Ñ˜ÔÜˆ„8à‡<�<×ÑœqÐ!4Ó5¸	ÑAÔBÜ
ûðûô" ò Ü	ˆ!„Hà‡L�L×Ñ¤Ð"7Ó 8¸9Ñ DÔEÜûð	úsc   ÃAG Ä"A(I Æ7J, Ç	IÇ G9Ç3IÇ9IÈ
IÈ/IÉIÉ	J)ÉAJ$Ê$J)Ê,	K1Ê52K,Ë,K1c                 ó(  — | j                   j                  «       }|j                  «       ry|j                  «       }|€t	        d«      dz   }t	        d«      }n$|j                  d«      d   }|j                  «       }t        | j                   «      }|j                  t	        d«      d	«      }|j                  t	        d
«      d«      }|j                  t	        d«      dd«      }|j                  t	        d«      |z  «       | j                   j                  j                  «        t        j                  «       j                  | j                   j                  j                  «      }t        j                   t        j"                  j$                  t        j"                  j$                  ¬«      }	|	j'                  |«       |j)                  |	«       |j+                  «       }
|j-                  «        |
|k(  r| j                   j/                  «       S |
|k(  ryy)z§Return True if the image can be closed/overwritten (whether it's
		saved or not), or False otherwise (usually if the user clicked 'cancel',
		or if an error occurred).TNÚUntitledú.pngzthis pictureú/éÿÿÿÿÚDiscardúdestructive-actionÚCancelÚSavez&There are unsaved modifications to %s.©ÚvalignÚhalignF)r   r   Úis_savedr   r0   ÚsplitÚget_filename_for_displayr   Ú
set_actionÚ
add_stringÚminimapÚupdate_contentr   ÚImageÚnew_from_pixbufÚmini_pixbufÚFrameÚAlignÚCENTERÚaddÚ
add_widgetÚrunÚdestroyÚaction_save)r   r<   ÚfnÚunsaved_file_nameÚdisplay_nameÚdialogÚ
discard_idÚ	cancel_idÚsave_idÚframeÚresults              r   Úconfirm_save_modifsz#DrSavingManager.confirm_save_modifsƒ   s”  € ð �,‰,×
'Ñ
'Ó
)€%Ø
‡^�^ÔØ
Ø×ÑÓ€"Ø€ZÜ˜“} vÑ-Ðä�NÓ#�<à—x‘x “} RÑ(ÐØ×0Ñ0Ó2€<Ü˜4Ÿ<™<Ó(€&Ø× Ñ ¤ 9£Ð/CÓD€*Ø×Ñ¤ (£¨TÓ2€)Ø×Ñœa ›i¨¨tÓ4€'Ø×Ñ”QÐ?Ó@À<ÑOÔPØ‡,�,×Ñ×%Ñ%Ô'Ü
�)‰)‹+×
%Ñ
% d§l¡l×&:Ñ&:×&FÑ&FÓ
G€%Ü
�)‰)œ3Ÿ9™9×+Ñ+´C·I±I×4DÑ4DÔ
E€%Ø‡)�)ˆEÔØ×Ñ�EÔØ�:‰:‹<€&Ø‡.�.ÔØˆwÒØ
�,‰,×
"Ñ
"Ó
$Ð$Ø�ÒØ
à
r   c                 óÆ  — d}| j                   j                  «       j                  «       rt        d«      }n3| j                   j	                  «       j                  «       rt        d«      }|€yt        | j                   «      }| j                   j                  d«      j                  «       }|r%| j                   j	                  «       j                  }n)| j                   j                  d«      j                  «       }|xs | }|j                  t        d«      d|«      }|rd}nd}d}|r|j                  t        d	«      d
d«      }n|r|j                  t        d«      d
d«      }|j                  t        d«      |«      }	|j                  |«       |j                  t        d«      «       | j                   j                  j                  «        t        j                  «       j!                  | j                   j                  j"                  «      }
t        j$                  t        j&                  j(                  t        j&                  j(                  ¬«      }|j+                  |
«       |j-                  |«       |j/                  «       }|j1                  «        ||	k(  ry||k(  ry||k(  r9|r| j                   j3                  «        |r| j                   j5                  «        yy)z‰Ask to the user whether or not they want to apply the operation of
		the current tool (curve, shape, transform, selection) before saving.NzrA part of the image is selected: the pixels beneath the selection will be saved with a color you might not expect!z9Modifications from the current tool haven't been applied.TÚapply_transformÚunselectrK   rJ   zApply & savezsuggested-actionzDeselect & savezSave anywayzDo you want to save anyway?rM   F)r   Úget_selection_toolÚselection_is_activer0   Úactive_toolÚhas_ongoing_operationr   Úlookup_actionÚget_enabledÚapply_to_selectionrS   rT   rU   rV   r   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   Úaction_apply_transformÚaction_unselect)r   Úmsgre   Ú	can_applyÚcan_unselectÚonly_2_itemsrg   Ú
save_styleÚapply_idrh   r<   ri   rj   s                r   r   z2DrSavingManager._confirm_despite_ongoing_operation¥   sU  € ð 	€#Ø	‡\�\×$Ñ$Ó&×:Ñ:Ô<Ü	
ð Gó 
H�3à‡|�|×ÑÓ!×7Ñ7Ô9ô 
ÐFÓ	G€3Ø€[Ø
Ü˜4Ÿ<™<Ó(€&ð �l‰l×(Ñ(Ð):Ó;×GÑGÓI€)ÙØ—,‘,×*Ñ*Ó,×?Ñ?�<à—,‘,×,Ñ,¨ZÓ8×DÑDÓF€<ð  Ò/ <Ð0€,Ø×Ñ¤ (£¨T°<Ó@€)ÙØ$�:à€:Ø€(Ùà×Ñ¤ .Ó 1Ø.@À$óH�8ñ à×Ñ¤Ð"3Ó 4Ø.@À$óH€8à×Ñœa Ó.°
Ó;€'à×Ñ�CÔØ×Ñ”AÐ3Ó4Ô5Ø‡,�,×Ñ×%Ñ%Ô'Ü
�)‰)‹+×
%Ñ
% d§l¡l×&:Ñ&:×&FÑ&FÓ
G€%Ü
�)‰)œ3Ÿ9™9×+Ñ+´C·I±I×4DÑ4DÔ
E€%Ø‡)�)ˆEÔØ×Ñ�EÔØ�:‰:‹<€&Ø‡.�.ÔàˆwÒØ
Ø�ÒØ
Ø�ÒÙØ‡L�L×'Ñ'Ô)ÙØ‡L�L× Ñ Ô"Ø
à
r   c           	      ó<  — d}t         j                  j                  t        d«      | j                  t         j
                  j                  t        d«      t        d«      «      }t        |«       t        j                  t        j                  «      }|dk7  r|j                  |«       t        t        d«      dz   «      }|j                  |«       |j                  «       }|t         j                  j                   k(  r|j#                  «       }|j%                  «        |S )zBOpens an "save" file chooser dialog, and return a GioFile or None.Nu   Save picture asâ€¦rL   rK   rE   rF   )r   ÚFileChooserNativeÚnewr0   r   ÚFileChooserActionÚSAVEr   r   Úget_user_special_dirÚUSER_DIRECTORY_PICTURESÚset_current_folderÚstrÚset_current_namer_   ÚResponseTypeÚACCEPTÚget_filer`   )r   r    Úfile_chooserÚ
images_dirÚdefault_file_nameÚresponses         r   r   z"DrSavingManager._file_chooser_saveå   sß   € à
€%Ü×&Ñ&×*Ñ*¬1Ð-AÓ+BØ	�‰”s×,Ñ,×1Ñ1´1°V³9¼aÀ»kóK€,ä# LÔ1ä×(Ñ(¬×)EÑ)EÓF€*Ø�4ÒØ×"Ñ" :Ô.äœ!˜J›-¨&Ñ0Ó1ÐØ×ÑÐ 1Ô2à×ÑÓ€(Ø”×!Ñ!×(Ñ(Ò(Ø× Ñ Ó"€5Ø×ÑÔØ	€,r   c                 ór   — |j                  d«      d   }|j                  «       }|dv rd}|S |t        vrd}|S )zfBuild a short string which will be recognized as a file format by the
		GdkPixbuf.Pixbuf.savev method.ú.rH   )r
   r   r   r
   r   )rQ   ÚlowerÚALL_SUPPORTED_FORMAT)r   r=   r>   s      r   r"   zDrSavingManager._get_formatü   sQ   € ð —‘ Ó$ RÑ(€+Ø×!Ñ!Ó#€+ØÐ*Ñ*Ø€;ð 
Ðð Ô.Ñ.Ø€;Ø	Ðr   c                 óÒ  — t        | j                  «      }|j                  t        d«      d«      }|r|j                  t        d«      d«      }nd}|j                  t        d«      dd«      }|s|j	                  t        d«      «       |r|j	                  t        d«      «       n|j	                  t        d«      «       t        j                  t
        j                  j                  ¬	«      }|j                  d
t        d«      «       |j                  dt        d«      «       |j                  dt        d«      «       |j                  dt        d«      «       |s|j                  dt        d«      «       |j                  d
«       |j                  |«       |j                  «       }|j                  «       }	|j                  «        ||k(  r
t        «       ‚||k(  r
t!        «       ‚|	S )zÌWarn the user about the replacement of the alpha channel for JPG or
		BMP files, but it may quickly annoy users to see a dialog so it's an
		option. Can be used on PNG files (if 'supports_alpha' is true).rK   Nu
   Save asâ€¦ÚReplaceTz4This file format doesn't support transparent colors.zCYou can save the image as a PNG file, or replace transparency with:zReplace transparency with:)rO   ÚinitialzDefault colorÚwhiteÚWhiteÚblackÚBlackÚ
checkboardÚ
CheckboardÚnothingÚNothing)r   r   rS   r0   rT   r   ÚComboBoxTextr[   r\   ÚappendÚset_active_idr^   r_   Úget_active_idr`   r,   r*   )
r   rA   r@   re   rg   Ú
save_as_idÚ
replace_idÚalpha_comboboxrj   Úrepls
             r   r(   z$DrSavingManager._ask_overwrite_alpha  s›  € ô ˜4Ÿ<™<Ó(€&Ø×Ñ¤ (£¨TÓ2€)ÙØ×!Ñ!¤! L£/°4Ó8�:à€:à× Ñ ¤ 9£¨t°TÓ:€*á	Ø	×Ñ”QÐMÓNÔOÙØ	×Ñ”Qð Fó Gõ Hð 
×Ñ”QÐ3Ó4Ô5ä×#Ñ#¬3¯9©9×+;Ñ+;Ô<€.ð
 ×Ñ˜	¤1 _Ó#5Ô6Ø×Ñ˜¤ 7£Ô,Ø×Ñ˜¤ 7£Ô,ð ×Ñ˜¤a¨£oÔ6Ù	ð ×Ñ˜¤A i£LÔ1Ø×Ñ˜yÔ)ð 	×Ñ�NÔ#à�:‰:‹<€&Ø	×	%Ñ	%Ó	'€$Ø‡.�.ÔØˆyÒÜ	Ó	 Ð ØˆzÒÜ	#Ó	%Ð%Ø	€+r   c           	      óR  — |dk(  r|S |j                  «       }|j                  «       }|dk(  rt        ddd«      }t        ddd«      }n²|dk(  rs|j                  «       }t	        |j
                  dz  «      }	t	        |j                  dz  «      }
t	        |j                  dz  «      }t        |	|
|«      }t        |	|
|«      }n:|dk(  rt        ddd«      }t        ddd«      }nt        ddd«      }t        ddd«      }|j                  ||t        j                  j                  dd	||«      S )
Nrœ   r–   éÿ   r•   rš   éU   éª   r   é   )Ú	get_widthÚ
get_heightr	   Úget_initial_rgbaÚintÚredÚgreenÚblueÚcomposite_color_simpler   Ú
InterpTypeÚTILES)r   r?   rB   r<   ÚwidthÚheightÚpcolor1Úpcolor2Úinitial_rgbaÚrÚgÚbs               r   r)   zDrSavingManager._replace_alpha9  s2  € Ø�IÒà
€=Ø
×
Ñ
Ó
€%Ø×ÑÓ€&Ø�GÒÜ)¨#¨s°CÓ8€7Ü)¨#¨s°CÓ8�7Ø�iÒØ×(Ñ(Ó*€<Ü
ˆ<×Ñ˜cÑ!Ó"€1Ü
ˆ<×Ñ Ñ#Ó$€1Ü
ˆ<×Ñ˜sÑ"Ó#€1ô *¨!¨Q°Ó2€7Ü)¨!¨Q°Ó2�7Ø�lÒ"Ü)¨"¨b°"Ó5€7Ü)¨#¨s°CÓ8�7ä)¨!¨Q°Ó2€7Ü)¨!¨Q°Ó2€7Ø	×	&Ñ	& u¨fÜ×)Ñ)×/Ñ/°°a¸À'ó
Kð Kr   N)Ú__name__Ú
__module__Ú__qualname__Ú__gtype_name__r   r+   rk   r   r   r"   r(   r)   © r   r   r   r      s5   „ Ø#€òò]òD òD>ò@ò.	ò0ódKr   r   c                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )r,   c                 ó6   •— t         ‰| �  t        d«      «       y )NrK   ©Úsuperr   r0   ©r   Ú	__class__s    €r   r   zWantToCancelException.__init__X  s   ø€ Ü�'Ñ”1�X“;Õr   ©r½   r¾   r¿   r   Ú__classcell__©rÇ   s   @r   r,   r,   W  s   ø„ ÷ ð  r   r,   c                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )r*   c                 ó6   •— t         ‰| �  t        d«      «       y )Nr”   rÄ   rÆ   s    €r   r   z#WantAnotherFormatException.__init__\  s   ø€ Ü�'Ñ”1�Y“<Õ r   rÈ   rÊ   s   @r   r*   r*   [  s   ø„ ÷!ð !r   r*   N)Úgi.repositoryr   r   r   Úmessage_dialogr   Úutilities_filesr   Úutilities_colorsr	   r’   r   r-   r,   r*   rÁ   r   r   ú<module>rÑ      sC   ð÷$ /Ñ .Ý +Ý >Ý :âJÐ ÷wKñ wKôx	 ˜Iô  ô! õ !r   