
    tj'                     ~    d Z ddlZddlZddlZddlmZ ddlZ G d dej                        Zd Z	e
dk(  r e	        yy)aj  
Description:

  Provides a pyGtk vtkRenderWindowInteractor widget.  This embeds a
  vtkRenderWindow inside a GTK widget and uses the
  vtkGenericRenderWindowInteractor for the event handling.  This is
  based on vtkTkRenderWindow.py.

  The class uses the gtkgl.GtkGLArea widget (gtkglarea).  This avoids
  a lot of problems with flicker.

  There is a working example at the bottom.

Created by Prabhu Ramachandran, April 2002.

Bugs:

  (*) There is a focus related problem.  Tkinter has a focus object
  that handles focus events.  I don't know of an equivalent object
  under GTK.  So, when an 'enter_notify_event' is received on the
  GtkVTKRenderWindow I grab the focus but I don't know what to do when
  I get a 'leave_notify_event'.

  (*) Will not work under Win32 because it uses the XID of a window in
  OnRealize.  Suggestions to fix this will be appreciated.

    N) vtkGenericRenderWindowInteractorc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd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y)GtkVTKRenderWindowInteractora   Embeds a vtkRenderWindow into a pyGTK widget and uses
    vtkGenericRenderWindowInteractor for the event handling.  This
    class embeds the RenderWindow correctly.  A __getattr__ hook is
    provided that makes the class behave like a
    vtkGenericRenderWindowInteractor.c                    t        |      }t        j                  t        j                  f}|j	                  d|        |j	                  d|       t        t        j                  j                  |       t               | _	        d| _
        d| _        t               | _        | j                  j                  | j                         | j                  j                  d| j                          | j                  j                  d| j"                         | j%                          | j'                  t(        j*                         | j-                  dd       y )Nr      CreateTimerEventDestroyTimerEventi,  )listgtkglRGBADOUBLEBUFFERinsertapply	GtkGLArea__init__vtkRenderWindow_RenderWindow&_GtkVTKRenderWindowInteractor__Created_ActiveButtonr   _IrenSetRenderWindowAddObserverCreateTimerDestroyTimerConnectSignals	set_flagsgtk	CAN_FOCUS	set_usize)selfargslattrs       X/DATA/.local/lib/python3.12/site-packages/vtkmodules/gtk/GtkVTKRenderWindowInteractor.pyr   z%GtkVTKRenderWindowInteractor.__init__*   s    J

E../	D	Deoo&&*,. 57


""4#5#56

143C3CD

2D4E4EF 	s}}%sC     c                     t         j                  j                  | ||       | j                  j	                  ||       | j
                  j	                  ||       | j
                  j                          y N)r   r   r   r   SetSizer   ConfigureEvent)r    whs      r$   r   z&GtkVTKRenderWindowInteractor.set_usizeB   sR    !!$1-""1a(

1a 

!!#r%   c                 `   | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j
                         | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d	| j                         | j                  d
| j                         | j                  t        j                  t        j                  z  t        j                  z  t        j                   z  t        j"                  z  t        j$                  z  t        j&                  z  t        j(                  z         y )Nrealizeexpose_eventconfigure_eventbutton_press_eventbutton_release_eventmotion_notify_evententer_notify_eventleave_notify_eventkey_press_eventdelete_event)connect	OnRealizeOnExposeOnConfigureOnButtonDown
OnButtonUpOnMouseMoveOnEnterOnLeave
OnKeyPress	OnDestroy
add_eventsGDKEXPOSURE_MASKBUTTON_PRESS_MASKBUTTON_RELEASE_MASKKEY_PRESS_MASKPOINTER_MOTION_MASKPOINTER_MOTION_HINT_MASKENTER_NOTIFY_MASKLEAVE_NOTIFY_MASKr    s    r$   r   z+GtkVTKRenderWindowInteractor.ConnectSignalsH   s@   Y/^T]]3&(8(89)4+<+<=+T__=*D,<,<=)4<<8)4<<8&8^T^^4))3+@+@@//0**+ //0 44	5
 --.
 140E0EF 	Gr%   c                     |dk(  r| j                   fdS t        | j                   |      rt        | j                   |      S t        | j                  j
                  dz   |z         )zGMakes the object behave like a
        vtkGenericRenderWindowInteractor__vtk__c                     | S r'    )ts    r$   <lambda>z:GtkVTKRenderWindowInteractor.__getattr__.<locals>.<lambda>^   s    r%   z has no attribute named )r   hasattrgetattrAttributeError	__class____name__)r    r#   s     r$   __getattr__z(GtkVTKRenderWindowInteractor.__getattr__Z   sa     9 JJ))TZZ&4::t,, !8!8,"-/3"4 5 5r%   c                 X    t        j                  d| j                  j                         y )N
   )r   timeout_addr   
