
    cc                     B    d dl Z d dlZddlmZ ddlmZ  G d de      Zy)    N   )AbstractClassicTool)utilities_add_arrow_trianglec                   `     e Zd Zd Z fdZd Zd Zd Zd Zd Z	d Z
ddZd	 Zd
 Zd Z xZS )ToolLinec                    t         |   dt        d      d|       d| _        d| _        d| _        d| _        d| _        d| _        | j                  dd       | j                  d	| j
                         | j                  d
| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                          y )NlineLineztool-line-symbolicTFnone
line_shaperounddashes-type
arrow-typeuse_gradientpencil-outlineline-ortholock)super__init___use_operator_use_outline_dashes_type_arrow_type_use_gradient
_ortholockadd_tool_action_enumadd_tool_action_boolean_set_options_attributes)selfwindowkwargs	__class__s      3/usr/lib/python3/dist-packages/drawing/tool_line.pyr   zToolLine.__init__   s    '61V9&:FC$$$$$$/L'2M4+<+<=L$*:*:;~t/A/AB/1B1BC/A     c                 `   |dk7  ry t        | j                  |z
        }t        | j                  |z
        }t        d      t	        |      z  }t        d      t	        |      z  }t        t        j                  ||z  ||z  z         d      }|dz   |z   dz   t        d      t	        |      z  z   S )Nr   zWidth: %spxzHeight: %spx   
zLength: %spx)absx_pressy_pressr   strr   mathsqrt)	r   event_xevent_ymotion_behaviordelta_xdelta_yline1line2lengths	            r#   get_tooltipzToolLine.get_tooltip,   s    
w&''w&''
M
S\
)%
N
c'l
*%7W,w/@@A1E&			$q'83v;'F	FFr$   c                     | j                  d      }|dk(  r t        j                  j                  | _        y t        j                  j
                  | _        y )Nr   thin)get_option_valuecairoLineCapBUTT_cap_idROUND)r   state_as_strings     r#   _set_active_shapezToolLine._set_active_shape9   s<    )),7/--$$4<--%%4<r$   c                     t        d      S )NzLine options)r   r   s    r#   get_options_labelzToolLine.get_options_label@   s    	
>	r$   c                     | j                  d      | _        | j                  d      | _        | j                  d      | _        | j                  d      | _        | j                  d      | _        | j                          y )Nr   r   r   r   r   )r9   r   r   r   r   r   r@   rB   s    r#   r   z ToolLine._set_options_attributesC   sn    ++,<=$++M:$**<8$,,^<$))*:;$/r$   c                    | j                          | j                  dk7  }| j                  dk7  }| j                  }|r|r|dt	        d      z   z  }n*|r|dt	        d      z   z  }n|r|dt	        d      z   z  }nd }| j                  dz   }| j
                  r|t	        d      z  }n|t	        d      z  }| j                  dz   t	        d      z   }| j                         j                         rd }d }|||g}t        t        d |            S )	Nr   z - zDashed arrowArrowDashedz*Press <Shift> to unlock the line directionz(Press <Shift> to lock the line directionz*Press <Alt> to toggle the 'outline' option)
r   r   r   labelr   r   	get_imageget_mouse_is_pressedlistfilter)r   is_arrow
use_dasheslabel_optionslabel_modifier_shiftlabel_modifier_alt	full_lists          r#   get_editing_tipszToolLine.get_editing_tipsK   s    '(  F****-*EAn---=EAgJ&&=EAhK''==e+	__1IJJ1GHHzzE)IJK 
^^**,24FG)	fT9%	&&r$   c                     | j                  |j                  ||       | j                  |j                         d| j                  v r| j
                   | _        d| j                  v r| j                   | _        y y )NSHIFTALT)set_common_valuesbuttonupdate_modifier_statestate_modifier_keysr   r   )r   eventsurfacer.   r/   s        r#   on_press_on_areazToolLine.on_press_on_areal   sj    w8U[[)###(4?
d!!!,,,4 "r$   c                 P    |sy | j                  ||      }| j                  |       y N)build_operationdo_tool_operation)r   r\   r]   r.   r/   render	operations          r#   on_motion_on_areazToolLine.on_motion_on_areau   s(    		""7G4)#r$   c                 J    | j                  ||      }| j                  |       y r`   )ra   apply_operation)r   r\   r]   r.   r/   rd   s         r#   on_release_on_areazToolLine.on_release_on_area{   s"    ""7G4)y!r$   c                    i d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d|d|d| j                  d| j                  }|S )Ntool_idrgbargba2	antialiasoperator
line_widthline_capdashesarrowgradientoutline	ortholock	x_release	y_releaser)   r*   )id
main_colorsecondary_color_use_antialias	_operator
tool_widthr=   r   r   r   r   r   r)   r*   )r   r.   r/   rd   s       r#   ra   zToolLine.build_operation   s   dgg	4?? D   ##	
 t~~  t|| T D t!! d    dll  dll!)$ 
r$   c                    | j                  |      }|j                  |d          |d   }|j                  |       |d   }|d   }|d   }|d   }|d   rbt        ||z
        }t        ||z
        }	|d|	z  kD  r|}n;|dz  |	k  r|}n0t	        ||	      }
||z
  d	k  r||
z   n||
z
  }||z
  d	k  r||
z   n||
z
  }| j                  |||d
   |d          |d   dk(  rt        ||||||       |j                  ||       |j                  ||       |d   dk7  rt        ||||||       |d   r9 |j                  |d     |j                  |dz  dz          |j                          |d   rVt        j                  ||||      } |j                  dg|d      |j                  dg|d     |j                  |       n |j                  |d     |j                  |       |j                          y )Nrn   ro   r)   r*   rv   rw   ru   r&   r   rq   rp   rr   doubler   rt   rl   g333333?rs   g?rk   g?)start_tool_operationset_operatorset_line_widthr(   minset_dashes_and_capr   move_toline_toset_source_rgbastroke_preserver:   LinearGradientadd_color_stop_rgba
set_sourcestroke)r   rd   cairo_contextro   x1y1x2y2r1   r2   delta45patterns               r#   rb   zToolLine.do_tool_operation   s=   ++I6-Yz23&*z*""""{b\7b\7G	B!g	B '7#Gr'A+gBLBr'A+gBLB-(2Ij4IK w8#r2r2zJ BBw6!r2r2zJy =  )G"45
S 01 45  "z!!"b"b177s7Yv%677s8Yw%78G$ =  )F"34z*r$   )T)__name__
__module____qualname____gtype_name__r   r6   r@   rC   r   rS   r^   re   rh   ra   rb   __classcell__)r"   s   @r#   r   r      sA    !&	G&'B-$"*4r$   r   )r:   r,   abstract_classic_toolr   utilities_pathsr   r    r$   r#   <module>r      s   $  6 9t" tr$   