
    ը	f#                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
  ej                         Z ej                         Z ej                  e      Z ej                  e      Z G d de      Z G d	 d
ej$                        Zy)a  
@package swipe.mapwindow

@brief Map Swipe map window.

Class _MouseEvent taken from wxPython FloatCanvas source code (Christopher Barker).

Classes:
 - mapwindow::SwipeBufferedWindow
 - mapwindow::_MouseEvent

(C) 2012 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Anna Kratochvilova <kratochanna gmail.com>
    N)Debug)UserSettings)BufferedMapWindow)RectNewIdc                        e Zd ZdZ fdZd Zd Zd Zd Z fdZ	d Z
d	 Zd
 Zd Z fdZdddg dddf fd	Z fdZ fdZd Zd Zd fd	Zd Z xZS )SwipeBufferedWindowzA subclass of BufferedWindow class.

    Enables to draw the image translated.
    Special mouse events with changed coordinates are used.
    c                     t        j                  | f||||d| t        j                  dd       t        t
        |          | _        ddg| _        d| _	        d| _
        d| _        t               | _        y )N)parentgifaceMap
properties   zSwipeBufferedWindow.__init__()r   c   Fswipe)r   __init__r   msgsuperr	   GetClientSizespecialSizespecialCoordsimageId
movingSash_moder   lineid)selfr   r   r   r   kwargs	__class__s         3/usr/lib/grass83/gui/wxpython/mapswipe/mapwindow.pyr   zSwipeBufferedWindow.__init__)   sx    ""	
CJ	
RX	
 			!56 !4dIKV
g    c                    | j                  t        j                  | j                         | j                  t        j                  | j
                         | j                  t        | j                         | j                  t        | j                         | j                  t        j                  | j                         y)z-Binds wx mouse events and custom mouse eventsN)
BindwxEVT_MOUSE_EVENTS_mouseActions
EVT_MOTION_mouseMotionOnMotionMouseActionsEVT_CONTEXT_MENUOnContextMenur   s    r   _bindMouseEventsz$SwipeBufferedWindow._bindMouseEvents6   su    		"%%t'9'9:		"--!2!23		*dmm,		"D$5$56		"%%t'9'9:r    c                 D   t        j                  dd       |j                         \  }}|| j                         d   z
  || j                         d   z
  f}t	        ||| j                         |      }| j                         j                  |       |j                          y)z=This is called in various other places to raise a Mouse Event   z&SwipeBufferedWindow._RaiseMouseEvent()r      N)	r   r   GetPositionGetImageCoords_MouseEventGetIdGetEventHandlerProcessEventSkip)r   Event	EventTypexyptevts          r   _RaiseMouseEventz$SwipeBufferedWindow._RaiseMouseEvent>   s    		!=>   "1$$&q))1t/B/B/DQ/G+GG)UDJJL"=++C0

r    c                 0    | j                  |t               y N)r>   EVT_MY_MOUSE_EVENTSr   events     r   r%   z!SwipeBufferedWindow._mouseActionsJ   s    e%89r    c                 0    | j                  |t               y r@   )r>   EVT_MY_MOTIONrB   s     r   r'   z SwipeBufferedWindow._mouseMotionM   s    e]3r    c                 ^    | j                   dk(  r| j                  S t        t        |          S )z6Overridden method which returns simulated window size.r   )r   r   r   r	   r   )r   r   s    r   r   z!SwipeBufferedWindow.GetClientSizeP   s,    :: ###,dACCr    c                 D    t        j                  dd|z         || _        y)z3Overridden method which sets simulated window size.   z.SwipeBufferedWindow.SetClientSize(): size = %sN)r   r   r   )r   sizes     r   SetClientSizez!SwipeBufferedWindow.SetClientSizeW   s    		!ELMr    c                     || _         y)zWSets mode of the window.

        :param mode: mode can be 'swipe' or 'mirror'
        N)r   )r   modes     r   SetModezSwipeBufferedWindow.SetMode\   s    
 
