
    tj	(                         d Z ddlZddlZ ej                  d       ddlZddlmZ ddlZddlmZ ddl	m
Z
  G d dej                  j                        Zd	 Zed
k(  r e        yy)at  
Description:

  Provides a pyGtk vtkRenderWindowInteractor widget.  This embeds a
  vtkRenderWindow inside a GTK widget and uses the
  vtkGenericRenderWindowInteractor for the event handling.  This is
  similar to GtkVTKRenderWindowInteractor.py.

  The extensions here allow the use of gtkglext rather than gtkgl and
  pygtk-2 rather than pygtk-0.  It requires pygtk-2.0.0 or later.

  There is a working example at the bottom.

Credits:

  John Hunter <jdhunter@ace.bsd.uchicago.edu> developed and tested
  this code based on VTK's GtkVTKRenderWindow.py and extended it to
  work with pygtk-2.0.0.

License:

  VTK license.

    Nz2.0)gdk)vtkRenderWindow) 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 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y)!GtkGLExtVTKRenderWindowInteractora   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         j                  j                  j                  |        | j	                  t         j
                         t               | _        d| _        d| _	        t               | _        | j                  j                  | j                         | j                  j                         j                          | j                  j                  d| j                          | j                  j                  d| j"                         | j%                          | j'                  t         j(                         y )Nr   CreateTimerEventDestroyTimerEvent)gtkgtkglDrawingArea__init__set_double_bufferedFALSEr   _RenderWindow+_GtkGLExtVTKRenderWindowInteractor__Created_ActiveButtonr   _IrenSetRenderWindowGetInteractorStyle SetCurrentStyleToTrackballCameraAddObserverCreateTimerDestroyTimerConnectSignals	set_flags	CAN_FOCUSselfargss     ]/DATA/.local/lib/python3.12/site-packages/vtkmodules/gtk/GtkGLExtVTKRenderWindowInteractor.pyr   z*GtkGLExtVTKRenderWindowInteractor.__init__+   s    		&&t,  +,. 57


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

%%'HHJ

143C3CD

