Class: Vtk::TkRenderWindowInteractor
- Inherits:
-
TkWindow
- Object
- TkWindow
- Vtk::TkRenderWindowInteractor
- Defined in:
- lib/VTK/tk/vtkTkRenderWindowInteractor.rb
Constant Summary collapse
- TkCommandNames =
A vtkTkRenderWidndowInteractor for Python.
Use GetRenderWindow to get the vtkRenderWindow. Create with the keyword stereo=1 in order to generate a stereo-capable window. Create with the keyword focus_on_enter=1 to enable focus-follows-mouse. The default is for a click-to-focus mode. __getattr__ is used to make the widget also behave like a vtkGenericRenderWindowInteractor.
['vtkTkRenderWidget'.freeze].freeze
Instance Method Summary collapse
- #_GrabFocus(enter = 0) ⇒ Object
- #BindEvents ⇒ Object
- #ConfigureEvent(event) ⇒ Object
- #EnterEvent(event, ctrl, shift) ⇒ Object
- #ExposeEvent ⇒ Object
- #GetRenderWindow ⇒ Object
-
#initialize(master, kw = {}) ⇒ TkRenderWindowInteractor
constructor
A new instance of TkRenderWindowInteractor.
- #KeyPressEvent(event, ctrl, shift) ⇒ Object
- #KeyReleaseEvent(event, ctrl, shift) ⇒ Object
- #LeaveEvent(event, ctrl, shift) ⇒ Object
- #LeftButtonPressEvent(event, ctrl, shift) ⇒ Object
- #LeftButtonReleaseEvent(event, ctrl, shift) ⇒ Object
- #MiddleButtonPressEvent(event, ctrl, shift) ⇒ Object
- #MiddleButtonReleaseEvent(event, ctrl, shift) ⇒ Object
- #MouseMoveEvent(event, ctrl, shift) ⇒ Object
- #MouseWheelBackwardEvent(event, ctrl, shift) ⇒ Object
- #MouseWheelEvent(event, ctrl, shift) ⇒ Object
- #MouseWheelForwardEvent(event, ctrl, shift) ⇒ Object
- #Render ⇒ Object
- #RightButtonPressEvent(event, ctrl, shift) ⇒ Object
- #RightButtonReleaseEvent(event, ctrl, shift) ⇒ Object
Constructor Details
#initialize(master, kw = {}) ⇒ TkRenderWindowInteractor
Returns a new instance of TkRenderWindowInteractor.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 31 def initialize(master, kw={} ) =begin Constructor. Keyword arguments: rw -- Use passed render window instead of creating a new one. stereo -- If True, generate a stereo-capable window. Defaults to False. focus_on_enter -- If True, use a focus-follows-mouse mode. Defaults to False where the widget will use a click-to-focus mode. =end # load the necessary extensions into tk Vtk.LoadRubyTkWidgets _symbolkey2str(kw) if kw['rw'] renderWindow = kw['rw'] else renderWindow = Vtk::RenderWindow.new end if kw['stereo'] renderWindow.StereoCapableWindowOn kw.delete('stereo') end # check if focus should follow mouse if kw['focus_on_enter'] @FocusOnEnter = true kw.delte('focus_on_enter') else @FocusOnEnter = false end kw['rw'] = renderWindow.GetAddressAsString("vtkRenderWindow") kw['widgetname'] = 'vtkTkRenderWindowInteractor' # kw['widgetname'] = 'vtkTkRenderWidget' super( master, kw ) renderWindow.UnRegister(nil) @Iren = Vtk::GenericRenderWindowInteractor.new @Iren.SetRenderWindow(renderWindow) @Iren.UnRegister(nil) createTimer = Proc.new{|obj, evt| self.after(10, Proc.new{ @Iren.TimerEvent }) } destroyTimer = Proc.new{|obj, event| =begin The timer is a one shot timer so will expire automatically. =end return 1 } @Iren.AddObserver('CreateTimerEvent', createTimer) @Iren.AddObserver('DestroyTimerEvent', destroyTimer) @OldFocus = nil # private attributes @InExpose = false # create the Tk bindings self.BindEvents #self.tk_focusFollowsMouse end |
Instance Method Details
#_GrabFocus(enter = 0) ⇒ Object
188 189 190 191 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 188 def _GrabFocus(enter=0) @OldFocus=self.focus self.focus end |
#BindEvents ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 106 def BindEvents =begin Bind all the events. =end self.bind("Motion"){|e,s| s||s=self; s.MouseMoveEvent(e, 0, 0) } self.bind("Control-Motion"){|e,s| s||s=self; s.MouseMoveEvent(e, 1, 0) } self.bind("Shift-Motion"){|e,s| s||s=self; s.MouseMoveEvent(e, 1, 1) } self.bind("Control-Shift-Motion"){|e,s| s||s=self; s.MouseMoveEvent(e, 0, 1) } # Left Button self.bind("ButtonPress-1"){|e,s| s||s=self; s.LeftButtonPressEvent(e, 0, 0) } self.bind("Control-ButtonPress-1"){|e,s| s||s=self; s.LeftButtonPressEvent(e, 1, 0) } self.bind("Shift-ButtonPress-1"){|e,s| s||s=self; s.LeftButtonPressEvent(e, 0, 1) } self.bind("Control-Shift-ButtonPress-1"){|e,s| s||s=self; s.LeftButtonPressEvent(e, 1, 1) } self.bind("ButtonRelease-1"){|e,s| s||s=self; s.LeftButtonReleaseEvent(e, 0, 0) } self.bind("Control-ButtonRelease-1"){|e,s| s||s=self; s.LeftButtonReleaseEvent(e, 1, 0) } self.bind("Shift-ButtonRelease-1"){|e,s| s||s=self; s.LeftButtonReleaseEvent(e, 0, 1) } self.bind("Control-Shift-ButtonRelease-1"){|e,s| s||s=self; s.LeftButtonReleaseEvent(e, 1, 1) } # Middle Button self.bind("ButtonPress-2"){|e,s| s||s=self; s.MiddleButtonPressEvent(e, 0, 0) } self.bind("Control-ButtonPress-2"){|e,s| s||s=self; s.MiddleButtonPressEvent(e, 1, 0) } self.bind("Shift-ButtonPress-2"){|e,s| s||s=self; s.MiddleButtonPressEvent(e, 0, 1) } self.bind("Control-Shift-ButtonPress-2"){|e,s| s||s=self; s.MiddleButtonPressEvent(e, 1, 1) } self.bind("ButtonRelease-2"){|e,s| s||s=self; s.MiddleButtonReleaseEvent(e, 0, 0) } self.bind("Control-ButtonRelease-2"){|e,s| s||s=self; s.MiddleButtonReleaseEvent(e, 1, 0) } self.bind("Shift-ButtonRelease-2"){|e,s| s||s=self; s.MiddleButtonReleaseEvent(e, 0, 1) } self.bind("Control-Shift-ButtonRelease-2"){|e,s| s||s=self; s.MiddleButtonReleaseEvent(e, 1, 1) } # Right Button self.bind("ButtonPress-3"){|e,s| s||s=self; s.RightButtonPressEvent(e, 0, 0) } self.bind("Control-ButtonPress-3"){|e,s| s||s=self; s.RightButtonPressEvent(e, 1, 0) } self.bind("Shift-ButtonPress-3"){|e,s| s||s=self; s.RightButtonPressEvent(e, 0, 1) } self.bind("Control-Shift-ButtonPress-3"){|e,s| s||s=self; s.RightButtonPressEvent(e, 1, 1) } self.bind("ButtonRelease-3"){|e,s| s||s=self; s.RightButtonReleaseEvent(e, 0, 0) } self.bind("Control-ButtonRelease-3"){|e,s| s||s=self; s.RightButtonReleaseEvent(e, 1, 0) } self.bind("Shift-ButtonRelease-3"){|e,s| s||s=self; s.RightButtonReleaseEvent(e, 0, 1) } self.bind("Control-Shift-ButtonRelease-3"){|e,s| s||s=self; s.RightButtonReleaseEvent(e, 1, 1) } if Config::CONFIG['arch'] =~ /win32/ self.bind("MouseWheel"){|e,s| s||s=self; s.MouseWheelEvent(e, 0, 0) } self.bind("Control-MouseWheel"){|e,s| s||s=self; s.MouseWheelEvent(e, 1, 0) } self.bind("Shift-MouseWheel"){|e,s| s||s=self; s.MouseWheelEvent(e, 0, 1) } self.bind("Control-Shift-MouseWheel"){|e,s| s||s=self; s.MouseWheelEvent(e, 1, 1) } else # Mouse wheel forward event self.bind("ButtonPress-4"){|e,s| s||s=self; s.MouseWheelForwardEvent(e, 0, 0) } self.bind("Control-ButtonPress-4"){|e,s| s||s=self; s.MouseWheelForwardEvent(e, 1, 0) } self.bind("Shift-ButtonPress-4"){|e,s| s||s=self; s.MouseWheelForwardEvent(e, 0, 1) } self.bind("Control-Shift-ButtonPress-4"){|e,s| s||s=self; s.MouseWheelForwardEvent(e, 1, 1) } # Mouse wheel backward event self.bind("ButtonPress-5"){|e,s| s||s=self; s.MouseWheelBackwardEvent(e, 0, 0) } self.bind("Control-ButtonPress-5"){|e,s| s||s=self; s.MouseWheelBackwardEvent(e, 1, 0) } self.bind("Shift-ButtonPress-5"){|e,s| s||s=self; s.MouseWheelBackwardEvent(e, 0, 1) } self.bind("Control-Shift-ButtonPress-5"){|e,s| s||s=self; s.MouseWheelBackwardEvent(e, 1, 1) } end # Key related events self.bind("KeyPress"){|e,s| s||s=self; s.KeyPressEvent(e, 0, 0) } self.bind("Control-KeyPress"){|e,s| s||s=self; s.KeyPressEvent(e, 1, 0) } self.bind("Shift-KeyPress"){|e,s| s||s=self; s.KeyPressEvent(e, 0, 1) } self.bind("Control-Shift-KeyPress"){|e,s| s||s=self; s.KeyPressEvent(e, 1, 1) } self.bind("KeyRelease"){|e,s| s||s=self; s.KeyReleaseEvent(e, 0, 0) } self.bind("Control-KeyRelease"){|e,s| s||s=self; s.KeyReleaseEvent(e, 1, 0) } self.bind("Shift-KeyRelease"){|e,s| s||s=self; s.KeyReleaseEvent(e, 0, 1) } self.bind("Control-Shift-KeyRelease"){|e,s| s||s=self; s.KeyReleaseEvent(e, 1, 1) } self.bind("Enter"){|e,s| s||s=self; s.EnterEvent(e, 0, 0) } self.bind("Control-Enter"){|e,s| s||s=self; s.EnterEvent(e, 1, 0) } self.bind("Shift-Enter"){|e,s| s||s=self; s.EnterEvent(e, 0, 1) } self.bind("Control-Shift-Enter"){|e,s| s||s=self; s.EnterEvent(e, 1, 1) } self.bind("Leave"){|e,s| s||s=self; s.LeaveEvent(e, 0, 0) } self.bind("Control-Leave"){|e,s| s||s=self; s.LeaveEvent(e, 1, 0) } self.bind("Shift-Leave"){|e,s| s||s=self; s.LeaveEvent(e, 0, 1) } self.bind("Control-Shift-Leave"){|e,s| s||s=self; s.LeaveEvent(e, 1, 1) } self.bind("Configure"){|e,s| s||s=self; s.ConfigureEvent(e) } self.bind("Expose"){|e,s| s||s=self; s.ExposeEvent } end |
#ConfigureEvent(event) ⇒ Object
287 288 289 290 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 287 def ConfigureEvent(event) @Iren.SetSize(event.width, event.height) @Iren.ConfigureEvent end |
#EnterEvent(event, ctrl, shift) ⇒ Object
292 293 294 295 296 297 298 299 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 292 def EnterEvent(event, ctrl, shift) if @FocusOnEnter _GrabFocus end @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.EnterEvent end |
#ExposeEvent ⇒ Object
310 311 312 313 314 315 316 317 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 310 def ExposeEvent if !@InExpose @InExpose = true self.update self.GetRenderWindow.Render @InExpose = false end end |
#GetRenderWindow ⇒ Object
319 320 321 322 323 324 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 319 def GetRenderWindow addr = Tk.tk_call(self, 'GetRenderWindow')[5..-1] renderWindow = Vtk::RenderWindow.new('_%s_vtkRenderWindow_p' % addr) renderWindow.UnRegister(nil) return renderWindow end |
#KeyPressEvent(event, ctrl, shift) ⇒ Object
266 267 268 269 270 271 272 273 274 275 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 266 def KeyPressEvent(event, ctrl, shift) key = 0.chr if event.keysym_num < 256 key = event.keysym_num.chr end @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, key, 0, event.keysym) @Iren.KeyPressEvent @Iren.CharEvent end |
#KeyReleaseEvent(event, ctrl, shift) ⇒ Object
277 278 279 280 281 282 283 284 285 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 277 def KeyReleaseEvent(event, ctrl, shift) key = 0.chr if event.keysym_num < 256 key = event.keysym_num.chr end @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, key, 0, event.keysym) @Iren.KeyReleaseEvent end |
#LeaveEvent(event, ctrl, shift) ⇒ Object
301 302 303 304 305 306 307 308 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 301 def LeaveEvent(event, ctrl, shift) if @FocusOnEnter && (@OldFocus != nil) @OldFocus.focus end @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.LeaveEvent end |
#LeftButtonPressEvent(event, ctrl, shift) ⇒ Object
199 200 201 202 203 204 205 206 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 199 def LeftButtonPressEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.LeftButtonPressEvent if !@FocusOnEnter _GrabFocus end end |
#LeftButtonReleaseEvent(event, ctrl, shift) ⇒ Object
208 209 210 211 212 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 208 def LeftButtonReleaseEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.LeftButtonReleaseEvent end |
#MiddleButtonPressEvent(event, ctrl, shift) ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 214 def MiddleButtonPressEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.MiddleButtonPressEvent if !@FocusOnEnter _GrabFocus end end |
#MiddleButtonReleaseEvent(event, ctrl, shift) ⇒ Object
223 224 225 226 227 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 223 def MiddleButtonReleaseEvent( event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.MiddleButtonReleaseEvent end |
#MouseMoveEvent(event, ctrl, shift) ⇒ Object
193 194 195 196 197 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 193 def MouseMoveEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.MouseMoveEvent end |
#MouseWheelBackwardEvent(event, ctrl, shift) ⇒ Object
260 261 262 263 264 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 260 def MouseWheelBackwardEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.MouseWheelBackwardEvent end |
#MouseWheelEvent(event, ctrl, shift) ⇒ Object
244 245 246 247 248 249 250 251 252 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 244 def MouseWheelEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) if event.delta > 0 @Iren.MouseWheelForwardEvent else @Iren.MouseWheelBackwardEvent end end |
#MouseWheelForwardEvent(event, ctrl, shift) ⇒ Object
254 255 256 257 258 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 254 def MouseWheelForwardEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.MouseWheelForwardEvent end |
#Render ⇒ Object
326 327 328 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 326 def Render self.GetRenderWindow.Render end |
#RightButtonPressEvent(event, ctrl, shift) ⇒ Object
229 230 231 232 233 234 235 236 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 229 def RightButtonPressEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.RightButtonPressEvent if !@FocusOnEnter _GrabFocus end end |
#RightButtonReleaseEvent(event, ctrl, shift) ⇒ Object
238 239 240 241 242 |
# File 'lib/VTK/tk/vtkTkRenderWindowInteractor.rb', line 238 def RightButtonReleaseEvent(event, ctrl, shift) @Iren.SetEventInformationFlipY(event.x, event.y, ctrl, shift, 0.chr, 0, nil) @Iren.RightButtonReleaseEvent end |