Ë
    c­øc6+  ã                   ó`   — d dl Z d dlmZmZmZ  G d„ de«      Z G d„ de«      Z G d„ d«      Zy)	é    N)ÚGtkÚGdkÚ	GdkPixbufc                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )ÚNoSelectionPixbufExceptionc                 ó6   •— t         ‰| �  t        d«      «       y )NzThe selection pixbuf is empty.©ÚsuperÚ__init__Ú_©ÚselfÚargsÚ	__class__s     €ú;/usr/lib/python3/dist-packages/drawing/selection_manager.pyr   z#NoSelectionPixbufException.__init__   s   ø€ ä�'Ñ”1Ð5Ó6Õ7ó    ©Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__©r   s   @r   r   r      s   ø„ ÷8ð 8r   r   c                   ó   ‡ — e Zd Zˆ fd„Zˆ xZS )ÚNoSelectionPathExceptionc                 ó6   •— t         ‰| �  t        d«      «       y )NzThe selection path is empty.r	   r   s     €r   r   z!NoSelectionPathException.__init__   s   ø€ Ü�'Ñ”1Ð3Ó4Õ5r   r   r   s   @r   r   r      s   ø„ ÷6ð 6r   r   c                   ó¢   — e Zd Zd Zd„ Zd„ Zd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d„ Zd„ Zy)ÚDrSelectionManagerc                 ó´  — || _         | j                  «        | j                  «        t        j                  j                  d«      }|j                  d«      }t        j                  j                  | j                   |«      | _	        |j                  d«      }t        j                  j                  | j                   |«      | _
        | j                  dd«       y )Nz5/com/github/maoschanz/drawing/ui/selection-manager.uizinactive-selection-menuzactive-selection-menug      ð?)ÚimageÚinit_pixbufÚreset_future_datar   ÚBuilderÚnew_from_resourceÚ
get_objectÚPopoverÚnew_from_modelÚmenu_if_inactiveÚmenu_if_activeÚset_popovers_position)r   r   ÚbuilderÚmenu_rÚmenu_ls        r   r   zDrSelectionManager.__init__#   s¥   € Ø€$„*Ø×ÑÔØ×ÑÔä�K‰K×)Ñ)ØIóK€'à×ÑÐ7Ó8€&ÜŸ+™+×4Ñ4°T·Z±ZÀÓH€$ÔØ×ÑÐ5Ó6€&ÜŸ™×2Ñ2°4·:±:¸vÓF€$ÔØ×Ñ˜S #Õ&r   c                 óÆ   — t         j                  j                  t         j                  j                  dddd«      | _        | j                  ddd«       d | _        d| _        y )NTé   é   r   F)	r   ÚPixbufÚnewÚ
ColorspaceÚRGBÚselection_pixbufÚ
set_coordsÚselection_pathÚ	is_active©r   s    r   r    zDrSelectionManager.init_pixbuf0   sR   € ä#×*Ñ*×.Ñ.¬y×/CÑ/C×/GÑ/GØ<@À!ÀQÈóK€$Ôà‡/�/�$˜˜1ÔØ€$ÔØ€$….r   Nc           	      óF  — |€
t        «       ‚|| _        d| _        | j                  j                  }t        j                  |dd«      }|j                  | j                  j                  | j                  j                  «       t        j                  |«      }|j                  t        j                  j                  «       |j                  «        |j                  | j                  «       |j!                  «        |j                  t        j                  j"                  «       |j%                  «       }|j'                  «       }|j)                  «       \  }}	}
}t+        |
|«      }
t+        ||«      }t-        t/        |d«      «      }t-        t/        |	d«      «      }	| j0                  dk  r| j0                  }| j2                  dk  r| j2                  }	t-        |
|z
  «      }t-        ||	z
  «      }|dkD  r…|dkD  r€t        j4                  |t-        |«      t-        |	«      ||«      }|�d|�I|d   dkD  rA|j7                  dt-        |d   dz  «      t-        |d   dz  «      t-        |d   dz  «      «      }|| _        n| j;                  d«       | j                  j=                  «        y)	zwCreate a selection_pixbuf from a minimal part of the main surface by
		erasing everything outside of the provided path.NTr   ç        é   éÿ   r/   é   )r   r6   r7   r   Úmain_pixbufr   Ú cairo_surface_create_from_pixbufÚset_device_scaleÚSCALE_FACTORÚcairoÚContextÚset_operatorÚOperatorÚDEST_INÚnew_pathÚappend_pathÚfill_preserveÚOVERÚ	get_widthÚ
get_heightÚpath_extentsÚminÚintÚmaxÚselection_xÚselection_yÚpixbuf_get_from_surfaceÚ	add_alphar4   ÚresetÚupdate_actions_state)r   rG   Úrgbar>   ÚsurfaceÚcairo_contextÚ
main_widthÚmain_heightÚxminÚyminÚxmaxÚymaxÚselection_widthÚselection_heightÚpixbufs                  r   Úload_from_pathz!DrSelectionManager.load_from_path8   sG  € ð ÐÜ	!Ó	#Ð#à €$ÔØ€$„.Ø—
‘
×&Ñ&€+ô ×0Ñ0°¸aÀÓF€'Ø	×Ñ˜4Ÿ:™:×2Ñ2°D·J±J×4KÑ4KÔLÜ—-‘- Ó(€-Ø×ÑœUŸ^™^×3Ñ3Ô4Ø×ÑÔØ×Ñ˜D×/Ñ/Ô0Ø×ÑÔØ×ÑœUŸ^™^×0Ñ0Ô1ð ×$Ñ$Ó&€*Ø×&Ñ&Ó(€+Ø(×5Ñ5Ó7Ñ€$ˆˆd�DÜ	ˆT�:Ó	€$Ü	ˆT�;Ó	€$Ü	Œc�$˜‹nÓ	€$Ü	Œc�$˜‹nÓ	€$Ø	×Ñ˜ÒØ
×
Ñ
€4Ø	×Ñ˜ÒØ
×
Ñ
€4ô ˜˜t™Ó$€/Ü˜ ™Ó%ÐØ�qÒÐ-°Ò1ä×'Ñ'¨´°T³¼CÀ»IØ%4Ð6FóH€6àÐØÐ˜D ™G cšMØ×Ñ˜t¤S¨¨a©°3©Ó%7Ü%(¨¨a©°3©Ó%7Ü%(¨¨a©°3©Ó%7ó9€Vð #€DÕð ‡:�:ˆdÔØ‡*�*×!Ñ!Õ#r   c                 óB   — || _         || _        |r|| _        || _        y y ©N)rQ   rR   Útemp_xÚtemp_y)r   Útemp_tooÚxÚys       r   r5   zDrSelectionManager.set_coordsl   s(   € Ø€$ÔØ€$ÔÙØ€4„;Ø€4…;ð r   c                 ó2   — || _         | j                  «        y re   )r4   Ú_create_path_from_pixbuf)r   rb   s     r   Ú
set_pixbufzDrSelectionManager.set_pixbufs   s   € à €$ÔØ×ÑÕ!r   c                 ó   — | j                   S re   )r4   r8   s    r   Ú
get_pixbufzDrSelectionManager.get_pixbufx   s   € Ø	×	Ñ	Ðr   c                 óÂ   — d | _         d | _        | j                  ddd«       d| _        |r5| j                  j                  «        | j                  j                  «        y y )NTr   F)r4   r6   r5   r7   r   rV   Úupdate)r   Úupdate_images     r   rU   zDrSelectionManager.reset{   sQ   € à€$ÔØ€$ÔØ‡/�/�$˜˜1ÔØ€$„.ÙØ‡:�:×"Ñ"Ô$Ø‡:�:×ÑÕð r   c                 ó^  — | j                   €
t        «       ‚|| j                  j                  z
  | j                  z   | j
                  z
  }|| j                  j                  z
  | j                  z   | j                  z
  }| j                  ||«      }|j                  «        |j                  «       S re   )r6   r   r   Úscroll_xrQ   rf   Úscroll_yrR   rg   Ú_get_context_with_pathÚ
close_pathÚ	copy_path)r   Útool_dxÚtool_dyÚdelta_xÚdelta_yrY   s         r   Úget_path_with_scrollz'DrSelectionManager.get_path_with_scroll…   s”   € à	×ÑÐ Ü	!Ó	#Ð#Ø�d—j‘j×)Ñ)Ñ)¨D×,<Ñ,<Ñ<¸t¿{¹{ÑJ€'Ø�d—j‘j×)Ñ)Ñ)¨D×,<Ñ,<Ñ<¸t¿{¹{ÑJ€'Ø×-Ñ-¨g°wÓ?€-Ø×ÑÔØ	×	 Ñ	 Ó	"Ð"r   c                 óü  — | j                   €
t        «       ‚|rM| j                  | j                  j                  z
  |z   }| j
                  | j                  j                  z
  |z   }n| j                  |z   }| j
                  |z   }t        j                  || j                   ||«       | j                  j                  «       r-|j                  «       j                  t        j                  «       |j                  «        y re   )r4   r   rQ   r   rt   rR   ru   r   Úcairo_set_source_pixbufÚis_zoomed_surface_sharpÚ
get_sourceÚ
set_filterrB   ÚFILTER_NEARESTÚpaint)r   rY   Úwith_scrollry   rz   ri   rj   s          r   Úshow_selection_on_surfacez,DrSelectionManager.show_selection_on_surface�   sË   € Ø	×ÑÐ"Ü	#Ó	%Ð%ÙØ×Ñ˜$Ÿ*™*×-Ñ-Ñ-°Ñ7€1Ø×Ñ˜$Ÿ*™*×-Ñ-Ñ-°Ñ7�1à×Ñ˜'Ñ!€1Ø×Ñ˜'Ñ!€1Ü×Ñ˜m¨T×-BÑ-BÀAÀqÔIØ	‡Z�Z×'Ñ'Ô)Ø×ÑÓ×(Ñ(¬×)=Ñ)=Ô>Ø×ÑÕr   c                 ó²   — | j                   j                  «       }| j                   j                  «       }| j                  |dz  z   | j                  |dz  z   fS )z1Return the coords of the center of the selection.r=   )r4   rK   rL   rQ   rR   )r   ÚwÚhs      r   Úget_center_coordsz$DrSelectionManager.get_center_coords�   sS   € à
×Ñ×%Ñ%Ó'€!Ø
×Ñ×&Ñ&Ó(€!Ø	×	Ñ	˜A ™EÑ	! 4×#3Ñ#3°a¸!±eÑ#;Ð	;Ð;r   c                 ó  — | j                   sy| j                  | j                  j                  | j                  j                  «      }| j                  «       }|j                  «        |j                  |«       |j                  ||«      S )z£Returns a boolean if the point whose coordinates are "(tested_x,
		tested_y)" is in the path defining the selection. If such path doesn't
		exist, it returns None.T)	r7   r}   r   rt   ru   Ú_get_contextrG   rH   Úin_fill)r   Útested_xÚtested_yÚscrolled_pathrY   s        r   Úpoint_is_in_selectionz(DrSelectionManager.point_is_in_selection£   so   € ð 
�ŠØ
Ø×+Ñ+¨D¯J©J×,?Ñ,?ÀÇÁ×ATÑATÓU€-Ø×#Ñ#Ó%€-Ø×ÑÔØ×Ñ˜MÔ*Ø	×	Ñ	˜x¨Ó	2Ð2r   c                 óŽ  — | j                   €
t        «       ‚| j                  | _        | j                  | _        d| _        | j                  «       }|j                  | j                  | j                  «       |j                  | j                   j                  «       d«       |j                  d| j                   j                  «       «       |j                  d| j                   j                  «       z  d«       |j                  «        |j                  «       | _        | j                  «        | j                   j#                  «        y)zàThis method creates a rectangle selection from the currently set
		selection pixbuf.
		It can be the result of an editing operation (crop, scale, etc.), or it
		can be an imported picture (from a file or from the clipboard).NTr   éÿÿÿÿ)r4   r   rQ   rf   rR   rg   r7   rŒ   Úmove_toÚrel_line_torK   rL   rw   rx   r6   Úhide_popoversr   rV   )r   rY   s     r   rl   z+DrSelectionManager._create_path_from_pixbuf±   sÿ   € ð
 
×ÑÐ"Ü	#Ó	%Ð%Ø× Ñ €$„+Ø× Ñ €$„+Ø€$„.Ø×#Ñ#Ó%€-Ø×Ñ˜×(Ñ(¨$×*:Ñ*:Ô;Ø×Ñ˜D×1Ñ1×;Ñ;Ó=¸qÔAØ×Ñ˜A˜t×4Ñ4×?Ñ?ÓAÔBØ×Ñ˜B ×!6Ñ!6×!@Ñ!@Ó!BÑBÀAÔFØ×ÑÔØ%×/Ñ/Ó1€$ÔØ×ÑÔØ‡*�*×!Ñ!Õ#r   c                 óT   — t        j                  | j                  j                  «      S re   )rB   rC   r   rX   r8   s    r   rŒ   zDrSelectionManager._get_contextÅ   s   € Ü	�‰�t—z‘z×)Ñ)Ó	*Ð*r   c                 óÎ   — | j                  «       }| j                  D ]E  }|d   dk7  sŒ|d   d   |z   }|d   d   |z   }|j                  t        |«      t        |«      «       ŒG |S )Nr/   © r   )rŒ   r6   Úline_torO   )r   r{   r|   rY   Úptsri   rj   s          r   rv   z)DrSelectionManager._get_context_with_pathÈ   st   € Ø×#Ñ#Ó%€-Ø× Ñ ò *€cØ	ˆ!�f�ƒlØˆA‰ˆq‰	�GÑ€AØˆA‰ˆq‰	�GÑ€AØ×Ñœ#˜a›&¤# a£&Õ)ð	*ð
 
Ðr   c                 óô   — t        j                  «       }t        |«      |_        t        |«      |_        d|_        d|_        | j                  j                  |«       | j                  j                  |«       y)zpSet the coords where the popover should be opened. These coords are
		relative TO THE WIDGET, not to the pixbuf.r/   N)
r   Ú	RectanglerO   ri   rj   ÚheightÚwidthr'   Úset_pointing_tor(   )r   ri   rj   Ú	rectangles       r   r)   z(DrSelectionManager.set_popovers_positionÔ   s\   € ô �m‰m‹o€)Ü�A“€)„+Ü�A“€)„+Ø€)ÔØ€)„/Ø×Ñ×'Ñ'¨	Ô2Ø×Ñ×%Ñ% iÕ0r   c                 ól   — | j                   j                  «        | j                  j                  «        y re   )r(   Úpopdownr'   r8   s    r   r–   z DrSelectionManager.hide_popoversß   s&   € Ø×Ñ×ÑÔØ×Ñ×ÑÕ!r   c                 ó†   — | j                   r| j                  j                  «        y| j                  j                  «        y)z7Open the adequate popover at the previously set coords.N)r7   r(   Úpopupr'   r8   s    r   Úshow_popoverzDrSelectionManager.show_popoverã   s-   € à	‡^‚^Ø×Ñ×ÑÕà×Ñ×ÑÕ r   c                 ó.   — d| _         d| _        d | _        y )Nr   )Ú	_future_xÚ	_future_yÚ_future_pathr8   s    r   r!   z$DrSelectionManager.reset_future_dataí   s   € Ø€$„.Ø€$„.Ø€$Õr   c                 óD   — t        |«      | _        t        |«      | _        y re   )rO   r¨   r©   )r   ri   rj   s      r   Úset_future_coordsz$DrSelectionManager.set_future_coordsò   s   € Ü�q“6€$„.Ü�q“6€$….r   c                 ó2   — | j                   | j                  fS re   )r¨   r©   r8   s    r   Úget_future_coordsz$DrSelectionManager.get_future_coordsö   s   € Ø	�‰˜Ÿ™Ð	'Ð'r   c                 óx  — || _         |sy | j                  j                  j                  «       }| j                  j                  j	                  «       }||}}| j                   D ]/  }|d   dk7  sŒt        |d   d   |«      }t        |d   d   |«      }Œ1 | j                  t        |d«      t        |d«      «       y )Nr/   r™   r   r:   )rª   r   r>   rK   rL   rN   r¬   rP   )r   ÚpathÚresync_coordsrZ   r[   r\   r]   r›   s           r   Úset_future_pathz"DrSelectionManager.set_future_pathù   s±   € Ø€$Ôá	Ø	ð �z‰z×%Ñ%×/Ñ/Ó1€*Ø—
‘
×&Ñ&×1Ñ1Ó3€+Ø˜;ˆ€$Ø×Ñò  €cØ	ˆ!�f�ƒlÜˆs�1‰v�a‰y˜$Ó€DÜˆs�1‰v�a‰y˜$Ó�Dð ð ×Ñœ˜T 3›¬¨T°3«Õ8r   c                 ó   — | j                   S re   )rª   r8   s    r   Úget_future_pathz"DrSelectionManager.get_future_path	  s   € Ø	×	Ñ	Ðr   c                 óà   — | j                  |«       | j                  |z   }| j                  |z   }| j                  d||«       | j	                  | j
                  |z   | j                  |z   «       y )NF)rm   rQ   rR   r5   r¬   r¨   r©   )r   Ú
new_pixbufÚdxÚdyri   rj   s         r   Úupdate_from_transform_toolz-DrSelectionManager.update_from_transform_tool  s`   € Ø‡/�/�*ÔØ
×Ñ˜Ñ€!Ø
×Ñ˜Ñ€!Ø‡/�/�%˜˜AÔØ×Ñ˜Ÿ™¨"Ñ,¨d¯n©n¸rÑ.AÕBr   c                 ó  — t        d| j                  | j                  «       t        d| j                  | j                  «       t        d| j
                  j                  | j
                  j                  «       t        d| j
                  j                  «       t        d«       d| j
                  j                  z
  | j                  z   | j                  z
  }d| j
                  j                  z
  | j                  z   | j                  z
  }| j                  D ].  }|d   dk7  sŒ|d   d   |z   }|d   d   |z   }t        d	||«       Œ0 t        d
