
    cc                        d dl Z d dlmZmZmZmZ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mZmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ dZdZ ej@                  edz          G d dejB                               Z"y)    N)GtkGdkGio	GdkPixbufGLib   )DrImage)DrCustomImageDialog)	DrMinimap)DrOptionsManager)DrMessageDialog)DrDecoManagerMenubarDrDecoManagerHeaderbarDrDecoManagerToolbar)DrSavingManager)DrPrintingManager)DrToolsInitializer)!utilities_add_filechooser_filtersutilities_gfile_is_imagez!/com/github/maoschanz/drawing/ui/pencilz	window.ui)resource_pathc                       e Zd Zd Zej
                  j                  d      Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Zej                  j                         Z f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#ddZ$ddddg dfdZ%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0g fd Z1d! Z2d" Z3d# Z4d$ Z5d% Z6d& Z7dd'Z8dd(Z9d) Z:d* Z;d+ Z<d, Z=d- Z>d. Z?d/ Z@d0 ZAd1 ZBd2 ZCdd3ZDd4 ZEd5 ZFd6 ZGd7 ZHd8 ZId9 ZJd: ZKd; ZLd< ZMd= ZNd> ZOd? ZPd@ ZQddAZRdB ZSdC ZTdD ZUdE ZVdF ZWdG ZXdH ZYdI ZZdJ Z[dK Z\dL Z]dM Z^dN Z_dO Z`dP ZadQ ZbdR ZcdS ZddT ZeddUZfdV ZgdW ZhdX ZidY ZjdZ Zkd[ Zld\ Zmd] Znd^ Zod_ Zpd` Zqda Zrdb Zsdc Ztdd Zude Zvdf Zwdg Zxdh Zydi Zzdj Z{dk Z|dl Z}dm Z~dn Zdo Zdp Zdq Zdr Zds Zdt Zdu Zdv Zdw Zdx Zdy Zdz Zd{ Zd| Zd} Zd~ Zd Zd Zd Z xZS )DrWindowzcom.github.maoschanz.drawingc                    t        |   di | |d   | _        d | _        d | _        d| _        d| _        d| _        | j                  j                  d      r| j                          | j                          | j                          y )NapplicationF	maximized )super__init__apppointer_to_current_pageactive_tool_id!_is_tools_initialisation_finished
devel_modeshould_track_framerate	gsettingsget_booleanmaximize_update_theme_variant_set_ui_bars)selfkwargs	__class__s     0/usr/lib/python3/dist-packages/drawing/window.pyr   zDrWindow.__init__?   s}    'VM"$(!%$ $+0$($/ %$	^^,==?     c                    | j                  t        d             |d   }|d   }i | _        t        | d      | _        t        |       | _        t        |       | _        t        |       | _
        | j                  j                  d      | _        | j                          | j                          | j!                          	 |r| j#                          n%|| j%                  |       n| j'                          | j/                         j1                          d| _        | j5                          y# t(        $ r$}| j+                  t-        |             Y d}~^d}~ww xY w)	a  Initialize the window's content, such as the minimap, the color
		popovers, the tools, their options, and a new image. Depending on the
		parameters, the new image can be imported from the clipboard, loaded
		from a GioFile, or (else) it can be a blank image.

		This method is called asynchronously, which isn't *correct* (not very
		thread-safe or anything) but it allows the window to be shown quicker.
		If it fails, a window is here anyway because this is independent from
		the object constructor.z7Error starting the application, please report this bug.gfileget_cbN
devel-onlyr1   TF)reveal_action_report_toolsr   minimapr   options_managerr   saving_managerr   printing_managerr&   r'   r$   add_all_win_actions_init_toolsconnect_signalsdelayed_build_from_clipboard_build_new_tabbuild_blank_image	Exceptionreveal_messagestractive_toolselect_flowbox_childr#   _try_show_release_notes)r+   content_paramsr1   r2   excps        r.   init_window_content_asyncz"DrWindow.init_window_content_asyncS   s;    A I J K 
!%(#&$*4&$,)$/$'-$+D1$NN..|<$/"%%'e$ ))++/$(  
 
 "s4y!!"s   >8D, ,	E5EEc                    | j                   j                  d      }| j                  j                         }||k(  ry|j	                  d      d   |j	                  d      d   k(  rF|j	                  d      d   |j	                  d      d   k(  r| j                   j                  d|       yt        |       }|dk(  r|j                  t        d             n9t        d      }|j                  ||z         |j                  t        d	             |j                  t        d
      dd      }|j                  t        d      d      }|j                         }|j                          ||k(  r:|dk(  r| j                  j                          n| j                  j                          | j                   j                  d|       y)zAdd specific actions to the primary menu if the current version is a
		new one (the corresponding release notes have never been opened or
		dismissed)zlast-versionN.r   r   z0.0.0zLIt's the first time you use Drawing, would you like to read the help manual?zJIt's the first time you use Drawing %s, would you like to read what's new?zeThese news will always be available in the help manual: click the 'Help' menu item whenever you want!NoTYessuggested-action)r&   
get_stringr    get_current_versionsplit
set_stringr   
add_stringr6   
set_actionrundestroyon_help_indexon_help_whats_new)r+   last_versioncurrent_versiondialoglabelno_idyes_idresults           r.   rG   z DrWindow._try_show_release_notes   s    **>:,HH002/$	 Q?#8#8#=a#@@a O$9$9#$>q$AA>>^_=	4 &W	Q F G H  G H5	U_,-	Q F G H 

AdGT4
0%QuX'9:&::<&..vgHHHH ..NO<r/   c                    | j                   j                  d      }| j                   j                  d      }i | _        | j	                  d       | j                          t        |       }|j                  ||      | _        | j                  j                  d| j                         | j                  D ]*  }| j                  |   j                  | j                         , | j                          | j                  j                  s| j                          | j                   j!                  d      }|| j                  vrt"        }|| _        || _        y)zdInitialize all tools, building the UI for them including the menubar,
		and enable the default tool.zdisabled-toolsr3   z%window has started, now loading toolszselected-children-changedlast-active-toolN)r&   get_strvr'   r7   log_message_hide_messager   load_all_toolstools_flowboxconnect'_update_active_tool_from_flowbox_signalbuild_flowbox_childon_show_labels_setting_changedr    has_tools_in_menubarbuild_menubar_tools_menurP   DEFAULT_TOOL_IDr"   former_tool_id)r+   disabled_toolsdevtools_initializertool_ids        r.   r=   zDrWindow._init_tools   s     >>**+;<.""<0#$*:;(. //^D$* 8!IIK ?g::g**4+=+=>?%%' 
	&	&  " NN%%&89'DJJ7$$r/   c                 Z    | j                         }| j                  |j                         y N)_get_newly_selected_tool	switch_toid)r+   argsselected_tools      r.   ri   z0DrWindow._update_active_tool_from_flowbox_signal   s"    //1-..!!"r/   c                     | j                   D ]0  }| j                   |   j                         s!| j                   |   c S  y ru   )r7   is_flowbox_child_selected)r+   rs   s     r.   rv   z!DrWindow._get_newly_selected_tool   s9     g