2D4E4EF 	s}}%    c                     t         j                  j                  j                  | ||       | j                  j                  ||       | j                  j                  ||       | j                  j                          y N)r   r   r   set_size_requestr   SetSizer   ConfigureEvent)r   whs      r!   r%   z2GtkGLExtVTKRenderWindowInteractor.set_size_request@   sX    		..tQ:""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_eventsr   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   z0GtkGLExtVTKRenderWindowInteractor.ConnectSignalsF   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?GtkGLExtVTKRenderWindowInteractor.__getattr__.<locals>.<lambda>\   s    r"   z has no attribute named )r   hasattrgetattrAttributeError	__class____name__)r   attrs     r!   __getattr__z-GtkGLExtVTKRenderWindowInteractor.__getattr__X   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-GtkGLExtVTKRenderWindowInteractor.CreateTimerc   s    DJJ112r"   c                      y)z;The timer is a one shot timer so will expire automatically.   rM   r[   s      r!   r   z.GtkGLExtVTKRenderWindowInteractor.DestroyTimerf   s    r"   c                     | j                   S r$   )r   rI   s    r!   GetRenderWindowz1GtkGLExtVTKRenderWindowInteractor.GetRenderWindowj   s    !!!r"   c                 R    | j                   r| j                  j                          y y r$   )r   r   RenderrI   s    r!   rc   z(GtkGLExtVTKRenderWindowInteractor.Renderm   s     >>%%' r"   c                 p   | j                   dk(  r| j                          t        j                  dk(  r*t	        | j
                  j                  j                        }n)t	        | j
                  j                  j                        }| j                  j                  |       d| _         t        j                  S )Nr   win32r_   )r   r+   sysplatformstrwidgetwindowhandlexidr   SetWindowInfor   TRUE)r   r    win_ids      r!   r6   z+GtkGLExtVTKRenderWindowInteractor.OnRealizeq   s{    >>QLLN||W$T[[//667T[[//334,,V4DNxxr"   c                     || _         | j                  j                  |j                  |j                         | j                  j                          | j                          t        j                  S r$   )	ri   r   r&   widthheightr'   rc   r   rn   )r   ri   r]   s      r!   r8   z-GtkGLExtVTKRenderWindowInteractor.OnConfigure   sG    

5;;5

!!#xxr"   c                 B    | j                          t        j                  S r$   )rc   r   rn   r   s     r!   r7   z*GtkGLExtVTKRenderWindowInteractor.OnExpose   s    xxr"   Nc                 f    | j                          | `| j                          t        j                  S r$   )hider   destroyr   rn   )r   r]   s     r!   r?   z+GtkGLExtVTKRenderWindowInteractor.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_   )stater   CONTROL_MASK
SHIFT_MASK)r   r]   ctrlshifts       r!   _GetCtrlShiftz/GtkGLExtVTKRenderWindowInteractor._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   rn   LeftButtonPressEventMiddleButtonPressEventr   r   widr]   mr{   r|   r   s          r!   r9   z.GtkGLExtVTKRenderWindowInteractor.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   rn   LeftButtonReleaseEventMiddleButtonReleaseEventr   r   s          r!   r:   z,GtkGLExtVTKRenderWindowInteractor.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   rn   r   r   r]   r   r{   r|   s         r!   r;   z-GtkGLExtVTKRenderWindowInteractor.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   rn   r   s         r!   r<   z)GtkGLExtVTKRenderWindowInteractor.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   rn   r   s         r!   r=   z)GtkGLExtVTKRenderWindowInteractor.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   rn   	r   r   r]   r   r{   r|   keycodekeysymkeys	            r!   r>   z,GtkGLExtVTKRenderWindowInteractor.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   rn   r   s	            r!   OnKeyReleasez.GtkGLExtVTKRenderWindowInteractor.OnKeyRelease   s    ((/e,,!fS=g,C

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

""$xxr"   c                 R    | j                   r| j                  j                          y y r$   )r   r   
InitializerI   s    r!   r   z,GtkGLExtVTKRenderWindowInteractor.Initialize   s    >>JJ!!# r"   c                 :    | j                   j                  |       y r$   )r   	SetPickerr   pickers     r!   r   z+GtkGLExtVTKRenderWindowInteractor.SetPicker   s    

V$r"   c                 6    | j                   j                         S r$   )r   	GetPickerr   s     r!   r   z+GtkGLExtVTKRenderWindowInteractor.GetPicker   s    zz##%%r"   r$   )rT   
__module____qualname____doc__r   r%   r   rV   r   r   ra   rc   r6   r8   r7   r?   r}   r9   r:   r;   r<   r=   r>   r   r   r   r   rM   r"   r!   r   r   #   s{    )&*$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!rv   r4   rX   r   )spacingi  	ExitEventc                     |S r$   rM   )oexs      r!   rO   zmain.<locals>.<lambda>  s    Qr"   P   g      ?g      ?zQuit!clickedr$   )#vtkmodules.vtkFiltersSourcesr   vtkmodules.vtkRenderingCorer   r   r   vtkmodules.vtkRenderingOpenGL2vtkmodules.vtkInteractionStyler   WindowWINDOW_TOPLEVEL	set_titler5   mainquitset_border_widthVBoxaddshowr   r%   
pack_startr   Startr   SetResolutionSetInputConnectionGetOutputPort	SetMapperGetPropertySetColorra   AddRendererAddActorButtonmainloop)r   r   r   r   
vtkmodulesrj   vboxgvtkcone
coneMapper	coneActorrenquits                r!   mainr      s   :TT)) ZZ++,F
12
NN9cll+
NN>3<<0
B 88AD
JJtIIK -.D#s#OODIIKOOJJL["67 ?Dr"$J!!$"4"4"67
I
#$$S#s3
-C&&s+LL ::gDLLCLL)OODIIK KKMLLNr"   __main__)r   rf   pygtkrequirer   r   	gtk.gtkglr   r   vtkmodules.vtkRenderingUIr   r   r   r   r   rT   rM   r"   r!   <module>r      sb   2   e  
   7 FZ&		(=(= Z&z3l zF r"   