| j                  «       t        d| j                  | j                  «       t        d«       y)z_Development only: is linked to the "troubleshoot selection" item in
		the short hamburger menu.zselection coordsztemp coordszimage.scroll coordszimage.zoom_levelz(selection_path with scroll & temp deltasr   r/   r™   ú	zfuture pathzfuture coordsz?---------------------------------------------------------------N)ÚprintrQ   rR   rf   rg   r   rt   ru   Ú
zoom_levelr6   rª   r¨   r©   )r   r   r{   r|   r›   ri   rj   s          r   Úprint_valueszDrSelectionManager.print_values  s?  € ô Ð˜D×,Ñ,¨d×.>Ñ.>Ô?Üˆ�t—{‘{ D§K¡KÔ0ÜÐ˜tŸz™z×2Ñ2°D·J±J×4GÑ4GÔHÜÐ˜DŸJ™J×1Ñ1Ô2äÐ2Ô3Ø�—
‘
×#Ñ#Ñ# d×&6Ñ&6Ñ6¸¿¹ÑD€'Ø�—
‘
×#Ñ#Ñ# d×&6Ñ&6Ñ6¸¿¹ÑD€'Ø× Ñ ò €cØ	ˆ!�f�ƒlØˆA‰ˆq‰	�GÑ€AØˆA‰ˆq‰	�GÑ€AÜ	ˆ$��1Õð	ô ˆ�t×(Ñ(Ô)Üˆ˜Ÿ™¨¯©Ô8ÜÐIÕJr   re   )r   r   r   Ú__gtype_name__r   r    rc   r5   rm   ro   rU   r}   r†   rŠ   r‘   rl   rŒ   rv   r)   r–   r¦   r!   r¬   r®   r²   r´   r¹   r¾   r™   r   r   r   r       s‚   „ Ø&€ò'òó2$òhò"ò
òò#òò<ò
3ò$ò(+òò	1ò"ò!òò
ò(ò9ò òCóKr   r   )	rB   Úgi.repositoryr   r   r   Ú	Exceptionr   r   r   r™   r   r   ú<module>rÂ      s6   ðó$ ß -Ñ -ô8 ô 8ô
6˜yô 6÷IKò IKr   