jj335::gr/   c                 "   g d}| j                  d      |d<   | j                  d      |d<   | j                  d      |d<   | j                  D ]/  }| j                  |   }|j                  ||j                            1 d| j                  _        y )N)NNNr      r   T)_get_menubar_tools_sectionr7   add_item_to_menumenu_idr    rl   )r+   sectionsrs   tools       r.   rm   z!DrWindow.build_menubar_tools_menu   s    ( //2(1+//2(1+//2(1+ 1g
**W
4$,,/01 #'$((r/   c                 <    | j                  ddgddgddgd|gg      S )NT   Fr   r   )_get_menubar_item)r+   section_indexs     r.   r   z#DrWindow._get_menubar_tools_section   s7    			!9	1:!9	=	! 
 r/   c                     | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                  |||       | j	                          y)zaOpen a new tab with a drawable blank image using the default values
		defined by user's settings.zdefault-widthzdefault-heightzdefault-rgbawidthheightbackground_rgbaN)r&   get_intrc   r@   update_picture_title)r+   ry   r   r   rgbas        r.   rA   zDrWindow.build_blank_image   sb     ..
 
 
1%>>!!"23&		 	 	0$E&$Gr/   c                    t        |       }|j                         }|t        j                  j                  k(  r8|j                         \  }}}| j                  |||       | j                          |j                          y)z]Open a new tab with a drawable blank image using the custom values
		defined by user's input.r   N)	r
   rV   r   ResponseTypeOK
get_valuesr@   r   rW   )r+   ry   r\   r`   r   r   r   s          r.   build_new_customzDrWindow.build_new_custom   sm     t$&::<&s"""**,5&$U64H..r/   c                 f    | j                          t        j                  d| j                  i        y)z2Calls `async_build_from_clipboard` asynchronously.i  N)r@   r   timeout_addasync_build_from_clipboardr+   ry   s     r.   r?   z%DrWindow.delayed_build_from_clipboard  s&    377<r/   c                     | j                         j                          | j                         r| j                  | j                         y)8This is used as a GSourceFunc so it should return False.F)get_active_imagetry_close_tabbuild_image_from_clipboardrw   r"   )r+   rH   s     r.   r   z#DrWindow.async_build_from_clipboard  s8    '')	$$&>>$%%&	r/   c                 :   t         j                  j                  t        j                        }|j                         }|J| j                  t        d      d       | j                  j                         dk  r| j                          yy| j                  |       y)a  Open a new tab with the image in the clipboard. If the clipboard is
		empty, and there is no existing tab, a new blank image will be created
		to ensure the window can display the message.
		It returns `True` if an image (blank or not idc) has been created.z(The clipboard doesn't contain any image.Tr   Fpixbuf)r   	Clipboardgetr   SELECTION_CLIPBOARDwait_for_imagerC   r6   notebookget_current_pagerA   r@   )r+   ry   cbr   s       r.   r   z#DrWindow.build_image_from_clipboard  s    
 }}001"&^qCDdK
mm$$&*
f%
r/   c                 x    | j                         j                  j                         }| j                  |       y)z/Open a new tab with the image in the selection.r   N)r   	selection
get_pixbufr@   r+   ry   r   s      r.   build_image_from_selectionz#DrWindow.build_image_from_selection$  s0      ",,779&V$r/   c                     |r[| j                   j                  |j                               \  }}|-| j                  |      s|j                  j                  |       y | j                  |       y )Nr4   )r    has_image_openedget_pathconfirm_open_twicer   set_current_pager@   r+   r1   check_duplicatesw	duplicates        r.   build_new_from_filezDrWindow.build_new_from_file)  s]    ((++ENN,<=<1iD$;$;E$BJJ	*
E"r/   N   )      ?r   r   r   c                    t        |       }| j                  j                  ||j                                | j                  j	                  |dd       ||j                  |       n'||j                  |       n|j                  |||       | j                          | j                  j                  | j                  j                         dz
         y)zwOpen a new tab with an optional file to load in it, or directly a
		pixbuf, or the color and dimensions of a blank tab.reorderableTNr   )r	   r   append_pagebuild_tab_widgetchild_set_propertytry_load_filetry_load_pixbufinit_background_update_tabs_visibilityr   get_n_pages)r+   r1   r   r   r   r   	new_images          r.   r@   zDrWindow._build_new_tab1  s     dm)--Iy'A'A'CD--""9mTB
5!V$
 UFO< --  !:!:!<Q!>?r/   c                 R   |j                         j                  d      d   }t        |       }t        d      }|j	                  ||z         |j                  t        d      d       }|j                  t        d      dd      }|j                         }|j                          ||k(  S )N/zThe file %s is already openedz
Open againzSwitch to this imagerO   T)r   rR   r   r6   rT   rU   rV   rW   )r+   r1   
image_namer\   r]   open_again_idswitch_to_idr`   s           r.   r   zDrWindow.confirm_open_twiceF  s    ~~%%c*2.*4 &
+
,%EJ&' ##AlOT:-""1%;#<1CTK,::<&..	=	  r/   c                    | j                   sy | j                  | j                  |d          | j                  |d   j	                                | j
                  j                  |d   j                  dz         |d   j                          y )Nr   d   )	r#   rw   r"   r   update_titler8   set_zoom_label
zoom_levelupdate_image_wide_actionsr   s     r.   on_active_tab_changedzDrWindow.on_active_tab_changedU  sr    		/	/	..$$d1g.DG0023,,d1g00367q'##%r/   c                 J   | j                  d      }| j                  ddgddgg      }|j                          | j                  j	                         D ]N  }|j                         }| j                  j                  |      }|j                  |dt        |      z   dz          P y )N
active_tabTr~   Fr   zwin.active_tab())	lookup_actionr   
remove_allr   get_childrenr   page_numappendrD   )r+   ry   actionsectionpage	tab_title	tab_indexs          r.   update_tabs_menu_sectionz!DrWindow.update_tabs_menu_section_  s    l+&""T1Iqz#:;'	mm((* Gd  "9}}%%d+9
>>).Y?#EFGr/   c                     | j                   j                         }|dk(  r7| j                   j                  | j                   j                         dz
         y | j                   j                  |dz
         y Nr   r   )r   r   r   r   r+   ry   current_pages      r.   action_tab_leftzDrWindow.action_tab_lefth  sW    //1,Q==!!$--";";"="AB==!!,"23r/   c                     | j                   j                         }|| j                   j                         dz
  k(  r| j                   j                  d       y | j                   j                  |dz          y Nr   r   )r   r   r   r   r   s      r.   action_tab_rightzDrWindow.action_tab_rightp  sW    //1,T]]..0144==!!!$==!!,"23r/   c                 R   | j                   j                  |      }| j                   j                  |      j                         s8| j                   j	                  |       | j
                  j                         }|sy| j                   j                  |       | j                          y)z-Close a tab (after asking to save if needed).FT)	r   r   get_nth_pageis_savedr   r:   confirm_save_modifsremove_pager   )r+   tabindexr   s       r.   	close_tabzDrWindow.close_tabx  s~    
--
 
 
%%		#	#E	*	3	3	5==!!%(!!5578
--E" 	r/   c                     | j                   j                         dkD  r| j                         j                          y | j	                          y Nr   )r   r   r   r   closer   s     r.   action_close_tabzDrWindow.action_close_tab  s5    	]] 1$((*::<r/   c                 $    | j                          y ru   )r   r   s     r.   action_close_windowzDrWindow.action_close_window  s    **,r/   c                    | j                   j                         dk7  r=| j                         j                         sy| j                   j                         dk7  r=| j                  j                          | j                  j                          | j                  j                  d| j                         | j                  j                  d| j                                y)zEvent callback when trying to close a window. It saves/closes each
		tab and saves the current window settings in order to restore them.
		Returns `False` on success, `True` otherwise.r   Trb   r   F)r   r   r   r   _decorationsremove_from_uir9   persist_tools_optionsr&   rS   r"   set_booleanis_maximizedr   s     r.   on_closezDrWindow.on_close  s     	!!#q(