r    c                 :    | j                   dk(  r| j                  S y)z%Returns coordinates of rendered imager   )r   r   )r   r   r,   s    r   r2   z"SwipeBufferedWindow.GetImageCoordsc   s    :: %%%r    c                 V    t        j                  dd|d   d|d          || _        y)z"Sets coordinates of rendered imagerH   z/SwipeBufferedWindow.SetImageCoords(): coords = r   z, r0   N)r   r   r   )r   coordss     r   SetImageCoordsz"SwipeBufferedWindow.SetImageCoordsj   s-    		ay&)%	

 $r    c                 r    t        j                  dd       | j                  st        t        |   |       yy)z1Calls superclass's OnSize method only when neededr/   zSwipeBufferedWindow.OnSize()N)r   r   r   r   r	   OnSize)r   rC   r   s     r   rS   zSwipeBufferedWindow.OnSizes   s.    		!34%t3E: r    Nimage)r   r   r   r   c           	          t        j                  dd       |dk(  r| j                         }t        t        |   |||||||      S )z.Draws image (map) with translated coordinates.r   zSwipeBufferedWindow.Draw()rT   )r   r   r2   r   r	   Draw)	r   pdcimgdrawidpdctyperP   penbrushr   s	           r   rV   zSwipeBufferedWindow.Drawy   sN     			!12g((*F($4fgvsE
 	
r    c                    | j                   d   dk(  r|j                         dd \  }}| j                         \  }}||z   ||z   f| _        d| _        | j
                  j                  | j                  d   | j                  d   | j                        }d|v r|j                  d       |r|d   | _        yyt        t        | /  |       y)zeLeft mouse button pressed.

        In case of 'pointer' mode, coordinates must be adjusted.
        usepointerNr   r0   r   )mouseGetPositionTupler2   lastposdragidrW   FindObjects	hitradiusremover   r	   
OnLeftDown)r   rC   evXevYimXimYidlistr   s          r   rg   zSwipeBufferedWindow.OnLeftDown   s    
 ::e	)--/2HC**,HC9cCi/DLDKXX))Qa$..F V|b!$Qi  %t7>r    c                     | j                   d   dk(  rW| j                  K|j                         \  }}| j                         \  }}| j	                  | j                  ||z   ||z   f       yt
        t        |   |       y)zZMouse dragging - overlay (text) is moving.

        Coordinates must be adjusted.
        r^   r_   N)r`   rc   ra   r2   DragItemr   r	   
OnDragging)r   rC   rh   ri   rj   rk   r   s         r   ro   zSwipeBufferedWindow.OnDragging   sr    
 ::e	)dkk.E--/HC**,HCMM$++c	39'=>%t7>r    c                     t        j                  dd|d|       | j                  j                  | j                  ||       | j                          y)zTranslate image and redraw.r/   z+SwipeBufferedWindow.TranslateImage(): dx = z, dy = N)r   r   rW   TranslateIdr   Refresh)r   dxdys      r   TranslateImagez"SwipeBufferedWindow.TranslateImage   s=    		2rR	
 	T\\2r2r    c           	          t               ddg| j                         t        j                  t        j                  d|dd| j
                  |<   y)zSets text label with map name.
   r   T)bboxrP   fontcolor
backgroundrotationtextactiveN)r   GetFontr#   BLACK
LIGHT_GREYtextdict)r   nametextIds      r   SetRasterNameTextz%SwipeBufferedWindow.SetRasterNameText   s@     F2hLLNXX--	!
fr    c                 *   t        j                  dd       | j                         \  }}| j                  d   d   |z   | j                  d   d   |z   f}| j                  d   d   |z   | j                  d   d   |z   f}t        t
        |   |||       y)z|Overridden method to recompute coordinates back to original values
        so that e.g. drawing of zoom box is done properlyr/   zSwipeBufferedWindow.MouseDraw()beginr   r0   endN)r   r   r2   r`   r   r	   	MouseDraw)r   rW   r   r   offsetXoffsetYr   s         r   r   zSwipeBufferedWindow.MouseDraw   s     			!67..0G$Q''14::g3Fq3IG3STzz% #g-tzz%/@/Cg/MN!423sCr    c           
      <   | j                   j                  | j                         t        j                  ddd      }t        j                  ddddg      }t        j                  ddd      }t        j                  ddd      }|d	k(  rI| j                  | j                   ||t        j                  t        j                  | |      
      | _        y|dk(  rq| j                  | j                   |d	   |dz  z
  |d   |dz  z
  f|d	   |dz  z   |d   |dz  z   ft        j                  t        j                  | |            | _        y|dk(  rL| j                  | j                   ||dz  t        j                  t        j                  | |            | _        yy)zDraw moving cross.mapswipecursorrz   )groupkeysubkeytype	selectionrI   widthr   )rW   rP   rI   r[   r0   r   )rW   point1point2r[   )rW   rP   radiusr[   N)pdcTmpClearIdr   r   Get	DrawCrossr#   PenColourDrawRectangle