TimerEventr    objevents      r$   r   z(GtkVTKRenderWindowInteractor.CreateTimere   s    DJJ112r%   c                      y)z;The timer is a one shot timer so will expire automatically.r   rP   r]   s      r$   r   z)GtkVTKRenderWindowInteractor.DestroyTimerh   s    r%   c                     | j                   S r'   )r   rL   s    r$   GetRenderWindowz,GtkVTKRenderWindowInteractor.GetRenderWindowl   s    !!!r%   c                 R    | j                   r| j                  j                          y y r'   )r   r   RenderrL   s    r$   rd   z#GtkVTKRenderWindowInteractor.Rendero   s     >>%%' r%   c                    | j                   dk(  ro| j                          t        | j                         j                        }| j
                  j                  |       | j                  j                          d| _         t        j                  S Nr   r   )r   r-   str
get_windowxidr   SetWindowInfor   
Initializer   TRUE)r    r!   win_ids      r$   r8   z&GtkVTKRenderWindowInteractor.OnRealizes   sb    >>QLLN*../F,,V4JJ!!#DNxxr%   Nc                 2   | j                   j                         }|j                  |d   k7  s|j                  |d   k7  rJ| j                  j                  |j                  |j                         | j                  j                          t        j                  S rf   )	r   GetSizewidthheightr   r(   r)   r   rl   )r    widr_   szs       r$   r:   z(GtkVTKRenderWindowInteractor.OnConfigure}   sj    '')KK2a5 ellbe&;JJu{{ELL9JJ%%'xxr%   c                 B    | j                          t        j                  S r'   )rd   r   rl   )r    r!   s     r$   r9   z%GtkVTKRenderWindowInteractor.OnExpose   s    xxr%   c                 f    | j                          | `| j                          t        j                  S r'   )hider   destroyr   rl   )r    r_   s     r$   rA   z&GtkVTKRenderWindowInteractor.OnDestroy   s#    		xxr%   c                     d\  }}|j                   t        j                  z  t        j                  k(  rd}|j                   t        j                  z  t        j                  k(  rd}||fS )N)r   r   r   )staterC   CONTROL_MASK
SHIFT_MASK)r    r_   ctrlshifts       r$   _GetCtrlShiftz*GtkVTKRenderWindowInteractor._GetCtrlShift   sU    e[[3+++0@0@@D[[3>>)cnn<EU{r%   c           	         | j                         }| j                  |      \  }}| j                  j                  |d   |d   ||t	        d      dd       |j
                  }|dk(  r*| j                  j                          t        j                  S |dk(  r*| j                  j                          t        j                  S |dk(  r*| j                  j                          t        j                  S t        j                  S )zMouse button pressed.r   r   N      )get_pointerr~   r   SetEventInformationFlipYchrbuttonRightButtonPressEventr   rl   LeftButtonPressEventMiddleButtonPressEventFALSEr    rr   r_   mr|   r}   r   s          r$   r;   z)GtkVTKRenderWindowInteractor.OnButtonDown   s    ((/e

++AaD!A$e,/FAt	=Q;JJ,,.88Oq[JJ++-88Oq[JJ--/88O99r%   c           	         | j                         }| j                  |      \  }}| j                  j                  |d   |d   ||t	        d      dd       |j
                  }|dk(  r*| j                  j                          t        j                  S |dk(  r*| j                  j                          t        j                  S |dk(  r*| j                  j                          t        j                  S t        j                  S )zMouse button released.r   r   Nr   r   )r   r~   r   r   r   r   RightButtonReleaseEventr   rl   LeftButtonReleaseEventMiddleButtonReleaseEventr   r   s          r$   r<   z'GtkVTKRenderWindowInteractor.OnButtonUp   s    ((/e

++AaD!A$e,/FAt	=Q;JJ..088Oq[JJ--/88Oq[JJ//188Oyyr%   c           	          | j                         }| j                  |      \  }}| j                  j                  |d   |d   ||t	        d      dd       | j                  j                          t        j                  S )zMouse has moved.r   r   N)r   r~   r   r   r   MouseMoveEventr   rl   r    rr   r_   r   r|   r}   s         r$   r=   z(GtkVTKRenderWindowInteractor.OnMouseMove   sj    ((/e

++AaD!A$e,/FAt	=

!!#xxr%   c           	         | j                          | j                         }| j                  |      \  }}| j                  j	                  |d   |d   ||t        d      dd       | j                  j                          t        j                  S )zEntering the vtkRenderWindow.r   r   N)	
grab_focusr   r~   r   r   r   
EnterEventr   rl   r   s         r$   r>   z$GtkVTKRenderWindowInteractor.OnEnter   st    ((/e

++AaD!A$e,/FAt	=

xxr%   c           	          | j                         }| j                  |      \  }}| j                  j                  |d   |d   ||t	        d      dd       | j                  j                          t        j                  S )zLeaving the vtkRenderWindow.r   r   N)r   r~   r   r   r   
LeaveEventr   rl   r   s         r$   r?   z$GtkVTKRenderWindowInteractor.OnLeave   sj    ((/e

++AaD!A$e,/FAt	=

xxr%   c           	         | j                         }| j                  |      \  }}|j                  |j                  }}t	        d      }|dk  rt	        |      }| j
                  j                  |d   |d   |||d|       | j
                  j                          | j
                  j                          t        j                  S )zKey pressed.r      r   )r   r~   keyvalstringr   r   r   KeyPressEvent	CharEventr   rl   	r    rr   r_   r   r|   r}   keycodekeysymkeys	            r$   r@   z'GtkVTKRenderWindowInteractor.OnKeyPress   s    ((/e,,!fS=g,C