!
/
/
1 	!!#q( ""$,,....0C0CD..[$*;*;*=>	r/   c                    | j                   j                  d| j                         | j                   j                  d| j                         | j                  d| 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| j                         | j                  d| j                         | j                  j                  ry | j                  j!                  t"        j$                  j&                  g t(        j*                  j,                         | j                  j                  d| j.                         | j                  j1                          y )Nr   responsezdelete-eventzconfigure-eventzchanged::show-labelszchanged::deco-typezchanged::big-iconszchanged::preview-sizezchanged::disabled-toolszchanged::dark-theme-variantzswitch-pagezkey-press-eventzkey-release-eventzdrag-data-received)info_barrh   re   r   _adapt_to_window_sizer&   rk   on_layout_changedon_icon_size_changedshow_info_settingsr)   r   r   _check_for_alt_keyr    runs_in_sandboxdrag_dest_setr   DestDefaultsALLr   
DragActionMOVEon_data_droppeddrag_dest_add_uri_targetsr+   s    r.   r>   zDrWindow.connect_signals  s   --!3!34--
D$6$67 ,,~t}}- ,, $"<"<= ../1T1TU..-t/E/EF..-t/H/HI..0$2I2IJ..2D4K4KL..68R8RS --t'A'AB ,, $"9"9:,,"D$;$;< 
XX	 --c..22B8K8KL--,d.B.BC--))+r/   c                     | j                   j                         }|D ]=  }|d   rt        j                  }nt        j                  }|j                  |d   |      }? |S )zGet an item of the app-wide menubar. The `path_description` object
		is an array of [boolean, int] couples. The boolean means if we're
		looking for a submenu, the int is an index.r   r   )r    get_menubarr   MENU_LINK_SUBMENUMENU_LINK_SECTIONget_item_link)r+   path_descriptioncurrent_itemitem	link_types        r.   r   zDrWindow._get_menubar_item  sb     %%', Ad
1g%%I%%I,,T!Wi@<A 
r/   c                     t         j                  j                  |d      }|j                  d|       | j	                  |       | j
                  j                  d|z   |       y)zConvenient wrapper method adding a stateless action to the window. It
		will be named 'action_name' (string) and activating the action will
		trigger the method 'callback'.Nactivatezwin.)r   SimpleActionnewrh   