DrawCircle)r   rP   rz   cursTyperI   r   s         r   DrawMouseCursorz#SwipeBufferedWindow.DrawMouseCursor   s   DKK(  zxP##(FK3H
 jhvN  zxPq=..KKFF299e,e4	 ) DK ],,KKq	D1H,fQi$(.BCq	D1H,fQi$(.BCFF299e,e4	 - DK ]//KKaxFF299e,e4	 * DK r    )NNN)__name__
__module____qualname____doc__r   r-   r>   r%   r'   r   rJ   rM   r2   rQ   rS   rV   rg   ro   ru   r   r   r   __classcell__)r   s   @r   r	   r	   "   sx    ;
:4D 
$; 
(?*
?
Dr    r	   c                   6    e Zd ZdZd	dZd Zd Zd Zd Zd Z	y)
r3   a  
    This event class takes a regular wxWindows mouse event as a parameter,
    and wraps it so that there is access to all the original methods. This
    is similar to subclassing, but you can't subclass a wxWindows event.

    The goal is to be able to it just like a regular mouse event.

    Difference is that it is a CommandEvent, which propagates up the
    window hierarchy until it is handled.
    Nc                     t        j                  dd       t        j                  j	                  |        || j
                  d<   || j
                  d<   | j                  |       y )Nr/   z_MouseEvent:__init__()_NativeEventchanged)r   r   r#   PyCommandEventr   __dict__SetEventType)r   r9   NativeEventWinIDr   s        r   r   z_MouseEvent.__init__   sO    		!-.
""4((3n%#*i )$r    c                 :    t        j                  | j                   S r@   )r#   Pointr   r,   s    r   r1   z_MouseEvent.GetPosition  s    xx&&r    c                     | j                   S r@   r   r,   s    r   ra   z_MouseEvent.GetPositionTuple  s    ||r    c                      | j                   d   S )Nr   r   r,   s    r   GetXz_MouseEvent.GetX      ||Ar    c                      | j                   d   S )Nr0   r   r,   s    r   GetYz_MouseEvent.GetY  r   r    c                 .    t        | j                  |      S r@   )getattrr   )r   r   s     r   __getattr__z_MouseEvent.__getattr__  s    t(($//r    r@   )
r   r   r   r   r   r1   ra   r   r   r    r    r   r3   r3      s%    	%'0r    r3   )r   r#   
core.debugr   core.settingsr   mapwin.bufferedr   gui_core.wrapr   r   NewEventTyperA   rE   PyEventBinderr$   r&   r	   r   r3   r   r    r   <module>r      s   & 
  & - % &boo' !#2##$78 Rm,
I+ IX"0"## "0r    