++AaD!A$e,/F	<

  "

xxr%   c           	      R   | j                         }| j                  |      \  }}|j                  |j                  }}t	        d      }|dk  rt	        |      }| j
                  j                  |d   |d   |||d|       | j
                  j                          t        j                  S )zKey released.r   r   r   )
r   r~   r   r   r   r   r   KeyReleaseEventr   rl   r   s	            r$   OnKeyReleasez)GtkVTKRenderWindowInteractor.OnKeyRelease   s    ((/e,,!fS=g,C

++AaD!A$e,/F	<

""$xxr%   c                 R    | j                   r| j                  j                          y y r'   )r   r   rk   rL   s    r$   rk   z'GtkVTKRenderWindowInteractor.Initialize   s    >>JJ!!# r%   r'   )rW   
__module____qualname____doc__r   r   r   rX   r   r   rb   rd   r8   r:   r9   rA   r~   r;   r<   r=   r>   r?   r@   r   rk   rP   r%   r$   r   r   "   sq    )!0$G$	53"(&&$r%   r   c                     ddl m}  ddlm}m}m} dd l}dd l}t        j                  t        j                        }|j                  d       |j                  dt        j                         |j                  dt        j                         |j                  d       t        j                  d	      }|j!                  |       |j#                          t%               }|j'                  d
d
       |j)                  |       |j#                          |j+                          |j-                          |j/                  ddd        |        }|j1                  d        |       }	|	j3                  |j5                                 |       }
|
j7                  |	       |
j9                         j;                  ddd        |       }|j=                         j?                  |       |jA                  |
       t        jB                  d      }|j                  dt        j                         |j)                  |       |j#                          |j#                          t        jD                          y )Nr   )vtkConeSource)vtkActorvtkPolyDataMappervtkRendererzA GtkVTKRenderWindow Demo!rw   r6   rZ   r   )spacingi  	ExitEventc                     |S r'   rP   )oexs      r$   rR   zmain.<locals>.<lambda>  s    Qr%   P   g      ?g      ?zQuit!clickedr'   )#vtkmodules.vtkFiltersSourcesr   vtkmodules.vtkRenderingCorer   r   r   vtkmodules.vtkRenderingOpenGL2vtkmodules.vtkInteractionStyler   	GtkWindowWINDOW_TOPLEVEL	set_titler7   mainquitset_border_widthGtkVBoxaddshowr   r   
pack_startrk   Startr   SetResolutionSetInputConnectionGetOutputPort	SetMapperGetPropertySetColorrb   AddRendererAddActor	GtkButtonmainloop)r   r   r   r   
vtkmoduleswindowvboxgvtkcone
coneMapper	coneActorrenquits                r$   mainr      s   :TT)) ]]3../F
12
NN9cll+
NN>3<<0
B ;;q!D
JJtIIK ()DNN3OODIIKOOJJL["67 ?Dr"$J!!$"4"4"67
I
#$$S#s3
-C&&s+LL ==!DLLCLL)OODIIK KKMLLNr%   __main__)r   r   rC   r   vtkmodules.vtkRenderingUIr   mathr   r   r   rW   rP   r%   r$   <module>r      sE   8   F S$5?? S$l3l zF r%   