add_actionr    set_accels_for_action)r+   action_namecallback	shortcutsr   s        r.   add_action_simplezDrWindow.add_action_simple  sO     T2&..X&//&((  +!5yAr/   c                     t        j                         j                  |dt        j                  j                  |            }|j                  d|       | j                  |       y)zConvenient wrapper method adding a stateful action to the window. It
		will be named 'action_name' (string), be created with the state 'default'
		(boolean), and activating the action will trigger the method 'callback'.Nchange-state)r   r  new_statefulr   Variantnew_booleanrh   r  r+   r  defaultr  r   s        r.   add_action_booleanzDrWindow.add_action_boolean  sN     **;(,(@(@(IK&..*//&r/   c                    t        j                         j                  |t        j                  j                  d      t        j                  j                  |            }|j                  d|       | j                  |       y)zConvenient wrapper method adding a stateful action to the window. It
		will be named 'action_name' (string), be created with the state 'default'
		(string), and changing the active target of the action will trigger the
		method 'callback'.sr!  N)
r   r  r"  r   VariantTyper  r#  
new_stringrh   r  r%  s        r.   add_action_enumzDrWindow.add_action_enum  s_    
 **;""3')@)@)IK&..*//&r/   c                 "   | j                  d| j                  dg       | j                  d| j                  dg       t        j                  j                  d| d      }| j                  |       | j                  j                  ddg       | j                  dd	| j                         | j                  j                  d
dg       | j                  j                  d      }| j                  d|| j                         | j                  j                  d      }| j                  d|| j                         | j                  j                  ddg       | j                  dd	| j                         | j                  j                  ddg       | j!                  d      j#                  d	       | j                  dd	| j$                         | j                  j                  ddg       | j                  d| j&                  dg       | j                  d| j(                  dg       | j                  d| j*                         | j                  d| j,                         | j                  d| j.                  dg       | j                  d | j0                  d!g       | j                  d"| j2                  d#g       | j                  d$| j4                  d%g       | j                  d&| j6                  d'd(g       | j                  d)| j8                  d*d+g       | j                  d,| j:                  d-d.g       | j                  d/| j<                  d0d1g       | j                  d2| j>                  d3d4g       | j                  d5| j@                  d6d7g       | j                  d8| jB                  d9d:g       | j                  d;| jD                  d<d=g       | j                  d>| jF                  d?d@g       | j                  dA| jH                  dBg       | j                  dC| jJ                         | j                  dD| jL                  dEg       | j                  dF| jN                  dGg       | j                  dH| jP                  dIg       | j                  dJ| jR                  dKg       | j                  dL| jT                  dMg       | j                  dN| jV                  dOg       | j                  dP| jX                         | j                  dQ| jZ                  dRg       | j                  dS| j\                  dTg       | j                  dU| j^                  dVg       | j                  dW| j`                         | j                  dX| jb                  dYg       | j                  dZ| jd                         | j                  d[| jf                  d\g       | j                  d]| jh                         | j                  d^| jj                  d_g       | j                  d`| jl                  dag       | j                  db| jn                  dcg       | j                  dd| jp                  deg       | j                  df| jr                  dgg       | j                  dh| jt                  dig       | j                  dj| jv                  dkg       | j                  dl| jx                         | j                  dm| jz                         | j                  dn| j|                         | j                  do| j~                  dpg       | j                  dq| j                  drg       | j                  ds| j                         | j                  dtt        | j                         | j                  du| j                  dvg       | j                  dw| j                  dxg       | j                  dy| j                  dzg       | j                  j                  d{      }| j                  j                  d||| j                         | j                  d}| j                  d~g       | j                  d| j                  dg       | j                  rs| j                  d| j                         | j                  d| j                         | j                  d| j                  dg       | j                  dd	| j                         t        j                  j                  d| j                  d      }| j                  |       y)z~This doesn't add all window-wide GioActions, but only the GioActions
		which are here "by default", independently of any tool.	main_menuF10options_menuz
<Shift>F10zshow-menubarzwin.show-menubarz<Ctrl>F2toggle_previewFzwin.toggle_previewz<Ctrl>mdark-theme-variantzdark-variantshow-labelsshow_labelszwin.show_labelsF9hide_controlszwin.hide_controlsF8
fullscreenzwin.fullscreenF11reset_canvasz<Ctrl>BackSpacereload_filez<Ctrl>r
propertiesunfullscreengo_upz<Ctrl>Upgo_downz
<Ctrl>Downgo_leftz
<Ctrl>Leftgo_rightz<Ctrl>Rightgo_topz<Ctrl>Page_Upz<Ctrl>KP_Page_Up	go_bottomz<Ctrl>Page_Downz<Ctrl>KP_Page_Downgo_firstz
<Ctrl>Homez<Ctrl>KP_Homego_lastz	<Ctrl>Endz<Ctrl>KP_Endzoom_inz
<Ctrl>plusz<Ctrl>KP_Addzoom_outz<Ctrl>minusz<Ctrl>KP_Subtractzoom_100z<Ctrl>1z
<Ctrl>KP_1	zoom_optiz<Ctrl>0z
<Ctrl>KP_0zoom_maxz<Ctrl><Shift>plusz<Ctrl><Shift>KP_Addnew_tabz<Ctrl>tnew_tab_customnew_tab_selectionz<Ctrl><Shift>tnew_tab_clipboardz<Ctrl><Shift>vopenz<Ctrl>o	tab_rightz	<Ctrl>Tabtab_leftz<Ctrl><Shift>Tabr   z<Ctrl>wr   undoz<Ctrl>zredoz<Ctrl><Shift>zsavez<Ctrl>ssave_alphalesssave_asz<Ctrl><Shift>s	export_asto_clipboardz<Ctrl><Shift>cprintimportz<Ctrl>ipastez<Ctrl>v
select_allz<Ctrl>aunselectz<Ctrl><Shift>aselection_cutz<Ctrl>xselection_copyz<Ctrl>cselection_deleteDeleteselection_exportzselection-replace-canvaszselection-expand-canvasback_to_previousz<Ctrl>bapply_transformz<Ctrl>Returncancel_transformrE   
main_colorz<Ctrl><Shift>lsecondary_colorz<Ctrl><Shift>rexchange_colorz<Ctrl>edirect-color-edit
use_editor	size_morez<Ctrl><Shift>Up	size_lessz<Ctrl><Shift>Downrestore_pixbufrebuild_from_histor   z<Ctrl>gtrack_framerater   r   N)Qr  action_main_menuaction_options_menur   PropertyActionr  r  r    r  r'  action_toggle_previewr&   r'   action_dark_themeaction_show_labelsaction_hide_controlsr   set_enabledaction_fullscreenaction_resetaction_reloadaction_propertiesaction_unfullscreenaction_go_upaction_go_downaction_go_leftaction_go_rightaction_go_topaction_go_bottomaction_go_firstaction_go_lastaction_zoom_inaction_zoom_outaction_zoom_100action_zoom_optiaction_zoom_maxrA   r   r   r   action_openr   r   r   r   action_undoaction_redoaction_saveaction_save_alphalessaction_save_asaction_export_asaction_export_cbaction_printaction_importaction_pasteaction_select_allaction_unselect
action_cutaction_copyaction_deleteaction_selection_exportaction_selection_replace_canvasaction_selection_expand_canvasrc  action_apply_transformaction_cancel_transformr,  rn   on_change_active_toolaction_color1action_color2exchange_colorsaction_use_editoraction_size_moreaction_size_lessr$   action_restoreaction_rebuildaction_getvalues
action_fspr   )r+   r   dark_variantr4  editors        r.   r<   zDrWindow.add_all_win_actions  s    d&;&;eWE)A)AL>R!!.$G&//&((  !3j\B*E43M3MN((  !5	{C++,@A,.,8N8NO**=9+-d6M6MN((  !2TF;/5$2K2KL((  !4tf=_%11%8,t/E/EF((  !1E7;):):=N<OP(:(:YKHt'='=>)A)AB$"3"3j\BD$7$7,HD$7$7,HT%9%9M?K4#5#5%46H$IKd&;&;!24H IKT%9%9+7*IKD$7$7-8.,IK D$7$7,8.+IKT%9%9&35H%IKT%9%9I|;TUd&;&;i=VWT%9%9<OQf;ghD$:$:YKH)4+@+@A,558H7IK,558H7IK!1!1I;?d&;&;k]KT%9%9<N;OPd&;&;i[I$":":;!1!1I;?!1!14D3EF!1!1I;?)4+E+EFD$7$7:J9KLd&;&;<)>)>AQ@RS$"3"344#5#5	{C$"3"3i[At'='=	{KT%9%9<L;MN$//I;G)4+;+;i[I+T-?-?(L+T-I-IJ3%)%I%IK2&*&I&IK +T-B-BYKP*D,G,G.IYZ+T-I-IJ}ot7Q7QRt'9'9<L;MN*D,>,>AQ@RS)4+?+?)M>>%%&9:&((lFD4J4JKd&;&;>O=PQd&;&;>Q=RS	__*D,?,?@.0C0CD,(=(=	{K,eT__E!!,vF&//&r/   c                     |r| j                         j                  }nd}t        j                  j	                  t        j
                  j                         |      }| j                         j                  |       y)zCalled by the tools at various occasions, this method updates the
		mouse cursor according to `is_custom` (if False, use the default cursor)
		and the active tool `cursor_name` attribute.r&  N)	rE   cursor_namer   Cursornew_from_nameDisplayget_default
get_window
set_cursor)r+   	is_customnamecursors       r.   r  zDrWindow.set_cursorb  sX     




(
(4
4::##CKK$;$;$=tD&//v&r/   c                     	 | j                   j                         }| j                          | j                   j                  |       | j	                          | j                          y #  Y y xY wru   )r   r   r*   set_compactr   set_window_subtitles)r+   ry   	is_narrows      r.   r   zDrWindow.on_layout_changedp  s]      //19  +s   A%A( (A,c                 8    | j                  t        d             y)zuThis is executed when a setting changed but the method to apply it
		immediately in the current window doesn't exist.z6Modifications will take effect in the next new window.N)rC   r6   r   s     r.   r  zDrWindow.show_info_settings|  s     aPQRr/   c                     || j                         j                         }| j                          | j                  j	                  |      r| j                  j                          yy)zdSet the window's title (regardless of the current UI bars), and the
		active tab title (indirectly).N)r   r   r   r   	set_titleforce_update_titles)r+   
main_titles     r.   r   zDrWindow.update_picture_title  sX     %%'446:!	  ,((* -r/   c                     || j                         j                         }| j                  j                  |      r| j                  j	                          yy)zSet the window's subtitles list (regardless of the current UI bars).
		Tools have to be initialized before calling this method, for now.N)rE   get_editing_tipsr   set_subtitlesr  )r+   subtitles_lists     r.   r  zDrWindow.set_window_subtitles  sL     $$&779>	$$^4((* 5r/   c                 l    t        j                  dd      }d|v ryd|v ryd|v ryd|v ry	d
|v ry|dv ryy)zWReturn the decorations setting based on the XDG_CURRENT_DESKTOP
		environment variable.XDG_CURRENT_DESKTOPGNOMEhgPantheonheUnitytcKDEtsCinnamonmts)MATEXFCELXDELXQtmtc)osgetenv)r+   desktop_envs     r.   get_auto_decorationszDrWindow.get_auto_decorations  s[     		/9+
[ 
+

[ 
66

r/   c                    d| _         | j                  j                  d      | _        | j                  dk(  r| j	                         | _        | j                  dk(  rt        d|       | _        n| j                  dk(  rt        d|       | _        n| j                  dk(  rt        | d      | _        nid| j                  v r/d	| j                  v }d| j                  v }t        |||       | _        n,| j                  j                  dd       | j                          | j                  j                         r | j                         j                  d
       yy)zSet the UI "bars" (headerbar, menubar, titlebar, toolbar, whatever)
		according to the user's preference, which by default is an empty string.
		In this case, an useful string is set by `get_auto_decorations()`.Fz	deco-type r  r  Tmtr)  develN)has_good_width_limitsr&   rP   deco_layoutr  r   r   r   r   rS   r*   r    is_betaget_style_context	add_class)r+   symbolicmenubars      r.   r*   zDrWindow._set_ui_bars  s&     %$ ^^..{;$	//14	-eT:44-dD943+D$74
dT%%%8D$$$7+HgtD4>>["-	XX%%g. r/   c                 8    | j                   j                          y ru   )r   toggle_menur   s     r.   rp  zDrWindow.action_main_menu  s    !r/   c                 8    | j                   j                          y)zsThis displays/hides the tool's options menu, and is implemented as an
		action to ease the accelerator (shift+f10).N)r9   r  r   s     r.   rq  zDrWindow.action_options_menu  s     ""$r/   c                    | j                   sN| j                         dkD  r;| j                  j                          | j                  j                          d| _         | j                  j                          | j                  j                         }| j                  sy| j                  j                  |       | j                         j                          y)zAdapts the headerbar (if any) and the default bottom pane to the new
		window size. If the current bottom pane isn't the default one, this
		will call the tool method applying the new size to the tool pane.i  TN)
r  get_allocated_widthr9   init_adaptabilityr   adapt_to_window_sizebottom_panes_boxr#   r   fake_scrollbar_update)r+   ry   available_widths      r.   r   zDrWindow._adapt_to_window_size  s     
	#	#(@(@(BS(H))+&&( $4((*))==?/		/	/	++O< //1r/   c                     | j                  d      j                         }| j                  j                         dkD  xr | }| j                  j	                  |       y )Nr6  r   )r   	get_stater   r   set_show_tabs)r+   controls_hiddenshould_shows      r.   r   z DrWindow._update_tabs_visibility  sL    &&7AAC/**,q0I/6I+--k*r/   c                     |d   }| j                   j                  d|       |d   j                  t        j                  j                  |             y )Nr   r2  r   )r&   r   	set_stater   r#  r$  )r+   ry   shall_be_darks      r.   rt  zDrWindow.action_dark_theme  sA    q'-..1=Aq'DLL,,];<r/   c                     d}| j                   j                  d      }t        j                  j	                         j                  ||       y )Nz!gtk-application-prefer-dark-themer2  )r&   r'   r   Settingsr  set_property)r+   ry   keyuse_dark_themes       r.   r)   zDrWindow._update_theme_variant  s9    +#>>--.BC.,,))#~>r/   c                 :    | j                   rt        d|z          y y )Nz	Drawing: )r$   rY  r+   messages     r.   rd   zDrWindow.log_message  s    	__w	 r/   c                 F   | j                   j                  d       | j                  j                  |       | j                  j                  d       | j                  j                  t        d             | j                  j                  d       | j                  |       y)z\Update the label and the visibility of the info bar. The 'report bug'
		action is suggested.Tzapp.report-issuezReport a bugN)r   set_visible
info_label	set_labelinfo_actionset_action_namer6   rd   r  s     r.   r5   zDrWindow.reveal_action_report  sx     --D!//G$""#56Q~./t$7r/   c                    |r#t        j                  d| j                  d|i       | j                  j	                  d       | j
                  j	                  d       | j                  j                  |       | j                  |       y)zUpdate the label and the visibility of the info bar. No action is
		suggested, and the info bar may optionally be hidden after 4 seconds.i  r]   TFN)	r   r   _DrWindow__hide_message_asyncr   r   r  r  r  rd   )r+   r]   hide_afterwardss      r.   rC   zDrWindow.reveal_message  sj     D$33gu5EF--D!u%//E"5r/   c                 d    |d   | j                   j                         k(  r| j                          y)r   r]   F)r  	get_labelre   )r+   async_cb_datas     r.   __hide_message_asynczDrWindow.__hide_message_async  s+    7t88::	r/   c                     | j                   j                  d       | j                  j                  d       | j                  j	                  d       y )NFr  )r   r   r  r  r  r   s     r.   re   zDrWindow._hide_message  s:    --E"u%//Br/   c                     | j                  d      }|j                  t        j                  j	                  d             y)z"Simple action, exiting fullscreen.r8  FNr   change_stater   r#  r$  )r+   ry   	fs_actions      r.   r|  zDrWindow.action_unfullscreen  s/      .)11%89r/   c                    |d   }|r;| j                          | j                  t        d      dz   t        d      z   d       n| j                          | j	                  |       | j                  d      j                  |       | j                  j                  |       |d   j                  t        j                  j                  |             y)	z)Boolean action, toggling fullscreen mode.r   z/Middle-click or press F8 to show/hide controls. zPress F11 to exit fullscreen.Tr6  r   N)r8  rC   r6   r=  _set_controls_hiddenr   rw  unfullscreen_btnr   r  r   r#  r$  )r+   ry   shall_fullscreens      r.   rx  zDrWindow.action_fullscreen  s     !W??qJK ?@ABFH ,-_%112BC##$45q'DLL,,-=>?r/   c                    |d   }| j                   j                  |        d| j                  v r| j                  j                  |        d| j                  v r| j	                  |        | j
                  j                  |        |d   j                  t        j                  j                  |             | j                          y)zBoolean action controlling the visibility of the UI elements such as
		the tools list, the bottom pane, the menubar/toolbar if any. This can
		only (in theory) be used while in fullscreen.r   r  r  r   N)rg   r   r  toolbar_boxset_show_menubarbottom_meta_boxr  r   r#  r$  r   )r+   ry   r  s      r.   rv  zDrWindow.action_hide_controls-  s     G/  _!45DO 34D_,-""#67q'DLL,,_=> r/   c                     | j                  d      }|j                  t        j                  j	                  |             y )Nr6  r  )r+   state	hc_actions      r.   r  zDrWindow._set_controls_hidden;  s/      1)11%89r/   c                     | j                  d      j                         }|r2| j                  d      }| j                  |j                                 y | j                  j	                         j                          y )Nr8  r6  )r   r  r  r9   get_active_panemiddle_click_action)r+   is_fullscreenedr  s      r.   on_middle_clickzDrWindow.on_middle_click?  sc    &&|4>>@/!!/29!4!4!667'')==?r/   c                 `    | j                   D ]  }| j                   |   j                          ! y ru   )r7   update_icon_size)r+   ry   rs   s      r.   r  zDrWindow.on_icon_size_changedJ  s*     *g::g'')*r/   c                    | j                   D ]   }| j                   |   j                  |       " t        | j                         }| j                  j	                         }|ru| j                  j                  |       || j                  k(  r| j                  j                  | j                         | j                  j                  | j                         n|| j                  k(  rJ| j                  j                  | j                         | j                  j                  | j                         t        ||dz  z   dz        dz
  }| j                  j                  |       | j                  j                  |       y)zChange the way tools are displayed in the side pane. Visible labels
		mean the tools will be arranged in a scrollable list of buttons, else
		they will be in an adaptative flowbox.   r   N)r7   set_show_labellenrg   
get_parentset_min_children_per_linetools_nonscrollable_boxremovetools_scrollable_boxaddintset_max_children_per_line)r+   visiblers   nb_tools
parent_boxnb_mins         r.   set_tools_labels_visibilityz$DrWindow.set_tools_labels_visibilityN  s/     /g::g%%g./_(!!,,.*//9D000  ''(:(:;!!$"4"45D---$$T%7%78  $$T%7%78(HqL)1,.26//7..x8r/   c                 X    | j                  | j                  j                  d             y )Nr3  )r4  r&   r'   r   s     r.   rk   z'DrWindow.on_show_labels_setting_changedc  s    ""4>>#=#=m#LMr/   c                     |d   j                          }| j                  j                  d|       |d   j                  t        j
                  j                  |             y )Nr   r3  )r  r&   r   r  r   r#  r$  )r+   ry   r4  s      r.   ru  zDrWindow.action_show_labelsg  sL    G%%''+..]K8q'DLL,,[9:r/   c                 ,   |d   j                   t        j                  j                  z  |d   j                   k(  sy |d   j                  t        j
                  j                  k(  }| j                  D ]   }| j                  |   j                  |       " y r   )	r  r   ModifierType	MOD1_MASKtype	EventType	KEY_PRESSr7   show_only_mnemonics)r+   ry   is_pressrs   s       r.   r  zDrWindow._check_for_alt_keyl  st    	a))33	3tAw}}	D	!W\\S]]444( 5g::g**845r/   c                    |d   j                         }||d   j                         j                         k(  ry| j                  |   j                         r| j	                  |       y| j                  |   j                          y)zAction callback, doing nothing in some situations, thus avoiding
		infinite loops. It sets the correct `tool_id` using adequate methods
		otherwise.r   r   N)rP   r  r7   r|   rw   rF   )r+   ry   state_as_strings      r.   r  zDrWindow.on_change_active_toolv  sm     G&&(/Q))+6688		ZZ ::<>>/"::o335r/   c                    d| _         | j                  d      }|j                  t        j                  j                  |             | j                  | _        | j                  |   j                  }| j                         j                  |       | j                         j                          | j                         j                  j                          || _         | j                         j!                          || _        | j#                         j%                          | j'                          | j                         j)                          | j+                          d| _         y)zSwitch from the current tool to `new_tool_id` and to the current
		image to `image_pointer` (`None` if the image is not changing).NrE   )r!   r   r  r   r#  r+  r"   ro   r7   accept_selectionformer_toolgive_back_controlon_tool_unselectedr   r   hide_popoversupdaterE   on_tool_selected_update_bottom_paneupdate_actions_stater  )r+   new_tool_idimage_pointerr   should_preserve_selections        r.   rw   zDrWindow.switch_to  s    "&$m,&4<<**;78 ++$"jj5FF&&'@A'')##113!.$   "#$%%'..0!%$r/   c                    	 | j                   j                  | j                         j                         | j                   j	                  | j                                | j                          | j                          y# t        $ r<}| j                  t        d      | j                  z         t        |       Y d}~yd}~ww xY w)zAShow the correct bottom pane, with the correct tool options menu.zHError loading the bottom pane for the tool '%s', please report this bug.N)r9   try_enable_panerE   pane_idupdate_pane_build_options_menur   rB   rC   r6   r"   rY  )r+   es     r.   rI  zDrWindow._update_bottom_pane  s    ''(8(8(:(B(BC##D$4$4$67	 q 0 1373F3FG H88s   A<A? ?	C2B??Cc                 4    | j                   | j                     S ru   )r7   r"   r  s    r.   rE   zDrWindow.active_tool      	D''	((r/   c                 4    | j                   | j                     S ru   )r7   ro   r  s    r.   rC  zDrWindow.former_tool  rU  r/   c                     | j                   | j                  k(  r| j                          y| j                  | j                      j	                          y)zTSwitch back to the previously active tool, if it's different from the
		current one.N)ro   r"   force_selectionr7   rF   r   s     r.   rc  zDrWindow.back_to_previous  sA     
D/// ::d!!"779r/   c                    | j                         j                         }| j                         j                         }| j                         j                         }|| j                  j                         j                  d       t        j                         }|j                  |       |j                  dd       | j                  j                         j                  d|       nT| j                  j                         j                  d       | j                  j                         j                  d||       | j                  j                         }|j                  |||       y)a
  Build the active tool's option menus.
		The first menu is the popover from the bottom bar. It can be built from
		a Gio.MenuModel, or it can contain any widget.
		The second menu is build from a Gio.MenuModel and is in the menubar (not
		available with all layouts).N   zwin.PLACEHOLDER)rE   get_options_widgetget_options_modelget_options_labelr    r  r+  r   MenuItemr  set_action_and_target_valueinsert_iteminsert_submenur9   r  build_options_menu)r+   widgetmodelr]   r  panes         r.   rR  zDrWindow._build_options_menu  s    002&




.
.
0%




.
.
0%
]88  #
,,.4>>%##$5t<88%%a.88  #88((E59				-	-	/$&%/r/   c                     |d   j                          }| j                  j                  d|       |d   j                  t        j
                  j                  |             | j                  j                  |       y )Nr   ri  )	r  r&   r   r  r   r#  r$  r9   set_palette_setting)r+   ry   rj  s      r.   r  zDrWindow.action_use_editor  sa    7$$&&*..0*=q'DLL,,Z89**:6r/   c                 T    | j                   j                         j                          y ru   )r9   get_classic_tools_paner  r   s     r.   r  zDrWindow.exchange_colors  s    --/CCEr/   c                     | j                         j                  r)| j                  j                         j	                          y y ru   )rE   	use_colorr9   left_color_btnrO  r   s     r.   r  zDrWindow.action_color1  s4    	!!&&(--/ "r/   c                     | j                         j                  r)| j                  j                         j	                          y y ru   )rE   rk  r9   right_color_btnrO  r   s     r.   r  zDrWindow.action_color2  s4    	!!'')..0 "r/   c                 :    | j                   j                  d       y r   r9   update_tool_widthr   s     r.   r  zDrWindow.action_size_more  s    ((+r/   c                 :    | j                   j                  d       y )Nr   rp  r   s     r.   r  zDrWindow.action_size_less  s    ((,r/   c                 @    | j                         j                          y)zDisplay the properties dialog for the current image. This could be
		done here but it's done in DrImage to have a satisfying UML diagram.N)r   show_propertiesr   s     r.   r{  zDrWindow.action_properties  s     ))+r/   c                     | j                    | _         | j                  j                         D ]  }|j                           |d   j	                  t
        j                  j                  | j                                y)zqDevelopment only: tracks and displays the framerate, thus it helps
		debugging how Gdk/cairo draws on the widget.r   N)r%   r   r   reset_fps_counterr  r   r#  r$  )r+   ry   imgs      r.   r  zDrWindow.action_fsp  sd     %)$?$? ?$]]'') cq'DLL,,T-H-HIJr/   c                     | j                   3| j                  j                  | j                  j                               S | j                   S ru   )r!   r   r   r   r  s    r.   r   zDrWindow.get_active_image  s<    	!!)
--
$
$T]]%C%C%E
FF

&
&&r/   c                 @    | j                         j                          y ru   )r   reset_to_initial_pixbufr   s     r.   ry  zDrWindow.action_reset  s    113r/   c                 @    | j                         j                          y ru   )r   reload_from_diskr   s     r.   rz  zDrWindow.action_reload  s    **,r/   c                    | j                         }|y|j                         j                  d      d   }| j                  t	        d      |z         | j                         j                         r| j                  |       n| j                  j                  |j                               \  }}|=| j                  |      s,|j                  j                  |       | j                          yt        |       }|j                  t	        d      dd      }|j                  t	        d      d      }|j                  t	        d      d	      }	| j                         j!                         s9|j#                  t	        d
      | j                         j%                         z         |j#                  t	        d      |z         |j'                         }
|j)                          |
|k(  r| j+                  |d       n:|
|	k(  r| j                  |d       n"|
|k(  r| j                  j-                  |dd       | j                          y)zHandle the result of an "open" file chooser dialog, and open it in
		the current tab, or in a new one, or in a new window. The decision is
		made depending on what's in the current tab, and (if any doubt)
		according to the user explicit decision.Nr   r   z
Loading %szNew TabTz
New WindowzDiscard changeszdestructive-actionz&There are unsaved modifications to %s.zWhere do you want to open %s?F)file_chooser_openr   rR   rC   r6   r   should_replace_try_load_filer    r   r   r   r   re   r   rU   r   rT   get_filename_for_displayrV   rW   r   open_window_with_content)r+   ry   r1   	file_namer   r   r\   
new_tab_idnew_window_id
discard_idr`   s              r.   r  zDrWindow.action_open   s   
 
 
 
"%
]	~~%%c*2.9q23	++- u ((++ENN,<=<1iD$;$;E$BJJ	*
D!6!!!I,d;:$$Q|_d;=!!!$5"68LM:



!
*
*
,
a@A&&(AACD E 
Q67)CDJJL6	>>
UE**u%-HH%%eUE:r/   c           	      f   d}t         j                  j                  t        d      | t         j                  j
                  t        d      t        d            }t        |       |j                         }|t         j                  j                  k(  r|j                         }|j                          |S )zBOpens an "open" file chooser dialog, and return a GioFile or None.NzOpen a pictureOpenCancel)r   FileChooserNativer  r6   FileChooserActionOPENr   rV   r   ACCEPTget_filerW   )r+   ry   r1   file_chooserr   s        r.   r~  zDrWindow.file_chooser_open,  s    
%&&**1-=+>,,111V9akK,#L1(!!(((  "5	,r/   c                    t        |       }|j                  t        d      d      }	|j                  t        d      d      }
|j                  t        d      dd      }|j                         }g }|D ]U  }	 t        j
                  j                  |      }t        |      \  }}|r|j                         E| j                  |       W t        |      dk(  ryt        |      dk(  r&|d   j                         j                  d	      d
   }nt        d      }|j                  t        d      |z         |j!                         }|j#                          ||
k(  r|D ]  }| j%                  |        y||k(  r#| j'                  |d   j                                yy# t        $ r}d}|j                  }Y d}~d}~ww xY w)zSignal callback: when files are dropped on `self.notebook`, a message
		dialog is shown, asking if the user prefers to open them (one new tab
		per image), or to import them (it will only import the first), or to
		cancel (if the user dropped mistakenly).r  Nr  ImportTFr   r   r   r   zthese fileszWhat do you want to do with %s?r4   )r   rU   r6   get_urisr   Filenew_for_urir   rB   r  r   rC   r'  r   rR   rT   rV   rW   r@   import_from_path)r+   rc  drag_contextxydatainfotimer\   	cancel_idopen_id	import_idurisgfilesurir1   is_valid_image	error_msgrI   r]   r`   fs                         r.   r
  zDrWindow.on_data_dropped8  s   
 4 &(T2)ai.'(T48)	$& 
#cHH  %E 8 ?NI 
MM%	"
# 	[A	
6{a!9%%c*2.5 ]5 	A785@A::<&..w !qa !++-. 3  NIs   6-F	F?&F::F?c                 "   |y |r[| j                   j                  |j                               \  }}|-| j                  |      s|j                  j                  |       y | j                         j                  |       | j                          y ru   )	r    r   r   r   r   r   r   r   r   r   s        r.   r  zDrWindow._try_load_filed  sv    
]	((++ENN,<=<1imD33E:JJ	*
''.r/   c                     | j                   j                         D ]2  }|j                         |k(  s| j                   j                  |      c S  y ru   )r   r   get_file_pathr   )r+   	file_pathr   s      r.   r   zDrWindow.has_image_openedp  sI    ]]'') 'c	Y&==!!#&&' 
r/   c                 >    | j                   j                  dddd      S )zYTry to save the active image, and return True if the image has been
		successfully saved.FTr:   save_current_imager   s     r.   r  zDrWindow.action_savev  s!     
			/	/ueT	JJr/   c                 >    | j                   j                  dddd      S )NFTr  r   s     r.   r  zDrWindow.action_save_as{  s    				/	/tUD	IIr/   c                 >    | j                   j                  dddd      S NFr  r   s     r.   r  zDrWindow.action_save_alphaless~  s    				/	/ueU	KKr/   c                 >    | j                   j                  dddd      S )NTFr  r   s     r.   r  zDrWindow.action_export_as  s    				/	/dE4	HHr/   c                 n    | j                         j                  }| j                  j                  |       y ru   )r   main_pixbufr;   print_pixbufr   s      r.   r  zDrWindow.action_print  s*      "..&$$V,r/   c                     t         j                  j                  t        j                        }|j                  | j                         j                         | j                  t        d      d       y )NzImage copied to clipboardT)
r   r   r   r   r   	set_imager   r  rC   r6   )r+   ry   r   s      r.   r  zDrWindow.action_export_cb  sM    
}}001",,t$$&223a34d;r/   c                 T    | j                         j                  j                          y)z0Development only: helps debugging the selection.N)r   r   print_valuesr   s     r.   r  zDrWindow.action_getvalues  s    ##002r/   c                 `    | j                          | j                         j                          y ru   )rX  get_selection_toolr\  r   s     r.   r  zDrWindow.action_select_all  s#    &&(r/   c                 B    | j                         j                  d       y r  )r  rD  r   s     r.   r  zDrWindow.action_unselect  s    --e4r/   c                 D    | j                          | j                          y ru   )copy_operationr  r   s     r.   r  zDrWindow.action_cut  s    r/   c                 $    | j                          y ru   )r  r   s     r.   r  zDrWindow.action_copy  s    r/   c                     t         j                  j                  t        j                        }|j                  | j                         j                  j                                y ru   )	r   r   r   r   r   r  r   r   r   )r+   r   s     r.   r  zDrWindow.copy_operation  s@    
}}001",,t$$&00;;=>r/   c                 @    | j                         j                          y ru   )r  delete_selectionr   s     r.   r  zDrWindow.action_delete      ,,.r/   c                 D   t         j                  j                  t        j                        }|j                         }|0| j                          | j                         j                  |       y|j                         }|| j                  d   j                  |       yy)a  By default, this action pastes an image, but if there is no image in
		the clipboard, it will paste text using the text tool. Once the text
		tool is active, this action is disabled to not interfere with the default
		behavior of ctrl+v provided by the GTK text entry.Ntext)r   r   r   r   r   r   rX  r  import_selectionwait_for_textr7   force_text_tool)r+   ry   r   r   strings        r.   r  zDrWindow.action_paste  s    
 }}001"&--f56JJv&&v. r/   c           	      ~   t         j                  j                  t        d      | t         j                  j
                  t        d      t        d            }t        |       |j                         }|t         j                  j                  k(  r| j                  |j                                |j                          y)zeHandle the result of an 'open' file chooser dialog. It will then try
		to import it as the selection.zImport a picturer  r  N)r   r  r  r6   r  r  r   rV   r   r  r  get_filenamerW   )r+   ry   r  r   s       r.   r  zDrWindow.action_import  s     &&**1-?+@$**//8akK,#L1(!!(((2245r/   c                     | j                          t        j                  j                  |      }| j	                         j                  |       y)zyImport a file as the selection pixbuf. Called by the 'win.import'
		action or when an image is imported by drag-and-drop.N)rX  r   Pixbufnew_from_filer  r  )r+   r  r   s      r.   r  zDrWindow.import_from_path  s=     )))4&,,V4r/   c                 >    | j                   j                  dddd      S )NTr  r   s     r.   r  z DrWindow.action_selection_export  s    				/	/dD$	GGr/   c                 @    | j                         j                          y ru   )r  replace_canvasr   s     r.   r  z(DrWindow.action_selection_replace_canvas  s    **,r/   c                 d    | j                   d   }|j                         }|j                  |       y )Ncrop)r7   build_selection_fit_operationapply_operation)r+   ry   	crop_tool	operations       r.   r  z'DrWindow.action_selection_expand_canvas  s,    jj )557)I&r/   c                 @    | j                         j                          y ru   )r  invert_selectionr   s     r.   action_selection_invertz DrWindow.action_selection_invert  r  r/   c                    d| j                   v r| j                   d   S d| j                   v r| j                   d   S d| j                   v r| j                   d   S | j                  t        d             | j                         S )Nrect_selectfree_selectcolor_selectzRequired tool is not available)r7   r5   r6   rE   r  s    r.   r  zDrWindow.get_selection_tool  sv    djj 
**]
##

"
**]
###
**^
$$Q?@A



r/   c                 @    | j                         j                          y ru   )r  rF   r  s    r.   rX  zDrWindow.force_selection  s    002r/   c                 @    | j                         j                          y ru   )rE   !on_apply_transform_tool_operationr   s     r.   r  zDrWindow.action_apply_transform  s    668r/   c                 @    | j                         j                          y ru   )rE   "on_cancel_transform_tool_operationr   s     r.   r  z DrWindow.action_cancel_transform  s    779r/   c                 @    | j                         j                          y ru   )r   try_undor   s     r.   r  zDrWindow.action_undo  s    ""$r/   c                 @    | j                         j                          y ru   )r   try_redor   s     r.   r  zDrWindow.action_redo  s    ""$r/   c                 |    | j                         j                          | j                         j                          y)z4[Dev only] show the last saved pixbuf on the canvas.N)r   use_stable_pixbufrG  r   s     r.   r  zDrWindow.action_restore  s,    ++-  "r/   c                 T    | j                         j                  j                          y)z>[Dev only] rebuild the image according to the history content.N)r   _history_rebuild_from_historyr   s     r.   r  zDrWindow.action_rebuild  s    ""88:r/   c                 p    | j                   j                  |       | j                   j                  |       y ru   )r   set_undo_labelset_redo_label)r+   
undo_label
redo_labels      r.   update_history_actions_labelsz&DrWindow.update_history_actions_labels  s*    "":."":.r/   c                 F    | j                         j                  ddd       y )Nr   r   r   r   
add_deltasr   s     r.   r}  zDrWindow.action_go_up  s    $$QC0r/   c                 F    | j                         j                  ddd       y )Nr   r   r   r  r   s     r.   r~  zDrWindow.action_go_down      $$Q3/r/   c                 F    | j                         j                  ddd       y )Nr   r   r   r  r   s     r.   r  zDrWindow.action_go_left  s    $$RC0r/   c                 F    | j                         j                  ddd       y )Nr   r   r   r  r   s     r.   r  zDrWindow.action_go_right  r  r/   c                 D    | j                         j                  dd       y )Nr   r   r   reset_deltasr   s     r.   r  zDrWindow.action_go_top  s    &&q"-r/   c                 D    | j                         j                  dd       y r   r  r   s     r.   r  zDrWindow.action_go_bottom      &&q!,r/   c                 D    | j                         j                  dd       y )Nr   r   r  r   s     r.   r  zDrWindow.action_go_first  s    &&r1-r/   c                 D    | j                         j                  dd       y r   r  r   s     r.   r  zDrWindow.action_go_last  r  r/   c                 0   |d   j                          }|r5| j                  j                          | j                  j                          n| j                  j	                          |d   j                  t        j                  j                  |             y)zAAction callback, showing or hiding the "minimap" preview popover.r   N)	r  r8   popupupdate_contentpopdownr  r   r#  r$  )r+   ry   preview_visibles      r.   rs  zDrWindow.action_toggle_preview   sk    Q))++/<<<< <<q'DLL,,_=>r/   c                 B    | j                         j                  d       y )N   r   inc_zoom_levelr   s     r.   r  zDrWindow.action_zoom_in*  s    ((,r/   c                 B    | j                         j                  d       y )Nir  r   s     r.   r  zDrWindow.action_zoom_out-      ((-r/   c                 B    | j                         j                  d       y )Nr   r   set_zoom_levelr   s     r.   r  zDrWindow.action_zoom_1000  r  r/   c                 @    | j                         j                          y ru   )r   set_opti_zoom_levelr   s     r.   r  zDrWindow.action_zoom_opti3  s    --/r/   c                     | j                         j                  d       | j                         j                  d       y )Ni  r
  r   s     r.   r  zDrWindow.action_zoom_max6  s0    ((.((.r/   )Tru   )F)__name__
__module____qualname____gtype_name__r   r  r  r&   r   TemplateChildrg   r  r   r  r  r   r  r  r  r,  r*  r   rJ   rG   r=   ri   rv   rm   r   rA   r   r?   r   r   r   r   r@   r   r   r   r   r   r   r   r   r   r>   r   r  r'  r,  r<   r  r   r  r   r  r  r*   rp  rq  r   r   rt  r)   rd   r5   rC   r  re   r|  rx  rv  r  r!  r  r4  rk   ru  r  r  rw   rI  rE   rC  rc  rR  r  r  r  r  r  r  r{  r  r   ry  rz  r  r~  r
  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rX  r  r  r  r  r  r  r  r}  r~  r  r  r  r  r  r  rs  r  r  r  r  r  __classcell__)r-   s   @r.   r   r   ,   s   \\<= ##%||!!#LL ll  "||!!#LL LL&&(LL&&(<<%%'**,<<--/(0d)=V B#

'	=$%
# !%T ';@*!&G44
"#,L ?A Bsj	'S
++(/8"%
2$+
=
?  :
@"!:@*9*N;
5
6&6
)):0*7F01,-,
K'4-*X
*/X
K
JLI-<3)5?//	5H-'
/	39:%%#
;/1010.-.-?-..0/r/   r   )#r  gi.repositoryr   r   r   r   r   imager	   new_image_dialogr
   r8   r   r9   r   message_dialogr   deco_managerr   r   r   r:   r   r;   r   rr   r   utilities_filesr   r   UI_PATHrn   r  ApplicationWindowr   r   r/   r.   <module>r     s{   & 
 8 8  1  - +/ / , / 16 . GK/0L/s$$ L/ 1L/r/   